Skip to main content

DbSetQuery

Struct DbSetQuery 

Source
pub struct DbSetQuery<E: Entity> { /* private fields */ }
Expand description

Fluent query builder bound to one DbSet<E>.

DbSetQuery stores query intent as AST until execution. SQL text is generated only by the SQL Server compiler. Mandatory runtime policies such as tenant filtering and root-entity soft-delete visibility are applied when the query is compiled or executed.

Implementations§

Source§

impl<E: Entity> DbSetQuery<E>

Source

pub fn with_select_query(self, select_query: SelectQuery) -> Self

Replaces the underlying SelectQuery AST while keeping this query bound to the same connection and runtime policies.

Source

pub fn filter(self, predicate: Predicate) -> Self

Adds a predicate to the query.

Source

pub fn join(self, join: Join) -> Self

Adds an explicit join described by the query AST.

Source

pub fn inner_join<J: Entity>(self, on: Predicate) -> Self

Adds an explicit INNER JOIN to another entity.

Source

pub fn left_join<J: Entity>(self, on: Predicate) -> Self

Adds an explicit LEFT JOIN to another entity.

Source

pub fn try_inner_join_navigation<J: Entity>( self, navigation: &'static str, ) -> Result<Self, OrmError>

Adds an INNER JOIN inferred from navigation metadata.

The navigation must be declared on the root entity E, and its target table must match J. This only builds the SQL join; it does not load or materialize the related entity.

Source

pub fn try_left_join_navigation<J: Entity>( self, navigation: &'static str, ) -> Result<Self, OrmError>

Adds a LEFT JOIN inferred from navigation metadata.

The navigation must be declared on the root entity E, and its target table must match J. This only builds the SQL join; it does not load or materialize the related entity.

Source

pub fn try_inner_join_navigation_as<J: Entity>( self, navigation: &'static str, alias: &'static str, ) -> Result<Self, OrmError>

Adds an aliased INNER JOIN inferred from navigation metadata.

Source

pub fn try_left_join_navigation_as<J: Entity>( self, navigation: &'static str, alias: &'static str, ) -> Result<Self, OrmError>

Adds an aliased LEFT JOIN inferred from navigation metadata.

Source

pub fn include<J: Entity>( self, navigation: &'static str, ) -> Result<DbSetQueryIncludeOne<E, J>, OrmError>

Includes a single related entity through a belongs_to or has_one navigation.

This first eager-loading cut uses a left join and materializes the related row into Navigation<J>. Collection navigations (has_many) are intentionally rejected because they need grouping or split-query semantics.

Source

pub fn include_as<J: Entity>( self, navigation: &'static str, alias: &'static str, ) -> Result<DbSetQueryIncludeOne<E, J>, OrmError>

Includes a single related entity using an explicit table alias.

Source

pub fn include_many<J: Entity>( self, navigation: &'static str, ) -> Result<DbSetQueryIncludeMany<E, J>, OrmError>

Includes a collection navigation through a has_many relationship.

This first collection include cut uses a left join, materializes joined rows, then groups them by the root entity primary key before assigning Collection<J>. Pagination is rejected for this join-based path because limiting joined rows is not equivalent to limiting root entities.

Source

pub fn include_many_as<J: Entity>( self, navigation: &'static str, alias: &'static str, ) -> Result<DbSetQueryIncludeMany<E, J>, OrmError>

Includes a collection navigation using an explicit table alias.

Source

pub fn order_by(self, order: OrderBy) -> Self

Adds an ordering expression.

Source

pub fn limit(self, limit: u64) -> Self

Limits the number of returned rows with zero offset.

Source

pub fn take(self, limit: u64) -> Self

Alias for limit(...).

Source

pub fn paginate(self, request: PageRequest) -> Self

Applies page-based pagination.

Source

pub fn select<P>(self, projection: P) -> Self

Selects an explicit projection instead of materializing full entities.

Use all_as::<T>() or first_as::<T>() to materialize the projection into a DTO implementing FromRow.

Source

pub fn group_by<G>(self, group_by: G) -> Result<DbSetGroupedQuery<E>, OrmError>

Starts a grouped aggregate query over one or more group key expressions.

The returned builder materializes DTOs through all_as::<T>() and first_as::<T>(); it does not expose full-entity materialization.

Source

pub fn with_deleted(self) -> Self

Includes logically deleted rows for entities with soft_delete.

This affects only the root entity E, not every manually joined entity.

Source

pub fn only_deleted(self) -> Self

Returns only logically deleted rows for entities with soft_delete.

This affects only the root entity E, not every manually joined entity.

Source

pub async fn all(self) -> Result<Vec<E>, OrmError>

Executes the query and materializes full entities.

Source

pub async fn first(self) -> Result<Option<E>, OrmError>

Executes the query and materializes the first full entity, if any.

Source

pub async fn all_as<T>(self) -> Result<Vec<T>, OrmError>

Executes the query and materializes projected rows as DTOs.

Source

pub async fn first_as<T>(self) -> Result<Option<T>, OrmError>

Executes the query and materializes the first projected DTO, if any.

Source

pub async fn count(self) -> Result<i64, OrmError>

Executes the query as a COUNT(*) over the effective filters.

Source

pub async fn exists(self) -> Result<bool, OrmError>

Executes the query as an EXISTS predicate over the effective filters.

Source

pub async fn any(self) -> Result<bool, OrmError>

Alias for exists().

Source

pub async fn sum<T>( self, column: impl Into<Expr>, ) -> Result<Option<T>, OrmError>

Executes the query as a scalar SUM(...) aggregate.

Source

pub async fn avg<T>( self, column: impl Into<Expr>, ) -> Result<Option<T>, OrmError>

Executes the query as a scalar AVG(...) aggregate.

Source

pub async fn min<T>( self, column: impl Into<Expr>, ) -> Result<Option<T>, OrmError>

Executes the query as a scalar MIN(...) aggregate.

Source

pub async fn max<T>( self, column: impl Into<Expr>, ) -> Result<Option<T>, OrmError>

Executes the query as a scalar MAX(...) aggregate.

Trait Implementations§

Source§

impl<E: Clone + Entity> Clone for DbSetQuery<E>

Source§

fn clone(&self) -> DbSetQuery<E>

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<E: Entity> Debug for DbSetQuery<E>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<E> Freeze for DbSetQuery<E>

§

impl<E> !RefUnwindSafe for DbSetQuery<E>

§

impl<E> Send for DbSetQuery<E>

§

impl<E> Sync for DbSetQuery<E>

§

impl<E> Unpin for DbSetQuery<E>

§

impl<E> UnsafeUnpin for DbSetQuery<E>

§

impl<E> !UnwindSafe for DbSetQuery<E>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more