From 685b47247aad71468f190c42929ca6f0dce843fa Mon Sep 17 00:00:00 2001 From: Melody Horn / boringcactus Date: Wed, 16 Jun 2021 12:36:47 -0600 Subject: make database backends generic --- src/db/backend.rs | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) (limited to 'src/db') 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; +} + +pub struct Sqlite { + pub db_file: &'static str, +} + +impl Connectable for Sqlite { + type Connection = diesel::sqlite::SqliteConnection; + + fn connect(&self) -> diesel::ConnectionResult { + Self::Connection::establish(self.db_file) } } -- cgit v1.2.3