Skip to main content

pypaginate.adapters.sqlalchemy.cursor

Cursor / keyset pagination backends (async and sync).

Each backend over-fetches limit + 1 rows for a keyset-ordered query and returns a :class:CursorPage; the page-assembly mechanics live in :mod:pypaginate.adapters.sqlalchemy.cursor_page. The query must carry an ORDER BY that uniquely orders rows (e.g. a trailing primary key).

SQLAlchemyCursorBackend Objects

class SQLAlchemyCursorBackend(Generic[ItemT])

Async cursor / keyset pagination backend.

Arguments:

  • session - An async SQLAlchemy session.

fetch_page

async def fetch_page(query: Select[Any],
params: CursorParams) -> CursorPage[ItemT]

Fetch one keyset page for query as a :class:CursorPage.

Arguments:

  • query - A SQLAlchemy Select with an ORDER BY clause.
  • params - The cursor request (limit + optional after / before).

Returns:

The matched page with next / previous cursors.

SyncSQLAlchemyCursorBackend Objects

class SyncSQLAlchemyCursorBackend(Generic[ItemT])

Sync cursor / keyset pagination backend.

Arguments:

  • session - A synchronous SQLAlchemy session.

fetch_page

def fetch_page(query: Select[Any], params: CursorParams) -> CursorPage[ItemT]

Fetch one keyset page for query as a :class:CursorPage.

Arguments:

  • query - A SQLAlchemy Select with an ORDER BY clause.
  • params - The cursor request (limit + optional after / before).

Returns:

The matched page with next / previous cursors.