pub struct SharedTx<DB: Dialect> { /* private fields */ }Expand description
An app’s sqlx transaction that fastauth server API calls can join with InTx::in_tx.
The rows those calls write commit or roll back with the app’s own, and their events
fire after commit, never on rollback.
use fastauth_core::routes::CreateUserInput;
use fastauth_sqlx::{InTx, SharedTx};
let tx = SharedTx::new(pool.begin().await?);
let user = auth
.api()
.in_tx(&tx)
.create_user(CreateUserInput {
email: "lasse@acme.dk".into(),
name: "Lasse".into(),
..Default::default()
})
.await?;
fastauth_sqlx::sqlx::query("insert into team_member (team_id, user_id) values (?, ?)")
.bind(1)
.bind(user.id.as_str())
.execute(&mut **tx.lock().await)
.await?;
tx.commit().await?; // UserCreated fires hereImplementations§
pub fn new(tx: Transaction<'static, DB>) -> Self
Sourcepub async fn lock(&self) -> MutexGuard<'_, Transaction<'static, DB>>
pub async fn lock(&self) -> MutexGuard<'_, Transaction<'static, DB>>
The transaction, for the app’s own queries: .execute(&mut **tx.lock().await).
Don’t hold the guard across a fastauth call; the call waits for it.
Trait Implementations§
Auto Trait Implementations§
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
Converts
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
Converts
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more