pub struct Query<'db, E>where
E: EntityTrait,{ /* private fields */ }Expand description
A typed query bound to an explicit &Db, over a SeaORM entity E.
Construct on the golden path with QueryModel::query:
use arcature_data::QueryModel;
let posts = post::Entity::query(db)
.filter(post::Column::UserId.eq(7))
.order_by_desc(post::Column::CreatedAt)
.all()
.await?;Or construct directly with Query::new. The builder carries the &Db
for the lifetime of the query, so terminal methods need no extra argument.
Implementations§
Source§impl<'db, E> Query<'db, E>where
E: EntityTrait,
impl<'db, E> Query<'db, E>where
E: EntityTrait,
Sourcepub fn filter<C>(self, condition: C) -> Selfwhere
C: IntoCondition,
pub fn filter<C>(self, condition: C) -> Selfwhere
C: IntoCondition,
Add a filter condition. Accepts anything SeaORM’s Select::filter
accepts — typically Column::X.eq(v) or a built Condition.
post::Entity::query(db).filter(post::Column::Active.eq(true))Sourcepub fn order_by<C>(self, column: C, order: Order) -> Selfwhere
C: IntoSimpleExpr,
pub fn order_by<C>(self, column: C, order: Order) -> Selfwhere
C: IntoSimpleExpr,
Add an ORDER BY clause on a column with an explicit direction.
Sourcepub fn order_by_asc<C>(self, column: C) -> Selfwhere
C: IntoSimpleExpr,
pub fn order_by_asc<C>(self, column: C) -> Selfwhere
C: IntoSimpleExpr,
Add an ascending ORDER BY clause on a column.
Sourcepub fn order_by_desc<C>(self, column: C) -> Selfwhere
C: IntoSimpleExpr,
pub fn order_by_desc<C>(self, column: C) -> Selfwhere
C: IntoSimpleExpr,
Add a descending ORDER BY clause on a column.
Sourcepub fn paginate(self, per_page: u64) -> Paginated<'db, E>
pub fn paginate(self, per_page: u64) -> Paginated<'db, E>
Begin pagination with the given per-page size (must be >= 1). Chain
.page(n) (1-based) and then .fetch() to run the count + page query.
Source§impl<'db, E> Query<'db, E>where
E: EntityTrait,
impl<'db, E> Query<'db, E>where
E: EntityTrait,
Sourcepub async fn with<R>(
self,
_relation: Relation<R>,
) -> Result<Vec<(E::Model, Option<R::Model>)>, DataError>
pub async fn with<R>( self, _relation: Relation<R>, ) -> Result<Vec<(E::Model, Option<R::Model>)>, DataError>
Eager-load a related entity R alongside each row of E, returning
(parent, Option<related>) pairs. Delegates to SeaORM’s
find_also_related.
let rows = post::Entity::query(db)
.with(arcature_data::Relation::of::<user::Entity>())
.await?; // Vec<(post::Model, Option<user::Model>)>R must be Default — SeaORM’s generated Entity is a unit struct
that derives Default, so this is satisfied by every
#[derive(DeriveEntityModel)] entity without extra work.
§Errors
Returns DataError::Database if the underlying SeaORM query fails.
Auto Trait Implementations§
impl<'db, E> !RefUnwindSafe for Query<'db, E>
impl<'db, E> !UnwindSafe for Query<'db, E>
impl<'db, E> Freeze for Query<'db, E>
impl<'db, E> Send for Query<'db, E>
impl<'db, E> Sync for Query<'db, E>
impl<'db, E> Unpin for Query<'db, E>where
E: Unpin,
impl<'db, E> UnsafeUnpin for Query<'db, E>
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> 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