Token-based pagination support for AshScylla.
ScyllaDB/Cassandra doesn't support OFFSET natively. Instead, it uses Xandra's native paging state mechanism for efficient pagination.
Token-Based Pagination
When pagination :token is set in the ash_scylla DSL, queries use
Xandra's built-in paging state to efficiently page through results
without OFFSET.
Usage
# First page
{:ok, records, next_page_token} =
AshScylla.DataLayer.Pagination.fetch_page(repo, table, filters, nil, 10)
# Subsequent pages
{:ok, records, next_page_token} =
AshScylla.DataLayer.Pagination.fetch_page(repo, table, filters, page_token, 10)Page Token Format
Page tokens are opaque binaries returned by Xandra's paging_state. They should be treated as opaque by callers and only passed back to fetch the next page.
Summary
Functions
Builds a CQL query string with LIMIT for pagination.
Builds a CQL query string with LIMIT for pagination, with optional page token.
Decodes a page token string back to a paging state binary.
Returns the default page size.
Encodes a paging state binary to an opaque page token string.
Fetches a page of results using Xandra's native paging state.
Returns the maximum allowed page size.
Types
Functions
@spec build_paginated_query(String.t(), list(), pos_integer()) :: {String.t(), list()}
Builds a CQL query string with LIMIT for pagination.
Returns {query, params} suitable for repo.query/3.
@spec build_paginated_query(String.t(), list(), page_token(), pos_integer()) :: {String.t(), list()}
Builds a CQL query string with LIMIT for pagination, with optional page token.
When page_token is non-nil, adds a token() > ? condition to the WHERE clause.
Returns {query, params} suitable for repo.query/3.
Decodes a page token string back to a paging state binary.
@spec default_page_size() :: pos_integer()
Returns the default page size.
Encodes a paging state binary to an opaque page token string.
@spec fetch_page(module(), String.t(), list(), page_token(), pos_integer()) :: page_result()
Fetches a page of results using Xandra's native paging state.
Parameters
repo- The Ecto repo moduletable- The table namefilters- Filter list for WHERE clausepage_token- Opaque page token from previous page (nil for first page)page_size- Number of results per page (default: 50, max: 1000)
Returns
{:ok, records, next_page_token} where next_page_token is nil
when there are no more pages.
@spec max_page_size() :: pos_integer()
Returns the maximum allowed page size.