pub struct TransactionManager<'c> { /* private fields */ }Expand description
事务管理器
提供了事务的自动提交和回滚功能。
§示例
use baichun_framework_db::{DbPool, TransactionManager};
async fn example(pool: &DbPool) -> Result<()> {
let tx = pool.begin().await?;
let mut tm = TransactionManager::new(tx);
tm.execute(|tx| Box::pin(async move {
tx.execute("INSERT INTO users (name) VALUES ('Alice')").await?;
tx.execute("UPDATE users SET status = 'active' WHERE name = 'Alice'").await?;
Ok(())
})).await?;
Ok(())
}Implementations§
Source§impl<'c> TransactionManager<'c>
impl<'c> TransactionManager<'c>
Sourcepub fn new(tx: Transaction<'c, MySql>) -> Self
pub fn new(tx: Transaction<'c, MySql>) -> Self
创建新的事务管理器
Auto Trait Implementations§
impl<'c> Freeze for TransactionManager<'c>
impl<'c> !RefUnwindSafe for TransactionManager<'c>
impl<'c> Send for TransactionManager<'c>
impl<'c> Sync for TransactionManager<'c>
impl<'c> Unpin for TransactionManager<'c>
impl<'c> !UnwindSafe for TransactionManager<'c>
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