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 const fn raw_const(text: &'static str) -> SQL<'a, V>

Creates SQL with raw text at const time.

Source

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

Creates SQL with a single token

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 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: impl Into<Cow<'a, 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>

Source

pub fn sql(&self) -> String

Returns the SQL string

Source

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

Write SQL to a buffer

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) -> Vec<&V>

Returns references to parameter values

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, 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<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> From<SQL<'a, PostgresValue<'a>>> for PostgresValue<'a>

Source§

fn from(_value: SQL<'a, PostgresValue<'a>>) -> Self

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<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<'a, T> ToPostgresSQL<'a> for T
where T: ToSQL<'a, PostgresValue<'a>>,

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>,