mirror of
https://github.com/launchbadge/sqlx
synced 2024-11-10 06:24:16 +00:00
Add example on how to use Transaction as Executor (#3311)
* add example using Transaction as Executor to docs * change tx.as_mut() to &mut *tx
This commit is contained in:
parent
eaad7b2c9a
commit
940d9fb994
1 changed files with 18 additions and 0 deletions
|
@ -46,6 +46,24 @@ pub trait TransactionManager {
|
|||
/// executed after it was established to be rolled back, restoring the transaction state to
|
||||
/// what it was at the time of the savepoint.
|
||||
///
|
||||
/// A transaction can be used as an [`Executor`] when performing queries:
|
||||
/// ```rust,no_run
|
||||
/// # use sqlx_core::acquire::Acquire;
|
||||
/// # async fn example() -> sqlx::Result<()> {
|
||||
/// # let id = 1;
|
||||
/// # let mut conn: sqlx::PgConnection = unimplemented!();
|
||||
/// let mut tx = conn.begin().await?;
|
||||
///
|
||||
/// let result = sqlx::query("DELETE FROM \"testcases\" WHERE id = $1")
|
||||
/// .bind(id)
|
||||
/// .execute(&mut *tx)
|
||||
/// .await?
|
||||
/// .rows_affected();
|
||||
///
|
||||
/// tx.commit().await
|
||||
/// # }
|
||||
/// ```
|
||||
/// [`Executor`]: crate::executor::Executor
|
||||
/// [`Connection::begin`]: crate::connection::Connection::begin()
|
||||
/// [`Pool::begin`]: crate::pool::Pool::begin()
|
||||
/// [`commit`]: Self::commit()
|
||||
|
|
Loading…
Reference in a new issue