From 9829bbfcd57c57e237c6aacb96a78d0b9f5bab68 Mon Sep 17 00:00:00 2001 From: Melody Horn Date: Tue, 29 Jun 2021 22:44:11 -0600 Subject: lol no generics --- src/db/backend/mod.rs | 7 +++++++ src/db/backend/sqlite.rs | 22 ++++++++++++++++++++++ 2 files changed, 29 insertions(+) create mode 100644 src/db/backend/mod.rs create mode 100644 src/db/backend/sqlite.rs (limited to 'src/db/backend') diff --git a/src/db/backend/mod.rs b/src/db/backend/mod.rs new file mode 100644 index 0000000..b266f1e --- /dev/null +++ b/src/db/backend/mod.rs @@ -0,0 +1,7 @@ +#[cfg(feature = "sqlite")] +mod sqlite; +#[cfg(feature = "sqlite")] +pub use sqlite::*; + +#[cfg(not(feature = "sqlite"))] +compile_error!("pick a backend pls"); diff --git a/src/db/backend/sqlite.rs b/src/db/backend/sqlite.rs new file mode 100644 index 0000000..002d0d3 --- /dev/null +++ b/src/db/backend/sqlite.rs @@ -0,0 +1,22 @@ +use diesel::connection::Connection as _; + +pub use barrel::backend::Sqlite as SqlGenerator; +pub use diesel::sqlite::SqliteConnection as Connection; + +pub struct Database { + pub db_file: &'static str, +} + +impl Database { + pub fn connect(&self) -> diesel::ConnectionResult { + Connection::establish(self.db_file) + } +} + +impl Default for Database { + fn default() -> Self { + Self { + db_file: "db.sqlite3", + } + } +} -- cgit v1.2.3