[−][src]Struct sqlx::Transaction
Represents an in-progress database transaction.
A transaction ends with a call to commit
or rollback
in which the wrapped connection (
or outer transaction) is returned. If neither are called before the transaction
goes out-of-scope, rollback
is called. In other words, rollback
is called on drop
if the transaction is still in-progress.
// Acquire a new connection and immediately begin a transaction let mut tx = pool.begin().await?; sqlx::query("INSERT INTO articles (slug) VALUES ('this-is-a-slug')") .execute(&mut tx) // As we didn't fill in all the required fields in this INSERT, // this statement will fail. Since we used `?`, this function // will immediately return with the error which will cause // this transaction to be rolled back. .await?;
Methods
impl<C> Transaction<C> where
C: Connection,
[src]
C: Connection,
pub async fn begin(self) -> Result<Transaction<Transaction<C>>, Error>
[src]
Creates a new save point in the current transaction and returns
a new Transaction
object to manage its scope.
pub async fn commit(__arg0: Self) -> Result<C, Error>
[src]
Commits the current transaction or save point. Returns the inner connection or transaction.
pub async fn rollback(__arg0: Self) -> Result<C, Error>
[src]
Rollback the current transaction or save point. Returns the inner connection or transaction.
Trait Implementations
impl<C> Connection for Transaction<C> where
C: Connection,
[src]
C: Connection,
fn close(
self
) -> Pin<Box<dyn Future<Output = Result<(), Error>> + 'static + Send>>
[src]
self
) -> Pin<Box<dyn Future<Output = Result<(), Error>> + 'static + Send>>
fn ping(&mut self) -> Pin<Box<dyn Future<Output = Result<(), Error>> + Send>>
[src]
fn begin(
self
) -> Pin<Box<dyn Future<Output = Result<Transaction<Self>, Error>> + 'static + Send>>
[src]
self
) -> Pin<Box<dyn Future<Output = Result<Transaction<Self>, Error>> + 'static + Send>>
impl<C> Deref for Transaction<C> where
C: Connection,
[src]
C: Connection,
type Target = C
The resulting type after dereferencing.
fn deref(&self) -> &<Transaction<C> as Deref>::Target
[src]
impl<C> DerefMut for Transaction<C> where
C: Connection,
[src]
C: Connection,
fn deref_mut(&mut self) -> &mut <Transaction<C> as Deref>::Target
[src]
impl<C> Drop for Transaction<C> where
C: Connection,
[src]
C: Connection,
impl<DB, C> Executor for Transaction<C> where
C: Connection<Database = DB>,
DB: Database,
[src]
C: Connection<Database = DB>,
DB: Database,
type Database = <C as Executor>::Database
The specific database that this type is implemented for.
fn execute<'e, 'q, 'c, E>(
&'c mut self,
query: E
) -> Pin<Box<dyn Future<Output = Result<u64, Error>> + 'e + Send>> where
'q: 'e,
'c: 'e,
E: 'e + Execute<'q, <Transaction<C> as Executor>::Database>,
[src]
&'c mut self,
query: E
) -> Pin<Box<dyn Future<Output = Result<u64, Error>> + 'e + Send>> where
'q: 'e,
'c: 'e,
E: 'e + Execute<'q, <Transaction<C> as Executor>::Database>,
fn fetch<'q, E>(
&'e mut self,
query: E
) -> <<Transaction<C> as Executor>::Database as HasCursor<'e, 'q>>::Cursor where
E: Execute<'q, <Transaction<C> as Executor>::Database>,
[src]
&'e mut self,
query: E
) -> <<Transaction<C> as Executor>::Database as HasCursor<'e, 'q>>::Cursor where
E: Execute<'q, <Transaction<C> as Executor>::Database>,
impl<'e, DB, C> RefExecutor<'e> for &'e mut Transaction<C> where
C: Connection<Database = DB>,
DB: Database,
[src]
C: Connection<Database = DB>,
DB: Database,
type Database = DB
fn fetch_by_ref<'q, E>(
self,
query: E
) -> <<&'e mut Transaction<C> as RefExecutor<'e>>::Database as HasCursor<'e, 'q>>::Cursor where
E: Execute<'q, <&'e mut Transaction<C> as RefExecutor<'e>>::Database>,
[src]
self,
query: E
) -> <<&'e mut Transaction<C> as RefExecutor<'e>>::Database as HasCursor<'e, 'q>>::Cursor where
E: Execute<'q, <&'e mut Transaction<C> as RefExecutor<'e>>::Database>,
Auto Trait Implementations
impl<C> RefUnwindSafe for Transaction<C> where
C: RefUnwindSafe,
C: RefUnwindSafe,
impl<C> Send for Transaction<C>
impl<C> Sync for Transaction<C> where
C: Sync,
C: Sync,
impl<C> Unpin for Transaction<C> where
C: Unpin,
C: Unpin,
impl<C> UnwindSafe for Transaction<C> where
C: UnwindSafe,
C: UnwindSafe,
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T> Same<T> for T
type Output = T
Should always be Self
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,
type Error = <U as TryFrom<T>>::Error
The type returned in the event of a conversion error.
fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>
[src]
impl<V, T> VZip<V> for T where
V: MultiLane<T>,
V: MultiLane<T>,