pub struct SqlFragment { /* private fields */ }Expand description
A SQL fragment with its associated parameters.
This is the core type for building SQL queries safely. It maintains a SQL string with parameter placeholders ($1, $2, etc.) and a vector of parameter values.
Implementations§
Source§impl SqlFragment
impl SqlFragment
Sourcepub fn raw(sql: impl Into<String>) -> Self
pub fn raw(sql: impl Into<String>) -> Self
Create a SQL fragment from raw SQL (no parameters).
§Warning
Only use this for known-safe SQL strings (e.g., keywords, operators). Never use this with user input.
Sourcepub fn param(value: impl Into<SqlParam>) -> Self
pub fn param(value: impl Into<SqlParam>) -> Self
Create a SQL fragment with a single parameter.
Sourcepub fn param_count(&self) -> usize
pub fn param_count(&self) -> usize
Get the current parameter count.
Sourcepub fn push_param(&mut self, value: impl Into<SqlParam>) -> &mut Self
pub fn push_param(&mut self, value: impl Into<SqlParam>) -> &mut Self
Push a parameter and its placeholder.
Sourcepub fn push_typed_param(
&mut self,
value: impl Into<SqlParam>,
pg_type: &str,
) -> &mut Self
pub fn push_typed_param( &mut self, value: impl Into<SqlParam>, pg_type: &str, ) -> &mut Self
Push a typed parameter with explicit cast.
Sourcepub fn append(&mut self, other: SqlFragment) -> &mut Self
pub fn append(&mut self, other: SqlFragment) -> &mut Self
Append another SQL fragment.
This renumbers the parameters in the appended fragment to continue from the current count.
Sourcepub fn append_sep(&mut self, sep: &str, other: SqlFragment) -> &mut Self
pub fn append_sep(&mut self, sep: &str, other: SqlFragment) -> &mut Self
Append with a separator if not empty.
Sourcepub fn join(sep: &str, fragments: impl IntoIterator<Item = SqlFragment>) -> Self
pub fn join(sep: &str, fragments: impl IntoIterator<Item = SqlFragment>) -> Self
Join multiple fragments with a separator.
Trait Implementations§
Source§impl Clone for SqlFragment
impl Clone for SqlFragment
Source§fn clone(&self) -> SqlFragment
fn clone(&self) -> SqlFragment
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§impl Debug for SqlFragment
impl Debug for SqlFragment
Source§impl Default for SqlFragment
impl Default for SqlFragment
Source§fn default() -> SqlFragment
fn default() -> SqlFragment
Returns the “default value” for a type. Read more
Source§impl SqlBuilder for SqlFragment
impl SqlBuilder for SqlFragment
Source§fn build_sql(&self) -> SqlFragment
fn build_sql(&self) -> SqlFragment
Build the SQL fragment for this type.
Auto Trait Implementations§
impl Freeze for SqlFragment
impl RefUnwindSafe for SqlFragment
impl Send for SqlFragment
impl Sync for SqlFragment
impl Unpin for SqlFragment
impl UnwindSafe for SqlFragment
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
Mutably borrows from an owned value. Read more