EmbeddedDb

Struct EmbeddedDb 

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

嵌入式数据库

提供简化的数据库操作 API

Implementations§

Source§

impl EmbeddedDb

Source

pub fn open(name: &str) -> Result<Self, SqliteError>

打开或创建数据库

§Arguments
  • name - 数据库名称(用于生成文件路径)
§Example
let db = EmbeddedDb::open("my_app")?;
Source

pub fn open_path(path: impl Into<PathBuf>) -> Result<Self, SqliteError>

打开指定路径的数据库

Source

pub fn open_with_config( name: &str, config: SqliteConfig, ) -> Result<Self, SqliteError>

打开带配置的数据库

Source

pub fn memory() -> Result<Self, SqliteError>

创建内存数据库

Source

pub fn name(&self) -> &str

获取数据库名称

Source

pub fn connection(&self) -> &Connection

获取底层连接

Source

pub fn migrate<F>(&self, f: F) -> Result<MigrationReport, SqliteError>
where F: FnOnce(&mut MigrationBuilder),

执行迁移

Source

pub fn schema_version(&self) -> Result<u32, SqliteError>

获取当前 schema 版本

Source

pub fn select(&self, table: &str) -> SelectBuilder<'_>

创建 SELECT 查询

Source

pub fn insert(&self, table: &str) -> InsertBuilder<'_>

创建 INSERT 查询

Source

pub fn update(&self, table: &str) -> UpdateBuilder<'_>

创建 UPDATE 查询

Source

pub fn delete(&self, table: &str) -> DeleteBuilder<'_>

创建 DELETE 查询

Source

pub fn execute(&self, sql: &str, params: &[Param]) -> Result<usize, SqliteError>

执行原始 SQL

Source

pub fn execute_batch(&self, sql: &str) -> Result<(), SqliteError>

执行批量 SQL

Source

pub fn query_row( &self, sql: &str, params: &[Param], ) -> Result<Option<Row>, SqliteError>

查询单行

Source

pub fn query(&self, sql: &str, params: &[Param]) -> Result<Rows, SqliteError>

查询多行

Source

pub fn last_insert_id(&self) -> Result<i64, SqliteError>

获取最后插入的行 ID

Source

pub fn begin_transaction(&self) -> Result<Transaction<'_>, SqliteError>

开始事务

Source

pub fn with_transaction<F, T>(&self, f: F) -> Result<T, SqliteError>
where F: FnOnce(&Transaction<'_>) -> Result<T, SqliteError>,

在事务中执行操作

Source

pub fn table_exists(&self, table: &str) -> Result<bool, SqliteError>

检查表是否存在

Source

pub fn table_columns(&self, table: &str) -> Result<Vec<ColumnInfo>, SqliteError>

获取表的列信息

Source

pub fn database_size(&self) -> Result<i64, SqliteError>

获取数据库大小(字节)

Source

pub fn vacuum(&self) -> Result<(), SqliteError>

执行 VACUUM 优化

Source

pub fn close(self) -> Result<(), SqliteError>

关闭数据库

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