pub struct Transaction { /* private fields */ }Expand description
Transaction guard for automatic commit/rollback
This wrapper around SQLx transactions provides:
- Automatic commit on drop (if not already committed/rolled back)
- Explicit commit and rollback methods
- Prevents accidental use after commit/rollback
§Example
use ormkit::transaction::Transaction;
let mut tx = Transaction::begin(pool).await?;
// Perform operations
sqlx::query("INSERT INTO users (name) VALUES ($1)")
.bind("John")
.execute(&mut *tx)
.await?;
// Explicitly commit
tx.commit().await?;Implementations§
Source§impl Transaction
impl Transaction
Sourcepub async fn begin(pool: &PgPool) -> TransactionResult<Self>
pub async fn begin(pool: &PgPool) -> TransactionResult<Self>
Sourcepub async fn begin_with_isolation(
pool: &PgPool,
isolation_level: IsolationLevel,
) -> TransactionResult<Self>
pub async fn begin_with_isolation( pool: &PgPool, isolation_level: IsolationLevel, ) -> TransactionResult<Self>
Sourcepub async fn commit(self) -> TransactionResult<()>
pub async fn commit(self) -> TransactionResult<()>
Sourcepub async fn rollback(self) -> TransactionResult<()>
pub async fn rollback(self) -> TransactionResult<()>
Sourcepub async fn savepoint(&mut self, _name: &str) -> TransactionResult<()>
pub async fn savepoint(&mut self, _name: &str) -> TransactionResult<()>
Sourcepub fn is_committed(&self) -> bool
pub fn is_committed(&self) -> bool
Check if the transaction has been committed
Sourcepub fn is_rolled_back(&self) -> bool
pub fn is_rolled_back(&self) -> bool
Check if the transaction has been rolled back
Trait Implementations§
Source§impl Deref for Transaction
impl Deref for Transaction
Source§impl DerefMut for Transaction
impl DerefMut for Transaction
Auto Trait Implementations§
impl Freeze for Transaction
impl !RefUnwindSafe for Transaction
impl Send for Transaction
impl Sync for Transaction
impl Unpin for Transaction
impl UnsafeUnpin for Transaction
impl !UnwindSafe for Transaction
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