UUID Cursor Pagination
See original GitHub issueProblem
If you have non-sequential UUID’s as your primary key, the take/cursor prisma pagination API doesn’t work. I believe it actually did with the old first/after/before/last API (could be wrong here but it seemed to prior to beta.7).
In such cases, you can paginate using a query similar to this:
SELECT * FROM events
WHERE (created,id) >= ($<after>,$<id>)
ORDER BY created ASC ,id ASC LIMIT 10
Suggested solution
A cursor combining the uuid id field and a created_at field works when passed in as the cursor to prisma.
Alternatives
You can almost implement an equivalent query using just where/order by
but it is not currently possible to pass multiple fields to orderBy
.
Additional context
Issue Analytics
- State:
- Created 3 years ago
- Reactions:2
- Comments:12 (6 by maintainers)
Top Results From Across the Web
MySQL - UUID/created_at cursor based pagination?
Any idea how to query the users table based on uuid/created_at cursor combination to ensure we get the correct datasets (just as if...
Read more >Implementing cursor-based pagination - Users/mrinmoy
We will implement a cursor-based pagination module, also discuss about some gotchas for handling UUIDs.
Read more >How to keypaginate UUID in postgresql?
Stumbled across keyset and cursor pagination, in which I though that keyset may be a better fit, since its easier to implement in...
Read more >Stable Pagination — by Igor Šarčević - Morning Coffee
Cursor based pagination with UUIDs for primary keys. The previous examples are simple, but they rely on the fact that ids are incremental ......
Read more >Cursor-based pagination - Apollo GraphQL Docs
Using list element IDs as cursors. Since numeric offsets within paginated lists can be unreliable, a common improvement is to identify the beginning...
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
@dpetrick What’s the implication of the fix? Is it now that you can orderBy only a date and have an ID as cursor? Does it behind the scenes first sort on date and after that on id?
If so, the docs should also reflect this, since it mentions that you need to orderBy the cursor. Happy to make a docs PR.
A fix is available from
2.2.0-dev.19
onwards.