Skip to main content

EntityDatabaseMutation

Trait EntityDatabaseMutation 

Source
pub trait EntityDatabaseMutation: Entity {
    // Required methods
    fn save<'a, Tx>(&self, tx: &'a Tx) -> CryptoKeystoreResult<()>
       where &'a Tx: Into<Transactionlike<'a>>;
    fn delete<'a, Tx>(
        tx: &'a Tx,
        id: &Self::PrimaryKey,
    ) -> CryptoKeystoreResult<bool>
       where Transactionlike<'a>: From<&'a Tx>;
}
Expand description

Extend an Entity with db-mutating operations which can be performed when provided with a transaction.

Required Methods§

Source

fn save<'a, Tx>(&self, tx: &'a Tx) -> CryptoKeystoreResult<()>

Save this entity to the database in the context of this transaction.

The transaction is required instead of a simple connection to give us type-level assurances that we only mutate the database within the context of a transaction; every mutation can be rolled back if necessary.

Unlike in earlier iterations of this trait, saving makes no automatic adjustment to the entity being saved. Entities requiring a pre_save method must implement this manually.

Source

fn delete<'a, Tx>( tx: &'a Tx, 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<'a, Tx>(tx: &'a Tx, id: &Self::PrimaryKey) -> CryptoKeystoreResult<bool>
where
    &'a Tx: Into<Transactionlike<'a>>,
{
    <Self as EntityDeleteBorrowed>::delete_borrowed(tx, id)
}

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§