Trait DBTransactionManager

Source
pub trait DBTransactionManager<Tx, Conn>: Send + Sync {
    type Error: Send + Sync;
    type Tx: DatabaseTransaction<Error = Self::Error> + Send + Sync;

    // Required methods
    fn begin_transaction<'life0, 'async_trait>(
        &'life0 mut self,
    ) -> Pin<Box<dyn Future<Output = Result<Self::Tx, Self::Error>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait;
    fn commit_transaction<'life0, 'async_trait>(
        tx: &'life0 mut Self::Tx,
    ) -> Pin<Box<dyn Future<Output = Result<(), Self::Error>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait;
    fn rollback_transaction<'life0, 'async_trait>(
        tx: &'life0 mut Self::Tx,
    ) -> Pin<Box<dyn Future<Output = Result<(), Self::Error>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait;
}
Expand description

Trait for managing database transactions

This trait allows for common transaction operations like beginning, committing, and rolling back transactions. It’s used by the with_transaction operator to provide automatic transaction management.

Required Associated Types§

Source

type Error: Send + Sync

The error type for transaction operations

Source

type Tx: DatabaseTransaction<Error = Self::Error> + Send + Sync

The transaction type returned by begin_transaction

Required Methods§

Source

fn begin_transaction<'life0, 'async_trait>( &'life0 mut self, ) -> Pin<Box<dyn Future<Output = Result<Self::Tx, Self::Error>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Begin a new transaction

Source

fn commit_transaction<'life0, 'async_trait>( tx: &'life0 mut Self::Tx, ) -> Pin<Box<dyn Future<Output = Result<(), Self::Error>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Commit a transaction

Source

fn rollback_transaction<'life0, 'async_trait>( tx: &'life0 mut Self::Tx, ) -> Pin<Box<dyn Future<Output = Result<(), Self::Error>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Rollback a transaction

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§

Source§

impl<DB, T, Conn> DBTransactionManager<T, Conn> for TestContext<DB>
where DB: DatabaseBackend + Send + Sync + Debug + 'static, T: DatabaseTransaction<Error = DB::Error> + Send + Sync + 'static, Conn: TestDatabaseConnection + Send + Sync + 'static, DB::Pool: DatabasePool<Connection = Conn, Error = DB::Error>,