Skip to main content

ActiveModelTrait

Trait ActiveModelTrait 

Source
pub trait ActiveModelTrait:
    Clone
    + Send
    + Sync
    + Debug
    + Default {
    type Entity: EntityTrait<ActiveModel = Self>;

Show 15 methods // Required methods fn get( &self, column: <Self::Entity as EntityTrait>::Column, ) -> ActiveValue<Value>; fn set( &mut self, column: <Self::Entity as EntityTrait>::Column, value: Value, ) -> Result<()>; fn not_set(&mut self, column: <Self::Entity as EntityTrait>::Column); fn is_not_set(&self, column: <Self::Entity as EntityTrait>::Column) -> bool; fn reset(&mut self, column: <Self::Entity as EntityTrait>::Column); // Provided methods fn reset_all(self) -> Self { ... } fn is_changed(&self) -> bool { ... } fn set_from_json(&mut self, json: Value) -> Result<()> { ... } fn from_json(json: Value) -> Result<Self> { ... } fn get_primary_key_value(&self) -> Option<Vec<Value>> { ... } fn insert<'life0, 'async_trait, C>( self, db: &'life0 C, ) -> Pin<Box<dyn Future<Output = Result<<Self::Entity as EntityTrait>::Model>> + Send + 'async_trait>> where Self: ActiveModelBehavior + 'async_trait, C: 'async_trait + ConnectionTrait, 'life0: 'async_trait { ... } fn update<'life0, 'async_trait, C>( self, db: &'life0 C, ) -> Pin<Box<dyn Future<Output = Result<<Self::Entity as EntityTrait>::Model>> + Send + 'async_trait>> where Self: ActiveModelBehavior + 'async_trait, C: 'async_trait + ConnectionTrait, 'life0: 'async_trait { ... } fn save<'life0, 'async_trait, C>( self, db: &'life0 C, ) -> Pin<Box<dyn Future<Output = Result<Self>> + Send + 'async_trait>> where Self: ActiveModelBehavior + 'async_trait, <Self::Entity as EntityTrait>::Model: IntoActiveModel<Self>, C: 'async_trait + ConnectionTrait, 'life0: 'async_trait { ... } fn is_update(&self) -> bool { ... } fn delete<'life0, 'async_trait, C>( self, db: &'life0 C, ) -> Pin<Box<dyn Future<Output = Result<DeleteResult>> + Send + 'async_trait>> where Self: ActiveModelBehavior + 'async_trait, C: 'async_trait + ConnectionTrait, 'life0: 'async_trait { ... }
}
Expand description

The mutable form of an entity, derived by DeriveEntityModel.

Required Associated Types§

Source

type Entity: EntityTrait<ActiveModel = Self>

The entity this active model belongs to.

Required Methods§

Source

fn get( &self, column: <Self::Entity as EntityTrait>::Column, ) -> ActiveValue<Value>

Reads an attribute as a SQL value together with its state.

Source

fn set( &mut self, column: <Self::Entity as EntityTrait>::Column, value: Value, ) -> Result<()>

Sets an attribute from a SQL value, marking it Set.

§Errors

Returns DbErr::Type when the value cannot be decoded as the field type.

Source

fn not_set(&mut self, column: <Self::Entity as EntityTrait>::Column)

Marks an attribute NotSet.

Source

fn is_not_set(&self, column: <Self::Entity as EntityTrait>::Column) -> bool

Whether an attribute is NotSet.

Source

fn reset(&mut self, column: <Self::Entity as EntityTrait>::Column)

Marks an attribute Unchanged.

Provided Methods§

Source

fn reset_all(self) -> Self

Marks every attribute Unchanged.

Source

fn is_changed(&self) -> bool

Whether any attribute is Set.

Source

fn set_from_json(&mut self, json: Value) -> Result<()>

Available on crate feature with-json only.

Sets every attribute named by a key of the JSON object json, matching keys against column names.

Keys that are not columns are ignored. Numbers, strings, booleans and null map onto the storage classes; an array or an object is stored as its JSON text, which is how a JSON column expects it.

§Errors

Returns DbErr::Json when json is not an object; DbErr::Type when a value cannot be decoded as the attribute type.

Source

fn from_json(json: Value) -> Result<Self>

Available on crate feature with-json only.

Builds an active model with every attribute named in json set and the others NotSet; see set_from_json.

§Errors

Returns the errors of set_from_json.

Source

fn get_primary_key_value(&self) -> Option<Vec<Value>>

The primary key values, or None when any key attribute is NotSet.

Source

fn insert<'life0, 'async_trait, C>( self, db: &'life0 C, ) -> Pin<Box<dyn Future<Output = Result<<Self::Entity as EntityTrait>::Model>> + Send + 'async_trait>>
where Self: ActiveModelBehavior + 'async_trait, C: 'async_trait + ConnectionTrait, 'life0: 'async_trait,

Inserts the active model and returns the stored model via INSERT ... RETURNING *.

The ActiveModelBehavior hooks run around the statement.

§Errors

Returns DbErr::RecordNotInserted when the statement inserted nothing; DbErr::Driver when the statement or the decoding of the returned row fails; any error raised by the hooks.

Source

fn update<'life0, 'async_trait, C>( self, db: &'life0 C, ) -> Pin<Box<dyn Future<Output = Result<<Self::Entity as EntityTrait>::Model>> + Send + 'async_trait>>
where Self: ActiveModelBehavior + 'async_trait, C: 'async_trait + ConnectionTrait, 'life0: 'async_trait,

Updates the row matched by the primary key and returns the stored model.

Only Set attributes are written; with none, the row is simply fetched. The ActiveModelBehavior hooks run around the statement.

§Errors

Returns DbErr::PrimaryKeyNotSet when a key attribute is NotSet; DbErr::RecordNotUpdated when no row matches the key; DbErr::Driver when the statement or the decoding of the returned row fails; any error raised by the hooks.

Source

fn save<'life0, 'async_trait, C>( self, db: &'life0 C, ) -> Pin<Box<dyn Future<Output = Result<Self>> + Send + 'async_trait>>
where Self: ActiveModelBehavior + 'async_trait, <Self::Entity as EntityTrait>::Model: IntoActiveModel<Self>, C: 'async_trait + ConnectionTrait, 'life0: 'async_trait,

Inserts when the primary key is NotSet or Set, updates when it is Unchanged.

Returns the active model with every attribute Unchanged, so that it can be modified and saved again.

§Errors

Returns the errors of insert or update, whichever ran.

Source

fn is_update(&self) -> bool

Whether save would update: every primary-key attribute is Unchanged.

Source

fn delete<'life0, 'async_trait, C>( self, db: &'life0 C, ) -> Pin<Box<dyn Future<Output = Result<DeleteResult>> + Send + 'async_trait>>
where Self: ActiveModelBehavior + 'async_trait, C: 'async_trait + ConnectionTrait, 'life0: 'async_trait,

Deletes the row matched by the primary key.

The ActiveModelBehavior hooks run around the statement.

§Errors

Returns DbErr::PrimaryKeyNotSet when a key attribute is NotSet; DbErr::Driver when the statement fails; any error raised by the hooks.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§