wae_database/connection/
trait_impl.rs1use crate::connection::{config::DatabaseResult, row::DatabaseRows, statement::DatabaseStatement};
4use async_trait::async_trait;
5
6#[derive(Debug, Clone, Copy, PartialEq, Eq)]
8pub enum DatabaseBackend {
9 Turso,
11 Postgres,
13 MySql,
15}
16
17#[async_trait]
19pub trait DatabaseConnection: Send + Sync {
20 fn backend(&self) -> DatabaseBackend;
22
23 async fn query(&self, sql: &str) -> DatabaseResult<DatabaseRows>;
25
26 async fn query_with(&self, sql: &str, params: Vec<wae_types::Value>) -> DatabaseResult<DatabaseRows>;
28
29 async fn execute(&self, sql: &str) -> DatabaseResult<u64>;
31
32 async fn execute_with(&self, sql: &str, params: Vec<wae_types::Value>) -> DatabaseResult<u64>;
34
35 async fn prepare(&self, sql: &str) -> DatabaseResult<DatabaseStatement>;
37
38 async fn begin_transaction(&self) -> DatabaseResult<()>;
40
41 async fn commit(&self) -> DatabaseResult<()>;
43
44 async fn rollback(&self) -> DatabaseResult<()>;
46
47 #[cfg(feature = "turso")]
48 async fn query_with_turso(&self, _sql: &str, _params: Vec<turso::Value>) -> DatabaseResult<DatabaseRows> {
50 unimplemented!("query_with_turso is only implemented for Turso connections")
51 }
52
53 #[cfg(feature = "turso")]
54 async fn execute_with_turso(&self, _sql: &str, _params: Vec<turso::Value>) -> DatabaseResult<u64> {
56 unimplemented!("execute_with_turso is only implemented for Turso connections")
57 }
58}