Retrieve pagination information
See original GitHub issueProblem
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:
- Created 4 years ago
- Reactions:12
- Comments:13 (4 by maintainers)
Top 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 >
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 Free
Top 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
@pantharshit00 This looks like basic feature that a lot of pagination use cases need. Are there any updates on this?
I had initially solved this by using only one query,
findMany
withoutcursor
ortake
. 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: