Skip to main content

tank_core/
driver.rs

1use crate::{Connection, Prepared, Result, Transaction, writer::SqlWriter};
2use std::{borrow::Cow, fmt::Debug, future::Future};
3
4/// Backend connector and dialect.
5pub trait Driver: Default + Debug {
6    /// Concrete connection type.
7    type Connection: Connection<Driver = Self>;
8    /// Dialect-specific SQL writer.
9    type SqlWriter: SqlWriter;
10    /// Prepared statement implementation.
11    type Prepared: Prepared;
12    /// Transaction implementation.
13    type Transaction<'c>: Transaction<'c>;
14
15    /// Human-readable backend name.
16    const NAME: &'static [&'static str];
17
18    /// Driver name.
19    fn name(&self) -> &'static str {
20        Self::NAME[0]
21    }
22
23    /// Connect to database `url`.
24    fn connect(&self, url: Cow<'static, str>) -> impl Future<Output = Result<Self::Connection>> {
25        Self::Connection::connect(url)
26    }
27
28    /// Get a SQL writer object.
29    fn sql_writer(&self) -> Self::SqlWriter;
30}