Pagination
JSORM supports two types of pagination: offset (traditional) and cursor (keyset).
Offset pagination
Section titled “Offset pagination”Only works within .get() with pagination in the options:
const { data: users, meta } = await jsorm.users.get({ select: { id: true, name: true }, pagination: { page: 1, perPage: 10 },});meta.page; // current pagemeta.perPage; // records per pagemeta.total; // total recordsmeta.lastPage; // last pageCursor-based pagination (keyset)
Section titled “Cursor-based pagination (keyset)”Uses .cursor() with required orderBy:
const { data: users, meta } = await jsorm.users.cursor({ select: { id: true, name: true }, orderBy: { id: "asc" }, limit: 20,});Cursor meta
Section titled “Cursor meta”meta.cursor.hasNext; // true if there are more recordsmeta.cursor.next; // cursor for next pagemeta.cursor.previous; // cursor for previous pageExample usage
Section titled “Example usage”// First pageconst { data: users, meta } = await jsorm.users.cursor({ orderBy: { id: "asc" }, limit: 20,});
// Next pageif (meta.cursor.hasNext) { const { data: nextUsers } = await jsorm.users.cursor({ orderBy: { id: "asc" }, limit: 20, after: meta.cursor.next, });}When to use each?
Section titled “When to use each?”| Type | When to use |
|---|---|
| Offset | UI with traditional pagination (page buttons) |
| Cursor | APIs with infinite scroll, feeds, long lists |
