pub struct QueryBuilder<'a, T> { /* private fields */ }Expand description
A fluent Query Builder for constructing SQL queries.
Handles SELECT, INSERT, filtering (WHERE), pagination (LIMIT/OFFSET), and ordering.
Implementations§
Source§impl<'a, T: Model + Send + Sync + Unpin> QueryBuilder<'a, T>
impl<'a, T: Model + Send + Sync + Unpin> QueryBuilder<'a, T>
Sourcepub fn new(
db: &'a Database,
table_name: &'static str,
columns_info: Vec<ColumnInfo>,
columns: Vec<String>,
) -> Self
pub fn new( db: &'a Database, table_name: &'static str, columns_info: Vec<ColumnInfo>, columns: Vec<String>, ) -> Self
Creates a new QueryBuilder instance.
Usually called via db.model::<T>().
pub fn order(self, order: &str) -> Self
pub fn preload(self) -> Self
pub fn join(self) -> Self
pub fn pagination( self, max_value: usize, default: usize, page: usize, value: isize, ) -> Result<Self, Error>
Sourcepub fn select(self, columns: &str) -> Self
pub fn select(self, columns: &str) -> Self
Selects specific columns to return.
By default, all columns (*) are selected.
Sourcepub async fn insert(&self, model: &T) -> Result<&Self, Error>
pub async fn insert(&self, model: &T) -> Result<&Self, Error>
Inserts a new record into the database based on the model instance.
Uses manual string parsing to bind values (temporary solution until fuller serialization support).
Sourcepub fn to_sql(&self) -> String
pub fn to_sql(&self) -> String
Returns the generated SQL string (for debugging purposes, without arguments).
Auto Trait Implementations§
impl<'a, T> Freeze for QueryBuilder<'a, T>
impl<'a, T> !RefUnwindSafe for QueryBuilder<'a, T>
impl<'a, T> Send for QueryBuilder<'a, T>where
T: Send,
impl<'a, T> Sync for QueryBuilder<'a, T>where
T: Sync,
impl<'a, T> Unpin for QueryBuilder<'a, T>where
T: Unpin,
impl<'a, T> !UnwindSafe for QueryBuilder<'a, T>
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> 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