The cursor pagination is perfect in a context where there is an infinite scroll, itβs not used to retrieve a specific page. This is the offset pagination goal.
At this moment I don't have any idea if there are specific cases where we can mix both solutions. Maybe they exist but I think we use one or the other in the common use cases.
Otherwise, if you are using the offset pagination and you want to grab page X you need to calculate the skip in this way β(pageNumber - 1) * takeβ. Thus you have got the skip value to retrieve the data of your page.
I am trying to have a traditional pagination with page numbers on the bottom. I thought offset would be the way to go but if it's not scalable I don't know what to use. What would be the way to go about it?
If you are using the offset pagination, you have two ways:
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
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 π
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
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.
The cursor pagination is perfect in a context where there is an infinite scroll, itβs not used to retrieve a specific page. This is the offset pagination goal.
At this moment I don't have any idea if there are specific cases where we can mix both solutions. Maybe they exist but I think we use one or the other in the common use cases.
Otherwise, if you are using the offset pagination and you want to grab page X you need to calculate the skip in this way β(pageNumber - 1) * takeβ. Thus you have got the skip value to retrieve the data of your page.
I am trying to have a traditional pagination with page numbers on the bottom. I thought offset would be the way to go but if it's not scalable I don't know what to use. What would be the way to go about it?
If you are using the offset pagination, you have two ways:
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
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.
Thanks, that helps a ton, I have no where and just 1 orderBy so Offset is going to be the way I go!