Skip to main content

Transaction

Struct Transaction 

Source
pub struct Transaction<'a> { /* private fields */ }
Expand description

事务包装器 - 使用 trait object 实现泛型

Implementations§

Source§

impl<'a> Transaction<'a>

Source

pub fn new(engine: &'a mut dyn StorageEngine) -> Self

创建新事务(默认启用回滚日志)

Source

pub fn with_rollback_log( engine: &'a mut dyn StorageEngine, enable_log: bool, ) -> Self

创建新事务(带回滚日志开关)

Source

pub fn commit(&mut self) -> DbResult<()>

提交事务

Source

pub fn rollback(&mut self) -> DbResult<()>

回滚事务

反向应用所有写操作:

  • Inserted: 删除该行
  • Updated: 恢复旧值
  • Deleted: 重新插入该行
Source

pub fn insert( &mut self, table: &str, values: Vec<(&str, DbValue)>, ) -> DbResult<RowId>

插入数据

Source

pub fn engine(&self) -> &dyn StorageEngine

获取引擎的不可变引用(用于查询等操作)

Source

pub fn engine_mut(&mut self) -> &mut dyn StorageEngine

获取引擎的可变引用

Source

pub fn query_all(&self, table: &str) -> DbResult<Vec<Row>>

查询表中所有行(简化查询接口)

Source

pub fn with_engine<F, R>(&self, f: F) -> R
where F: FnOnce(&dyn StorageEngine) -> R,

直接访问底层引擎执行操作(不记录回滚日志) 适用于查询等只读操作

Source

pub fn with_engine_mut<F, R>(&mut self, f: F) -> R
where F: FnOnce(&mut dyn StorageEngine) -> R,

直接访问底层引擎执行操作(可变)

Source

pub fn update<F>( &mut self, table: &str, condition: F, updates: Vec<(&str, DbValue)>, ) -> DbResult<usize>
where F: Fn(&Row) -> bool,

更新操作(带条件)

Source

pub fn delete<F>(&mut self, table: &str, condition: F) -> DbResult<usize>
where F: Fn(&Row) -> bool,

删除操作(带条件)

Auto Trait Implementations§

§

impl<'a> Freeze for Transaction<'a>

§

impl<'a> !RefUnwindSafe for Transaction<'a>

§

impl<'a> !Send for Transaction<'a>

§

impl<'a> !Sync for Transaction<'a>

§

impl<'a> Unpin for Transaction<'a>

§

impl<'a> UnsafeUnpin for Transaction<'a>

§

impl<'a> !UnwindSafe for Transaction<'a>

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, 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, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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.