Skip to main content

Module sql

Module sql 

Source
Expand description

SQL helper utilities for building paginated queries.

These functions produce SQL fragments and parameter values that callers compose into their own sqlx::query calls. They deliberately do not build complete queries — the surrounding SELECT, FROM, WHERE, and result-mapping belong to the caller.

§Examples

use klauthed_data::pagination::{OffsetPageRequest, SortKey};
use klauthed_data::pagination::sql::{limit_offset, sort_clause};

let req = OffsetPageRequest::new(2, 20).unwrap();
let (limit, offset) = limit_offset(&req);
assert_eq!(limit, 20);
assert_eq!(offset, 20); // page 2, 20-per-page → offset 20

let order = sort_clause(
    &[SortKey::asc("created_at"), SortKey::desc("id")],
    &["created_at", "id", "name"],
);
assert_eq!(order, " ORDER BY created_at ASC, id DESC");

Re-exports§

pub use super::KeysetDialect;

Functions§

keyset_where_clause
Build the keyset WHERE clause fragment for compound column pagination.
limit_offset
Return (limit, offset) as i64 values ready to bind to a parameterised query:
sort_clause
Build an ORDER BY clause from sort, filtering to only fields in allowed_fields.