pub trait UnifiedEntityDatabaseMutation: UnifiedEntity {
type AutoGeneratedFields: Default;
// Required methods
fn save(&self, tx: &Transaction<'_>) -> CryptoKeystoreResult<()>;
fn count(tx: &Transaction<'_>) -> CryptoKeystoreResult<u32>;
fn delete(
tx: &Transaction<'_>,
id: &Self::PrimaryKey,
) -> CryptoKeystoreResult<bool>;
// Provided method
fn pre_save(&mut self) -> CryptoKeystoreResult<Self::AutoGeneratedFields> { ... }
}Expand description
Extend an Entity with db-mutating operations which can be performed when provided with a transaction.
Required Associated Types§
Sourcetype AutoGeneratedFields: Default
type AutoGeneratedFields: Default
The pre_save method might generate or update some fields of the item. The canonical example is an updated_at
field.
This type must contain a copy of each modification to the item, so that the caller of a .save(entity)
function can know what has changed and what the new values are.
For types which are not edited on save, () is perfectly acceptable for this type.
Required Methods§
Sourcefn save(&self, tx: &Transaction<'_>) -> CryptoKeystoreResult<()>
fn save(&self, tx: &Transaction<'_>) -> CryptoKeystoreResult<()>
Use the transaction’s interface to save this entity to the database
Sourcefn count(tx: &Transaction<'_>) -> CryptoKeystoreResult<u32>
fn count(tx: &Transaction<'_>) -> CryptoKeystoreResult<u32>
Use the transaction’s interface to count the number of entities of this type in the database.
Sourcefn delete(
tx: &Transaction<'_>,
id: &Self::PrimaryKey,
) -> CryptoKeystoreResult<bool>
fn delete( tx: &Transaction<'_>, id: &Self::PrimaryKey, ) -> CryptoKeystoreResult<bool>
Use the transaction’s inteface to delete this entity from the database.
Returns true if at least one entity was deleted, or false if the id was not found in the database.
For entites whose primary key has a distinct borrowed type, it is best to implement this as a direct passthrough:
fn delete(tx: &Self::Transaction, key: &Self::PrimaryKey) -> CoreCryptoKeystoreResult<bool> {
<Self as EntityTransactionDeleteBorrowed<'a>>::delete_borrowed(tx, id).await
}Provided Methods§
Sourcefn pre_save(&mut self) -> CryptoKeystoreResult<Self::AutoGeneratedFields>
fn pre_save(&mut self) -> CryptoKeystoreResult<Self::AutoGeneratedFields>
Adjust self before saving.
This will be called by the transaction’s implementation of save_mut and should not be called
as part of the save implementation.
Returns, in a format specific to the entity, all the data which has been generated or updated within this method.
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.