pub struct AnyTransaction { /* private fields */ }Expand description
两种后端事务的统一句柄,并携带逻辑数据源身份。
旧构造器 AnyTransaction::MySql / AnyTransaction::Postgres 保持调用语法,
但产生的事务没有数据源身份(source() == None);框架内部通过
AnyDatabase::begin 创建时会自动标注默认/具名源。
Implementations§
Source§impl AnyTransaction
impl AnyTransaction
Sourcepub fn MySql(transaction: Transaction) -> Self
pub fn MySql(transaction: Transaction) -> Self
用 MySQL 事务构造未标注数据源的事务句柄(兼容入口)。
Sourcepub fn Postgres(transaction: Transaction) -> Self
pub fn Postgres(transaction: Transaction) -> Self
用 PostgreSQL 事务构造未标注数据源的事务句柄(兼容入口)。
Sourcepub fn source(&self) -> Option<&DatasourceId>
pub fn source(&self) -> Option<&DatasourceId>
返回事务所属逻辑数据源;旧构造器创建的事务为 None。
Sourcepub fn backend(&self) -> BackendKind
pub fn backend(&self) -> BackendKind
返回事务所属后端。
Sourcepub fn as_mysql(&mut self) -> Option<&mut Transaction>
pub fn as_mysql(&mut self) -> Option<&mut Transaction>
当持有 MySQL 事务时返回其可变引用。
Sourcepub fn as_postgres(&mut self) -> Option<&mut Transaction>
pub fn as_postgres(&mut self) -> Option<&mut Transaction>
当持有 PostgreSQL 事务时返回其可变引用。
Sourcepub async fn savepoint(&mut self, name: &str) -> Result<(), DbError>
pub async fn savepoint(&mut self, name: &str) -> Result<(), DbError>
在当前事务内创建保存点(与后端无关的封装)。
PostgreSQL 走其后端原生 SAVEPOINT;MySQL 同样支持保存点语法,这里用
校验过的标识符拼接控制语句。name 必须是 ASCII 标识符(字母/下划线开头,
仅字母/数字/下划线),非法名称返回 DbError::InvalidArgument。
Trait Implementations§
Auto Trait Implementations§
impl !RefUnwindSafe for AnyTransaction
impl !UnwindSafe for AnyTransaction
impl Forget for AnyTransaction
impl Freeze for AnyTransaction
impl Move for AnyTransaction
impl Send for AnyTransaction
impl Sync for AnyTransaction
impl Unpin for AnyTransaction
impl UnsafeUnpin for AnyTransaction
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