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

Is there a way to get the total number of rows as soon as the query executor knows the total result size? #54

Open
gajus opened this issue Mar 15, 2019 · 1 comment

Comments

@gajus
Copy link

gajus commented Mar 15, 2019

I am streaming results and I would to cut off the stream after X rows, but I need to know how many rows there are in total.

I have tried to simply count chunks after I stop reading them, but the overhead is too big. It takes +30 seconds to count 30k+ rows.

@matthieusieben
Copy link

Add a count(*) as total in you select.

You can then make use of async iterables:

let current = 0
let max = 10
let total = 0
for await (const row of stream) {
  total = row.total
  current ++
  if (curent >= max) break // no need to go further
}

console.log("consumed " + current + " out of " + total + " rows")

Be aware of issues #52, #56, #66 if you choose to do that.

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

2 participants