diff --git a/src/database.rs b/src/database.rs index a330884e..62346659 100644 --- a/src/database.rs +++ b/src/database.rs @@ -288,12 +288,14 @@ impl KeyValueDatabase { Ok(()) } - #[cfg_attr( - not(any(feature = "rocksdb", feature = "sqlite")), - allow(unreachable_code) - )] - #[allow(clippy::too_many_lines)] - pub(crate) fn load_or_create(config: &Config) -> Result { + pub(crate) fn load_or_create_engine( + config: &Config, + ) -> Result> { + #[cfg(not(any(feature = "rocksdb", feature = "sqlite")))] + return Err(Error::BadConfig( + "Compiled without support for any databases", + )); + Self::check_db_setup(config)?; if !Path::new(&config.database.path).exists() { @@ -306,21 +308,28 @@ impl KeyValueDatabase { })?; } - #[cfg_attr( - not(any(feature = "rocksdb", feature = "sqlite")), - allow(unused_variables) - )] - let builder: Arc = - match config.database.backend { - #[cfg(feature = "sqlite")] - DatabaseBackend::Sqlite => { - Arc::new(Arc::::open(config)?) - } - #[cfg(feature = "rocksdb")] - DatabaseBackend::Rocksdb => { - Arc::new(Arc::::open(config)?) - } - }; + let x: Arc = match config.database.backend { + #[cfg(feature = "sqlite")] + DatabaseBackend::Sqlite => { + Arc::new(Arc::::open(config)?) + } + #[cfg(feature = "rocksdb")] + DatabaseBackend::Rocksdb => { + Arc::new(Arc::::open(config)?) + } + }; + + #[cfg(any(feature = "rocksdb", feature = "sqlite"))] + return Ok(x); + } + + #[cfg_attr( + not(any(feature = "rocksdb", feature = "sqlite")), + allow(unreachable_code) + )] + #[allow(clippy::too_many_lines)] + pub(crate) fn load_or_create(config: &Config) -> Result { + let builder = Self::load_or_create_engine(config)?; let db = Self { db: builder.clone(),