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.

Retrieve pagination information

See original GitHub issue

Problem

Prisma client currently does not provide the ability to retrieve pagination information about a certain query, which prevents developers from accounting for a result set’s size in a variety of cases (display paginated result lists, optimizing batch size…)

Proposed solution

Add support for a $withPageInfo() to functions returning collections (findMany ,1-n relations, …) returning pagination information alongside the results.

The pagination information could be described as:

type PageInfo<T> = {
  data: T[] // The query result
  hasNext: boolean // Indication that the cursor can move to the next page
  hasPrev: boolean // Indication that the cursor can move to the previous page
}

Example usage:

const samsPostsWithPageInfo: PageInfo<Post> = await prisma.users
  .findOne('sams-id')
  .posts({ first: 50 })
  .$withPageInfo()
console.log(samsPostsWithPageInfo.hasNext, samsPostsWithPageInfo.hasPrev, samsPostsWithPageInfo.data

Issue Analytics

  • State:open
  • Created 4 years ago
  • Reactions:12
  • Comments:13 (4 by maintainers)

github_iconTop GitHub Comments

5reactions
old-zoomercommented, May 2, 2022

@pantharshit00 This looks like basic feature that a lot of pagination use cases need. Are there any updates on this?

3reactions
Karl-EdwardFPJeanMehucommented, May 19, 2021

I had initially solved this by using only one query, findMany without cursor or take. After grabbing the length of the request, I did the cursor and take and etc myself. Upon discovering $transaction I simply did something like the following instead:

let [ result, count ] = await prisma.$transaction([
   prisma.entity.findMany(query),
   prisma.entity.count({where})
])
Read more comments on GitHub >

github_iconTop Results From Across the Web

Pagination and Sorting using Spring Data JPA - Baeldung
Learn how to paginate and sort query results in Spring Data JPA. ... Get started with Spring Data JPA through the reference Learn...
Read more >
Spring Boot Pagination and Sorting Example - HowToDoInJava
Learn to request partial data from the database using pagination and sorting inputs using the query parameters in spring boot and data apps....
Read more >
4. Paging and Sorting - Spring
Each paged response will return links to the previous and next pages of results based on the current page. If you are currently...
Read more >
Pagination in the REST API - Atlassian Developer
Pagination in the REST API. On This Page. Why pagination? Set the limit parameter. GET the next page of results. How do I...
Read more >
Paging with Spring Boot - Reflectoring
As a user of a web application we're expecting pages to load quickly and only show the information that's relevant to us.
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