pub trait TransactionExecutor: Send + Sync {
// Required methods
fn execute<'life0, 'life1, 'async_trait>(
&'life0 mut self,
sql: &'life1 str,
params: Vec<QueryValue>,
) -> Pin<Box<dyn Future<Output = Result<QueryResult, DatabaseError>> + Send + 'async_trait>>
where 'life0: 'async_trait,
'life1: 'async_trait,
Self: 'async_trait;
fn fetch_one<'life0, 'life1, 'async_trait>(
&'life0 mut self,
sql: &'life1 str,
params: Vec<QueryValue>,
) -> Pin<Box<dyn Future<Output = Result<Row, DatabaseError>> + Send + 'async_trait>>
where 'life0: 'async_trait,
'life1: 'async_trait,
Self: 'async_trait;
fn fetch_all<'life0, 'life1, 'async_trait>(
&'life0 mut self,
sql: &'life1 str,
params: Vec<QueryValue>,
) -> Pin<Box<dyn Future<Output = Result<Vec<Row>, DatabaseError>> + Send + 'async_trait>>
where 'life0: 'async_trait,
'life1: 'async_trait,
Self: 'async_trait;
fn fetch_optional<'life0, 'life1, 'async_trait>(
&'life0 mut self,
sql: &'life1 str,
params: Vec<QueryValue>,
) -> Pin<Box<dyn Future<Output = Result<Option<Row>, DatabaseError>> + Send + 'async_trait>>
where 'life0: 'async_trait,
'life1: 'async_trait,
Self: 'async_trait;
fn commit<'async_trait>(
self: Box<Self>,
) -> Pin<Box<dyn Future<Output = Result<(), DatabaseError>> + Send + 'async_trait>>
where Self: 'async_trait;
fn rollback<'async_trait>(
self: Box<Self>,
) -> Pin<Box<dyn Future<Output = Result<(), DatabaseError>> + Send + 'async_trait>>
where Self: 'async_trait;
// Provided methods
fn savepoint<'life0, 'life1, 'async_trait>(
&'life0 mut self,
name: &'life1 str,
) -> Pin<Box<dyn Future<Output = Result<(), DatabaseError>> + Send + 'async_trait>>
where 'life0: 'async_trait,
'life1: 'async_trait,
Self: 'async_trait { ... }
fn release_savepoint<'life0, 'life1, 'async_trait>(
&'life0 mut self,
name: &'life1 str,
) -> Pin<Box<dyn Future<Output = Result<(), DatabaseError>> + Send + 'async_trait>>
where 'life0: 'async_trait,
'life1: 'async_trait,
Self: 'async_trait { ... }
fn rollback_to_savepoint<'life0, 'life1, 'async_trait>(
&'life0 mut self,
name: &'life1 str,
) -> Pin<Box<dyn Future<Output = Result<(), DatabaseError>> + Send + 'async_trait>>
where 'life0: 'async_trait,
'life1: 'async_trait,
Self: 'async_trait { ... }
}database and non-WebAssembly only.Expand description
Transaction executor trait for database-specific transaction handling
This trait represents a dedicated database connection that is used for transaction operations. All queries executed through this executor are guaranteed to run on the same physical connection, ensuring proper transaction isolation.
§Implementation Notes
SQLx connection pools distribute queries across multiple connections.
To ensure transaction consistency, we need to acquire a dedicated
connection via pool.begin() which returns a Transaction that
maintains connection affinity.
Required Methods§
Sourcefn execute<'life0, 'life1, 'async_trait>(
&'life0 mut self,
sql: &'life1 str,
params: Vec<QueryValue>,
) -> Pin<Box<dyn Future<Output = Result<QueryResult, DatabaseError>> + Send + 'async_trait>>where
'life0: 'async_trait,
'life1: 'async_trait,
Self: 'async_trait,
fn execute<'life0, 'life1, 'async_trait>(
&'life0 mut self,
sql: &'life1 str,
params: Vec<QueryValue>,
) -> Pin<Box<dyn Future<Output = Result<QueryResult, DatabaseError>> + Send + 'async_trait>>where
'life0: 'async_trait,
'life1: 'async_trait,
Self: 'async_trait,
Execute a query that modifies the database within the transaction
Sourcefn fetch_one<'life0, 'life1, 'async_trait>(
&'life0 mut self,
sql: &'life1 str,
params: Vec<QueryValue>,
) -> Pin<Box<dyn Future<Output = Result<Row, DatabaseError>> + Send + 'async_trait>>where
'life0: 'async_trait,
'life1: 'async_trait,
Self: 'async_trait,
fn fetch_one<'life0, 'life1, 'async_trait>(
&'life0 mut self,
sql: &'life1 str,
params: Vec<QueryValue>,
) -> Pin<Box<dyn Future<Output = Result<Row, DatabaseError>> + Send + 'async_trait>>where
'life0: 'async_trait,
'life1: 'async_trait,
Self: 'async_trait,
Fetch a single row within the transaction
Sourcefn fetch_all<'life0, 'life1, 'async_trait>(
&'life0 mut self,
sql: &'life1 str,
params: Vec<QueryValue>,
) -> Pin<Box<dyn Future<Output = Result<Vec<Row>, DatabaseError>> + Send + 'async_trait>>where
'life0: 'async_trait,
'life1: 'async_trait,
Self: 'async_trait,
fn fetch_all<'life0, 'life1, 'async_trait>(
&'life0 mut self,
sql: &'life1 str,
params: Vec<QueryValue>,
) -> Pin<Box<dyn Future<Output = Result<Vec<Row>, DatabaseError>> + Send + 'async_trait>>where
'life0: 'async_trait,
'life1: 'async_trait,
Self: 'async_trait,
Fetch all matching rows within the transaction
Sourcefn fetch_optional<'life0, 'life1, 'async_trait>(
&'life0 mut self,
sql: &'life1 str,
params: Vec<QueryValue>,
) -> Pin<Box<dyn Future<Output = Result<Option<Row>, DatabaseError>> + Send + 'async_trait>>where
'life0: 'async_trait,
'life1: 'async_trait,
Self: 'async_trait,
fn fetch_optional<'life0, 'life1, 'async_trait>(
&'life0 mut self,
sql: &'life1 str,
params: Vec<QueryValue>,
) -> Pin<Box<dyn Future<Output = Result<Option<Row>, DatabaseError>> + Send + 'async_trait>>where
'life0: 'async_trait,
'life1: 'async_trait,
Self: 'async_trait,
Fetch an optional single row within the transaction
Provided Methods§
Sourcefn savepoint<'life0, 'life1, 'async_trait>(
&'life0 mut self,
name: &'life1 str,
) -> Pin<Box<dyn Future<Output = Result<(), DatabaseError>> + Send + 'async_trait>>where
'life0: 'async_trait,
'life1: 'async_trait,
Self: 'async_trait,
fn savepoint<'life0, 'life1, 'async_trait>(
&'life0 mut self,
name: &'life1 str,
) -> Pin<Box<dyn Future<Output = Result<(), DatabaseError>> + Send + 'async_trait>>where
'life0: 'async_trait,
'life1: 'async_trait,
Self: 'async_trait,
Create a savepoint within the transaction
Savepoints allow creating checkpoints within a transaction that can be rolled back to without affecting the entire transaction.
§Arguments
name- The name of the savepoint to create
§Default Implementation
Returns an error indicating savepoints are not supported. Backends that support savepoints should override this method.