Skip to main content

@rtorcato/db-common / cursorPaginate

Function: cursorPaginate()

cursorPaginate(__namedParameters): CursorQuery

Defined in: cursor.ts:70

Build a driver-agnostic keyset (cursor) page: a limit, a where predicate past the previous cursor, and an order. To detect a next page, fetch limit + 1 rows, trim the extra, and encodeCursor the last kept row's column value as the next after.

cursorPaginate({ size: 20, column: 'id', after }) // → { limit: 20, where: [{ col:'id', op:'gt', val: }], order:[…] }

after comes from the query string, so a junk cursor — one that doesn't decode, or decodes to anything but a string, number or boolean — is treated as no cursor and returns the first page. It never throws.

ponytail: single-column keyset — ties on a non-unique column can skip/repeat rows. Upgrade to a composite (sortCol, id) cursor if you paginate on a non-unique column.

Parameters​

__namedParameters​

CursorInput

Returns​

CursorQuery