Skip to content

Instantly share code, notes, and snippets.

@ZJONSSON
Last active December 15, 2015 19:59
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 ZJONSSON/5314920 to your computer and use it in GitHub Desktop.
Save ZJONSSON/5314920 to your computer and use it in GitHub Desktop.
Node-mysql Query.stream test
var stream = require("stream"),
mysql = require("/node-mysql");
var connection = mysql.createConnection({
host : 'localhost',
user : 'root'
});
var query = connection.query("select * from sakila.rental ")
.stream({highWaterMark:5});
// Simple writable stream that delays 1 sec before console.log and callback();
// Purpose: test whether the pipe pauses correctly while waiting for write to finish
var testStream = new stream.Writable({highWaterMark: 10, objectMode: true});
testStream._write = function(chunk,encoding,callback) {
setTimeout(function() {
console.log(chunk);
callback();
},500);
}
// Pipe the query stream into the testStream
query.pipe(testStream)
// Monitor data events on the side to see when we pause
query.on("result",function(d,i) {
console.log("Received data")
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment