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
impl QueryBuilder
pub fn table(name: impl Into<String>) -> Self
pub fn select(self, cols: Vec<impl Into<String>>) -> Self
pub fn where( self, col: impl Into<String>, op: CondOp, val: impl Into<Value>, ) -> Self
pub fn or_where( self, col: impl Into<String>, op: CondOp, val: impl Into<Value>, ) -> Self
pub fn order_by(self, col: impl Into<String>, dir: Direction) -> Self
pub fn limit(self, n: u64) -> Self
pub fn offset(self, n: u64) -> Self
pub fn set(self, col: impl Into<String>, val: impl Into<Value>) -> Self
pub fn operation(self, op: Operation) -> Self
Trait Implementations§
Source§impl Clone for QueryBuilder
impl Clone for QueryBuilder
Source§impl Debug for QueryBuilder
impl Debug for QueryBuilder
Auto Trait Implementations§
impl Freeze for QueryBuilder
impl RefUnwindSafe for QueryBuilder
impl Send for QueryBuilder
impl Sync for QueryBuilder
impl Unpin for QueryBuilder
impl UnsafeUnpin for QueryBuilder
impl UnwindSafe for QueryBuilder
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
Mutably borrows from an owned value. Read more