1use async_trait::async_trait;
2
3use crate::{error::Result, pool::PoolConfig, template::DatabaseName};
4
5#[async_trait]
7pub trait Connection: Send {
8 async fn is_valid(&self) -> bool;
10
11 async fn reset(&mut self) -> Result<()>;
13
14 async fn execute(&mut self, sql: &str) -> Result<()>;
16}
17
18#[async_trait]
20pub trait DatabaseBackend: Send + Sync + Clone {
21 type Connection: Connection;
23 type Pool: DatabasePool<Connection = Self::Connection>;
25
26 async fn create_database(&self, name: &DatabaseName) -> Result<()>;
28
29 async fn drop_database(&self, name: &DatabaseName) -> Result<()>;
31
32 async fn create_pool(&self, name: &DatabaseName, config: &PoolConfig) -> Result<Self::Pool>;
34
35 async fn terminate_connections(&self, name: &DatabaseName) -> Result<()>;
37
38 async fn create_database_from_template(
40 &self,
41 name: &DatabaseName,
42 template: &DatabaseName,
43 ) -> Result<()>;
44}
45
46#[async_trait]
48pub trait DatabasePool: Send + Sync + Clone {
49 type Connection: Connection;
51
52 async fn acquire(&self) -> Result<Self::Connection>;
54
55 async fn release(&self, conn: Self::Connection) -> Result<()>;
57}