aboutsummaryrefslogtreecommitdiff
path: root/src/db/backend.rs
diff options
context:
space:
mode:
authorMelody Horn / boringcactus <melody@boringcactus.com>2021-06-16 12:36:47 -0600
committerMelody Horn / boringcactus <melody@boringcactus.com>2021-06-16 12:36:47 -0600
commit685b47247aad71468f190c42929ca6f0dce843fa (patch)
tree7adf64a4c00b9ca8893fab26367ec01a30e24ad9 /src/db/backend.rs
parent92bf14bb7cc0c10f67a9a67e7512138c15db6ec0 (diff)
downloadtosin-685b47247aad71468f190c42929ca6f0dce843fa.tar.gz
tosin-685b47247aad71468f190c42929ca6f0dce843fa.zip
make database backends generic
Diffstat (limited to 'src/db/backend.rs')
-rw-r--r--src/db/backend.rs19
1 files changed, 16 insertions, 3 deletions
diff --git a/src/db/backend.rs b/src/db/backend.rs
index 5ae4de2..b75d5ca 100644
--- a/src/db/backend.rs
+++ b/src/db/backend.rs
@@ -1,5 +1,18 @@
-pub enum DbBackend {
- Sqlite {
- db_file: &'static str,
+pub use diesel::connection::Connection;
+
+pub trait Connectable {
+ type Connection: Connection;
+ fn connect(&self) -> diesel::ConnectionResult<Self::Connection>;
+}
+
+pub struct Sqlite {
+ pub db_file: &'static str,
+}
+
+impl Connectable for Sqlite {
+ type Connection = diesel::sqlite::SqliteConnection;
+
+ fn connect(&self) -> diesel::ConnectionResult<Self::Connection> {
+ Self::Connection::establish(self.db_file)
}
}