Skip to content
This repository has been archived by the owner on Dec 27, 2019. It is now read-only.

Get number of rows? #12

Open
vitaly-t opened this issue Jul 20, 2015 · 5 comments
Open

Get number of rows? #12

vitaly-t opened this issue Jul 20, 2015 · 5 comments

Comments

@vitaly-t
Copy link

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;
});
@brianc
Copy link
Owner

brianc commented Jul 21, 2015

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
#12.

@vitaly-t
Copy link
Author

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...

@vitaly-t
Copy link
Author

@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.

@vitaly-t vitaly-t mentioned this issue Aug 9, 2017
@shellscape
Copy link

@brianc this one is in zombie mode, but would be very much appreciated

@brianc
Copy link
Owner

brianc commented May 23, 2019

PRs welcome!

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants