pub struct EntityQuery<T, E: EntityTrait> { /* private fields */ }Expand description
A chainable query builder that wraps SeaORM’s Select<E> and
auto-converts results to the domain type T via From<E::Model>.
Construct one from E::find() or E::find_by_id(pk) and then chain
filter/order/limit/offset calls before executing with a terminal method.
§Example
ⓘ
let todos: Vec<Todo> = EntityQuery::new(TodoEntity::find())
.filter(todo::Column::Done.eq(false))
.order_by_asc(todo::Column::CreatedAt)
.limit(10)
.all(&db)
.await?;Implementations§
Source§impl<T, E> EntityQuery<T, E>
impl<T, E> EntityQuery<T, E>
Sourcepub fn filter(self, f: impl IntoCondition) -> Self
pub fn filter(self, f: impl IntoCondition) -> Self
Apply a WHERE condition.
Sourcepub fn order_by_asc<C: ColumnTrait>(self, col: C) -> Self
pub fn order_by_asc<C: ColumnTrait>(self, col: C) -> Self
ORDER BY col ASC.
Sourcepub fn order_by_desc<C: ColumnTrait>(self, col: C) -> Self
pub fn order_by_desc<C: ColumnTrait>(self, col: C) -> Self
ORDER BY col DESC.
Sourcepub async fn all(self, db: &impl ConnectionTrait) -> Result<Vec<T>, Error>
pub async fn all(self, db: &impl ConnectionTrait) -> Result<Vec<T>, Error>
Fetch all matching rows and convert each model to T.
Sourcepub async fn one(self, db: &impl ConnectionTrait) -> Result<Option<T>, Error>
pub async fn one(self, db: &impl ConnectionTrait) -> Result<Option<T>, Error>
Fetch at most one row and convert to T if present.
Sourcepub async fn count(self, db: &impl ConnectionTrait) -> Result<u64, Error>
pub async fn count(self, db: &impl ConnectionTrait) -> Result<u64, Error>
Return the number of rows that match the current query.
Sourcepub async fn paginate(
self,
db: &impl ConnectionTrait,
params: &PageParams,
) -> Result<PageResult<T>, Error>
pub async fn paginate( self, db: &impl ConnectionTrait, params: &PageParams, ) -> Result<PageResult<T>, Error>
Offset-based pagination. Results are auto-converted to T.
Sourcepub async fn paginate_cursor<C, V, F>(
self,
col: C,
cursor_fn: F,
db: &impl ConnectionTrait,
params: &CursorParams<V>,
) -> Result<CursorResult<T>, Error>
pub async fn paginate_cursor<C, V, F>( self, col: C, cursor_fn: F, db: &impl ConnectionTrait, params: &CursorParams<V>, ) -> Result<CursorResult<T>, Error>
Cursor-based pagination. Results are auto-converted to T.
col— the column to paginate on (e.g.Column::Id).cursor_fn— extracts the cursor string from a model instance.
Sourcepub fn into_select(self) -> Select<E>
pub fn into_select(self) -> Select<E>
Unwrap the inner Select<E> for advanced SeaORM usage.
Auto Trait Implementations§
impl<T, E> Freeze for EntityQuery<T, E>
impl<T, E> RefUnwindSafe for EntityQuery<T, E>where
T: RefUnwindSafe,
E: RefUnwindSafe,
impl<T, E> Send for EntityQuery<T, E>where
T: Send,
impl<T, E> Sync for EntityQuery<T, E>where
T: Sync,
impl<T, E> Unpin for EntityQuery<T, E>
impl<T, E> UnsafeUnpin for EntityQuery<T, E>
impl<T, E> UnwindSafe for EntityQuery<T, E>where
T: UnwindSafe,
E: UnwindSafe,
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> DefaultHooks for T
impl<T> DefaultHooks for 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>
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