chai icon indicating copy to clipboard operation
chai copied to clipboard

Paginations

Open gedw99 opened this issue 1 year ago • 1 comments

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.

gedw99 avatar Jul 22 '22 08:07 gedw99

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

asdine avatar Jul 25 '22 01:07 asdine

Closing this as it answered the question, feel free to re-open if needed

asdine avatar Aug 21 '22 03:08 asdine