Infinite scroll w/ Drizzle + tRPC

Has anyone implemented infinite scrolling/pagination using Drizzle? The example in the tRPC docs uses Prisma, which has a built-in cursor parameter for pagination. What would one use for Drizzle? https://trpc.io/docs/client/react/useInfiniteQuery
useInfiniteQuery | tRPC
- Your procedure needs to accept a cursor input of any type (string, number, etc) to expose this hook.
4 Replies
Angelelz
Angelelz14mo ago
I feel like I saw some pagination helper in the beta branch but it's now released yet. A workaround is just to implement it yourself. The cursor is just the last seen id of the table, and the query just needs to have a where(gt(table.id, cursor))
zendev
zendevOP14mo ago
Right, this would work for ids that autoincrement right? Because then it's a sequential number but what if you're using UUID or CUID or something of the like? I'm trying to figure out if I can use createdAt (which is a Date) but struggling to wrap my head around this for some reason
Angelelz
Angelelz14mo ago
I think UUID v7 is sortable. I don't know anything about CUID, but a really good one I discovered recently is ULID. Also, yes, you could use createdAt The Sorting just needs to be unique, I believe
zendev
zendevOP14mo ago
Think I made some progress towards figuring it out, thanks for your help
Want results from more Discord servers?
Add your server