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§
Sourcetype Entity: EntityTrait<ActiveModel = Self>
type Entity: EntityTrait<ActiveModel = Self>
The entity this active model belongs to.
Required Methods§
Sourcefn get(
&self,
column: <Self::Entity as EntityTrait>::Column,
) -> ActiveValue<Value>
fn get( &self, column: <Self::Entity as EntityTrait>::Column, ) -> ActiveValue<Value>
Reads an attribute as a SQL value together with its state.
Sourcefn set(
&mut self,
column: <Self::Entity as EntityTrait>::Column,
value: Value,
) -> Result<()>
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.
Sourcefn not_set(&mut self, column: <Self::Entity as EntityTrait>::Column)
fn not_set(&mut self, column: <Self::Entity as EntityTrait>::Column)
Marks an attribute NotSet.
Sourcefn is_not_set(&self, column: <Self::Entity as EntityTrait>::Column) -> bool
fn is_not_set(&self, column: <Self::Entity as EntityTrait>::Column) -> bool
Whether an attribute is NotSet.
Sourcefn reset(&mut self, column: <Self::Entity as EntityTrait>::Column)
fn reset(&mut self, column: <Self::Entity as EntityTrait>::Column)
Marks an attribute Unchanged.
Provided Methods§
Sourcefn is_changed(&self) -> bool
fn is_changed(&self) -> bool
Whether any attribute is Set.
Sourcefn set_from_json(&mut self, json: Value) -> Result<()>
Available on crate feature with-json only.
fn set_from_json(&mut self, json: Value) -> Result<()>
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.
Sourcefn from_json(json: Value) -> Result<Self>
Available on crate feature with-json only.
fn from_json(json: Value) -> Result<Self>
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.
Sourcefn get_primary_key_value(&self) -> Option<Vec<Value>>
fn get_primary_key_value(&self) -> Option<Vec<Value>>
The primary key values, or None when any key attribute is NotSet.
Sourcefn 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 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.
Sourcefn 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 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.
Sourcefn 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 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,
Sourcefn is_update(&self) -> bool
fn is_update(&self) -> bool
Whether save would update: every primary-key attribute is Unchanged.
Sourcefn 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,
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".