Skip to content

Pagination

rn_forge.sqlalchemy.pagination

Keyset pagination over :mod:rn_forge.web's opaque page token.

sqlakeyset is not adopted (checked 2026-09-23): its bookmark is its own marker tuple, so adopting it would mean translating the token both ways to replace a short predicate.

keyset(stmt, *, columns, terms, cursor, id_column)

Order stmt by every orderBy term and resume after cursor.

Rows are ordered by each term's column in turn, then by id_column in the last term's direction (ascending with no terms), unless id_column is already a term. Rows whose value is NULL come after those that have one, in both directions, on every database. Term columns need not be unique and may be nullable; id_column must not be.

Fetch page_size + 1 rows from the result to learn whether another page exists.

Parameters:

Name Type Description Default
stmt T

The query to order and filter.

required
columns Mapping[str, ColumnElement[Any]]

Each allowed wire field name mapped to its column.

required
terms Sequence[OrderField]

The parsed orderBy; pass the request's terms, empty when the request gave none.

required
cursor Cursor | None

The decoded page token, or None for the first page.

required
id_column ColumnElement[Any]

The unique, non-null tiebreaker column.

required

Raises:

Type Description
InvalidCursor

The token was issued for a different orderBy, or its values do not fit the columns.

next_page_token(row_values, entity_id, terms)

Encode the token that resumes after the row with these values.

row_values is the last row's value in each term's column, one per term (empty when terms is empty). Pass the same terms given to :func:keyset.