Skip to main content

Connection

Trait Connection 

Source
pub trait Connection: Send + Sync {
    // Required methods
    fn execute<'a>(
        &'a mut self,
        sql: &'a str,
    ) -> Pin<Box<dyn Future<Output = Result<u64, DbError>> + Send + 'a>>;
    fn query<'a>(
        &'a mut self,
        sql: &'a str,
    ) -> Pin<Box<dyn Future<Output = Result<QueryRows, DbError>> + Send + 'a>>;
    fn begin_transaction<'a>(
        &'a mut self,
    ) -> Pin<Box<dyn Future<Output = Result<(), DbError>> + Send + 'a>>;
    fn commit<'a>(
        &'a mut self,
    ) -> Pin<Box<dyn Future<Output = Result<(), DbError>> + Send + 'a>>;
    fn rollback<'a>(
        &'a mut self,
    ) -> Pin<Box<dyn Future<Output = Result<(), DbError>> + Send + 'a>>;
    fn is_connected(&self) -> bool;
    fn ping<'a>(&'a mut self) -> Pin<Box<dyn Future<Output = bool> + Send + 'a>>;
    fn close<'a>(
        &'a mut self,
    ) -> Pin<Box<dyn Future<Output = Result<(), DbError>> + Send + 'a>>;
}
Expand description

数据库连接 trait

注意:此 trait 手动解糖 async 方法(不使用 #[async_trait]), 以避免 &str 参数触发 HRTB 与 sqlx::Executor 冲突。 所有 async 方法使用单一生命周期 'a(绑定 &'a mut self&'a str), 而非 HRTB,从而允许 sqlx 适配器实现。

Required Methods§

Source

fn execute<'a>( &'a mut self, sql: &'a str, ) -> Pin<Box<dyn Future<Output = Result<u64, DbError>> + Send + 'a>>

Source

fn query<'a>( &'a mut self, sql: &'a str, ) -> Pin<Box<dyn Future<Output = Result<QueryRows, DbError>> + Send + 'a>>

Source

fn begin_transaction<'a>( &'a mut self, ) -> Pin<Box<dyn Future<Output = Result<(), DbError>> + Send + 'a>>

Source

fn commit<'a>( &'a mut self, ) -> Pin<Box<dyn Future<Output = Result<(), DbError>> + Send + 'a>>

Source

fn rollback<'a>( &'a mut self, ) -> Pin<Box<dyn Future<Output = Result<(), DbError>> + Send + 'a>>

Source

fn is_connected(&self) -> bool

Source

fn ping<'a>(&'a mut self) -> Pin<Box<dyn Future<Output = bool> + Send + 'a>>

Source

fn close<'a>( &'a mut self, ) -> Pin<Box<dyn Future<Output = Result<(), DbError>> + Send + 'a>>

Dyn Compatibility§

This trait is dyn compatible.

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

Implementors§