-
-
Save victusfate/1608557 to your computer and use it in GitHub Desktop.
node.js script to process couchdb output
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/env node | |
| // Sample usage: | |
| // | |
| // $ curl -s 'http://127.0.0.1:15984/seeds/_all_docs?limit=10&include_docs=true' | coucheval.js 'console.log(JSON.stringify(row.doc));' | |
| // | |
| var carrier = require('carrier'); | |
| var stdin = process.openStdin(); | |
| stdin.setEncoding('utf8'); | |
| var couchparse = function(callback) { | |
| var firstline = true; | |
| carrier.carry(stdin, function(line) { | |
| // skip first line | |
| if (firstline) { | |
| firstline = false; | |
| return; | |
| } | |
| // skip last line | |
| if (line.substr(0, 2) == "]}") { | |
| return; | |
| } | |
| if (line[line.length-1] == ",") | |
| line = line.substr(0, line.length-1); | |
| callback(line); | |
| }); | |
| }; | |
| couchparse(function(line) { | |
| var row = JSON.parse(line); | |
| eval(process.argv[2]); | |
| }); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment