TransactionManager

Trait TransactionManager 

Source
pub trait TransactionManager {
    type Database: Database;

    // Required methods
    fn begin(
        conn: &mut <Self::Database as Database>::Connection,
        statement: Option<SqlStr>,
    ) -> impl Future<Output = Result<(), Error>> + Send + '_;
    fn commit(
        conn: &mut <Self::Database as Database>::Connection,
    ) -> impl Future<Output = Result<(), Error>> + Send + '_;
    fn rollback(
        conn: &mut <Self::Database as Database>::Connection,
    ) -> impl Future<Output = Result<(), Error>> + Send + '_;
    fn start_rollback(conn: &mut <Self::Database as Database>::Connection);
    fn get_transaction_depth(
        conn: &<Self::Database as Database>::Connection,
    ) -> usize;
}
Expand description

Generic management of database transactions.

This trait should not be used, except when implementing [Connection].

Required Associated Types§

Required Methods§

Source

fn begin( conn: &mut <Self::Database as Database>::Connection, statement: Option<SqlStr>, ) -> impl Future<Output = Result<(), Error>> + Send + '_

Begin a new transaction or establish a savepoint within the active transaction.

If this is a new transaction, statement may be used instead of the default “BEGIN” statement.

If we are already inside a transaction and statement.is_some(), then Error::InvalidSavePoint is returned without running any statements.

Source

fn commit( conn: &mut <Self::Database as Database>::Connection, ) -> impl Future<Output = Result<(), Error>> + Send + '_

Commit the active transaction or release the most recent savepoint.

Source

fn rollback( conn: &mut <Self::Database as Database>::Connection, ) -> impl Future<Output = Result<(), Error>> + Send + '_

Abort the active transaction or restore from the most recent savepoint.

Source

fn start_rollback(conn: &mut <Self::Database as Database>::Connection)

Starts to abort the active transaction or restore from the most recent snapshot.

Source

fn get_transaction_depth( conn: &<Self::Database as Database>::Connection, ) -> usize

Returns the current transaction depth.

Transaction depth indicates the level of nested transactions:

  • Level 0: No active transaction.
  • Level 1: A transaction is active.
  • Level 2 or higher: A transaction is active and one or more SAVEPOINTs have been created within it.

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§