use crate::{
Connection, ConnectionPool, DBConnectionManager, Error, PoolConfig, Prepared, Result,
Transaction, writer::SqlWriter,
};
use deadpool::managed::Pool;
use std::{borrow::Cow, fmt::Debug, future::Future};
pub trait Driver: Default + Clone + Sync + Send + Debug {
type Connection: Connection<Driver = Self> + Debug;
type SqlWriter: SqlWriter;
type Prepared: Prepared;
type Transaction<'c>: Transaction<'c>;
const NAME: &'static [&'static str];
fn name(&self) -> &'static str {
Self::NAME[0]
}
fn connect_pool(
&self,
url: Cow<'static, str>,
config: PoolConfig,
) -> impl Future<Output = Result<impl ConnectionPool<Self>>> + Send {
let config = config.into();
async move {
Ok(Pool::builder(DBConnectionManager::new(self.clone(), url))
.config(config)
.build()
.map_err(Error::new)?)
}
}
fn sql_writer(&self) -> Self::SqlWriter;
}