Skip to main content

Expression

Trait Expression 

Source
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§

Source

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.

Source§

fn write_sql(&self, w: &mut SqlWriter<'_>)

Source§

impl Expression for String

Source§

fn write_sql(&self, w: &mut SqlWriter<'_>)

Source§

impl Expression for f32

Source§

fn write_sql(&self, w: &mut SqlWriter<'_>)

Source§

impl Expression for f64

Source§

fn write_sql(&self, w: &mut SqlWriter<'_>)

Source§

impl Expression for i8

Source§

fn write_sql(&self, w: &mut SqlWriter<'_>)

Source§

impl Expression for i16

Source§

fn write_sql(&self, w: &mut SqlWriter<'_>)

Source§

impl Expression for i32

Source§

fn write_sql(&self, w: &mut SqlWriter<'_>)

Source§

impl Expression for i64

Source§

fn write_sql(&self, w: &mut SqlWriter<'_>)

Source§

impl Expression for isize

Source§

fn write_sql(&self, w: &mut SqlWriter<'_>)

Source§

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§

fn write_sql(&self, w: &mut SqlWriter<'_>)

Source§

impl Expression for u8

Source§

fn write_sql(&self, w: &mut SqlWriter<'_>)

Source§

impl Expression for u16

Source§

fn write_sql(&self, w: &mut SqlWriter<'_>)

Source§

impl Expression for u32

Source§

fn write_sql(&self, w: &mut SqlWriter<'_>)

Source§

impl Expression for u64

Source§

fn write_sql(&self, w: &mut SqlWriter<'_>)

Source§

impl Expression for usize

Source§

fn write_sql(&self, w: &mut SqlWriter<'_>)

Source§

impl<T: Expression + ?Sized> Expression for &T

Source§

fn write_sql(&self, w: &mut SqlWriter<'_>)

Source§

impl<T: Expression + ?Sized> Expression for Arc<T>

Covers DynExprArc<dyn Expression> — as well as Arc<ConcreteExpr>.

Source§

fn write_sql(&self, w: &mut SqlWriter<'_>)

Source§

impl<T: Expression + ?Sized> Expression for Box<T>

Source§

fn write_sql(&self, w: &mut SqlWriter<'_>)

Implementors§