pub trait ToSQL<'a, V>where
V: SQLParam,{
// Required method
fn to_sql(&self) -> SQL<'a, V>;
// Provided method
fn into_sql(self) -> SQL<'a, V>
where Self: Sized { ... }
}Expand description
Something that renders as a SQL fragment for the value type V.
Columns, tables, expressions, query builders and plain Rust values all
implement it. Rust values (i64, &str, Option<T>, …) render as
bound parameters, None renders as NULL, and lists (Vec<T>, arrays,
slices) render as comma-separated items. 'a lets the fragment borrow
its inputs instead of copying them.
§Examples
Rendering a custom type:
use drizzle_core::{SQL, ToSQL};
struct Now;
impl<'a> ToSQL<'a, Value> for Now {
fn to_sql(&self) -> SQL<'a, Value> {
SQL::raw("CURRENT_TIMESTAMP")
}
}
assert_eq!(Now.to_sql().sql(), "CURRENT_TIMESTAMP");Required Methods§
Provided Methods§
Dyn Compatibility§
This trait is dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".
Implementations on Foreign Types§
Source§impl<'a, V, T0, T1, T2, T3, T4, T5, T6, T7> ToSQL<'a, V> for (T0, T1, T2, T3, T4, T5, T6, T7)
impl<'a, V, T0, T1, T2, T3, T4, T5, T6, T7> ToSQL<'a, V> for (T0, T1, T2, T3, T4, T5, T6, T7)
Source§impl<'a, V, T0, T1, T2, T3, T4, T5, T6> ToSQL<'a, V> for (T0, T1, T2, T3, T4, T5, T6)
impl<'a, V, T0, T1, T2, T3, T4, T5, T6> ToSQL<'a, V> for (T0, T1, T2, T3, T4, T5, T6)
Source§impl<'a, V, T0, T1, T2, T3, T4, T5> ToSQL<'a, V> for (T0, T1, T2, T3, T4, T5)
impl<'a, V, T0, T1, T2, T3, T4, T5> ToSQL<'a, V> for (T0, T1, T2, T3, T4, T5)
Source§impl<'a, V, T0, T1, T2, T3, T4> ToSQL<'a, V> for (T0, T1, T2, T3, T4)
impl<'a, V, T0, T1, T2, T3, T4> ToSQL<'a, V> for (T0, T1, T2, T3, T4)
Source§impl<'a, V, T0, T1, T2, T3> ToSQL<'a, V> for (T0, T1, T2, T3)
impl<'a, V, T0, T1, T2, T3> ToSQL<'a, V> for (T0, T1, T2, T3)
Source§impl<'a, V, T0, T1, T2> ToSQL<'a, V> for (T0, T1, T2)
impl<'a, V, T0, T1, T2> ToSQL<'a, V> for (T0, T1, T2)
Implementors§
impl<'a, Schema, State, Table, Marker, Row, Grouped> ToSQL<'a, SQLiteValue<'a>> for QueryBuilder<'a, Schema, State, Table, Marker, Row, Grouped>
impl<'a, V, C> ToSQL<'a, V> for Excluded<C>where
V: SQLParam + 'a,
<V as SQLParam>::DialectMarker: DialectSupports<Excluded>,
C: SQLColumnInfo,
impl<'a, V, E, Name> ToSQL<'a, V> for NamedExpr<E, Name>
impl<'a, V, E> ToSQL<'a, V> for AliasedExpr<E>
impl<'a, V, Lhs, Rhs, Op, D, SQLType, Nullable> ToSQL<'a, V> for ColumnBinOp<Lhs, Rhs, Op, D, SQLType, Nullable>
impl<'a, V, Name, Output> ToSQL<'a, V> for DerivedField<Name, Output>
impl<'a, V, Name, Projection, Query> ToSQL<'a, V> for Derived<'a, V, Name, Projection, Query>
impl<'a, V, S> ToSQL<'a, V> for Ordered<'a, V, S>where
V: SQLParam,
impl<'a, V, T, D, SQLType, Nullable> ToSQL<'a, V> for ColumnNeg<T, D, SQLType, Nullable>
impl<'a, V, T, N, A, S> ToSQL<'a, V> for SQLExpr<'a, V, T, N, A, S>
impl<'a, V, T, N> ToSQL<'a, V> for TypedPlaceholder<T, N>
impl<'a, V, Table, Query> ToSQL<'a, V> for CTEView<'a, V, Table, Query>
impl<'a, V> ToSQL<'a, V> for ColumnRefwhere
V: SQLParam + 'a,
impl<'a, V> ToSQL<'a, V> for Joinwhere
V: SQLParam + 'a,
impl<'a, V> ToSQL<'a, V> for OrderBywhere
V: SQLParam + 'a,
Renders ASC or DESC.