DEV Community

Aashutosh Poudel
Aashutosh Poudel

Posted on

Eagerly know if end of paginated results is reached in Prisma

Context

Prisma doesn't return meta information like total_page or no_of_pages when returning paginated results. With information like total_page we can know beforehand if we are at the end of the page and show/hide relevant information. In prisma, this doesn't seem to be possible at the moment without adding a second query to fetch the count of results.

Problem

There's a Fetch More button at the bottom of a list. We need to enable this button only if we have more records to show. If not, we should hide this button.

Solution

This demo implementation doesn't use a second query. While fetching each page it retrieves one more record than the required page size. With this approach, the maximum number of records fetched twice is equal to the number of page requests. A more detailed explanation is attached below.

eagerly-detect-end-of-results-prisma

GitHub, Stackblitz

Latest comments (0)