Skip to main content

AnyTransaction

Struct AnyTransaction 

Source
pub struct AnyTransaction { /* private fields */ }
Expand description

两种后端事务的统一句柄,并携带逻辑数据源身份。

旧构造器 AnyTransaction::MySql / AnyTransaction::Postgres 保持调用语法, 但产生的事务没有数据源身份(source() == None);框架内部通过 AnyDatabase::begin 创建时会自动标注默认/具名源。

Implementations§

Source§

impl AnyTransaction

Source

pub fn MySql(transaction: Transaction) -> Self

用 MySQL 事务构造未标注数据源的事务句柄(兼容入口)。

Source

pub fn Postgres(transaction: Transaction) -> Self

用 PostgreSQL 事务构造未标注数据源的事务句柄(兼容入口)。

Source

pub fn source(&self) -> Option<&DatasourceId>

返回事务所属逻辑数据源;旧构造器创建的事务为 None。

Source

pub fn backend(&self) -> BackendKind

返回事务所属后端。

Source

pub fn as_mysql(&mut self) -> Option<&mut Transaction>

当持有 MySQL 事务时返回其可变引用。

Source

pub fn as_postgres(&mut self) -> Option<&mut Transaction>

当持有 PostgreSQL 事务时返回其可变引用。

Source

pub async fn commit(self) -> Result<(), DbError>

提交事务。

Source

pub async fn savepoint(&mut self, name: &str) -> Result<(), DbError>

在当前事务内创建保存点(与后端无关的封装)。

PostgreSQL 走其后端原生 SAVEPOINT;MySQL 同样支持保存点语法,这里用 校验过的标识符拼接控制语句。name 必须是 ASCII 标识符(字母/下划线开头, 仅字母/数字/下划线),非法名称返回 DbError::InvalidArgument。

Source

pub async fn rollback_to(&mut self, name: &str) -> Result<(), DbError>

回滚到指定保存点(ROLLBACK TO SAVEPOINT)。

只撤销保存点之后的工作;更早的保存点与外层事务不受影响。

Source

pub async fn release(&mut self, name: &str) -> Result<(), DbError>

释放保存点(RELEASE SAVEPOINT)。

Source

pub async fn rollback(self) -> Result<(), DbError>

回滚事务。

Trait Implementations§

Source§

impl Debug for AnyTransaction

Source§

fn fmt(&self, formatter: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self> ⓘ

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self> ⓘ

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
where F: FnOnce(&Self) -> bool,

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
Source§

impl<T> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> ⓘ
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self> ⓘ

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more