Skip to main content

QueryBuilder

Struct QueryBuilder 

Source
pub struct QueryBuilder<S: Schema> { /* private fields */ }
Expand description

Typed query builder for OData queries.

This builder provides a fluent API for constructing ODataQuery instances with type-safe field references and automatic filter hashing.

§Example

let query = QueryBuilder::<UserSchema>::new()
    .filter(NAME.contains("john"))
    .order_by(NAME, SortDir::Asc)
    .select([NAME, EMAIL])
    .page_size(50)
    .build();

Implementations§

Source§

impl<S: Schema> QueryBuilder<S>

Source

pub fn new() -> Self

Create a new empty query builder.

Source

pub fn filter(self, expr: Expr) -> Self

Set the filter expression.

§Example
builder.filter(ID.eq(user_id).and(NAME.contains("john")))
Source

pub fn order_by<F>(self, field: F, dir: SortDir) -> Self
where F: AsFieldName,

Add an order-by clause.

Can be called multiple times to add multiple sort keys.

§Example
builder
    .order_by(NAME, SortDir::Asc)
    .order_by(ID, SortDir::Desc)
Source

pub fn select<I>(self, fields: I) -> Self
where I: IntoIterator, I::Item: AsFieldKey<S>,

Set the select fields (field projection).

§Example
builder.select([NAME, EMAIL])
builder.select(vec![NAME, EMAIL])

// Backwards-compatible (still supported)
builder.select(&[&ID, &NAME, &EMAIL])
Source

pub fn page_size(self, limit: u64) -> Self

Set the page size limit.

§Example
builder.page_size(50)
Source

pub fn build(self) -> ODataQuery

Build the final ODataQuery with computed filter hash.

The filter hash is computed using the stable hashing algorithm from pagination::short_filter_hash.

Trait Implementations§

Source§

impl<S: Schema> Default for QueryBuilder<S>

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

§

impl<S> Freeze for QueryBuilder<S>

§

impl<S> RefUnwindSafe for QueryBuilder<S>

§

impl<S> Send for QueryBuilder<S>
where S: Send, <S as Schema>::Field: Send,

§

impl<S> Sync for QueryBuilder<S>
where S: Sync, <S as Schema>::Field: Sync,

§

impl<S> Unpin for QueryBuilder<S>
where S: Unpin, <S as Schema>::Field: Unpin,

§

impl<S> UnsafeUnpin for QueryBuilder<S>

§

impl<S> UnwindSafe for QueryBuilder<S>
where S: UnwindSafe, <S as Schema>::Field: UnwindSafe,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.