pub struct QueryBuilder<M>where
M: Model,{ /* private fields */ }Implementations§
Source§impl<M> QueryBuilder<M>
impl<M> QueryBuilder<M>
pub fn new() -> QueryBuilder<M>
pub fn select_only(self, columns: &[&str]) -> QueryBuilder<M>
pub fn distinct(self) -> QueryBuilder<M>
pub fn where_eq<T>(self, column: Column<M, T>, value: T) -> QueryBuilder<M>
pub fn or_where_eq<T>(self, column: Column<M, T>, value: T) -> QueryBuilder<M>
pub fn where_ne<T>(self, column: Column<M, T>, value: T) -> QueryBuilder<M>
pub fn or_where_ne<T>(self, column: Column<M, T>, value: T) -> QueryBuilder<M>
pub fn where_gt<T>(self, column: Column<M, T>, value: T) -> QueryBuilder<M>
pub fn or_where_gt<T>(self, column: Column<M, T>, value: T) -> QueryBuilder<M>
pub fn where_gte<T>(self, column: Column<M, T>, value: T) -> QueryBuilder<M>
pub fn or_where_gte<T>(self, column: Column<M, T>, value: T) -> QueryBuilder<M>
pub fn where_lt<T>(self, column: Column<M, T>, value: T) -> QueryBuilder<M>
pub fn or_where_lt<T>(self, column: Column<M, T>, value: T) -> QueryBuilder<M>
pub fn where_lte<T>(self, column: Column<M, T>, value: T) -> QueryBuilder<M>
pub fn or_where_lte<T>(self, column: Column<M, T>, value: T) -> QueryBuilder<M>
pub fn where_in<T, I>(self, column: Column<M, T>, values: I) -> QueryBuilder<M>
pub fn or_where_in<T, I>( self, column: Column<M, T>, values: I, ) -> QueryBuilder<M>
pub fn where_not_in<T, I>( self, column: Column<M, T>, values: I, ) -> QueryBuilder<M>
pub fn or_where_not_in<T, I>( self, column: Column<M, T>, values: I, ) -> QueryBuilder<M>
pub fn where_null<T>(self, column: Column<M, T>) -> QueryBuilder<M>
pub fn or_where_null<T>(self, column: Column<M, T>) -> QueryBuilder<M>
pub fn where_not_null<T>(self, column: Column<M, T>) -> QueryBuilder<M>
pub fn or_where_not_null<T>(self, column: Column<M, T>) -> QueryBuilder<M>
pub fn where_between<T>( self, column: Column<M, T>, low: T, high: T, ) -> QueryBuilder<M>
pub fn or_where_between<T>( self, column: Column<M, T>, low: T, high: T, ) -> QueryBuilder<M>
pub fn where_not_between<T>( self, column: Column<M, T>, low: T, high: T, ) -> QueryBuilder<M>
pub fn where_like( self, column: Column<M, String>, pattern: impl Into<String>, ) -> QueryBuilder<M>
pub fn or_where_like( self, column: Column<M, String>, pattern: impl Into<String>, ) -> QueryBuilder<M>
pub fn where_not_like( self, column: Column<M, String>, pattern: impl Into<String>, ) -> QueryBuilder<M>
pub fn where_column<T>( self, a: Column<M, T>, b: Column<M, T>, ) -> QueryBuilder<M>
pub fn where_raw(self, raw: SimpleExpr) -> QueryBuilder<M>
pub fn or_where_raw(self, raw: SimpleExpr) -> QueryBuilder<M>
pub fn where_sql(self, sql: impl Into<String>) -> QueryBuilder<M>
pub fn or_where_sql(self, sql: impl Into<String>) -> QueryBuilder<M>
Sourcepub fn join(
self,
table: &str,
left_column: &str,
right_column: &str,
) -> QueryBuilder<M>
pub fn join( self, table: &str, left_column: &str, right_column: &str, ) -> QueryBuilder<M>
INNER JOIN table ON left_column = right_column. Mirrors Eloquent’s join.
Columns are passed as fully-qualified strings (e.g. "users.id").
Sourcepub fn left_join(
self,
table: &str,
left_column: &str,
right_column: &str,
) -> QueryBuilder<M>
pub fn left_join( self, table: &str, left_column: &str, right_column: &str, ) -> QueryBuilder<M>
LEFT JOIN table ON ....
Sourcepub fn right_join(
self,
table: &str,
left_column: &str,
right_column: &str,
) -> QueryBuilder<M>
pub fn right_join( self, table: &str, left_column: &str, right_column: &str, ) -> QueryBuilder<M>
RIGHT JOIN table ON ....
Sourcepub fn cross_join(self, table: &str) -> QueryBuilder<M>
pub fn cross_join(self, table: &str) -> QueryBuilder<M>
CROSS JOIN table (no ON clause).
pub fn group_by<T>(self, column: Column<M, T>) -> QueryBuilder<M>
Sourcepub fn group_by_raw(self, raw: impl Into<String>) -> QueryBuilder<M>
pub fn group_by_raw(self, raw: impl Into<String>) -> QueryBuilder<M>
GROUP BY raw_sql.
pub fn having(self, expr: SimpleExpr) -> QueryBuilder<M>
pub fn having_raw(self, sql: impl Into<String>) -> QueryBuilder<M>
Sourcepub fn with_trashed(self) -> QueryBuilder<M>
pub fn with_trashed(self) -> QueryBuilder<M>
Include soft-deleted rows. Eloquent’s ->withTrashed().
Sourcepub fn only_trashed(self) -> QueryBuilder<M>
pub fn only_trashed(self) -> QueryBuilder<M>
Only soft-deleted rows. Eloquent’s ->onlyTrashed().
Sourcepub fn without_trashed(self) -> QueryBuilder<M>
pub fn without_trashed(self) -> QueryBuilder<M>
Explicitly exclude soft-deleted rows (this is the default for models
with #[soft_deletes]). Eloquent’s ->withoutTrashed().
Sourcepub fn where_has<R, F>(self, _rel: R, f: F) -> QueryBuilder<M>where
R: RelationDef<Parent = M>,
<R as RelationDef>::Child: Model + for<'r> FromRow<'r, PgRow>,
F: FnOnce(QueryBuilder<<R as RelationDef>::Child>) -> QueryBuilder<<R as RelationDef>::Child>,
pub fn where_has<R, F>(self, _rel: R, f: F) -> QueryBuilder<M>where
R: RelationDef<Parent = M>,
<R as RelationDef>::Child: Model + for<'r> FromRow<'r, PgRow>,
F: FnOnce(QueryBuilder<<R as RelationDef>::Child>) -> QueryBuilder<<R as RelationDef>::Child>,
Filter parent rows by the existence of related child rows. Mirrors
Eloquent’s ->whereHas('posts', fn ($q) => $q->where(...)).
Emits WHERE EXISTS (SELECT 1 FROM child WHERE child.fk = parent.lk AND <closure conditions>).
User::query()
.where_has(User::posts_rel(), |q| q.where_eq(Post::columns().published(), true))
.get(pool).await?;Sourcepub fn where_doesnt_have<R, F>(self, _rel: R, f: F) -> QueryBuilder<M>where
R: RelationDef<Parent = M>,
<R as RelationDef>::Child: Model + for<'r> FromRow<'r, PgRow>,
F: FnOnce(QueryBuilder<<R as RelationDef>::Child>) -> QueryBuilder<<R as RelationDef>::Child>,
pub fn where_doesnt_have<R, F>(self, _rel: R, f: F) -> QueryBuilder<M>where
R: RelationDef<Parent = M>,
<R as RelationDef>::Child: Model + for<'r> FromRow<'r, PgRow>,
F: FnOnce(QueryBuilder<<R as RelationDef>::Child>) -> QueryBuilder<<R as RelationDef>::Child>,
Negated form of where_has. Mirrors Eloquent’s ->whereDoesntHave(...).
Sourcepub fn or_where_has<R, F>(self, _rel: R, f: F) -> QueryBuilder<M>where
R: RelationDef<Parent = M>,
<R as RelationDef>::Child: Model + for<'r> FromRow<'r, PgRow>,
F: FnOnce(QueryBuilder<<R as RelationDef>::Child>) -> QueryBuilder<<R as RelationDef>::Child>,
pub fn or_where_has<R, F>(self, _rel: R, f: F) -> QueryBuilder<M>where
R: RelationDef<Parent = M>,
<R as RelationDef>::Child: Model + for<'r> FromRow<'r, PgRow>,
F: FnOnce(QueryBuilder<<R as RelationDef>::Child>) -> QueryBuilder<<R as RelationDef>::Child>,
OR-combined where_has.
Sourcepub async fn paginate(
self,
per_page: u64,
page: u64,
pool: &Pool<Postgres>,
) -> Result<Paginator<M>, Error>
pub async fn paginate( self, per_page: u64, page: u64, pool: &Pool<Postgres>, ) -> Result<Paginator<M>, Error>
Pagination. Mirrors Eloquent’s ->paginate($perPage, ['*'], 'page', $page).
Sourcepub async fn with_count_of<R>(
self,
_rel: R,
pool: &Pool<Postgres>,
) -> Result<Vec<(M, i64)>, Error>
pub async fn with_count_of<R>( self, _rel: R, pool: &Pool<Postgres>, ) -> Result<Vec<(M, i64)>, Error>
Fetch the parent rows along with a related-row count. Mirrors Eloquent’s
->withCount('posts'). Returns Vec<(M, i64)> instead of dynamic attributes.
let users_with_counts: Vec<(User, i64)> = User::query()
.with_count_of(User::posts_rel(), pool)
.await?;pub fn order_by<T>( self, column: Column<M, T>, ascending: bool, ) -> QueryBuilder<M>
pub fn order_by_asc<T>(self, column: Column<M, T>) -> QueryBuilder<M>
pub fn order_by_desc<T>(self, column: Column<M, T>) -> QueryBuilder<M>
pub fn latest(self) -> QueryBuilder<M>
pub fn oldest(self) -> QueryBuilder<M>
pub fn latest_by<T>(self, column: Column<M, T>) -> QueryBuilder<M>
pub fn oldest_by<T>(self, column: Column<M, T>) -> QueryBuilder<M>
pub fn in_random_order(self) -> QueryBuilder<M>
pub fn reorder(self) -> QueryBuilder<M>
pub fn limit(self, n: u64) -> QueryBuilder<M>
pub fn take(self, n: u64) -> QueryBuilder<M>
pub fn offset(self, n: u64) -> QueryBuilder<M>
pub fn skip(self, n: u64) -> QueryBuilder<M>
pub async fn get(self, pool: &Pool<Postgres>) -> Result<Vec<M>, Error>
pub async fn first(self, pool: &Pool<Postgres>) -> Result<Option<M>, Error>
pub async fn first_or_fail(self, pool: &Pool<Postgres>) -> Result<M, Error>
pub async fn pluck<T>( self, column: Column<M, T>, pool: &Pool<Postgres>, ) -> Result<Vec<T>, Error>
pub async fn value<T>( self, column: Column<M, T>, pool: &Pool<Postgres>, ) -> Result<Option<T>, Error>
pub async fn count(self, pool: &Pool<Postgres>) -> Result<i64, Error>
pub async fn min<T>( self, column: Column<M, T>, pool: &Pool<Postgres>, ) -> Result<Option<T>, Error>
pub async fn max<T>( self, column: Column<M, T>, pool: &Pool<Postgres>, ) -> Result<Option<T>, Error>
pub async fn sum<T>( self, column: Column<M, T>, pool: &Pool<Postgres>, ) -> Result<i64, Error>
pub async fn avg<T>( self, column: Column<M, T>, pool: &Pool<Postgres>, ) -> Result<Option<f64>, Error>
pub async fn exists(self, pool: &Pool<Postgres>) -> Result<bool, Error>
pub async fn doesnt_exist(self, pool: &Pool<Postgres>) -> Result<bool, Error>
Trait Implementations§
Source§impl<M> Clone for QueryBuilder<M>where
M: Model,
impl<M> Clone for QueryBuilder<M>where
M: Model,
Source§fn clone(&self) -> QueryBuilder<M>
fn clone(&self) -> QueryBuilder<M>
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl<M> Default for QueryBuilder<M>where
M: Model,
impl<M> Default for QueryBuilder<M>where
M: Model,
Source§fn default() -> QueryBuilder<M>
fn default() -> QueryBuilder<M>
Auto Trait Implementations§
impl<M> Freeze for QueryBuilder<M>
impl<M> !RefUnwindSafe for QueryBuilder<M>
impl<M> Send for QueryBuilder<M>
impl<M> Sync for QueryBuilder<M>
impl<M> Unpin for QueryBuilder<M>
impl<M> UnsafeUnpin for QueryBuilder<M>
impl<M> !UnwindSafe for QueryBuilder<M>
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