SQL

Struct SQL 

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

A SQL statement or fragment with parameters.

This type is used to build SQL statements with proper parameter handling. It keeps track of both the SQL text and the parameters to be bound.

Fields§

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

The chunks that make up this SQL statement or fragment.

Implementations§

Source§

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

Source

pub const fn new<'b>(chunks: [SQLChunk<'b, V>; 3]) -> SQL<'b, V>

Source

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

Creates a new empty SQL fragment.

Source

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

Source

pub const fn text(text: &'static str) -> Self

Helper to create const SQL

Source

pub const fn wildcard() -> Self

Creates a wildcard SELECT fragment: “*”

Source

pub const fn null() -> Self

Creates a NULL SQL fragment

Source

pub const fn true() -> Self

Creates a TRUE SQL fragment

Source

pub const fn false() -> Self

Creates a FALSE SQL fragment

Source

pub fn raw<T: AsRef<str>>(sql: T) -> Self

Creates a new SQL fragment from a raw string.

The string is treated as literal SQL text, not a parameter.

Source

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

Creates a new SQL fragment representing a parameter.

A default positional placeholder (‘?’) is used, and the provided value is stored for later binding. Accepts both owned and borrowed values.

Source

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

Creates a new SQL fragment representing a table.

Source

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

Source

pub fn placeholder(name: &'static str) -> Self
where V: Default,

Creates a named placeholder without a value - for use in query building. Similar to drizzle-orm’s sql.placeholder(‘name’). The value will be bound later during execution.

Source

pub fn placeholder_with_style( name: &'static str, style: PlaceholderStyle, ) -> Self
where V: Default,

Creates a named placeholder with a specific style.

Source

pub fn from_placeholder(placeholder: Placeholder) -> Self
where V: Default,

Creates SQL from an existing Placeholder struct.

Source

pub fn append_raw(self, sql: impl AsRef<str>) -> Self

Appends a raw string to this SQL fragment.

The string is treated as literal SQL text, not a parameter.

Source

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

Appends another SQL fragment to this one.

Both the SQL text and parameters are merged.

Source

pub fn with_capacity(self, additional: usize) -> Self

Pre-allocates capacity for additional chunks.

Source

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

Joins multiple SQL fragments with a separator.

The separator is inserted between each fragment, but not before the first or after the last.

Source

pub fn sql(&self) -> String

Returns the SQL string represented by this SQL fragment, using placeholders for parameters.

Source

pub fn bind( self, params: impl IntoIterator<Item = ParamBind<'a, V>>, ) -> SQL<'a, V>

Source

pub fn params(&self) -> Vec<&V>

Returns references to parameter values from this SQL fragment in the correct order.

Source

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

Creates an aliased version of this SQL using the Alias chunk

Source

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

Wraps this SQL as a subquery

Source

pub fn parameters<I>(values: I) -> Self
where I: IntoIterator, I::Item: Into<Cow<'a, V>>,

Creates a comma-separated list of parameter placeholders with values: “?, ?, ?”

Source

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

Creates a comma-separated list of column assignments: “col1 = ?, col2 = ?”

Trait Implementations§

Source§

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

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

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

Source§

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

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

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

Source§

fn default() -> Self

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

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

Source§

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

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

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

Source§

fn from(value: &T) -> Self

Converts to this type from the input type.
Source§

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

Source§

fn from(s: &'a str) -> Self

Converts to this type from the input type.
Source§

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

Source§

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

Converts to this type from the input type.
Source§

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

Source§

type Item = SQLChunk<'a, V>

The type of the elements being iterated over.
Source§

type IntoIter = FlatMap<IntoIter<[SQLChunk<'a, V>; 3]>, Box<dyn Iterator<Item = SQLChunk<'a, V>> + 'a>, fn(SQLChunk<'a, V>) -> Box<dyn Iterator<Item = SQLChunk<'a, V>> + 'a>>

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

fn into_iter(self) -> Self::IntoIter

Creates an iterator from a value. Read more
Source§

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

Source§

fn to_sql(&self) -> 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<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> + Into<V>,