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() -> Condition
pub fn all() -> Condition
A condition that holds when every part holds (AND).
An empty all() holds trivially.
Sourcepub fn any() -> Condition
pub fn any() -> Condition
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) -> Condition
pub fn add(self, part: impl IntoCondition) -> Condition
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>) -> Condition
pub fn add_option(self, part: Option<impl IntoCondition>) -> Condition
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
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> ErasedDestructor for Twhere
T: 'static,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
Converts
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
Converts
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more