Skip to main content

QueryBuilder

Struct QueryBuilder 

Source
pub struct QueryBuilder {
    pub table: String,
    pub operation: Operation,
    pub conditions: Vec<Condition>,
    pub order_by: Vec<OrderBy>,
    pub limit: Option<u64>,
    pub offset: Option<u64>,
    pub columns: Vec<String>,
    pub values: Vec<(String, Value)>,
}
Expand description

Composable, database-agnostic query builder.

QueryBuilder is the primary way to express SELECT / UPDATE / DELETE conditions in Rusticx without writing raw SQL or MQL. Each backend’s compiler transforms it into parameterized SQL or a BSON filter document.

Obtain one from [Repository::query] so the table name is pre-filled, or construct one directly with QueryBuilder::table.

§Example

let adults = repo.find(
    repo.query()
        .r#where("age", CondOp::Gte, 18)
        .r#where("active", CondOp::Eq, true)
        .order_by("name", Direction::Asc)
        .limit(20)
        .offset(0)
).await?;

Fields§

§table: String§operation: Operation§conditions: Vec<Condition>§order_by: Vec<OrderBy>§limit: Option<u64>§offset: Option<u64>§columns: Vec<String>§values: Vec<(String, Value)>

Implementations§

Source§

impl QueryBuilder

Source

pub fn table(name: impl Into<String>) -> Self

Source

pub fn select(self, cols: Vec<impl Into<String>>) -> Self

Source

pub fn where( self, col: impl Into<String>, op: CondOp, val: impl Into<Value>, ) -> Self

Source

pub fn or_where( self, col: impl Into<String>, op: CondOp, val: impl Into<Value>, ) -> Self

Source

pub fn order_by(self, col: impl Into<String>, dir: Direction) -> Self

Source

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

Source

pub fn offset(self, n: u64) -> Self

Source

pub fn set(self, col: impl Into<String>, val: impl Into<Value>) -> Self

Source

pub fn operation(self, op: Operation) -> Self

Trait Implementations§

Source§

impl Clone for QueryBuilder

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for QueryBuilder

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for QueryBuilder

Source§

fn default() -> Self

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

Auto Trait Implementations§

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

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

Source§

type Error = !

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

fn try_from(value: U) -> Result<T, !>

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.