pub struct Condition { /* private fields */ }Expand description
A composable WHERE / HAVING condition.
A condition is an AND or OR group of parts. Groups nest, so arbitrary
boolean shapes can be built without thinking about precedence: OR
groups and negations are parenthesised when flattened. An empty condition
holds trivially and renders as nothing.
use turso_sql::prelude::*;
let cond = Condition::all()
.add(Expr::col("active").eq(true))
.add(Condition::any()
.add(Expr::col("role").eq("admin"))
.add(Expr::col("role").eq("owner")));Implementations§
Source§impl Condition
impl Condition
Sourcepub fn all() -> Self
pub fn all() -> Self
A condition that holds when every part holds (AND).
An empty all() holds trivially.
Sourcepub fn any() -> Self
pub fn any() -> Self
A condition that holds when any part holds (OR).
An empty any() holds trivially rather than failing, so that a
filter built from an empty list of alternatives does not silently
exclude every row.
Sourcepub fn add(self, part: impl IntoCondition) -> Self
pub fn add(self, part: impl IntoCondition) -> Self
Adds a part.
Empty nested conditions are dropped rather than added, so an unused
sub-group never leaves a stray () in the rendered SQL.
Sourcepub fn add_option(self, part: Option<impl IntoCondition>) -> Self
pub fn add_option(self, part: Option<impl IntoCondition>) -> Self
Adds a part when it is Some.
Trait Implementations§
Source§impl IntoCondition for Condition
impl IntoCondition for Condition
Source§fn into_condition(self) -> Condition
fn into_condition(self) -> Condition
Converts into a condition.
impl StructuralPartialEq for Condition
Auto Trait Implementations§
impl Freeze for Condition
impl RefUnwindSafe for Condition
impl Send for Condition
impl Sync for Condition
impl Unpin for Condition
impl UnsafeUnpin for Condition
impl UnwindSafe for Condition
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