Skip to main content

keepsake_sqlx/repository/
backend.rs

1use std::fmt::Debug;
2use std::marker::PhantomData;
3
4/// `SQLx` backend supported by Keepsake.
5pub trait KeepsakeSqlxBackend: Debug + Clone + Copy + Send + Sync + 'static {
6    /// `SQLx` database driver for this backend.
7    type Database: sqlx::Database;
8
9    /// Stable backend name stored in schema metadata.
10    const NAME: &'static str;
11}
12
13/// Postgres backend marker.
14#[cfg(feature = "postgres")]
15#[derive(Debug, Clone, Copy)]
16pub struct PostgresBackend;
17
18#[cfg(feature = "postgres")]
19impl KeepsakeSqlxBackend for PostgresBackend {
20    type Database = sqlx::Postgres;
21
22    const NAME: &'static str = "postgres";
23}
24
25/// `SQLite` backend marker.
26#[cfg(feature = "sqlite")]
27#[derive(Debug, Clone, Copy)]
28pub struct SqliteBackend;
29
30#[cfg(feature = "sqlite")]
31impl KeepsakeSqlxBackend for SqliteBackend {
32    type Database = sqlx::Sqlite;
33
34    const NAME: &'static str = "sqlite";
35}
36
37/// `MySQL` backend marker.
38#[cfg(feature = "mysql")]
39#[derive(Debug, Clone, Copy)]
40pub struct MySqlBackend;
41
42#[cfg(feature = "mysql")]
43impl KeepsakeSqlxBackend for MySqlBackend {
44    type Database = sqlx::MySql;
45
46    const NAME: &'static str = "mysql";
47}
48
49#[derive(Debug, Clone, Copy)]
50pub(super) struct BackendMarker<B>(PhantomData<B>);
51
52impl<B> BackendMarker<B> {
53    pub(super) const fn new() -> Self {
54        Self(PhantomData)
55    }
56}
57
58impl<B> Default for BackendMarker<B> {
59    fn default() -> Self {
60        Self::new()
61    }
62}