Skip to content

Instantly share code, notes, and snippets.

@brianc
Created January 28, 2015 17:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save brianc/d463f5d10ba3cad14320 to your computer and use it in GitHub Desktop.
Save brianc/d463f5d10ba3cad14320 to your computer and use it in GitHub Desktop.
var lineStream; <-- assume this is a readable stream of lines of text utf8 encoded
var through2 = require('through2')
var terminatingStream = through2(function(line, enc, cb) {
query('INSERT INTO line_table line VALUE ($)', [line], function(err, res) {
if (err) return cb(err);
return cb(null, line);
});
});
//pipe the output of terminatingStream to standard out
//so the data will start 'flowing' through the pipe
lineStream.pipe(terminatingStream).pipe(process.stdout);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment