SQLExpr

Struct SQLExpr 

Source
pub struct SQLExpr<'a, V: SQLParam, T: DataType, N: Nullability = NonNull, A: AggregateKind = Scalar> { /* private fields */ }
Expand description

A SQL expression that carries type information.

This wrapper preserves the SQL type through operations, enabling compile-time type checking of SQL expressions.

§Type Parameters

  • 'a: Lifetime of borrowed data
  • V: The dialect’s value type (SQLiteValue, PostgresValue)
  • T: The SQL data type marker (Int, Text, etc.)
  • N: The nullability marker (NonNull or Null)
  • A: The aggregation marker (Scalar or Agg)

§Example

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

let expr: SQLExpr<'_, SQLiteValue, Int, NonNull, Scalar> = ...;

Implementations§

Source§

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

Source

pub fn new(sql: SQL<'a, V>) -> Self

Create a new typed expression from raw SQL.

Source

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

Consume the wrapper and return the inner SQL.

Source

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

Get a reference to the inner SQL.

Methods from Deref<Target = SQL<'a, V>>§

Source

pub fn is_subquery(&self) -> bool

Check if this SQL fragment is a subquery (starts with SELECT)

Source

pub fn sql(&self) -> String

Returns the SQL string with dialect-appropriate placeholders Uses $1, $2, ... for PostgreSQL, ? for SQLite/MySQL

Source

pub fn write_to(&self, buf: &mut impl Write)

Write SQL to a buffer with dialect-appropriate placeholders Uses $1, $2, ... for PostgreSQL, ? or :name for SQLite, ? for MySQL Named placeholders use :name syntax only for SQLite; PostgreSQL always uses $N

Source

pub fn write_chunk_to( &self, buf: &mut impl Write, chunk: &SQLChunk<'a, V>, index: usize, )

Write a single chunk with pattern detection

Source

pub fn write_qualified_columns( &self, buf: &mut impl Write, table: &dyn SQLTableInfo, )

Write fully qualified columns

Source

pub fn params(&self) -> impl Iterator<Item = &V>

Returns an iterator over references to parameter values (avoids allocating a Vec - callers can collect if needed)

Trait Implementations§

Source§

impl<'a, V, T, N, A, Rhs> Add<Rhs> for SQLExpr<'a, V, T, N, A>
where V: SQLParam + 'a, T: ArithmeticOutput<Rhs::SQLType>, N: Nullability + NullOr<Rhs::Nullable>, A: AggregateKind, Rhs: Expr<'a, V>, Rhs::SQLType: Numeric, Rhs::Nullable: Nullability,

Source§

type Output = SQLExpr<'a, V, <T as ArithmeticOutput<<Rhs as Expr<'a, V>>::SQLType>>::Output, <N as NullOr<<Rhs as Expr<'a, V>>::Nullable>>::Output>

The resulting type after applying the + operator.
Source§

fn add(self, rhs: Rhs) -> Self::Output

Performs the + operation. Read more
Source§

impl<'a, V, T, N, A> AsRef<SQL<'a, V>> for SQLExpr<'a, V, T, N, A>

Provides reference conversion to inner SQL.

§Example

fn takes_sql_ref<'a, V>(sql: &SQL<'a, V>) { ... }
let expr = eq(users.id, 42);
takes_sql_ref(expr.as_ref());
Source§

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

Converts this type into a shared reference of the (usually inferred) input type.
Source§

impl<'a, V, N, A, Rhs> BitAnd<Rhs> for SQLExpr<'a, V, Bool, N, A>
where V: SQLParam + 'a, N: Nullability, A: AggregateKind, Rhs: Expr<'a, V>,

Implements expr1 & expr2 for boolean expressions (SQL AND).

§Example

let condition = eq(users.active, true) & gt(users.age, 18);
// ("users"."active" = TRUE AND "users"."age" > 18)
Source§

type Output = SQLExpr<'a, V, Bool>

The resulting type after applying the & operator.
Source§

fn bitand(self, rhs: Rhs) -> Self::Output

Performs the & operation. Read more
Source§

impl<'a, V, N, A, Rhs> BitOr<Rhs> for SQLExpr<'a, V, Bool, N, A>
where V: SQLParam + 'a, N: Nullability, A: AggregateKind, Rhs: Expr<'a, V>,

Implements expr1 | expr2 for boolean expressions (SQL OR).

§Example

let condition = eq(users.role, "admin") | eq(users.role, "moderator");
// ("users"."role" = 'admin' OR "users"."role" = 'moderator')
Source§

type Output = SQLExpr<'a, V, Bool>

The resulting type after applying the | operator.
Source§

fn bitor(self, rhs: Rhs) -> Self::Output

Performs the | operation. Read more
Source§

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

Source§

fn clone(&self) -> SQLExpr<'a, V, T, N, A>

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

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

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<'a, V, T, N, A> Deref for SQLExpr<'a, V, T, N, A>

Provides transparent access to inner SQL methods via Deref coercion.

§Example

let expr = eq(users.id, 42);
// Access SQL methods directly:
let sql_str = expr.to_string();
Source§

type Target = SQL<'a, V>

The resulting type after dereferencing.
Source§

fn deref(&self) -> &Self::Target

Dereferences the value.
Source§

impl<'a, V, T, N, A> Display for SQLExpr<'a, V, T, N, A>

Display the SQL expression as a string.

Delegates to the inner SQL type’s Display implementation.

§Example

let expr = eq(users.id, 42);
println!("{}", expr);  // "users"."id" = 42
Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<'a, V, T, N, A, Rhs> Div<Rhs> for SQLExpr<'a, V, T, N, A>
where V: SQLParam + 'a, T: ArithmeticOutput<Rhs::SQLType>, N: Nullability + NullOr<Rhs::Nullable>, A: AggregateKind, Rhs: Expr<'a, V>, Rhs::SQLType: Numeric, Rhs::Nullable: Nullability,

Source§

type Output = SQLExpr<'a, V, <T as ArithmeticOutput<<Rhs as Expr<'a, V>>::SQLType>>::Output, <N as NullOr<<Rhs as Expr<'a, V>>::Nullable>>::Output>

The resulting type after applying the / operator.
Source§

fn div(self, rhs: Rhs) -> Self::Output

Performs the / operation. Read more
Source§

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

Source§

type SQLType = T

The SQL data type this expression evaluates to.
Source§

type Nullable = N

Whether this expression can be NULL.
Source§

type Aggregate = A

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

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

Source§

fn from(expr: SQLExpr<'a, V, T, N, A>) -> Self

Converts to this type from the input type.
Source§

impl<'a, V, T, N, A, Rhs> Mul<Rhs> for SQLExpr<'a, V, T, N, A>
where V: SQLParam + 'a, T: ArithmeticOutput<Rhs::SQLType>, N: Nullability + NullOr<Rhs::Nullable>, A: AggregateKind, Rhs: Expr<'a, V>, Rhs::SQLType: Numeric, Rhs::Nullable: Nullability,

Source§

type Output = SQLExpr<'a, V, <T as ArithmeticOutput<<Rhs as Expr<'a, V>>::SQLType>>::Output, <N as NullOr<<Rhs as Expr<'a, V>>::Nullable>>::Output>

The resulting type after applying the * operator.
Source§

fn mul(self, rhs: Rhs) -> Self::Output

Performs the * operation. Read more
Source§

impl<'a, V, T, N, A> Neg for SQLExpr<'a, V, T, N, A>
where V: SQLParam + 'a, T: Numeric, N: Nullability, A: AggregateKind,

Source§

type Output = SQLExpr<'a, V, T, N>

The resulting type after applying the - operator.
Source§

fn neg(self) -> Self::Output

Performs the unary - operation. Read more
Source§

impl<'a, V, N, A> Not for SQLExpr<'a, V, Bool, N, A>
where V: SQLParam + 'a, N: Nullability, A: AggregateKind,

Implements !expr for boolean expressions (SQL NOT).

§Example

let condition = eq(users.active, true);
let negated = !condition;  // NOT "users"."active" = TRUE
Source§

type Output = SQLExpr<'a, V, Bool>

The resulting type after applying the ! operator.
Source§

fn not(self) -> Self::Output

Performs the unary ! operation. Read more
Source§

impl<'a, V, T, N, A, Rhs> Rem<Rhs> for SQLExpr<'a, V, T, N, A>
where V: SQLParam + 'a, T: ArithmeticOutput<Rhs::SQLType>, N: Nullability + NullOr<Rhs::Nullable>, A: AggregateKind, Rhs: Expr<'a, V>, Rhs::SQLType: Numeric, Rhs::Nullable: Nullability,

Source§

type Output = SQLExpr<'a, V, <T as ArithmeticOutput<<Rhs as Expr<'a, V>>::SQLType>>::Output, <N as NullOr<<Rhs as Expr<'a, V>>::Nullable>>::Output>

The resulting type after applying the % operator.
Source§

fn rem(self, rhs: Rhs) -> Self::Output

Performs the % operation. Read more
Source§

impl<'a, V, T, N, A, Rhs> Sub<Rhs> for SQLExpr<'a, V, T, N, A>
where V: SQLParam + 'a, T: ArithmeticOutput<Rhs::SQLType>, N: Nullability + NullOr<Rhs::Nullable>, A: AggregateKind, Rhs: Expr<'a, V>, Rhs::SQLType: Numeric, Rhs::Nullable: Nullability,

Source§

type Output = SQLExpr<'a, V, <T as ArithmeticOutput<<Rhs as Expr<'a, V>>::SQLType>>::Output, <N as NullOr<<Rhs as Expr<'a, V>>::Nullable>>::Output>

The resulting type after applying the - operator.
Source§

fn sub(self, rhs: Rhs) -> Self::Output

Performs the - operation. Read more
Source§

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

Source§

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

Source§

fn alias(&self, alias: &'static str) -> SQL<'a, V>

Auto Trait Implementations§

§

impl<'a, V, T, N, A> Freeze for SQLExpr<'a, V, T, N, A>
where V: Freeze,

§

impl<'a, V, T, N = NonNull, A = Scalar> !RefUnwindSafe for SQLExpr<'a, V, T, N, A>

§

impl<'a, V, T, N, A> Send for SQLExpr<'a, V, T, N, A>
where T: Send, N: Send, A: Send, V: Send + Sync,

§

impl<'a, V, T, N, A> Sync for SQLExpr<'a, V, T, N, A>
where T: Sync, N: Sync, A: Sync, V: Sync,

§

impl<'a, V, T, N, A> Unpin for SQLExpr<'a, V, T, N, A>
where T: Unpin, N: Unpin, A: Unpin, V: Unpin,

§

impl<'a, V, T, N = NonNull, A = Scalar> !UnwindSafe for SQLExpr<'a, V, T, N, A>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

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

Source§

fn eq<R>(self, other: R) -> SQLExpr<'a, V, Bool, NonNull, Scalar>
where R: Expr<'a, V>, Self::SQLType: Compatible<R::SQLType>,

Equality comparison (=). Read more
Source§

fn ne<R>(self, other: R) -> SQLExpr<'a, V, Bool, NonNull, Scalar>
where R: Expr<'a, V>, Self::SQLType: Compatible<R::SQLType>,

Inequality comparison (<>). Read more
Source§

fn gt<R>(self, other: R) -> SQLExpr<'a, V, Bool, NonNull, Scalar>
where R: Expr<'a, V>, Self::SQLType: Compatible<R::SQLType>,

Greater-than comparison (>). Read more
Source§

fn ge<R>(self, other: R) -> SQLExpr<'a, V, Bool, NonNull, Scalar>
where R: Expr<'a, V>, Self::SQLType: Compatible<R::SQLType>,

Greater-than-or-equal comparison (>=). Read more
Source§

fn lt<R>(self, other: R) -> SQLExpr<'a, V, Bool, NonNull, Scalar>
where R: Expr<'a, V>, Self::SQLType: Compatible<R::SQLType>,

Less-than comparison (<). Read more
Source§

fn le<R>(self, other: R) -> SQLExpr<'a, V, Bool, NonNull, Scalar>
where R: Expr<'a, V>, Self::SQLType: Compatible<R::SQLType>,

Less-than-or-equal comparison (<=). Read more
Source§

fn like<R>(self, pattern: R) -> SQLExpr<'a, V, Bool, NonNull, Scalar>
where R: Expr<'a, V>, Self::SQLType: Textual, R::SQLType: Textual,

LIKE pattern matching. Read more
Source§

fn not_like<R>(self, pattern: R) -> SQLExpr<'a, V, Bool, NonNull, Scalar>
where R: Expr<'a, V>, Self::SQLType: Textual, R::SQLType: Textual,

NOT LIKE pattern matching. Read more
Source§

fn is_null(self) -> SQLExpr<'a, V, Bool, NonNull, Scalar>

IS NULL check. Read more
Source§

fn is_not_null(self) -> SQLExpr<'a, V, Bool, NonNull, Scalar>

IS NOT NULL check. Read more
Source§

fn between<L, H>(self, low: L, high: H) -> SQLExpr<'a, V, Bool, NonNull, Scalar>
where L: Expr<'a, V>, H: Expr<'a, V>, Self::SQLType: Compatible<L::SQLType> + Compatible<H::SQLType>,

BETWEEN comparison. Read more
Source§

fn not_between<L, H>( self, low: L, high: H, ) -> SQLExpr<'a, V, Bool, NonNull, Scalar>
where L: Expr<'a, V>, H: Expr<'a, V>, Self::SQLType: Compatible<L::SQLType> + Compatible<H::SQLType>,

NOT BETWEEN comparison. Read more
Source§

fn in_array<I, R>(self, values: I) -> SQLExpr<'a, V, Bool, NonNull, Scalar>
where I: IntoIterator<Item = R>, R: Expr<'a, V>, Self::SQLType: Compatible<R::SQLType>,

IN array check. Read more
Source§

fn not_in_array<I, R>(self, values: I) -> SQLExpr<'a, V, Bool, NonNull, Scalar>
where I: IntoIterator<Item = R>, R: Expr<'a, V>, Self::SQLType: Compatible<R::SQLType>,

NOT IN array check. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<P, T> Receiver for P
where P: Deref<Target = T> + ?Sized, T: ?Sized,

Source§

type Target = T

🔬This is a nightly-only experimental API. (arbitrary_self_types)
The target type on which the method may be called.
Source§

impl<T> ToCompactString for T
where T: Display,

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<'a, V, L, R> SQLComparable<'a, V, R> for L
where V: SQLParam + 'a, L: ToSQL<'a, V>, R: ToSQL<'a, V>,