Aurora.Ctx.Pagination (Aurora.Ctx v0.1.3)

View Source

Struct for handling pagination state.

Fields

  • repo_module - Repository module used for database operations
  • schema_module - Schema module representing the data being paginated
  • entries_count - Total number of records available
  • pages_count - Total number of pages based on entries_count and per_page
  • page - Current page number (default: 1)
  • per_page - Number of entries per page (default: 40)
  • opts - Additional query options passed to database operations
  • entries - List of records for the current page

Configuration

Default pagination settings can be configured in your config.exs:

config :aurora_ctx, :pagination,
  page: 1,
  per_page: 40

If not configured, defaults to page: 1, per_page: 40.

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

t()

@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

new()

@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 system defaults:

  • page: 1
  • per_page: 40

Returns: t()

new(attrs)

@spec new(map() | keyword()) :: t()

Creates a new pagination struct with the given attributes.

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 to be passed to database operations
    • :entries (list): Initial list of entries for the current page

Any invalid or negative values for :page or :per_page will be replaced with defaults. Empty or invalid :opts and :entries will be initialized as empty lists.

Returns: t()