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 SQL dialect provider.
5pub trait Driver: Debug {
6    /// Concrete connection.
7    type Connection: Connection;
8    /// SQL dialect writer.
9    type SqlWriter: SqlWriter;
10    /// Prepared statement handle.
11    type Prepared: Prepared;
12    /// Transaction type.
13    type Transaction<'c>: Transaction<'c>;
14
15    /// Human-readable backend name.
16    const NAME: &'static str;
17
18    /// Driver name (used in URLs).
19    fn name(&self) -> &'static str {
20        Self::NAME
21    }
22
23    /// Connect to database `url`.
24    fn connect(&self, url: Cow<'static, str>) -> impl Future<Output = Result<impl Connection>> {
25        Self::Connection::connect(url)
26    }
27
28    /// Create a SQL writer.
29    fn sql_writer(&self) -> Self::SqlWriter;
30}