SQL

Struct SQL 

Source
pub struct SQL<'a, V>
where V: SQLParam,
{ pub chunks: SmallVec<[SQLChunk<'a, V>; 8]>, }
Expand description

SQL fragment builder with flat chunk storage.

Uses SmallVec<[SQLChunk; 8]> for inline storage of typical SQL fragments without heap allocation.

Fields§

§chunks: SmallVec<[SQLChunk<'a, V>; 8]>

Implementations§

Source§

impl<'a, V> SQL<'a, V>
where V: SQLParam,

Source

pub const fn empty() -> SQL<'a, V>

Creates an empty SQL fragment

Source

pub fn token(t: Token) -> SQL<'a, V>

Creates SQL with a single token

Source

pub fn with_capacity_chunks(capacity: usize) -> SQL<'a, V>

Creates an empty SQL fragment with pre-allocated chunk capacity.

Source

pub fn ident(name: impl Into<Cow<'a, str>>) -> SQL<'a, V>

Creates SQL with a quoted identifier

Source

pub fn raw(text: impl Into<Cow<'a, str>>) -> SQL<'a, V>

Creates SQL with raw text (unquoted)

Source

pub fn param(value: impl Into<Cow<'a, V>>) -> SQL<'a, V>

Creates SQL with a single parameter value

Source

pub fn bytes(bytes: impl Into<Cow<'a, [u8]>>) -> SQL<'a, V>
where V: From<&'a [u8]> + From<Vec<u8>> + Into<Cow<'a, V>>,

Creates SQL with a binary parameter value (BLOB/bytea)

Prefer this over SQL::param(Vec<u8>) to avoid list semantics.

Source

pub fn placeholder(name: &'static str) -> SQL<'a, V>

Creates SQL with a named placeholder (no value, for prepared statements)

Source

pub fn table(table: &'static dyn SQLTableInfo) -> SQL<'a, V>

Creates SQL referencing a table

Source

pub fn column(column: &'static dyn SQLColumnInfo) -> SQL<'a, V>

Creates SQL referencing a column

Source

pub fn func(name: &'static str, args: SQL<'a, V>) -> SQL<'a, V>

Creates SQL for a function call: NAME(args) Subqueries are automatically wrapped in parentheses: NAME((SELECT …))

Source

pub fn append(self, other: impl Into<SQL<'a, V>>) -> SQL<'a, V>

Append another SQL fragment (flat extend)

Source

pub fn push(self, chunk: impl Into<SQLChunk<'a, V>>) -> SQL<'a, V>

Push a single chunk

Source

pub fn with_capacity(self, additional: usize) -> SQL<'a, V>

Pre-allocates capacity for additional chunks

Source

pub fn join<T>(sqls: T, separator: Token) -> SQL<'a, V>
where T: IntoIterator, <T as IntoIterator>::Item: ToSQL<'a, V>,

Joins multiple SQL fragments with a separator

Source

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

Wrap in parentheses: (self)

Source

pub fn is_subquery(&self) -> bool

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

Source

pub fn alias(self, name: impl Into<Cow<'a, str>>) -> SQL<'a, V>

Creates an aliased version: self AS “name”

Source

pub fn param_list<I>(values: I) -> SQL<'a, V>
where I: IntoIterator, <I as IntoIterator>::Item: Into<Cow<'a, V>>,

Creates a comma-separated list of parameters

Source

pub fn assignments<I, T>(pairs: I) -> SQL<'a, V>
where I: IntoIterator<Item = (&'static str, T)>, T: Into<Cow<'a, V>>,

Creates a comma-separated list of column assignments: “col” = ?

Source

pub fn into_owned(self) -> OwnedSQL<V>

Converts to owned version (consuming self to avoid clone)

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 + 'static), )

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)

Source

pub fn bind<T>( self, params: impl IntoIterator>>, ) -> SQL<'a, V>
where T: SQLParam + Into<V>, <impl IntoIterator as IntoIterator>::Item: Into<ParamBind<'a, T>>,

Bind named parameters

Trait Implementations§

Source§

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

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> Clone for SQL<'a, V>
where V: Clone + SQLParam,

Source§

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

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 for SQL<'a, V>
where V: Debug + SQLParam,

Source§

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

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

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

Source§

fn default() -> SQL<'a, V>

Returns the “default value” for a type. Read more
Source§

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

Source§

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

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

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

Source§

type SQLType = Any

The SQL data type this expression evaluates to.
Source§

type Nullable = Null

Whether this expression can be NULL.
Source§

type Aggregate = Scalar

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

impl<'a, T, V> From<&T> for SQL<'a, V>
where T: ToSQL<'a, V>, V: SQLParam,

Source§

fn from(value: &T) -> SQL<'a, V>

Converts to this type from the input type.
Source§

impl<'a, V> From<&'a str> for SQL<'a, V>
where V: SQLParam + 'a,

Source§

fn from(s: &'a str) -> SQL<'a, V>

Converts to this type from the input type.
Source§

impl<'a> From<OwnedPostgresValue> for SQL<'a, OwnedPostgresValue>

Source§

fn from(value: OwnedPostgresValue) -> Self

Converts to this type from the input type.
Source§

impl<'a> From<PostgresValue<'a>> for SQL<'a, PostgresValue<'a>>

Source§

fn from(value: PostgresValue<'a>) -> Self

Converts to this type from the input type.
Source§

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

Source§

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

Converts to this type from the input type.
Source§

impl<'a, V> From<Token> for SQL<'a, V>
where V: SQLParam,

Source§

fn from(value: Token) -> SQL<'a, V>

Converts to this type from the input type.
Source§

impl<'a, V, T> FromIterator<T> for SQL<'a, V>
where V: SQLParam, SQLChunk<'a, V>: From<T>,

Source§

fn from_iter<I>(iter: I) -> SQL<'a, V>
where I: IntoIterator<Item = T>,

Creates a value from an iterator. Read more
Source§

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

Source§

type Item = SQLChunk<'a, V>

The type of the elements being iterated over.
Source§

type IntoIter = IntoIter<[SQLChunk<'a, V>; 8]>

Which kind of iterator are we turning this into?
Source§

fn into_iter(self) -> <SQL<'a, V> as IntoIterator>::IntoIter

Creates an iterator from a value. Read more
Source§

impl<'a, V> ToSQL<'a, V> for SQL<'a, V>
where V: SQLParam + '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> Freeze for SQL<'a, V>
where V: Freeze,

§

impl<'a, V> !RefUnwindSafe for SQL<'a, V>

§

impl<'a, V> Send for SQL<'a, V>
where V: Send + Sync,

§

impl<'a, V> Sync for SQL<'a, V>
where V: Sync,

§

impl<'a, V> Unpin for SQL<'a, V>
where V: Unpin,

§

impl<'a, V> !UnwindSafe for SQL<'a, V>

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>
where R: Expr<'a, V>, Self::SQLType: Compatible<<R as Expr<'a, V>>::SQLType>,

Equality comparison (=). Read more
Source§

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

Inequality comparison (<>). Read more
Source§

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

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

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

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

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

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

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

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

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

LIKE pattern matching. Read more
Source§

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

NOT LIKE pattern matching. Read more
Source§

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

IS NULL check. Read more
Source§

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

IS NOT NULL check. Read more
Source§

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

BETWEEN comparison. Read more
Source§

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

NOT BETWEEN comparison. Read more
Source§

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

IN array check. Read more
Source§

fn not_in_array<I, R>(self, values: I) -> SQLExpr<'a, V, Bool>
where I: IntoIterator<Item = R>, R: Expr<'a, V>, Self::SQLType: Compatible<<R as Expr<'a, V>>::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<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>,