Skip to main content

TransactionManager

Trait TransactionManager 

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§

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.

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.

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.

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

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

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".

Implementors§

§

impl TransactionManager for AnyTransactionManager

§

type Database = Any

§

impl TransactionManager for PgTransactionManager