-
Notifications
You must be signed in to change notification settings - Fork 2.5k
.query(...).stream().pipe(process.stdout) throws TypeError: invalid data #741
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
|
Exactly. Here is an example of a stringify transform: var stream = require('stream'),
util = require('util');
function StringifyStream(options) {
if (!(this instanceof StringifyStream))
return new StringifyStream(options);
options = options || {};
options.objectMode = true;
stream.Transform.call(this,options);
}
util.inherits(StringifyStream,stream.Transform);
StringifyStream.prototype._transform = function(d,e,callback) {
this.push(JSON.stringify(d));
callback();
}; which can be inserted into your pipeline like this: pool.getConnection(function (err, connection) {
connection.query('SELECT * FROM wp_users WHERE ID = ?', [req.params.id])
.stream({highWaterMark: 5})
.pipe(StringifyStream())
.pipe(process.stdout);
}); |
Thank you so much for the clarification and example. |
You can also use the at the command line in the root of your project, run:
then, in your file: var stringify = require('csv-stringify');
var stringifier = stringify();
pool.getConnection(function (err, connection) {
connection.query('SELECT * FROM wp_users WHERE ID = ?', [req.params.id])
.stream({highWaterMark: 5})
.pipe(stringifier).pipe(process.stdout);
}); notice the extra |
Excellent examples and documentation. I've tried this for piping to stdout and works ok. The only issue I'm having is that I wan't to pipe large datasets. For some reason, From buffering
From stream options
EDIT: nevermind, I thought that default |
@sidorares I think you should write this fact in here: |
Fixes mysqljs#741 Signed-off-by: INADA Naoki <[email protected]>
I'm using the following code to test out the functionality of .stream().pipe() and I'm getting an error when I pass fairly typical stream outputs I've seem used elsewhere to .pipe(). I'm wondering if I'm totally off base or if this functionality is no longer supported.
I get "TypeError: first argument must be a string or Buffer" when I call .pipe(res).
The text was updated successfully, but these errors were encountered: