Closed productdevbook closed 3 months ago
withCursorPagination
returns an object of this type:
{
orderBy: SQL[]
limit: number
where?: SQL
}
So, try something like this:
const { orderBy, limit, where } = withCursorPagination({
where: eq(schema.user.name, 'tom'), // 'where' is optional
limit: 32,
cursors: [
[
schema.user.id, // Column to use for cursor
'asc', // Sort order ('asc' or 'desc')
'94b5a795-5af4-40c3-8db8-a1c33906f5af' // Cursor value
]
]
})
// Then, use them with a .select query
const users = await db.select().from(users).where(where).orderBy(...orderBy).limit(limit)
Why can't it sort the data correctly in such a data? It's correct when going forward, it's nonsense when coming back.
Is this happening because the registration date times are the same?
Hmm, could you provide the code for the query you are making?
This is really helpful. I have a similar challenge where i want to use use this great code though with a more complex query.
I have a query that needs to bring in data from a many to many relationship. I’m doing this with joins. I want to use your code though am struggling to find a way to integrate with the complex query, paginate and restructure the data.
I’m hoping you may have a tip of two for me to explore
example code