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
WHEREclause fragment for compound column pagination. - limit_
offset - Return
(limit, offset)asi64values ready to bind to a parameterised query: - sort_
clause - Build an
ORDER BYclause fromsort, filtering to only fields inallowed_fields.