Skip to main content

Expr

Trait Expr 

Source
pub trait Expr<'a, V: SQLParam>: ToSQL<'a, V> {
    type SQLType: DataType;
    type Nullable: Nullability;
    type Aggregate: AggregateKind;

    // Provided methods
    fn to_expr_sql(&self) -> SQL<'a, V> { ... }
    fn into_expr_sql(self) -> SQL<'a, V>
       where Self: Sized { ... }
}
Expand description

An expression in SQL with an associated data type.

This is the core trait for type-safe SQL expressions. Every SQL expression (column, literal, function result) implements this with its SQL type.

§Type Parameters

  • 'a: Lifetime of borrowed data in the expression
  • V: The dialect’s value type (SQLiteValue, PostgresValue)

§Associated Types

  • SQLType: The SQL data type this expression evaluates to
  • Nullable: Whether this expression can be NULL
  • Aggregate: Whether this is an aggregate or scalar expression

§Example

use drizzle_core::expr::{Expr, NonNull, Scalar};
use drizzle_core::types::Int;

// i32 literals are Int, NonNull, Scalar
fn check_expr<'a, V, E: Expr<'a, V>>() {}
check_expr::<_, i32>(); // SQLType=Int, Nullable=NonNull, Aggregate=Scalar

Required Associated Types§

Source

type SQLType: DataType

The SQL data type this expression evaluates to.

Source

type Nullable: Nullability

Whether this expression can be NULL.

Source

type Aggregate: AggregateKind

Whether this is an aggregate (COUNT, SUM) or scalar expression.

Provided Methods§

Source

fn to_expr_sql(&self) -> SQL<'a, V>

Render this value as a scalar expression by reference.

Most expressions use their ToSQL implementation. A few Rust container types, notably byte buffers, need expression-specific rendering because their generic ToSQL form is a comma-separated list.

Source

fn into_expr_sql(self) -> SQL<'a, V>
where Self: Sized,

Render this value as a scalar expression, consuming it when useful.

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, T> Expr<'a, V> for &T
where V: SQLParam + 'a, T: Expr<'a, V>, T::Nullable: Nullability,

Source§

type SQLType = <T as Expr<'a, V>>::SQLType

Source§

type Nullable = <T as Expr<'a, V>>::Nullable

Source§

type Aggregate = <T as Expr<'a, V>>::Aggregate

Source§

fn to_expr_sql(&self) -> SQL<'a, V>

Source§

fn into_expr_sql(self) -> SQL<'a, V>

Source§

impl<'a, V, T> Expr<'a, V> for Option<T>
where V: SQLParam + 'a, T: Expr<'a, V>, T::Nullable: Nullability,

Source§

type SQLType = <T as Expr<'a, V>>::SQLType

Source§

type Nullable = Null

Source§

type Aggregate = <T as Expr<'a, V>>::Aggregate

Source§

impl<'a, V, const N: usize> Expr<'a, V> for [u8; N]
where V: SQLParam + 'a + From<&'a [u8]> + From<Vec<u8>> + From<u8> + Into<Cow<'a, V>>,

Source§

impl<'a, V> Expr<'a, V> for &'a [u8]
where V: SQLParam + 'a + From<&'a [u8]> + From<Vec<u8>> + From<u8> + Into<Cow<'a, V>>,

Source§

impl<'a, V> Expr<'a, V> for &'a str
where V: SQLParam + 'a + From<&'a str> + Into<Cow<'a, V>>,

Source§

impl<'a, V> Expr<'a, V> for Cow<'a, [u8]>
where V: SQLParam + 'a + From<&'a [u8]> + From<Vec<u8>> + Into<Cow<'a, V>>,

Source§

impl<'a, V> Expr<'a, V> for String
where V: SQLParam + 'a + From<Self> + Into<Cow<'a, V>>,

Source§

impl<'a, V> Expr<'a, V> for Vec<u8>
where V: SQLParam + 'a + From<&'a [u8]> + From<Vec<u8>> + From<u8> + Into<Cow<'a, V>>,

Source§

impl<'a, V> Expr<'a, V> for bool
where V: SQLParam + 'a + From<Self> + Into<Cow<'a, V>>,

Source§

impl<'a, V> Expr<'a, V> for f32
where V: SQLParam + 'a + From<Self> + Into<Cow<'a, V>>,

Source§

impl<'a, V> Expr<'a, V> for f64
where V: SQLParam + 'a + From<Self> + Into<Cow<'a, V>>,

Source§

impl<'a, V> Expr<'a, V> for i8
where V: SQLParam + 'a + From<Self> + Into<Cow<'a, V>>,

Source§

impl<'a, V> Expr<'a, V> for i16
where V: SQLParam + 'a + From<Self> + Into<Cow<'a, V>>,

Source§

impl<'a, V> Expr<'a, V> for i32
where V: SQLParam + 'a + From<Self> + Into<Cow<'a, V>>,

Source§

impl<'a, V> Expr<'a, V> for i64
where V: SQLParam + 'a + From<Self> + Into<Cow<'a, V>>,

Source§

impl<'a, V> Expr<'a, V> for isize
where V: SQLParam + 'a + From<Self> + Into<Cow<'a, V>>,

Source§

impl<'a, V> Expr<'a, V> for u8
where V: SQLParam + 'a + From<Self> + Into<Cow<'a, V>>,

Source§

impl<'a, V> Expr<'a, V> for u16
where V: SQLParam + 'a + From<Self> + Into<Cow<'a, V>>,

Source§

impl<'a, V> Expr<'a, V> for u32
where V: SQLParam + 'a + From<Self> + Into<Cow<'a, V>>,

Source§

impl<'a, V> Expr<'a, V> for u64
where V: SQLParam + 'a + From<Self> + Into<Cow<'a, V>>,

Source§

impl<'a, V> Expr<'a, V> for usize
where V: SQLParam + 'a + From<Self> + Into<Cow<'a, V>>,

Implementors§

Source§

impl<'a, V, C> Expr<'a, V> for Excluded<C>
where V: SQLParam + 'a, C: Expr<'a, V> + SQLColumnInfo,

Source§

type SQLType = <C as Expr<'a, V>>::SQLType

Source§

type Nullable = <C as Expr<'a, V>>::Nullable

Source§

type Aggregate = <C as Expr<'a, V>>::Aggregate

Source§

impl<'a, V, E> Expr<'a, V> for AliasedExpr<E>
where V: SQLParam + 'a, E: Expr<'a, V>,

Source§

type SQLType = <E as Expr<'a, V>>::SQLType

Source§

type Nullable = <E as Expr<'a, V>>::Nullable

Source§

type Aggregate = <E as Expr<'a, V>>::Aggregate

Source§

impl<'a, V: SQLParam + 'a, T: DataType, N: Nullability> Expr<'a, V> for TypedPlaceholder<T, N>

Source§

impl<'a, V: SQLParam + 'a> Expr<'a, V> for Placeholder

Source§

impl<'a, V: SQLParam, T: DataType, N: Nullability, A: AggregateKind> Expr<'a, V> for SQLExpr<'a, V, T, N, A>

Source§

impl<'a, V> Expr<'a, V> for SQL<'a, V>
where V: SQLParam + 'a,

Source§

impl<'a, V> Expr<'a, V> for SQLBytes<'a>
where V: SQLParam + 'a + From<&'a [u8]> + From<Vec<u8>> + Into<Cow<'a, V>>,