node-pg-query-stream
node-pg-query-stream copied to clipboard
Get number of rows?
Would it be difficult to make the library report the number of rows processed, as a parameter of the end
event?
It just seems to be the key information for any app that uses the stream, and no way to find out how many rows have been processed.
At the moment I have to intercept function _fetch
as shown in the following code, which is quite awkward, though it works:
var count = 0, qs = new QueryStream('SELECT * FROM test');
var stream = client.query(qs);
// intercepting the _fetch call to count rows;
var fetch = stream._fetch;
stream._fetch = function (size, func) {
fetch.call(stream, size, function (err, rows) {
count += rows.length;
return func(err, rows);
});
};
stream.pipe(JSONStream.stringify()).pipe(process.stdout);
stream.once('end', function () {
resolve(count); // resolve with number of rows;
});
Yah that's definitely possible - node-postgres (which this consumes) already emits that information somewhere. I can't remember where off the top of my head but if you dive in to the code it shouldn't be too hard to find & wire up.
On Mon, Jul 20, 2015 at 5:55 PM, Vitaly Tomilov [email protected] wrote:
Would it be difficult to make the library report the number of rows processed, as a parameter of the end event?
It just seems to be the key information for any app that uses the stream, and no way to find out how many rows have been processed.
— Reply to this email directly or view it on GitHub https://github.com/brianc/node-pg-query-stream/issues/12.
The only thing relevant to the total number of rows I found is within the Result object, which isn't used when streaming data. Therefore, I'm not sure where else to look at...
@brianc Too bad you never replied to this. I have released initial support for this library within pg-promise with the information I have managed to find.
Also, I would be happy to add support for pg-copy-streams, into pg-promise, but it hasn't built successfully for a while. Any chance that you resurrect support for such an otherwise a good library? It seems quite demanded.
@brianc this one is in zombie mode, but would be very much appreciated
PRs welcome!