Skip to main content

MemoryEngine

Struct MemoryEngine 

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

内存存储引擎实现

Implementations§

Source§

impl MemoryEngine

Source

pub fn new() -> Self

Source

pub fn create_index(&mut self, table: &str, column: &str) -> DbResult<()>

为表列创建索引(单列,向后兼容)

Source

pub fn create_composite_index( &mut self, table: &str, columns: &[&str], ) -> DbResult<()>

为表列创建复合索引

Source

pub fn create_unique_index( &mut self, table: &str, columns: &[&str], ) -> DbResult<()>

创建唯一复合索引

Source

pub fn drop_index(&mut self, table: &str, column: &str) -> DbResult<bool>

删除索引

Source

pub fn drop_composite_index( &mut self, table: &str, columns: &[&str], ) -> DbResult<bool>

删除复合索引

Source

pub fn has_index(&self, table: &str, column: &str) -> bool

检查列是否有索引

Source

pub fn has_composite_index(&self, table: &str, columns: &[&str]) -> bool

检查复合索引是否存在

Source

pub fn get_index(&self, table: &str, column: &str) -> Option<&BTreeIndex>

获取索引(不可变引用,单列)

Source

pub fn get_composite_index( &self, table: &str, columns: &[&str], ) -> Option<&BTreeIndex>

获取复合索引(不可变引用)

Source

pub fn get_index_mut( &mut self, table: &str, column: &str, ) -> Option<&mut BTreeIndex>

获取索引(可变引用,单列)

Source

pub fn get_composite_index_mut( &mut self, table: &str, columns: &[&str], ) -> Option<&mut BTreeIndex>

获取复合索引(可变引用)

Source

pub fn drop_table_indexes(&mut self, table: &str)

删除表的所有索引

Source

pub fn get_row_count(&self, table: &str) -> DbResult<usize>

获取表的行数

Source

pub fn remove_from_index( &mut self, table: &str, column: &str, key: &DbValue, row_id: RowId, )

从索引中删除键值对(用于 delete 操作,单列)

Source

pub fn remove_from_composite_index( &mut self, table: &str, columns: &[&str], key: &[DbValue], row_id: RowId, )

从复合索引中删除键值对

Source

pub fn add_to_index( &mut self, table: &str, column: &str, key: DbValue, row_id: RowId, )

向索引添加键值对(用于 insert 操作,单列)

Source

pub fn add_to_composite_index( &mut self, table: &str, columns: &[&str], key: Vec<DbValue>, row_id: RowId, )

向复合索引添加键值对

Source

pub fn find_best_index( &self, table: &str, filter_columns: &[&str], ) -> Option<(&IndexMeta, &BTreeIndex)>

查找最佳索引

Source

pub fn serialize(&self) -> Result<SerializableEngineData, String>

序列化引擎数据(用于快照)

Source

pub fn deserialize(data: SerializableEngineData) -> Self

从序列化数据恢复(用于快照加载)

Trait Implementations§

Source§

impl Default for MemoryEngine

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl StorageEngine for MemoryEngine

Source§

fn create_table(&mut self, schema: TableSchema) -> DbResult<()>

创建表
Source§

fn drop_table(&mut self, name: &str) -> DbResult<()>

删除表
Source§

fn has_table(&self, name: &str) -> bool

检查表是否存在
Source§

fn get_schema(&self, name: &str) -> DbResult<TableSchema>

获取表 schema(返回克隆,支持锁守卫场景)
Source§

fn insert(&mut self, table: &str, row: Row) -> DbResult<RowId>

插入行
Source§

fn get(&self, table: &str, row_id: RowId) -> DbResult<Option<Row>>

获取行(返回克隆,支持锁守卫场景)
Source§

fn update(&mut self, table: &str, row_id: RowId, values: Row) -> DbResult<()>

更新行
Source§

fn delete(&mut self, table: &str, row_id: RowId) -> DbResult<Option<Row>>

删除行
Source§

fn scan(&self, table: &str) -> DbResult<Vec<(RowId, Row)>>

扫描全表(返回克隆,支持锁守卫场景)

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, 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.