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

Top comments (0)

Billboard image

The Next Generation Developer Platform

Coherence is the first Platform-as-a-Service you can control. Unlike "black-box" platforms that are opinionated about the infra you can deploy, Coherence is powered by CNC, the open-source IaC framework, which offers limitless customization.

Learn more

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay