pub struct QueryBuilder<M = ()> { /* private fields */ }Expand description
Query builder for constructing database queries
Implementations§
Source§impl<M> QueryBuilder<M>
impl<M> QueryBuilder<M>
Sourcepub fn select_distinct(self, fields: &str) -> Self
pub fn select_distinct(self, fields: &str) -> Self
Add SELECT DISTINCT to the query
Sourcepub fn where_eq<T: Into<Value>>(self, column: &str, value: T) -> Self
pub fn where_eq<T: Into<Value>>(self, column: &str, value: T) -> Self
Add WHERE condition with equality
Sourcepub fn where_ne<T: Into<Value>>(self, column: &str, value: T) -> Self
pub fn where_ne<T: Into<Value>>(self, column: &str, value: T) -> Self
Add WHERE condition with not equal
Sourcepub fn where_gt<T: Into<Value>>(self, column: &str, value: T) -> Self
pub fn where_gt<T: Into<Value>>(self, column: &str, value: T) -> Self
Add WHERE condition with greater than
Sourcepub fn where_gte<T: Into<Value>>(self, column: &str, value: T) -> Self
pub fn where_gte<T: Into<Value>>(self, column: &str, value: T) -> Self
Add WHERE condition with greater than or equal
Sourcepub fn where_lt<T: Into<Value>>(self, column: &str, value: T) -> Self
pub fn where_lt<T: Into<Value>>(self, column: &str, value: T) -> Self
Add WHERE condition with less than
Sourcepub fn where_lte<T: Into<Value>>(self, column: &str, value: T) -> Self
pub fn where_lte<T: Into<Value>>(self, column: &str, value: T) -> Self
Add WHERE condition with less than or equal
Sourcepub fn where_like(self, column: &str, pattern: &str) -> Self
pub fn where_like(self, column: &str, pattern: &str) -> Self
Add WHERE condition with LIKE
Sourcepub fn where_not_like(self, column: &str, pattern: &str) -> Self
pub fn where_not_like(self, column: &str, pattern: &str) -> Self
Add WHERE condition with NOT LIKE
Sourcepub fn where_in<T: Into<Value>>(self, column: &str, values: Vec<T>) -> Self
pub fn where_in<T: Into<Value>>(self, column: &str, values: Vec<T>) -> Self
Add WHERE condition with IN
Sourcepub fn where_not_in<T: Into<Value>>(self, column: &str, values: Vec<T>) -> Self
pub fn where_not_in<T: Into<Value>>(self, column: &str, values: Vec<T>) -> Self
Add WHERE condition with NOT IN
Sourcepub fn where_null(self, column: &str) -> Self
pub fn where_null(self, column: &str) -> Self
Add WHERE condition with IS NULL
Sourcepub fn where_not_null(self, column: &str) -> Self
pub fn where_not_null(self, column: &str) -> Self
Add WHERE condition with IS NOT NULL
Sourcepub fn where_between<T: Into<Value>>(
self,
column: &str,
start: T,
end: T,
) -> Self
pub fn where_between<T: Into<Value>>( self, column: &str, start: T, end: T, ) -> Self
Add WHERE condition with BETWEEN
Sourcepub fn join(self, table: &str, left_col: &str, right_col: &str) -> Self
pub fn join(self, table: &str, left_col: &str, right_col: &str) -> Self
Add INNER JOIN to the query
Sourcepub fn left_join(self, table: &str, left_col: &str, right_col: &str) -> Self
pub fn left_join(self, table: &str, left_col: &str, right_col: &str) -> Self
Add LEFT JOIN to the query
Sourcepub fn right_join(self, table: &str, left_col: &str, right_col: &str) -> Self
pub fn right_join(self, table: &str, left_col: &str, right_col: &str) -> Self
Add RIGHT JOIN to the query
Sourcepub fn order_by_desc(self, column: &str) -> Self
pub fn order_by_desc(self, column: &str) -> Self
Add ORDER BY clause (descending)
Sourcepub fn having_eq<T: Into<Value>>(self, column: &str, value: T) -> Self
pub fn having_eq<T: Into<Value>>(self, column: &str, value: T) -> Self
Add HAVING clause (same as WHERE for now)
Sourcepub fn select_count(self, column: &str, alias: Option<&str>) -> Self
pub fn select_count(self, column: &str, alias: Option<&str>) -> Self
Add aggregate functions to SELECT
Sourcepub fn select_sum(self, column: &str, alias: Option<&str>) -> Self
pub fn select_sum(self, column: &str, alias: Option<&str>) -> Self
Add SUM aggregate
Sourcepub fn select_avg(self, column: &str, alias: Option<&str>) -> Self
pub fn select_avg(self, column: &str, alias: Option<&str>) -> Self
Add AVG aggregate
Sourcepub fn select_min(self, column: &str, alias: Option<&str>) -> Self
pub fn select_min(self, column: &str, alias: Option<&str>) -> Self
Add MIN aggregate
Sourcepub fn select_max(self, column: &str, alias: Option<&str>) -> Self
pub fn select_max(self, column: &str, alias: Option<&str>) -> Self
Add MAX aggregate
Sourcepub fn select_raw(self, expression: &str) -> Self
pub fn select_raw(self, expression: &str) -> Self
Add custom SELECT expression
Sourcepub fn paginate_cursor<T: Into<Value>>(
self,
cursor_column: &str,
cursor_value: Option<T>,
per_page: i64,
direction: OrderDirection,
) -> Self
pub fn paginate_cursor<T: Into<Value>>( self, cursor_column: &str, cursor_value: Option<T>, per_page: i64, direction: OrderDirection, ) -> Self
Cursor-based pagination (for better performance on large datasets)
Sourcepub fn union(self, _other_query: QueryBuilder<M>) -> Self
pub fn union(self, _other_query: QueryBuilder<M>) -> Self
Add UNION to combine results from another query
Sourcepub fn union_all(self, _other_query: QueryBuilder<M>) -> Self
pub fn union_all(self, _other_query: QueryBuilder<M>) -> Self
Add UNION ALL to combine results from another query
Sourcepub fn where_subquery<T: Into<Value>>(
self,
column: &str,
operator: QueryOperator,
subquery: QueryBuilder<M>,
) -> Self
pub fn where_subquery<T: Into<Value>>( self, column: &str, operator: QueryOperator, subquery: QueryBuilder<M>, ) -> Self
Add a subquery in the WHERE clause
Sourcepub fn where_exists(self, subquery: QueryBuilder<M>) -> Self
pub fn where_exists(self, subquery: QueryBuilder<M>) -> Self
Add EXISTS subquery condition
Sourcepub fn where_not_exists(self, subquery: QueryBuilder<M>) -> Self
pub fn where_not_exists(self, subquery: QueryBuilder<M>) -> Self
Add NOT EXISTS subquery condition
Sourcepub fn bindings(&self) -> Vec<Value>
pub fn bindings(&self) -> Vec<Value>
Get parameter bindings (for prepared statements) Enhanced to support subqueries and complex conditions
Sourcepub fn clone_for_subquery(&self) -> Self
pub fn clone_for_subquery(&self) -> Self
Clone this query builder for use in subqueries
Sourcepub fn complexity_score(&self) -> u32
pub fn complexity_score(&self) -> u32
Get query complexity score for performance monitoring
Source§impl<M: Model> QueryBuilder<M>
impl<M: Model> QueryBuilder<M>
Sourcepub async fn get(self, pool: &Pool<Postgres>) -> ModelResult<Vec<M>>
pub async fn get(self, pool: &Pool<Postgres>) -> ModelResult<Vec<M>>
Execute query and return models
Sourcepub async fn chunk<F>(
self,
pool: &Pool<Postgres>,
chunk_size: i64,
callback: F,
) -> ModelResult<()>
pub async fn chunk<F>( self, pool: &Pool<Postgres>, chunk_size: i64, callback: F, ) -> ModelResult<()>
Execute query with chunking for large datasets
Sourcepub async fn get_raw(self, pool: &Pool<Postgres>) -> ModelResult<Vec<Value>>
pub async fn get_raw(self, pool: &Pool<Postgres>) -> ModelResult<Vec<Value>>
Execute query and return raw SQL results (for complex aggregations)
Sourcepub async fn first(self, pool: &Pool<Postgres>) -> ModelResult<Option<M>>
pub async fn first(self, pool: &Pool<Postgres>) -> ModelResult<Option<M>>
Execute query and return first model
Sourcepub async fn first_or_fail(self, pool: &Pool<Postgres>) -> ModelResult<M>
pub async fn first_or_fail(self, pool: &Pool<Postgres>) -> ModelResult<M>
Execute query and return first model or error
Trait Implementations§
Source§impl<M> Clone for QueryBuilder<M>
impl<M> Clone for QueryBuilder<M>
Source§impl<M: Debug> Debug for QueryBuilder<M>
impl<M: Debug> Debug for QueryBuilder<M>
Auto Trait Implementations§
impl<M> Freeze for QueryBuilder<M>
impl<M> RefUnwindSafe for QueryBuilder<M>where
M: RefUnwindSafe,
impl<M> Send for QueryBuilder<M>where
M: Send,
impl<M> Sync for QueryBuilder<M>where
M: Sync,
impl<M> Unpin for QueryBuilder<M>where
M: Unpin,
impl<M> UnwindSafe for QueryBuilder<M>where
M: UnwindSafe,
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