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: impl Into<Cow<'static, str>>,
31 config: PoolConfig,
32 ) -> impl Future<Output = Result<impl ConnectionPool<Self>>> + Send {
33 let url = url.into();
34 let config = config.into();
35 async move {
36 Ok(Pool::builder(DBConnectionManager::new(self.clone(), url))
37 .config(config)
38 .build()
39 .map_err(Error::new)?)
40 }
41 }
42
43 fn sql_writer(&self) -> Self::SqlWriter;
45}