Skip to content

Instantly share code, notes, and snippets.

@thinkjson
Forked from max-mapper/couch-transform.js
Created January 14, 2012 07:26
Show Gist options
  • Select an option

  • Save thinkjson/1610604 to your computer and use it in GitHub Desktop.

Select an option

Save thinkjson/1610604 to your computer and use it in GitHub Desktop.
streaming functional transformer for couchdb using node
var request = require('request').defaults({json: true}),
transfuse = require('transfuse'),
JSONStream = require('JSONStream');
function transform(couchdb, funcString, headers) {
var down = request({url: couchdb + '/_all_docs?include_docs=true'}),
up = request({url: couchdb + '/_bulk_docs', method: "POST", headers: headers}),
tr = transfuse(['rows', /./, 'doc'], funcString, JSONStream.stringify("{\"docs\":[\n", "\n,\n", "\n]}\n"));
down.pipe(tr)
tr.pipe(up)
}
// transform('http://localhost:5984/cats', 'function(doc, map) { doc.type = "cat"; map(doc) }')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment