DEV Community

Discussion on: It's Prisma Time - Pagination

 
puppo profile image
Luca Del Puppo • Edited

If you are using the offset pagination, you have two ways:

  1. The client know the size and the take value and your API retrieves the data using the size and the take value passed by the client
  2. The client sends only the page, in this case, the take value is known only by the server and you need to calculate the skip value in this way β€œ(pageNumber - 1) * take”. At this moment you have the skip and the take value and you can perform your query. I think this can help you, if not, ask me more without any problem πŸ˜ƒ
Thread Thread
 
neeshsamsi profile image
Neesh Samsi

The second was what I was thinking of but apparently offset method is not that good for larger databases. I doubt I would hit those issues but incase I do will it just be slow or will it error out

Thread Thread
 
puppo profile image
Luca Del Puppo

Probably if you are using the offset method and you have more filters your where clause can generate problems. In these cases, you need to check the indexes of the tables used in your queries. In the common cases the skip and take handling in the database doesn't generate any problems of the slowness, but the where clause yes.

Thread Thread
 
neeshsamsi profile image
Neesh Samsi

Thanks, that helps a ton, I have no where and just 1 orderBy so Offset is going to be the way I go!