Skip to main content

Record

Trait Record 

Source
pub trait Record:
    Sized
    + Send
    + Sync
    + 'static {
    type Entity: EntityTrait;
    type ActiveModel: ActiveModelTrait<Entity = Self::Entity> + ActiveModelBehavior + Send + 'static;

    // Required methods
    fn from_model(model: <Self::Entity as EntityTrait>::Model) -> Self;
    fn into_active_model_full(&self) -> Self::ActiveModel;
    fn into_active_model(&self) -> Self::ActiveModel;
    fn apply_auto_fields(am: &mut Self::ActiveModel, is_insert: bool);

    // Provided methods
    fn find_all(
        db: &impl ConnectionTrait,
    ) -> impl Future<Output = Result<Vec<Self>, Error>> + Send
       where <Self::Entity as EntityTrait>::Model: FromQueryResult + Send + Sync,
             Self: From<<Self::Entity as EntityTrait>::Model> { ... }
    fn query() -> EntityQuery<Self, Self::Entity>
       where <Self::Entity as EntityTrait>::Model: FromQueryResult + Send + Sync,
             Self: From<<Self::Entity as EntityTrait>::Model> { ... }
    fn update_many() -> EntityUpdateMany<Self::Entity> { ... }
    fn delete_many() -> EntityDeleteMany<Self::Entity> { ... }
}
Expand description

Core trait for domain model types backed by a database table.

The #[modo_db::entity] macro generates an implementation of this trait for each entity struct. It provides CRUD operations and query builders.

Most methods are macro-generated (not default impls) because they need either PK-specific signatures or concrete type context for hook resolution.

Required Associated Types§

Required Methods§

Source

fn from_model(model: <Self::Entity as EntityTrait>::Model) -> Self

Convert a SeaORM model to the domain type.

Source

fn into_active_model_full(&self) -> Self::ActiveModel

Convert to an active model with ALL fields set.

Source

fn into_active_model(&self) -> Self::ActiveModel

Convert to an active model with only PK fields set (rest NotSet).

Source

fn apply_auto_fields(am: &mut Self::ActiveModel, is_insert: bool)

Fill auto-generated fields (ID, timestamps) on an active model.

Provided Methods§

Source

fn find_all( db: &impl ConnectionTrait, ) -> impl Future<Output = Result<Vec<Self>, Error>> + Send
where <Self::Entity as EntityTrait>::Model: FromQueryResult + Send + Sync, Self: From<<Self::Entity as EntityTrait>::Model>,

Fetch all records.

Source

fn query() -> EntityQuery<Self, Self::Entity>
where <Self::Entity as EntityTrait>::Model: FromQueryResult + Send + Sync, Self: From<<Self::Entity as EntityTrait>::Model>,

Start a chainable query builder.

Source

fn update_many() -> EntityUpdateMany<Self::Entity>

Start a bulk UPDATE builder.

Source

fn delete_many() -> EntityDeleteMany<Self::Entity>

Start a bulk DELETE builder.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§