pub trait ActiveRecord: Entity + Sized {
// Provided methods
fn query<C>(db: &C) -> DbSetQuery<Self>
where C: DbContextEntitySet<Self>,
Self: TenantScopedEntity { ... }
fn find<C, K>(
db: &C,
key: K,
) -> impl Future<Output = Result<Option<Self>, OrmError>> + Send
where C: DbContextEntitySet<Self>,
Self: FromRow + Send + SoftDeleteEntity + TenantScopedEntity,
K: SqlTypeMapping + Send { ... }
fn delete<C>(
&self,
db: &C,
) -> impl Future<Output = Result<bool, OrmError>> + Send
where C: DbContextEntitySet<Self> + Sync,
Self: EntityPrimaryKey + EntityPersist + FromRow + Send + SoftDeleteEntity + TenantScopedEntity { ... }
fn save<C>(
&mut self,
db: &C,
) -> impl Future<Output = Result<(), OrmError>> + Send
where C: DbContextEntitySet<Self> + Sync,
Self: AuditEntity + EntityPersist + FromRow + Send + SoftDeleteEntity + TenantScopedEntity { ... }
}Expand description
Convenience Active Record style API for entities.
Every Entity implements this trait. The methods delegate to the DbSet
declared on a DbContext, so Active Record remains a thin convenience
layer over the same query, insert, update, delete, tenant, audit, and
soft-delete pipelines used by the explicit context API.
Provided Methods§
Sourcefn query<C>(db: &C) -> DbSetQuery<Self>where
C: DbContextEntitySet<Self>,
Self: TenantScopedEntity,
fn query<C>(db: &C) -> DbSetQuery<Self>where
C: DbContextEntitySet<Self>,
Self: TenantScopedEntity,
Starts a query for this entity through the context’s DbSet<Self>.
Sourcefn find<C, K>(
db: &C,
key: K,
) -> impl Future<Output = Result<Option<Self>, OrmError>> + Sendwhere
C: DbContextEntitySet<Self>,
Self: FromRow + Send + SoftDeleteEntity + TenantScopedEntity,
K: SqlTypeMapping + Send,
fn find<C, K>(
db: &C,
key: K,
) -> impl Future<Output = Result<Option<Self>, OrmError>> + Sendwhere
C: DbContextEntitySet<Self>,
Self: FromRow + Send + SoftDeleteEntity + TenantScopedEntity,
K: SqlTypeMapping + Send,
Finds one entity by single-column primary key through the context.
Sourcefn delete<C>(
&self,
db: &C,
) -> impl Future<Output = Result<bool, OrmError>> + Sendwhere
C: DbContextEntitySet<Self> + Sync,
Self: EntityPrimaryKey + EntityPersist + FromRow + Send + SoftDeleteEntity + TenantScopedEntity,
fn delete<C>(
&self,
db: &C,
) -> impl Future<Output = Result<bool, OrmError>> + Sendwhere
C: DbContextEntitySet<Self> + Sync,
Self: EntityPrimaryKey + EntityPersist + FromRow + Send + SoftDeleteEntity + TenantScopedEntity,
Deletes this entity through the context’s DbSet<Self>.
Entities with soft_delete use logical delete. Entities with
rowversion participate in the same concurrency-conflict detection as
the explicit DbSet delete path.
Sourcefn save<C>(
&mut self,
db: &C,
) -> impl Future<Output = Result<(), OrmError>> + Sendwhere
C: DbContextEntitySet<Self> + Sync,
Self: AuditEntity + EntityPersist + FromRow + Send + SoftDeleteEntity + TenantScopedEntity,
fn save<C>(
&mut self,
db: &C,
) -> impl Future<Output = Result<(), OrmError>> + Sendwhere
C: DbContextEntitySet<Self> + Sync,
Self: AuditEntity + EntityPersist + FromRow + Send + SoftDeleteEntity + TenantScopedEntity,
Inserts or updates this entity according to the derived persistence strategy.
The method syncs the in-memory entity with the persisted row returned by SQL Server.
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".