Skip to main content

Query

Trait Query 

Source
pub trait Query:
    Debug
    + Serialize
    + MaybeSend
    + MaybeSync {
    // Provided methods
    fn filter(&self) -> Option<RestSql> { ... }
    fn pagination(&self) -> Option<Pagination> { ... }
    fn default_sort() -> Option<Vec<Sorter>>
       where Self: Sized { ... }
    fn sort(&self) -> Option<Vec<Sorter>>
       where Self: Sized { ... }
}
Expand description

Query abstraction for read-side storage.

All three methods have default implementations so minimal structs need zero boilerplate:

#[derive(Debug, Serialize, Deserialize)]
struct GameQuery { category: Option<String>, available: Option<bool> }
impl Query for GameQuery {}

The default filter() converts every non-None field to an equality constraint (field == value) ANDed together. Override only when you need non-equality operators (Gte, Like, …) or field-name remapping.

Provided Methods§

Source

fn filter(&self) -> Option<RestSql>

Returns a filter derived from the struct’s serializable fields. Override when you need operators other than == or custom field names.

Source

fn pagination(&self) -> Option<Pagination>

Pagination hint for the storage layer. Defaults to None (let the storage use its own defaults or rely on CqrsHttpQuery page params).

Source

fn default_sort() -> Option<Vec<Sorter>>
where Self: Sized,

Static default sort for this view type, applied when no explicit sort is requested (neither HTTP sort param nor sort() override). Use this instead of sort() when the sort is unconditional.

Source

fn sort(&self) -> Option<Vec<Sorter>>
where Self: Sized,

Dynamic sort order. Falls back to default_sort(). Override only when the sort depends on query field values.

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§