pub struct SqlCondition<P> { /* private fields */ }Expand description
A rendered SQL-style condition together with its positional bind parameters.
Parameters retain left-to-right placeholder order. Keys, operators, and
placeholders are interpolated verbatim; callers must validate or quote them
for the target backend. Only values are separated as bind parameters. The
condition records where each placeholder token sits, so
SqlCondition::render_placeholders rewrites placeholders without touching
spliced text that happens to contain the same characters.
Implementations§
Source§impl<P> SqlCondition<P>
impl<P> SqlCondition<P>
Sourcepub fn binary(
key: impl AsRef<str>,
op: &str,
placeholder: &str,
value: P,
) -> Self
pub fn binary( key: impl AsRef<str>, op: &str, placeholder: &str, value: P, ) -> Self
Renders <key> <op> <placeholder> bound to a single parameter, e.g.
price >= $.
Sourcepub fn list(
key: impl AsRef<str>,
op: &str,
placeholder: &str,
values: Vec<P>,
) -> Self
pub fn list( key: impl AsRef<str>, op: &str, placeholder: &str, values: Vec<P>, ) -> Self
Renders <key> <op> (<placeholder>, ...) with one placeholder per value,
e.g. id IN (?, ?).
Sourcepub fn range(key: impl AsRef<str>, placeholder: &str, lo: P, hi: P) -> Self
pub fn range(key: impl AsRef<str>, placeholder: &str, lo: P, hi: P) -> Self
Renders <key> >= <placeholder> AND <key> <= <placeholder> bound to
lo then hi, e.g. price >= ? AND price <= ?.
Sourcepub fn between(key: impl AsRef<str>, placeholder: &str, lo: P, hi: P) -> Self
pub fn between(key: impl AsRef<str>, placeholder: &str, lo: P, hi: P) -> Self
Renders <key> between <placeholder> and <placeholder> bound to lo
then hi, e.g. price between ? and ?.
Sourcepub fn raw(condition: impl Into<String>) -> Self
pub fn raw(condition: impl Into<String>) -> Self
Wraps an already-rendered, parameterless condition such as id is null.
The text holds no placeholders, whatever characters it contains.
Sourcepub fn and(self, rhs: Self) -> Self
pub fn and(self, rhs: Self) -> Self
Conjoins two conditions as (lhs) AND (rhs), concatenating their parameters.
Sourcepub fn or(self, rhs: Self) -> Self
pub fn or(self, rhs: Self) -> Self
Disjoins two conditions as (lhs) OR (rhs), concatenating their parameters.
Sourcepub fn condition(&self) -> &str
pub fn condition(&self) -> &str
The rendered condition, with placeholders as the caller supplied them.
Sourcepub fn render_placeholders<D: Display>(
&self,
placeholder: impl FnMut(usize) -> D,
) -> String
pub fn render_placeholders<D: Display>( &self, placeholder: impl FnMut(usize) -> D, ) -> String
Returns the condition with the placeholder for parameter i (zero-based,
in SqlCondition::params order) replaced by placeholder(i), e.g.
|i| format!("${}", i + 1) for Postgres. Only tokens emitted by the
constructors are replaced; keys and SqlCondition::raw text are
copied verbatim.
Sourcepub fn into_parts(self) -> (String, Vec<P>)
pub fn into_parts(self) -> (String, Vec<P>)
Consumes the condition, returning the rendered text and its parameters.
Trait Implementations§
Source§impl<P: Clone> Clone for SqlCondition<P>
impl<P: Clone> Clone for SqlCondition<P>
Source§impl<P: Debug> Debug for SqlCondition<P>
impl<P: Debug> Debug for SqlCondition<P>
Source§impl<P> Default for SqlCondition<P>
Hand-written so that P needs no Default of its own: a parameterless
empty condition is meaningful for every parameter type.
impl<P> Default for SqlCondition<P>
Hand-written so that P needs no Default of its own: a parameterless
empty condition is meaningful for every parameter type.
Source§impl<'de, P> Deserialize<'de> for SqlCondition<P>where
P: Deserialize<'de>,
impl<'de, P> Deserialize<'de> for SqlCondition<P>where
P: Deserialize<'de>,
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Auto Trait Implementations§
impl<P> Freeze for SqlCondition<P>
impl<P> RefUnwindSafe for SqlCondition<P>where
Vec<P>: RefUnwindSafe,
impl<P> Send for SqlCondition<P>
impl<P> Sync for SqlCondition<P>
impl<P> Unpin for SqlCondition<P>
impl<P> UnsafeUnpin for SqlCondition<P>where
Vec<P>: UnsafeUnpin,
impl<P> UnwindSafe for SqlCondition<P>where
Vec<P>: UnwindSafe,
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
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> DeserializeOwned for Twhere
T: for<'de> Deserialize<'de>,
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> ⓘ
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> ⓘ
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