Skip to content

pagination

Pagination operations for database controllers.

Classes:

Classes

PaginationResult pydantic-model

Bases: BaseModel

Result of a paginated query.

Show JSON schema:
JSON
{
  "description": "Result of a paginated query.",
  "properties": {
    "items": {
      "items": {},
      "title": "Items",
      "type": "array"
    },
    "total": {
      "title": "Total",
      "type": "integer"
    },
    "page": {
      "title": "Page",
      "type": "integer"
    },
    "per_page": {
      "title": "Per Page",
      "type": "integer"
    },
    "pages": {
      "title": "Pages",
      "type": "integer"
    },
    "has_prev": {
      "title": "Has Prev",
      "type": "boolean"
    },
    "has_next": {
      "title": "Has Next",
      "type": "boolean"
    }
  },
  "required": [
    "items",
    "total",
    "page",
    "per_page",
    "pages",
    "has_prev",
    "has_next"
  ],
  "title": "PaginationResult",
  "type": "object"
}

Fields:

Classes

Config

Pydantic configuration for PaginationResult.

PaginationController

Python
PaginationController(model: type[ModelT], db: DatabaseService)

Handles pagination logic and utilities.

Initialize the pagination controller.

Parameters:

  • model (type[ModelT]) –

    The SQLModel to paginate.

  • db (DatabaseService) –

    The database service instance.

Methods:

  • paginate

    Paginate records with metadata.

  • find_paginated

    Find paginated records with relationship loading.

Functions

paginate async
Python
paginate(
    page: int = 1,
    per_page: int = 20,
    filters: Any | None = None,
    order_by: Any | None = None,
) -> PaginationResult[ModelT]

Paginate records with metadata.

Returns:

  • PaginationResult[ModelT]

    Pagination result with items, total, and page info.

find_paginated async
Python
find_paginated(
    page: int = 1,
    per_page: int = 20,
    filters: Any | None = None,
    order_by: Any | None = None,
    load_relationships: list[str] | None = None,
) -> PaginationResult[ModelT]

Find paginated records with relationship loading.

Returns:

  • PaginationResult[ModelT]

    Pagination result with items and relationships loaded.