TransactionTrait

Trait TransactionTrait 

Source
pub trait TransactionTrait {
    type Transaction: ConnectionTrait + TransactionTrait + TransactionSession;

    // Required methods
    fn begin(&self) -> Result<Self::Transaction, DbErr>;
    fn begin_with_config(
        &self,
        isolation_level: Option<IsolationLevel>,
        access_mode: Option<AccessMode>,
    ) -> Result<Self::Transaction, DbErr>;
    fn transaction<F, T, E>(
        &self,
        callback: F,
    ) -> Result<T, TransactionError<E>>
       where F: for<'c> FnOnce(&'c Self::Transaction) -> Result<T, E>,
             E: Display + Debug;
    fn transaction_with_config<F, T, E>(
        &self,
        callback: F,
        isolation_level: Option<IsolationLevel>,
        access_mode: Option<AccessMode>,
    ) -> Result<T, TransactionError<E>>
       where F: for<'c> FnOnce(&'c Self::Transaction) -> Result<T, E>,
             E: Display + Debug;
}
Expand description

Spawn database transaction

Required Associated Typesยง

Source

type Transaction: ConnectionTrait + TransactionTrait + TransactionSession

The concrete type for the transaction

Required Methodsยง

Source

fn begin(&self) -> Result<Self::Transaction, DbErr>

Execute SQL BEGIN transaction. Returns a Transaction that can be committed or rolled back

Source

fn begin_with_config( &self, isolation_level: Option<IsolationLevel>, access_mode: Option<AccessMode>, ) -> Result<Self::Transaction, DbErr>

Execute SQL BEGIN transaction with isolation level and/or access mode. Returns a Transaction that can be committed or rolled back

Source

fn transaction<F, T, E>(&self, callback: F) -> Result<T, TransactionError<E>>
where F: for<'c> FnOnce(&'c Self::Transaction) -> Result<T, E>, E: Display + Debug,

Execute the function inside a transaction. If the function returns an error, the transaction will be rolled back. If it does not return an error, the transaction will be committed.

Source

fn transaction_with_config<F, T, E>( &self, callback: F, isolation_level: Option<IsolationLevel>, access_mode: Option<AccessMode>, ) -> Result<T, TransactionError<E>>
where F: for<'c> FnOnce(&'c Self::Transaction) -> Result<T, E>, E: Display + Debug,

Execute the function inside a transaction with isolation level and/or access mode. If the function returns an error, the transaction will be rolled back. If it does not return an error, the transaction will be committed.

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ยง