Paginate results
Use page numbers for bounded lists or keyset cursors for long result sets.
select() supports one based page numbers and a page size from 1 to 100. Results contain rows, columns, page, pageSize, hasMore, nextCursor, valuesTruncated, and rowsTruncated. When you request count: 'exact', the response also includes totalCount; this requires an additional query.
const first = await todos.select({ limit: 50, orderBy: 'id' })
const second = first.nextCursor
? await todos.select({ limit: 50, orderBy: 'id', cursor: first.nextCursor })
: nullPass the cursor back unchanged with the same filters and sort options. Cursor pagination is useful for large or frequently paged lists because it does not rely on deep offsets. A cursor cannot be combined with a page number other than the default first page.
React infinite queries
Use useInfiniteDatabaseRows() for successive bounded pages. Use useCursorDatabaseRows() to use the response cursor for each next page.
const rows = useCursorDatabaseRows<Todo>('todos', {
where: { completed: false },
limit: 50,
orderBy: 'id',
})
const items = rows.data?.pages.flatMap((page) => page.rows) ?? []Both hooks use TanStack Query's abort signal and expose the normal fetchNextPage, hasNextPage, and loading state. See React hooks for schema bound hook factories.
Page number requests are bounded to page 100,000 and a maximum offset of 1,000,000. If a dataset needs deeper navigation, use a keyset cursor.