AshScylla.DataLayer.Pagination (AshScylla v0.2.0)

Copy Markdown View Source

Pagination support for AshScylla using ScyllaDB/Cassandra tokens.

ScyllaDB/Cassandra doesn't support OFFSET natively. Instead, it uses tokens for efficient pagination.

Summary

Functions

Builds a CQL query with token-based pagination.

Fetches a page of results using token-based pagination.

Functions

build_paginated_query(table, filters, token, page_size)

(since 1.0.0)
@spec build_paginated_query(String.t(), map(), term(), pos_integer()) ::
  {String.t(), list()}

Builds a CQL query with token-based pagination.

fetch_page(repo, table, filters, token, page_size)

(since 1.0.0)
@spec fetch_page(module(), String.t(), map(), term(), pos_integer()) ::
  {:ok, {[term()], term()}} | {:error, term()}

Fetches a page of results using token-based pagination.

Examples

# First page
{:ok, {records, next_token}} = DataLayer.Pagination.fetch_page(repo, table, %{}, nil, 10)

# Next page using token
{:ok, {records, next_token}} = DataLayer.Pagination.fetch_page(repo, table, %{}, token, 10)