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>
impl<E: Entity> DbSetQuery<E>
Sourcepub fn with_select_query(self, select_query: SelectQuery) -> Self
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.
Sourcepub fn inner_join<J: Entity>(self, on: Predicate) -> Self
pub fn inner_join<J: Entity>(self, on: Predicate) -> Self
Adds an explicit INNER JOIN to another entity.
Sourcepub fn left_join<J: Entity>(self, on: Predicate) -> Self
pub fn left_join<J: Entity>(self, on: Predicate) -> Self
Adds an explicit LEFT JOIN to another entity.
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.
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.
Adds an aliased INNER JOIN inferred from navigation metadata.
Adds an aliased LEFT JOIN inferred from navigation metadata.
Sourcepub fn include<J: Entity>(
self,
navigation: &'static str,
) -> Result<DbSetQueryIncludeOne<E, J>, OrmError>
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.
Sourcepub fn include_as<J: Entity>(
self,
navigation: &'static str,
alias: &'static str,
) -> Result<DbSetQueryIncludeOne<E, J>, OrmError>
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.
Sourcepub fn include_many<J: Entity>(
self,
navigation: &'static str,
) -> Result<DbSetQueryIncludeMany<E, J>, OrmError>
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.
Sourcepub fn include_many_as<J: Entity>(
self,
navigation: &'static str,
alias: &'static str,
) -> Result<DbSetQueryIncludeMany<E, J>, OrmError>
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.
Sourcepub fn paginate(self, request: PageRequest) -> Self
pub fn paginate(self, request: PageRequest) -> Self
Applies page-based pagination.
Sourcepub fn select<P>(self, projection: P) -> Selfwhere
P: SelectProjections,
pub fn select<P>(self, projection: P) -> Selfwhere
P: SelectProjections,
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.
Sourcepub fn with_deleted(self) -> Self
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.
Sourcepub fn only_deleted(self) -> Self
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.
Sourcepub async fn all(self) -> Result<Vec<E>, OrmError>
pub async fn all(self) -> Result<Vec<E>, OrmError>
Executes the query and materializes full entities.
Sourcepub async fn first(self) -> Result<Option<E>, OrmError>
pub async fn first(self) -> Result<Option<E>, OrmError>
Executes the query and materializes the first full entity, if any.
Sourcepub async fn all_as<T>(self) -> Result<Vec<T>, OrmError>
pub async fn all_as<T>(self) -> Result<Vec<T>, OrmError>
Executes the query and materializes projected rows as DTOs.
Sourcepub async fn first_as<T>(self) -> Result<Option<T>, OrmError>
pub async fn first_as<T>(self) -> Result<Option<T>, OrmError>
Executes the query and materializes the first projected DTO, if any.
Sourcepub async fn count(self) -> Result<i64, OrmError>where
E: SoftDeleteEntity + TenantScopedEntity,
pub async fn count(self) -> Result<i64, OrmError>where
E: SoftDeleteEntity + TenantScopedEntity,
Executes the query as a COUNT(*) over the effective filters.