pub struct QueryBuilder<M> { /* private fields */ }Expand description
A type-safe SQL query builder.
Constructed primarily via <Model>::find() and <Model>::select(...).
Chain methods like .filter(), .order_by(), and .limit() before executing.
Implementations§
Source§impl<M: Model + Send + Sync> QueryBuilder<M>
impl<M: Model + Send + Sync> QueryBuilder<M>
pub fn new() -> Self
Sourcepub fn filter<E>(self, expr: E) -> Selfwhere
E: IntoExpr<M>,
pub fn filter<E>(self, expr: E) -> Selfwhere
E: IntoExpr<M>,
Add a WHERE filter clause, e.g., filter(Expr::new(“age >= {}”, vec![18.to_param()]))
Or using DSL: filter(UserColumn::Age.gte(18.to_param()))
Backwards compatibility raw signature with $1 etc is also supported if string literal passes without {}
pub fn select_only<E: IntoExpr<M>>(self, exprs: Vec<E>) -> Self
pub fn join(self, clause: &str) -> Self
Sourcepub fn join_child<R: Model + HasForeignKey<M>>(self) -> Self
pub fn join_child<R: Model + HasForeignKey<M>>(self) -> Self
Adds an INNER JOIN automatically resolving foreign keys using HasForeignKey.
Sourcepub fn join_parent<R: Model>(self) -> Selfwhere
M: HasForeignKey<R>,
pub fn join_parent<R: Model>(self) -> Selfwhere
M: HasForeignKey<R>,
Adds an INNER JOIN automatically resolving the parent entity foreign keys.
pub fn group_by(self, clause: &str) -> Self
pub fn having<E: IntoExpr<M>>(self, expr: E) -> Self
pub fn order_by(self, clause: &str) -> Self
pub fn limit(self, limit: usize) -> Self
pub fn offset(self, offset: usize) -> Self
Sourcepub fn into_raw(self, executor: &mut impl Executor) -> OrmResult<Vec<Row>>
pub fn into_raw(self, executor: &mut impl Executor) -> OrmResult<Vec<Row>>
Executes the query and returns raw Row results without model mapping.
Sourcepub fn all(self, executor: &mut impl Executor) -> OrmResult<Vec<M>>
pub fn all(self, executor: &mut impl Executor) -> OrmResult<Vec<M>>
Executes the query and returns a list of models.
Sourcepub fn paginate(self, page_size: usize) -> Paginator<M>
pub fn paginate(self, page_size: usize) -> Paginator<M>
Converts this query builder into a Paginator using the specified page size.