pub struct Transaction { /* private fields */ }Expand description
数据库事务
Implementations§
Source§impl Transaction
impl Transaction
Sourcepub fn table(&mut self, table_name: &str) -> TransactionQueryBuilder<'_>
pub fn table(&mut self, table_name: &str) -> TransactionQueryBuilder<'_>
选择表,返回事务中的查询构建器
§参数
- table_name: 表名
§返回
- TransactionQueryBuilder: 事务查询构建器
§示例
use yang_db::Database;
use serde_json::json;
let db = Database::connect("mysql://root:password@localhost/test").await?;
let mut tx = db.transaction().await?;
// 在事务中插入数据
let user_data = json!({"name": "张三", "email": "zhangsan@example.com"});
let user_id = tx.table("users").insert(&user_data).await?;
// 在事务中更新数据
let update_data = json!({"status": 1});
tx.table("users")
.where_and("id", "=", user_id)
.update(&update_data)
.await?;
// 提交事务
tx.commit().await?;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