pub struct QueryBuilder { /* private fields */ }Expand description
SQL query builder for SELECT statements
Implementations§
Source§impl QueryBuilder
impl QueryBuilder
Sourcepub fn new(table: &str) -> Self
pub fn new(table: &str) -> Self
Create a new query builder for the specified table
§Example
use oxify_storage::query_builder::QueryBuilder;
let builder = QueryBuilder::new("users");Sourcepub fn select(self, columns: &[&str]) -> Self
pub fn select(self, columns: &[&str]) -> Self
Specify columns to select
§Example
use oxify_storage::query_builder::QueryBuilder;
let builder = QueryBuilder::new("users")
.select(&["id", "name", "email"]);Sourcepub fn where_condition(self, condition: Condition) -> Self
pub fn where_condition(self, condition: Condition) -> Self
Add a WHERE condition
§Example
use oxify_storage::query_builder::{QueryBuilder, Condition};
let builder = QueryBuilder::new("users")
.where_condition(Condition::Eq("status".to_string()));Sourcepub fn where_if(self, predicate: bool, condition: Condition) -> Self
pub fn where_if(self, predicate: bool, condition: Condition) -> Self
Add a WHERE condition only if the predicate is true
This is useful for optional filters
Sourcepub fn join(self, join_type: JoinType, table: &str, on_condition: &str) -> Self
pub fn join(self, join_type: JoinType, table: &str, on_condition: &str) -> Self
Add a JOIN clause
Sourcepub fn order_by(self, column: &str, order: SortOrder) -> Self
pub fn order_by(self, column: &str, order: SortOrder) -> Self
Add an ORDER BY clause
§Example
use oxify_storage::query_builder::{QueryBuilder, SortOrder};
let builder = QueryBuilder::new("users")
.order_by("created_at", SortOrder::Desc);Sourcepub fn limit(self, limit: i64) -> Self
pub fn limit(self, limit: i64) -> Self
Set LIMIT
§Example
use oxify_storage::query_builder::QueryBuilder;
let builder = QueryBuilder::new("users").limit(10);Sourcepub fn build(&mut self) -> (String, usize)
pub fn build(&mut self) -> (String, usize)
Build the final SQL query and return the query string and total parameter count
Returns a tuple of (SQL string, number of parameters expected)
§Example
use oxify_storage::query_builder::{QueryBuilder, Condition};
let mut builder = QueryBuilder::new("users")
.select(&["id", "name"])
.where_condition(Condition::Eq("status".to_string()));
let (sql, param_count) = builder.build();
assert_eq!(param_count, 1);Sourcepub fn build_count(&mut self) -> (String, usize)
pub fn build_count(&mut self) -> (String, usize)
Build a COUNT query from this builder
This creates a COUNT(*) query using the same WHERE conditions
Trait Implementations§
Source§impl Clone for QueryBuilder
impl Clone for QueryBuilder
Source§fn clone(&self) -> QueryBuilder
fn clone(&self) -> QueryBuilder
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 moreAuto Trait Implementations§
impl Freeze for QueryBuilder
impl RefUnwindSafe for QueryBuilder
impl Send for QueryBuilder
impl Sync for QueryBuilder
impl Unpin for QueryBuilder
impl UnwindSafe for QueryBuilder
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
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>
Converts
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>
Converts
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