pub struct ChainBuilder { /* private fields */ }
Expand description
Main query builder for constructing SQL queries
This is the primary interface for building SQL queries with a fluent API. It supports all major SQL operations including SELECT, INSERT, UPDATE, DELETE, as well as complex features like JOINs, CTEs, and subqueries.
Implementations§
Source§impl ChainBuilder
impl ChainBuilder
Sourcepub fn new(client: Client) -> ChainBuilder
pub fn new(client: Client) -> ChainBuilder
Create a new ChainBuilder with the specified client
Sourcepub fn new_mysql() -> ChainBuilder
pub fn new_mysql() -> ChainBuilder
Create a new ChainBuilder for MySQL
Sourcepub fn db(&mut self, db: &str) -> &mut ChainBuilder
pub fn db(&mut self, db: &str) -> &mut ChainBuilder
Set the database name
Sourcepub fn table(&mut self, table: &str) -> &mut ChainBuilder
pub fn table(&mut self, table: &str) -> &mut ChainBuilder
Set the table name
Sourcepub fn table_raw(
&mut self,
table: &str,
val: Option<Vec<Value>>,
) -> &mut ChainBuilder
pub fn table_raw( &mut self, table: &str, val: Option<Vec<Value>>, ) -> &mut ChainBuilder
Set a raw table expression
Sourcepub fn distinct(&mut self) -> &mut ChainBuilder
pub fn distinct(&mut self) -> &mut ChainBuilder
Enable DISTINCT
Sourcepub fn select(&mut self, select: Select) -> &mut ChainBuilder
pub fn select(&mut self, select: Select) -> &mut ChainBuilder
Add a SELECT clause
Sourcepub fn select_raw(
&mut self,
sql: &str,
binds: Option<Vec<Value>>,
) -> &mut ChainBuilder
pub fn select_raw( &mut self, sql: &str, binds: Option<Vec<Value>>, ) -> &mut ChainBuilder
Add a raw SELECT expression
Sourcepub fn select_distinct(&mut self, columns: Vec<String>) -> &mut ChainBuilder
pub fn select_distinct(&mut self, columns: Vec<String>) -> &mut ChainBuilder
Add DISTINCT SELECT
Sourcepub fn select_count(&mut self, column: &str) -> &mut ChainBuilder
pub fn select_count(&mut self, column: &str) -> &mut ChainBuilder
Add COUNT aggregate function
Sourcepub fn select_sum(&mut self, column: &str) -> &mut ChainBuilder
pub fn select_sum(&mut self, column: &str) -> &mut ChainBuilder
Add SUM aggregate function
Sourcepub fn select_avg(&mut self, column: &str) -> &mut ChainBuilder
pub fn select_avg(&mut self, column: &str) -> &mut ChainBuilder
Add AVG aggregate function
Sourcepub fn select_max(&mut self, column: &str) -> &mut ChainBuilder
pub fn select_max(&mut self, column: &str) -> &mut ChainBuilder
Add MAX aggregate function
Sourcepub fn select_min(&mut self, column: &str) -> &mut ChainBuilder
pub fn select_min(&mut self, column: &str) -> &mut ChainBuilder
Add MIN aggregate function
Sourcepub fn select_alias(&mut self, column: &str, alias: &str) -> &mut ChainBuilder
pub fn select_alias(&mut self, column: &str, alias: &str) -> &mut ChainBuilder
Add SELECT with alias
Sourcepub fn insert(&mut self, data: Value) -> &mut ChainBuilder
pub fn insert(&mut self, data: Value) -> &mut ChainBuilder
Set INSERT data
Sourcepub fn insert_many(&mut self, data: Vec<Value>) -> &mut ChainBuilder
pub fn insert_many(&mut self, data: Vec<Value>) -> &mut ChainBuilder
Set INSERT multiple rows data
Sourcepub fn update(&mut self, data: Value) -> &mut ChainBuilder
pub fn update(&mut self, data: Value) -> &mut ChainBuilder
Set UPDATE data
Sourcepub fn insert_ignore(&mut self, data: Value) -> &mut ChainBuilder
pub fn insert_ignore(&mut self, data: Value) -> &mut ChainBuilder
Add INSERT IGNORE (MySQL)
Sourcepub fn insert_or_update(
&mut self,
data: Value,
_update_data: Value,
) -> &mut ChainBuilder
pub fn insert_or_update( &mut self, data: Value, _update_data: Value, ) -> &mut ChainBuilder
Add UPSERT (INSERT … ON DUPLICATE KEY UPDATE)
Sourcepub fn update_raw(
&mut self,
_sql: &str,
_binds: Option<Vec<Value>>,
) -> &mut ChainBuilder
pub fn update_raw( &mut self, _sql: &str, _binds: Option<Vec<Value>>, ) -> &mut ChainBuilder
Add raw UPDATE statement
Sourcepub fn increment(&mut self, column: &str, amount: i64) -> &mut ChainBuilder
pub fn increment(&mut self, column: &str, amount: i64) -> &mut ChainBuilder
Increment a column value
Sourcepub fn decrement(&mut self, column: &str, amount: i64) -> &mut ChainBuilder
pub fn decrement(&mut self, column: &str, amount: i64) -> &mut ChainBuilder
Decrement a column value
Sourcepub fn delete(&mut self) -> &mut ChainBuilder
pub fn delete(&mut self) -> &mut ChainBuilder
Set DELETE operation
Sourcepub fn as_name(&mut self, name: &str) -> &mut ChainBuilder
pub fn as_name(&mut self, name: &str) -> &mut ChainBuilder
Set table alias
Sourcepub fn with(
&mut self,
alias: &str,
chain_builder: ChainBuilder,
) -> &mut ChainBuilder
pub fn with( &mut self, alias: &str, chain_builder: ChainBuilder, ) -> &mut ChainBuilder
Add a WITH clause (CTE)
Sourcepub fn with_recursive(
&mut self,
alias: &str,
chain_builder: ChainBuilder,
) -> &mut ChainBuilder
pub fn with_recursive( &mut self, alias: &str, chain_builder: ChainBuilder, ) -> &mut ChainBuilder
Add a recursive WITH clause (CTE)
Sourcepub fn union(&mut self, chain_builder: ChainBuilder) -> &mut ChainBuilder
pub fn union(&mut self, chain_builder: ChainBuilder) -> &mut ChainBuilder
Add a UNION clause
Sourcepub fn union_all(&mut self, chain_builder: ChainBuilder) -> &mut ChainBuilder
pub fn union_all(&mut self, chain_builder: ChainBuilder) -> &mut ChainBuilder
Add a UNION ALL clause
Sourcepub fn query(&mut self, query: impl FnOnce(&mut QueryBuilder))
pub fn query(&mut self, query: impl FnOnce(&mut QueryBuilder))
Configure query parts (WHERE, JOIN, etc.)
Source§impl ChainBuilder
impl ChainBuilder
pub fn to_sqlx_query(&mut self) -> Query<'_, MySql, MySqlArguments>
pub fn to_sqlx_query_as<T>(&mut self) -> QueryAs<'_, MySql, T, MySqlArguments>
pub async fn count( &mut self, column: &str, pool: &Pool<MySql>, ) -> Result<i64, Error>
Trait Implementations§
Source§impl Clone for ChainBuilder
impl Clone for ChainBuilder
Source§fn clone(&self) -> ChainBuilder
fn clone(&self) -> ChainBuilder
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read moreSource§impl Debug for ChainBuilder
impl Debug for ChainBuilder
Source§impl<'de> Deserialize<'de> for ChainBuilder
impl<'de> Deserialize<'de> for ChainBuilder
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Auto Trait Implementations§
impl Freeze for ChainBuilder
impl RefUnwindSafe for ChainBuilder
impl Send for ChainBuilder
impl Sync for ChainBuilder
impl Unpin for ChainBuilder
impl UnwindSafe for ChainBuilder
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<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left
is true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left(&self)
returns true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read more