#[non_exhaustive]pub struct Transaction<'a> { /* private fields */ }Expand description
An active transaction guard.
Created via Connection::transaction or Connection::transaction_with.
The guard provides methods to execute queries within the transaction and
to commit or rollback it.
§Drop behaviour
Drop cannot perform async I/O. If the transaction is not explicitly
committed or rolled back before it goes out of scope, the connection may
be left in an idle-in-transaction state. Always call .commit().await
or .rollback().await explicitly.
Implementations§
Source§impl<'a> Transaction<'a>
impl<'a> Transaction<'a>
Sourcepub async fn query(&mut self, sql: &str) -> Result<QueryResult>
pub async fn query(&mut self, sql: &str) -> Result<QueryResult>
Execute a query that returns rows, within the transaction.
Sourcepub async fn execute(&mut self, sql: &str) -> Result<ExecuteResult>
pub async fn execute(&mut self, sql: &str) -> Result<ExecuteResult>
Execute a statement that does not return rows.
Sourcepub async fn query_one(&mut self, sql: &str) -> Result<Option<Row>>
pub async fn query_one(&mut self, sql: &str) -> Result<Option<Row>>
Execute a query and return at most one row.
Sourcepub async fn query_params(
&mut self,
sql: &str,
params: &[&dyn ToSql],
) -> Result<QueryResult>
pub async fn query_params( &mut self, sql: &str, params: &[&dyn ToSql], ) -> Result<QueryResult>
Execute a parameterized query that returns rows.
Sourcepub async fn execute_params(
&mut self,
sql: &str,
params: &[&dyn ToSql],
) -> Result<ExecuteResult>
pub async fn execute_params( &mut self, sql: &str, params: &[&dyn ToSql], ) -> Result<ExecuteResult>
Execute a parameterized statement that does not return rows.
Sourcepub async fn prepare(&mut self, sql: &str) -> Result<PreparedStatement>
pub async fn prepare(&mut self, sql: &str) -> Result<PreparedStatement>
Prepare a statement within the transaction.
Sourcepub async fn savepoint(&mut self, name: &str) -> Result<Savepoint<'_, 'a>>
pub async fn savepoint(&mut self, name: &str) -> Result<Savepoint<'_, 'a>>
Create a savepoint (nested transaction scope).
Only one Savepoint guard can be active at a time for a given
Transaction because it holds a mutable borrow.