pub trait Transaction: Send {
type Error: Error + Send + Sync + 'static;
type Row: Row;
type Nested<'a>: Transaction<Error = Self::Error, Row = Self::Row> + 'a
where Self: 'a;
// Required methods
fn query(
&self,
sql: &str,
params: &[&dyn ToSqlParam],
) -> impl Future<Output = Result<Vec<Self::Row>, Self::Error>> + Send;
fn execute(
&self,
sql: &str,
params: &[&dyn ToSqlParam],
) -> impl Future<Output = Result<u64, Self::Error>> + Send;
fn transaction(
&mut self,
) -> impl Future<Output = Result<Self::Nested<'_>, Self::Error>> + Send;
fn commit(self) -> impl Future<Output = Result<(), Self::Error>> + Send;
fn rollback(self) -> impl Future<Output = Result<(), Self::Error>> + Send;
}Expand description
Trait for a database transaction.
Supports the same query/execute operations as Client, plus commit/rollback.
Dropping without calling commit() should rollback the transaction.
Required Associated Types§
type Error: Error + Send + Sync + 'static
type Row: Row
type Nested<'a>: Transaction<Error = Self::Error, Row = Self::Row> + 'a where Self: 'a
Required Methods§
Sourcefn query(
&self,
sql: &str,
params: &[&dyn ToSqlParam],
) -> impl Future<Output = Result<Vec<Self::Row>, Self::Error>> + Send
fn query( &self, sql: &str, params: &[&dyn ToSqlParam], ) -> impl Future<Output = Result<Vec<Self::Row>, Self::Error>> + Send
Execute a query that returns rows.
Sourcefn execute(
&self,
sql: &str,
params: &[&dyn ToSqlParam],
) -> impl Future<Output = Result<u64, Self::Error>> + Send
fn execute( &self, sql: &str, params: &[&dyn ToSqlParam], ) -> impl Future<Output = Result<u64, Self::Error>> + Send
Execute a statement that returns the number of affected rows.
Sourcefn transaction(
&mut self,
) -> impl Future<Output = Result<Self::Nested<'_>, Self::Error>> + Send
fn transaction( &mut self, ) -> impl Future<Output = Result<Self::Nested<'_>, Self::Error>> + Send
Begin a nested transaction (savepoint).
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.