Aurora.Ctx.Pagination (Aurora.Ctx v0.1.9)
View SourceProvides a structured approach to handling pagination state in database queries and data retrieval operations.
This module defines a struct that encapsulates all necessary pagination information including options used for the initial records request, current page position, page size, total counts, and the actual data entries. It supports configurable defaults and safe initialization with automatic fallback to sensible defaults when invalid values are provided.
Configuration
Default pagination settings can be configured in your config.exs:
config :aurora_ctx, :pagination,
page: 1,
per_page: 40If not configured, defaults to page: 1, per_page: 40.
Fields
repo_module- Repository module used for database operationsschema_module- Schema module representing the data being paginatedentries_count- Total number of records availablepages_count- Total number of pages based on entries_count and per_pagepage- Current page number (default: 1)per_page- Number of entries per page (default: 40)opts- Additional query options passed to database operationsentries- List of records for the current page
Summary
Functions
Creates a new pagination struct with safe defaults from the application configuration. Delegates to new/1 with the configured defaults.
Creates a new pagination struct with the given attributes.
Types
@type t() :: %Aurora.Ctx.Pagination{ entries: list(), entries_count: non_neg_integer() | nil, opts: keyword(), page: pos_integer(), pages_count: pos_integer() | nil, per_page: pos_integer(), repo_module: module() | nil, schema_module: module() | nil }
Functions
@spec new() :: t()
Creates a new pagination struct with safe defaults from the application configuration. Delegates to new/1 with the configured defaults.
Any invalid configuration values will be replaced with pagination defaults.
Returns
Returns a t() struct with default values applied.
Creates a new pagination struct with the given attributes.
Validates and normalizes input attributes, ensuring that page and per_page are positive
integers. Invalid or missing values are replaced with safe defaults.
Parameters
attrs (
map()|keyword()) - Pagination attributes:page(pos_integer()) - Page number (default: 1):per_page(pos_integer()) - Items per page (default: 40):opts(keyword()) - Additional query options for database operations:entries(list()) - Initial list of entries for the current page
Returns
Returns a t() struct with validated and normalized values.