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,
impl<'a, V> SQL<'a, V>where
V: SQLParam,
Sourcepub fn with_capacity_chunks(capacity: usize) -> SQL<'a, V>
pub fn with_capacity_chunks(capacity: usize) -> SQL<'a, V>
Creates an empty SQL fragment with pre-allocated chunk capacity.
Sourcepub fn param(value: impl Into<Cow<'a, V>>) -> SQL<'a, V>
pub fn param(value: impl Into<Cow<'a, V>>) -> SQL<'a, V>
Creates SQL with a single parameter value
Sourcepub fn bytes(bytes: impl Into<Cow<'a, [u8]>>) -> SQL<'a, V>
pub fn bytes(bytes: impl Into<Cow<'a, [u8]>>) -> SQL<'a, V>
Creates SQL with a binary parameter value (BLOB/bytea)
Prefer this over SQL::param(Vec<u8>) to avoid list semantics.
Sourcepub fn placeholder(name: &'static str) -> SQL<'a, V>
pub fn placeholder(name: &'static str) -> SQL<'a, V>
Creates SQL with a named placeholder (no value, for prepared statements)
Sourcepub fn table(table: &'static dyn SQLTableInfo) -> SQL<'a, V>
pub fn table(table: &'static dyn SQLTableInfo) -> SQL<'a, V>
Creates SQL referencing a table
Sourcepub fn column(column: &'static dyn SQLColumnInfo) -> SQL<'a, V>
pub fn column(column: &'static dyn SQLColumnInfo) -> SQL<'a, V>
Creates SQL referencing a column
Sourcepub fn func(name: &'static str, args: SQL<'a, V>) -> SQL<'a, V>
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 …))
Sourcepub fn append(self, other: impl Into<SQL<'a, V>>) -> SQL<'a, V>
pub fn append(self, other: impl Into<SQL<'a, V>>) -> SQL<'a, V>
Append another SQL fragment (flat extend)
Sourcepub fn with_capacity(self, additional: usize) -> SQL<'a, V>
pub fn with_capacity(self, additional: usize) -> SQL<'a, V>
Pre-allocates capacity for additional chunks
Sourcepub fn join<T>(sqls: T, separator: Token) -> SQL<'a, V>
pub fn join<T>(sqls: T, separator: Token) -> SQL<'a, V>
Joins multiple SQL fragments with a separator
Sourcepub fn is_subquery(&self) -> bool
pub fn is_subquery(&self) -> bool
Check if this SQL fragment is a subquery (starts with SELECT)
Sourcepub fn alias(self, name: impl Into<Cow<'a, str>>) -> SQL<'a, V>
pub fn alias(self, name: impl Into<Cow<'a, str>>) -> SQL<'a, V>
Creates an aliased version: self AS “name”
Sourcepub fn param_list<I>(values: I) -> SQL<'a, V>
pub fn param_list<I>(values: I) -> SQL<'a, V>
Creates a comma-separated list of parameters
Sourcepub fn assignments<I, T>(pairs: I) -> SQL<'a, V>
pub fn assignments<I, T>(pairs: I) -> SQL<'a, V>
Creates a comma-separated list of column assignments: “col” = ?
Sourcepub fn into_owned(self) -> OwnedSQL<V>
pub fn into_owned(self) -> OwnedSQL<V>
Converts to owned version (consuming self to avoid clone)
Sourcepub fn sql(&self) -> String
pub fn sql(&self) -> String
Returns the SQL string with dialect-appropriate placeholders
Uses $1, $2, ... for PostgreSQL, ? for SQLite/MySQL
Sourcepub fn write_to(&self, buf: &mut impl Write)
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
Sourcepub fn write_chunk_to(
&self,
buf: &mut impl Write,
chunk: &SQLChunk<'a, V>,
index: usize,
)
pub fn write_chunk_to( &self, buf: &mut impl Write, chunk: &SQLChunk<'a, V>, index: usize, )
Write a single chunk with pattern detection
Sourcepub fn write_qualified_columns(
&self,
buf: &mut impl Write,
table: &(dyn SQLTableInfo + 'static),
)
pub fn write_qualified_columns( &self, buf: &mut impl Write, table: &(dyn SQLTableInfo + 'static), )
Write fully qualified columns
Sourcepub fn params(&self) -> impl Iterator<Item = &V>
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> From<OwnedSQLiteValue> for SQL<'a, OwnedSQLiteValue>
impl<'a> From<OwnedSQLiteValue> for SQL<'a, OwnedSQLiteValue>
Source§fn from(value: OwnedSQLiteValue) -> Self
fn from(value: OwnedSQLiteValue) -> Self
Source§impl<'a> From<SQLiteValue<'a>> for SQL<'a, SQLiteValue<'a>>
impl<'a> From<SQLiteValue<'a>> for SQL<'a, SQLiteValue<'a>>
Source§fn from(value: SQLiteValue<'a>) -> Self
fn from(value: SQLiteValue<'a>) -> Self
Source§impl<'a, V, T> FromIterator<T> for SQL<'a, V>
impl<'a, V, T> FromIterator<T> for SQL<'a, V>
Source§impl<'a, V> IntoIterator for SQL<'a, V>where
V: SQLParam,
impl<'a, V> IntoIterator for SQL<'a, V>where
V: SQLParam,
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>
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> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<'a, V, E> ExprExt<'a, V> for E
impl<'a, V, E> ExprExt<'a, V> for E
Source§fn ge<R>(self, other: R) -> SQLExpr<'a, V, Bool>
fn ge<R>(self, other: R) -> SQLExpr<'a, V, Bool>
>=). Read moreSource§fn le<R>(self, other: R) -> SQLExpr<'a, V, Bool>
fn le<R>(self, other: R) -> SQLExpr<'a, V, Bool>
<=). Read moreSource§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>,
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>,
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>,
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>,
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>,
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>,
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>,
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>,
Source§impl<T> ToCompactString for Twhere
T: Display,
impl<T> ToCompactString for Twhere
T: Display,
Source§fn try_to_compact_string(&self) -> Result<CompactString, ToCompactStringError>
fn try_to_compact_string(&self) -> Result<CompactString, ToCompactStringError>
ToCompactString::to_compact_string() Read moreSource§fn to_compact_string(&self) -> CompactString
fn to_compact_string(&self) -> CompactString
CompactString. Read more