1use crate::{
2 Connection, ConnectionPool, DBConnectionManager, Error, PoolConfig, Prepared, Result,
3 Transaction, writer::SqlWriter,
4};
5use deadpool::managed::Pool;
6use std::{borrow::Cow, fmt::Debug, future::Future};
7
8pub trait Driver: Default + Clone + Sync + Send + Debug {
10 type Connection: Connection<Driver = Self> + Debug;
12 type SqlWriter: SqlWriter;
14 type Prepared: Prepared;
16 type Transaction<'c>: Transaction<'c>;
18
19 const NAME: &'static [&'static str];
21
22 fn name(&self) -> &'static str {
24 Self::NAME[0]
25 }
26
27 fn connect_pool(
29 &self,
30 url: Cow<'static, str>,
31 config: PoolConfig,
32 ) -> impl Future<Output = Result<impl ConnectionPool<Self>>> + Send {
33 let config = config.into();
34 async move {
35 Ok(Pool::builder(DBConnectionManager::new(self.clone(), url))
36 .config(config)
37 .build()
38 .map_err(Error::new)?)
39 }
40 }
41
42 fn sql_writer(&self) -> Self::SqlWriter;
44}