Skip to main content

Paginator

Trait Paginator 

Source
pub trait Paginator: Entity + Sized {
    // Required method
    fn paginate(pool: &PgPool) -> PaginatedQueryBuilder<'_, Self>;

    // Provided methods
    async fn fetch_paginated(
        pool: &PgPool,
        request: &PaginationRequest,
    ) -> Result<Paginated<Self>, PaginationError>
       where Self: for<'r> FromRow<'r, PgRow> + Send + Unpin + Debug { ... }
    async fn fetch_page(
        pool: &PgPool,
        page: u64,
        per_page: u64,
    ) -> Result<Vec<Self>, PaginationError>
       where Self: for<'r> FromRow<'r, PgRow> + Send + Unpin + Debug { ... }
    async fn count(pool: &PgPool) -> Result<u64, PaginationError> { ... }
    fn cursor_paginate(
        pool: &PgPool,
        cursor_column: impl Into<String>,
    ) -> CursorPaginator<'_, Self> { ... }
    async fn fetch_cursor_paginated(
        pool: &PgPool,
        cursor_column: &str,
        cursor: Option<Cursor>,
        limit: u64,
        _direction: CursorDirection,
    ) -> Result<CursorPaginated<Self>, PaginationError>
       where Self: for<'r> FromRow<'r, PgRow> + Send + Unpin + Debug { ... }
}
Expand description

Trait for paginating entities

This trait provides methods for paginating queries on entities

Required Methods§

Source

fn paginate(pool: &PgPool) -> PaginatedQueryBuilder<'_, Self>

Create a paginated query for this entity type

§Arguments
  • pool - The database connection pool
§Returns

A builder for paginated queries

Provided Methods§

Source

async fn fetch_paginated( pool: &PgPool, request: &PaginationRequest, ) -> Result<Paginated<Self>, PaginationError>
where Self: for<'r> FromRow<'r, PgRow> + Send + Unpin + Debug,

Fetch a paginated result

§Arguments
  • pool - The database connection pool
  • request - Pagination request parameters
§Returns

A paginated result set

Source

async fn fetch_page( pool: &PgPool, page: u64, per_page: u64, ) -> Result<Vec<Self>, PaginationError>
where Self: for<'r> FromRow<'r, PgRow> + Send + Unpin + Debug,

Fetch a specific page of entities

§Arguments
  • pool - The database connection pool
  • page - The page number (1-indexed)
  • per_page - The number of items per page
§Returns

A vector of entities

Source

async fn count(pool: &PgPool) -> Result<u64, PaginationError>

Count all entities

§Arguments
  • pool - The database connection pool
§Returns

The total count

Source

fn cursor_paginate( pool: &PgPool, cursor_column: impl Into<String>, ) -> CursorPaginator<'_, Self>

Create a cursor-based paginator for this entity

§Arguments
  • pool - The database connection pool
  • cursor_column - The column to use for cursoring (e.g., “id”, “created_at”)
§Returns

A cursor paginator

Source

async fn fetch_cursor_paginated( pool: &PgPool, cursor_column: &str, cursor: Option<Cursor>, limit: u64, _direction: CursorDirection, ) -> Result<CursorPaginated<Self>, PaginationError>
where Self: for<'r> FromRow<'r, PgRow> + Send + Unpin + Debug,

Fetch using cursor-based pagination

§Arguments
  • pool - The database connection pool
  • cursor_column - The column to use for cursoring
  • cursor - Optional cursor to start from
  • limit - Number of items to fetch
  • direction - Direction to paginate
§Returns

A cursor-paginated result set

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§

Source§

impl<E> Paginator for E
where E: Entity + Sized,

Blanket implementation for all Entity types