Need a sanity check on my idea for cursor pagination helper

I wanna create a helper to manage cursor-based pagination with Drizzle. To create a cursor your select query needs to contain the columns on which your data is ordered - so you need to include those columns in select. But my concern is that that may cause collisions say
{
name: posts.authorName // this is the data I want to return
name: posts.name // this was provided by my cursor helper
}
{
name: posts.authorName // this is the data I want to return
name: posts.name // this was provided by my cursor helper
}
or
{
postedAt: sql`posts.postedAt`.mapWith(formatDate)
postedAt: posts.postedAt // this will result in unexpected data format returned
}
{
postedAt: sql`posts.postedAt`.mapWith(formatDate)
postedAt: posts.postedAt // this will result in unexpected data format returned
}
So I thought what if I would hash the keys provided with the cursor config - these have to be defined only once on app start-up so hashing perf cost is minimal. and then what I will get is something like
{
name: posts.authorName // this is the data I want to return
dsaffhewqf: posts.name // this was provided by my cursor helper
}
{
name: posts.authorName // this is the data I want to return
dsaffhewqf: posts.name // this was provided by my cursor helper
}
And then I will also provide the helper which will remove these keys from returned array so that some junk doesn't go to the client The only downside here is that sometimes columns may be returned twice:
{
name: posts.name // this is the data I want to return
dsaffhewqf: posts.name // this was provided by my cursor helper
}
{
name: posts.name // this is the data I want to return
dsaffhewqf: posts.name // this was provided by my cursor helper
}
but I'm not sure how bad this is sooo... I just want a sanity check really. Does that sound like an okay-ish idea?
0 Replies
No replies yetBe the first to reply to this messageJoin
Want results from more Discord servers?
Add your server