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.

UUID Cursor Pagination

See original GitHub issue

Problem

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:closed
  • Created 3 years ago
  • Reactions:2
  • Comments:12 (6 by maintainers)

github_iconTop GitHub Comments

6reactions
gersomvgcommented, Jul 2, 2020

@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.

4reactions
dpetrickcommented, Jun 29, 2020

A fix is available from 2.2.0-dev.19 onwards.

Read more comments on GitHub >

github_iconTop 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 >

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