pub trait TransactionManager<Conn: Connection> {
type TransactionStateData;
// Required methods
fn begin_transaction(conn: &mut Conn) -> QueryResult<()>;
fn rollback_transaction(conn: &mut Conn) -> QueryResult<()>;
fn commit_transaction(conn: &mut Conn) -> QueryResult<()>;
fn transaction_manager_status_mut(
conn: &mut Conn,
) -> &mut TransactionManagerStatus;
// Provided methods
fn transaction<F, R, E>(conn: &mut Conn, callback: F) -> Result<R, E>
where F: FnOnce(&mut Conn) -> Result<R, E>,
E: From<Error> { ... }
fn is_broken_transaction_manager(conn: &mut Conn) -> bool { ... }
}
Expand description
Manages the internal transaction state for a connection.
You will not need to interact with this trait, unless you are writing an
implementation of Connection
.
Required Associated Types§
Sourcetype TransactionStateData
type TransactionStateData
Data stored as part of the connection implementation to track the current transaction state of a connection
Required Methods§
Sourcefn begin_transaction(conn: &mut Conn) -> QueryResult<()>
fn begin_transaction(conn: &mut Conn) -> QueryResult<()>
Begin a new transaction or savepoint
If the transaction depth is greater than 0, this should create a savepoint instead. This function is expected to increment the transaction depth by 1.
Sourcefn rollback_transaction(conn: &mut Conn) -> QueryResult<()>
fn rollback_transaction(conn: &mut Conn) -> QueryResult<()>
Rollback the inner-most transaction or savepoint
If the transaction depth is greater than 1, this should rollback to the most recent savepoint. This function is expected to decrement the transaction depth by 1.
Sourcefn commit_transaction(conn: &mut Conn) -> QueryResult<()>
fn commit_transaction(conn: &mut Conn) -> QueryResult<()>
Commit the inner-most transaction or savepoint
If the transaction depth is greater than 1, this should release the most recent savepoint. This function is expected to decrement the transaction depth by 1.
Sourcefn transaction_manager_status_mut(
conn: &mut Conn,
) -> &mut TransactionManagerStatus
Available on crate feature i-implement-a-third-party-backend-and-opt-into-breaking-changes
only.
fn transaction_manager_status_mut( conn: &mut Conn, ) -> &mut TransactionManagerStatus
i-implement-a-third-party-backend-and-opt-into-breaking-changes
only.Fetch the current transaction status as mutable
Used to ensure that begin_test_transaction
is not called when already
inside of a transaction, and that operations are not run in a InError
transaction manager.
Provided Methods§
Sourcefn transaction<F, R, E>(conn: &mut Conn, callback: F) -> Result<R, E>
fn transaction<F, R, E>(conn: &mut Conn, callback: F) -> Result<R, E>
Executes the given function inside of a database transaction
Each implementation of this function needs to fulfill the documented
behaviour of Connection::transaction
Sourcefn is_broken_transaction_manager(conn: &mut Conn) -> bool
Available on crate feature i-implement-a-third-party-backend-and-opt-into-breaking-changes
only.
fn is_broken_transaction_manager(conn: &mut Conn) -> bool
i-implement-a-third-party-backend-and-opt-into-breaking-changes
only.This methods checks if the connection manager is considered to be broken by connection pool implementations
A connection manager is considered to be broken by default if it either contains an open transaction (because you don’t want to have connections with open transactions in your pool) or when the transaction manager is in an error state.
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.