Skip to main content

wae_database/connection/
trait_impl.rs

1//! 数据库连接抽象 trait
2
3use crate::connection::{config::DatabaseResult, row::DatabaseRows, statement::DatabaseStatement};
4use async_trait::async_trait;
5
6/// 数据库连接抽象
7#[async_trait]
8pub trait DatabaseConnection: Send + Sync {
9    /// 执行查询,返回结果集
10    async fn query(&self, sql: &str) -> DatabaseResult<DatabaseRows>;
11
12    /// 执行带参数的查询 (使用 wae_types::Value)
13    async fn query_with(&self, sql: &str, params: Vec<wae_types::Value>) -> DatabaseResult<DatabaseRows>;
14
15    /// 执行语句,返回影响的行数
16    async fn execute(&self, sql: &str) -> DatabaseResult<u64>;
17
18    /// 执行带参数的语句 (使用 wae_types::Value)
19    async fn execute_with(&self, sql: &str, params: Vec<wae_types::Value>) -> DatabaseResult<u64>;
20
21    /// 准备语句
22    async fn prepare(&self, sql: &str) -> DatabaseResult<DatabaseStatement>;
23
24    #[cfg(feature = "turso")]
25    /// 执行带参数的查询 (内部使用 turso::Value)
26    async fn query_with_turso(&self, _sql: &str, _params: Vec<turso::Value>) -> DatabaseResult<DatabaseRows> {
27        unimplemented!("query_with_turso is only implemented for Turso connections")
28    }
29
30    #[cfg(feature = "turso")]
31    /// 执行带参数的语句 (内部使用 turso::Value)
32    async fn execute_with_turso(&self, _sql: &str, _params: Vec<turso::Value>) -> DatabaseResult<u64> {
33        unimplemented!("execute_with_turso is only implemented for Turso connections")
34    }
35}