chai
chai copied to clipboard
Paginations
I am trying to built a service that does pagination .
I am not sure of the syntax that is appropriate for this .
The docs don’t mention anything so if anyone as some examples it would be awesome.
It works essentially the same as any other SQL database, so you can follow any tutorial for Postgres or SQLite and it should work. Here is a reference of the Genji SQL statement: https://genji.dev/docs/reference/select/
As an example:
- For offset based pagination:
page := 5
perPage := 100
db.Query("SELECT * FROM foo WHERE ... OFFSET ? LIMIT ?", (page - 1) * perPage, perPage)
- For cursor based pagination:
// let's say your cursor is the id
cursor := "abcdef"
perPage := 100
res, err := db.Query("SELECT * FROM foo WHERE id > ? LIMIT ?", cursor, perPage)
// the new cursor will be the last document returned by this query
Closing this as it answered the question, feel free to re-open if needed