pub struct EmbeddedDb { /* private fields */ }Expand description
嵌入式数据库
提供简化的数据库操作 API
Implementations§
Source§impl EmbeddedDb
impl EmbeddedDb
Sourcepub fn open(name: &str) -> Result<Self, SqliteError>
pub fn open(name: &str) -> Result<Self, SqliteError>
Sourcepub fn open_with_config(
name: &str,
config: SqliteConfig,
) -> Result<Self, SqliteError>
pub fn open_with_config( name: &str, config: SqliteConfig, ) -> Result<Self, SqliteError>
打开带配置的数据库
Sourcepub fn memory() -> Result<Self, SqliteError>
pub fn memory() -> Result<Self, SqliteError>
创建内存数据库
Sourcepub fn connection(&self) -> &Connection
pub fn connection(&self) -> &Connection
获取底层连接
Sourcepub fn migrate<F>(&self, f: F) -> Result<MigrationReport, SqliteError>where
F: FnOnce(&mut MigrationBuilder),
pub fn migrate<F>(&self, f: F) -> Result<MigrationReport, SqliteError>where
F: FnOnce(&mut MigrationBuilder),
执行迁移
Sourcepub fn schema_version(&self) -> Result<u32, SqliteError>
pub fn schema_version(&self) -> Result<u32, SqliteError>
获取当前 schema 版本
Sourcepub fn select(&self, table: &str) -> SelectBuilder<'_>
pub fn select(&self, table: &str) -> SelectBuilder<'_>
创建 SELECT 查询
Sourcepub fn insert(&self, table: &str) -> InsertBuilder<'_>
pub fn insert(&self, table: &str) -> InsertBuilder<'_>
创建 INSERT 查询
Sourcepub fn update(&self, table: &str) -> UpdateBuilder<'_>
pub fn update(&self, table: &str) -> UpdateBuilder<'_>
创建 UPDATE 查询
Sourcepub fn delete(&self, table: &str) -> DeleteBuilder<'_>
pub fn delete(&self, table: &str) -> DeleteBuilder<'_>
创建 DELETE 查询
Sourcepub fn execute_batch(&self, sql: &str) -> Result<(), SqliteError>
pub fn execute_batch(&self, sql: &str) -> Result<(), SqliteError>
执行批量 SQL
Sourcepub fn query_row(
&self,
sql: &str,
params: &[Param],
) -> Result<Option<Row>, SqliteError>
pub fn query_row( &self, sql: &str, params: &[Param], ) -> Result<Option<Row>, SqliteError>
查询单行
Sourcepub fn last_insert_id(&self) -> Result<i64, SqliteError>
pub fn last_insert_id(&self) -> Result<i64, SqliteError>
获取最后插入的行 ID
Sourcepub fn begin_transaction(&self) -> Result<Transaction<'_>, SqliteError>
pub fn begin_transaction(&self) -> Result<Transaction<'_>, SqliteError>
开始事务
Sourcepub fn with_transaction<F, T>(&self, f: F) -> Result<T, SqliteError>
pub fn with_transaction<F, T>(&self, f: F) -> Result<T, SqliteError>
在事务中执行操作
Sourcepub fn table_exists(&self, table: &str) -> Result<bool, SqliteError>
pub fn table_exists(&self, table: &str) -> Result<bool, SqliteError>
检查表是否存在
Sourcepub fn table_columns(&self, table: &str) -> Result<Vec<ColumnInfo>, SqliteError>
pub fn table_columns(&self, table: &str) -> Result<Vec<ColumnInfo>, SqliteError>
获取表的列信息
Sourcepub fn database_size(&self) -> Result<i64, SqliteError>
pub fn database_size(&self) -> Result<i64, SqliteError>
获取数据库大小(字节)
Sourcepub fn vacuum(&self) -> Result<(), SqliteError>
pub fn vacuum(&self) -> Result<(), SqliteError>
执行 VACUUM 优化
Sourcepub fn close(self) -> Result<(), SqliteError>
pub fn close(self) -> Result<(), SqliteError>
关闭数据库
Auto Trait Implementations§
impl Freeze for EmbeddedDb
impl !RefUnwindSafe for EmbeddedDb
impl Send for EmbeddedDb
impl Sync for EmbeddedDb
impl Unpin for EmbeddedDb
impl !UnwindSafe for EmbeddedDb
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