Skip to main content

DatabaseSession

Trait DatabaseSession 

Source
pub trait DatabaseSession: Send + Sync {
    // Required methods
    fn execute<'life0, 'life1, 'async_trait>(
        &'life0 self,
        sql: &'life1 str,
    ) -> Pin<Box<dyn Future<Output = DbResult<ExecResult>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait,
             'life1: 'async_trait;
    fn execute_raw<'life0, 'life1, 'async_trait>(
        &'life0 self,
        sql: &'life1 str,
    ) -> Pin<Box<dyn Future<Output = DbResult<ExecResult>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait,
             'life1: 'async_trait;
    fn execute_raw_ddl<'life0, 'life1, 'async_trait>(
        &'life0 self,
        sql: &'life1 str,
    ) -> Pin<Box<dyn Future<Output = DbResult<ExecResult>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait,
             'life1: 'async_trait;
    fn begin_transaction<'life0, 'async_trait>(
        &'life0 self,
    ) -> Pin<Box<dyn Future<Output = DbResult<()>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait;
    fn commit<'life0, 'async_trait>(
        &'life0 self,
    ) -> Pin<Box<dyn Future<Output = DbResult<()>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait;
    fn rollback<'life0, 'async_trait>(
        &'life0 self,
    ) -> Pin<Box<dyn Future<Output = DbResult<()>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait;
    fn role(&self) -> &str;
    fn is_in_transaction<'life0, 'async_trait>(
        &'life0 self,
    ) -> Pin<Box<dyn Future<Output = bool> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait;
}
Expand description

数据库会话抽象 trait

定义数据库会话的通用接口,便于测试和替换实现

Required Methods§

Source

fn execute<'life0, 'life1, 'async_trait>( &'life0 self, sql: &'life1 str, ) -> Pin<Box<dyn Future<Output = DbResult<ExecResult>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

执行 SQL(带权限检查)

§Arguments
  • sql - SQL 语句
§Returns

返回执行结果

Source

fn execute_raw<'life0, 'life1, 'async_trait>( &'life0 self, sql: &'life1 str, ) -> Pin<Box<dyn Future<Output = DbResult<ExecResult>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

执行原始 SQL(不带权限检查)

§Arguments
  • sql - SQL 语句
§Returns

返回执行结果

Source

fn execute_raw_ddl<'life0, 'life1, 'async_trait>( &'life0 self, sql: &'life1 str, ) -> Pin<Box<dyn Future<Output = DbResult<ExecResult>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

执行原始 DDL(仅限管理员)

§Arguments
  • sql - DDL SQL 语句
§Returns

返回执行结果

Source

fn begin_transaction<'life0, 'async_trait>( &'life0 self, ) -> Pin<Box<dyn Future<Output = DbResult<()>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

开始事务

§Returns

返回成功或错误

Source

fn commit<'life0, 'async_trait>( &'life0 self, ) -> Pin<Box<dyn Future<Output = DbResult<()>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

提交事务

§Returns

返回成功或错误

Source

fn rollback<'life0, 'async_trait>( &'life0 self, ) -> Pin<Box<dyn Future<Output = DbResult<()>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

回滚事务

§Returns

返回成功或错误

Source

fn role(&self) -> &str

获取角色

§Returns

返回用户角色

Source

fn is_in_transaction<'life0, 'async_trait>( &'life0 self, ) -> Pin<Box<dyn Future<Output = bool> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

是否在事务中

§Returns

返回是否在事务中

Dyn Compatibility§

This trait is dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§