How to know when on last page of query
See original GitHub issueSo I’ve written a wrapper for this library that I’ve been using for more than a year but need to add a method for fetching all records together
Heres what I have
let getAllDataFromTable = (table) => (filterQuery = {}) => {
return new Promise((resolve, reject) => {
let data = [];
table.select(filterQuery)
.eachPage((records, fetchNextPage) => {
data = data.concat(records);
fetchNextPage();
});
});
}
I’m not sure when to call resolve(data)
because there’s no way for me to know when on the last page. How come fetchNextPage()
doesn’t return anything or have a 3rd parameter to know when on the last page?
The documentation shows that page
will be called or done
will be called, is there any way to know what’s about to be called?
Issue Analytics
- State:
- Created 6 years ago
- Comments:5 (3 by maintainers)
Top Results From Across the Web
How to check if I'm on the last page of posts?
The WP_Query object contains a max_num_pages field which contains how many pages of posts there are. You can compare the current page number...
Read more >How to show a message on the last page of pagination
1 Answer 1 ; if · >= $total_pages){ · 'this is the last page of pagination' ; elseif · === 1 ) {...
Read more >Finding the last page number for pagination? - ProcessWire
$num_pages = $pages->count("selector");. Then obviously divide this by the number of items you are displaying on each page and then ceil() the ...
Read more >Paginating table query results - Amazon DynamoDB
To determine whether there are more results, and to retrieve them one page at a time, applications should do the following: Examine the...
Read more >Pagination (Reference) - Prisma
The following example returns the first 4 Post records that contain the word "Prisma" and saves the ID of the last record as...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
You’re right! Didn’t know that about the Promise spec, thanks.
Whoa thanks
But I also found the solution, I didn’t realize that the second function was called when finished.
The
if (err)
part confused me and made me think that it was an error handler method