question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

How to know when on last page of query

See original GitHub issue

So 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?

image

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
kasrakcommented, Feb 23, 2018

You’re right! Didn’t know that about the Promise spec, thanks.

1reaction
eorroecommented, Feb 20, 2018

Whoa thanks

But I also found the solution, I didn’t realize that the second function was called when finished.

function done (error) {
 if (error) reject({ error });
 resolve(data);
}

The if (err) part confused me and made me think that it was an error handler method

Read more comments on GitHub >

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

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found