zeph_db/driver.rs
1// SPDX-FileCopyrightText: 2026 Andrei G <bug-ops>
2// SPDX-License-Identifier: MIT OR Apache-2.0
3
4//! [`DatabaseDriver`] trait and per-backend implementations.
5
6#[cfg(feature = "postgres")]
7pub mod postgres;
8#[cfg(feature = "sqlite")]
9pub mod sqlite;
10
11#[cfg(feature = "postgres")]
12pub use postgres::PostgresDriver;
13#[cfg(feature = "sqlite")]
14pub use sqlite::SqliteDriver;
15
16/// Unifies a sqlx `Database` type with its [`crate::Dialect`].
17///
18/// Each backend (`SqliteDriver`, `PostgresDriver`) implements this trait once.
19/// Consumer crates use `D: DatabaseDriver` as their single generic parameter,
20/// which gives access to both `D::Database` (for sqlx pool/query bounds) and
21/// `D::Dialect` (for SQL fragment substitution).
22///
23/// Connection, migration, and transaction logic live in [`crate::DbConfig`],
24/// [`crate::migrate`], and [`crate::transaction`] respectively — not here.
25pub trait DatabaseDriver: Send + Sync + 'static {
26 /// The sqlx `Database` type (e.g., `sqlx::Sqlite`, `sqlx::Postgres`).
27 type Database: sqlx::Database;
28
29 /// The dialect providing SQL fragment constants.
30 type Dialect: crate::dialect::Dialect;
31}