pub struct OPager<'a, E, C>{ /* private fields */ }Expand description
Minimal fluent builder for Secure + OData pagination.
This builder combines security-scoped queries with OData pagination
in a single, ergonomic interface. It enforces tenant isolation and
access control while providing cursor-based pagination with filtering
and ordering.
§Type Parameters
E: TheSeaORMentity type (must implementScopableEntity)C: The secure database capability (e.g.&SecureConnor&SecureTx)
§Usage
OPager::<UserEntity, _>::new(db, ctx, db, &FMAP)
.tiebreaker("id", SortDir::Desc) // optional, defaults to ("id", Desc)
.limits(25, 1000) // optional, defaults to (25, 1000)
.fetch(&query, |m| dto_from(m))
.await§Default Behavior
- Tiebreaker:
("id", SortDir::Desc)- ensures stable pagination - Limits:
{ default: 25, max: 1000 }- reasonable defaults for most APIs
Implementations§
Source§impl<'a, E, C> OPager<'a, E, C>
impl<'a, E, C> OPager<'a, E, C>
Sourcepub fn new(scope: &'a AccessScope, conn: &'a C, fmap: &'a FieldMap<E>) -> Self
pub fn new(scope: &'a AccessScope, conn: &'a C, fmap: &'a FieldMap<E>) -> Self
Construct a new pager over a secured, scoped Select
§Parameters
scope: Security scope defining access boundaries (tenant/resource)conn: Database connection runner for executing queriesfmap: Field map definingODatafield → entity column mappings
§Example
let pager = OPager::<UserEntity, _>::new(
&scope,
&conn,
&USER_FIELD_MAP
);Sourcepub fn tiebreaker(self, field: &'a str, dir: SortDir) -> Self
pub fn tiebreaker(self, field: &'a str, dir: SortDir) -> Self
Override the default tiebreaker (“id”, Desc).
The tiebreaker ensures stable, deterministic pagination by providing a final sort key when the primary order has duplicate values.
§Parameters
field: The field name (as defined in theFieldMap) to use as tiebreakerdir: Sort direction for the tiebreaker field
§Example
pager.tiebreaker("created_at", SortDir::Asc)Sourcepub fn limits(self, default: u64, max: u64) -> Self
pub fn limits(self, default: u64, max: u64) -> Self
Override default/max limits (defaults: 25/1000).
Controls pagination limits:
default: Used when client doesn’t specify a limitmax: Maximum limit value (client requests clamped to this)
§Parameters
default: Default page size (if client doesn’t specify)max: Maximum allowed page size (requests clamped to this)
§Example
pager.limits(10, 100) // Smaller pages for this endpointSourcepub async fn fetch<D, F>(
self,
q: &ODataQuery,
map: F,
) -> Result<Page<D>, ODataError>
pub async fn fetch<D, F>( self, q: &ODataQuery, map: F, ) -> Result<Page<D>, ODataError>
Execute paging and map models to domain DTOs.
This is the terminal operation that:
- Applies security scope (tenant/resource filtering)
- Applies
ODatafilter (if present in query) - Applies cursor-based pagination
- Fetches limit+1 rows (to detect “has more”)
- Maps entity models to domain DTOs
- Returns a
Page<D>with items and pagination metadata
§Type Parameters
D: The domain DTO type (result of mapping)F: Mapper function fromE::ModeltoD
§Parameters
q:ODataquery containing filter, order, cursor, and limitmap: Function to convert entity models to domain DTOs
§Errors
Returns ODataError if:
- Security scope cannot be applied
ODatafilter is invalid- Database query fails
- Cursor is malformed or inconsistent
§Example
let page: Page<UserDto> = pager
.fetch(&odata_query, |model| UserDto {
id: model.id,
name: model.name,
email: model.email,
})
.await?;Auto Trait Implementations§
impl<'a, E, C> Freeze for OPager<'a, E, C>
impl<'a, E, C> RefUnwindSafe for OPager<'a, E, C>
impl<'a, E, C> Send for OPager<'a, E, C>
impl<'a, E, C> Sync for OPager<'a, E, C>
impl<'a, E, C> Unpin for OPager<'a, E, C>
impl<'a, E, C> UnsafeUnpin for OPager<'a, E, C>
impl<'a, E, C> UnwindSafe for OPager<'a, E, C>
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> Paint for Twhere
T: ?Sized,
impl<T> Paint for Twhere
T: ?Sized,
Source§fn fg(&self, value: Color) -> Painted<&T>
fn fg(&self, value: Color) -> Painted<&T>
Returns a styled value derived from self with the foreground set to
value.
This method should be used rarely. Instead, prefer to use color-specific
builder methods like red() and
green(), which have the same functionality but are
pithier.
§Example
Set foreground color to white using fg():
use yansi::{Paint, Color};
painted.fg(Color::White);Set foreground color to white using white().
use yansi::Paint;
painted.white();Source§fn bright_black(&self) -> Painted<&T>
fn bright_black(&self) -> Painted<&T>
Source§fn bright_red(&self) -> Painted<&T>
fn bright_red(&self) -> Painted<&T>
Source§fn bright_green(&self) -> Painted<&T>
fn bright_green(&self) -> Painted<&T>
Source§fn bright_yellow(&self) -> Painted<&T>
fn bright_yellow(&self) -> Painted<&T>
Source§fn bright_blue(&self) -> Painted<&T>
fn bright_blue(&self) -> Painted<&T>
Source§fn bright_magenta(&self) -> Painted<&T>
fn bright_magenta(&self) -> Painted<&T>
Source§fn bright_cyan(&self) -> Painted<&T>
fn bright_cyan(&self) -> Painted<&T>
Source§fn bright_white(&self) -> Painted<&T>
fn bright_white(&self) -> Painted<&T>
Source§fn bg(&self, value: Color) -> Painted<&T>
fn bg(&self, value: Color) -> Painted<&T>
Returns a styled value derived from self with the background set to
value.
This method should be used rarely. Instead, prefer to use color-specific
builder methods like on_red() and
on_green(), which have the same functionality but
are pithier.
§Example
Set background color to red using fg():
use yansi::{Paint, Color};
painted.bg(Color::Red);Set background color to red using on_red().
use yansi::Paint;
painted.on_red();Source§fn on_primary(&self) -> Painted<&T>
fn on_primary(&self) -> Painted<&T>
Source§fn on_magenta(&self) -> Painted<&T>
fn on_magenta(&self) -> Painted<&T>
Source§fn on_bright_black(&self) -> Painted<&T>
fn on_bright_black(&self) -> Painted<&T>
Source§fn on_bright_red(&self) -> Painted<&T>
fn on_bright_red(&self) -> Painted<&T>
Source§fn on_bright_green(&self) -> Painted<&T>
fn on_bright_green(&self) -> Painted<&T>
Source§fn on_bright_yellow(&self) -> Painted<&T>
fn on_bright_yellow(&self) -> Painted<&T>
Source§fn on_bright_blue(&self) -> Painted<&T>
fn on_bright_blue(&self) -> Painted<&T>
Source§fn on_bright_magenta(&self) -> Painted<&T>
fn on_bright_magenta(&self) -> Painted<&T>
Source§fn on_bright_cyan(&self) -> Painted<&T>
fn on_bright_cyan(&self) -> Painted<&T>
Source§fn on_bright_white(&self) -> Painted<&T>
fn on_bright_white(&self) -> Painted<&T>
Source§fn attr(&self, value: Attribute) -> Painted<&T>
fn attr(&self, value: Attribute) -> Painted<&T>
Enables the styling Attribute value.
This method should be used rarely. Instead, prefer to use
attribute-specific builder methods like bold() and
underline(), which have the same functionality
but are pithier.
§Example
Make text bold using attr():
use yansi::{Paint, Attribute};
painted.attr(Attribute::Bold);Make text bold using using bold().
use yansi::Paint;
painted.bold();Source§fn rapid_blink(&self) -> Painted<&T>
fn rapid_blink(&self) -> Painted<&T>
Source§fn quirk(&self, value: Quirk) -> Painted<&T>
fn quirk(&self, value: Quirk) -> Painted<&T>
Enables the yansi Quirk value.
This method should be used rarely. Instead, prefer to use quirk-specific
builder methods like mask() and
wrap(), which have the same functionality but are
pithier.
§Example
Enable wrapping using .quirk():
use yansi::{Paint, Quirk};
painted.quirk(Quirk::Wrap);Enable wrapping using wrap().
use yansi::Paint;
painted.wrap();Source§fn clear(&self) -> Painted<&T>
👎Deprecated since 1.0.1: renamed to resetting() due to conflicts with Vec::clear().
The clear() method will be removed in a future release.
fn clear(&self) -> Painted<&T>
resetting() due to conflicts with Vec::clear().
The clear() method will be removed in a future release.Source§fn whenever(&self, value: Condition) -> Painted<&T>
fn whenever(&self, value: Condition) -> Painted<&T>
Conditionally enable styling based on whether the Condition value
applies. Replaces any previous condition.
See the crate level docs for more details.
§Example
Enable styling painted only when both stdout and stderr are TTYs:
use yansi::{Paint, Condition};
painted.red().on_yellow().whenever(Condition::STDOUTERR_ARE_TTY);