pub trait Expression:
Debug
+ Send
+ Sync {
// Required method
fn write_sql(&self, w: &mut SqlWriter<'_>);
}Expand description
A fragment of SQL that can render itself.
Rendering is infallible: appending to a String cannot fail, and neither can
anything else an expression does. The one genuine failure — asking a dialect
for a named argument it has no syntax for — is recorded on the writer with
SqlWriter::record_error and surfaced once, by build. bob checks an
error return more than fifteen times inside a single SELECT; none of that
bookkeeping exists here.
The Debug + Send + Sync bounds are deliberate. Clauses store erased
expressions, so a query must stay printable while debugging and holdable
across an .await in the async execution layer; the bounds have to sit here
rather than at every use site.
Required Methods§
Sourcefn write_sql(&self, w: &mut SqlWriter<'_>)
fn write_sql(&self, w: &mut SqlWriter<'_>)
Append this fragment to w.
Every bound argument must go through SqlWriter::push_arg; that is the
only thing that advances the placeholder counter, which is what makes
nesting re-index correctly for free.
Dyn Compatibility§
This trait is dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".
Implementations on Foreign Types§
Source§impl Expression for Cow<'_, str>
The form identifiers and raw SQL are stored in: a literal costs nothing and a
computed string is owned, with no lifetime parameter leaking into query types.
impl Expression for Cow<'_, str>
The form identifiers and raw SQL are stored in: a literal costs nothing and a computed string is owned, with no lifetime parameter leaking into query types.
Source§impl Expression for str
A raw string is rendered verbatim.
impl Expression for str
A raw string is rendered verbatim.
This is bob’s “progressive enhancement”: anywhere an expression is accepted, a
hand-written fragment works too. Covers &str of any lifetime through the
blanket &T impl below, which includes the &'static str that clauses store.
Source§impl<T: Expression + ?Sized> Expression for &T
impl<T: Expression + ?Sized> Expression for &T
Source§impl<T: Expression + ?Sized> Expression for Arc<T>
Covers DynExpr — Arc<dyn Expression> — as well as Arc<ConcreteExpr>.
impl<T: Expression + ?Sized> Expression for Arc<T>
Covers DynExpr — Arc<dyn Expression> — as well as Arc<ConcreteExpr>.