break out function for opening unstructured db

This commit is contained in:
Charles Hall 2024-09-26 16:56:11 -07:00
parent 27dcb83c7e
commit 4dd7e13f41
No known key found for this signature in database
GPG key ID: 7B8E0645816E07CF

View file

@ -288,12 +288,14 @@ impl KeyValueDatabase {
Ok(()) Ok(())
} }
#[cfg_attr( pub(crate) fn load_or_create_engine(
not(any(feature = "rocksdb", feature = "sqlite")), config: &Config,
allow(unreachable_code) ) -> Result<Arc<dyn KeyValueDatabaseEngine>> {
)] #[cfg(not(any(feature = "rocksdb", feature = "sqlite")))]
#[allow(clippy::too_many_lines)] return Err(Error::BadConfig(
pub(crate) fn load_or_create(config: &Config) -> Result<KeyValueDatabase> { "Compiled without support for any databases",
));
Self::check_db_setup(config)?; Self::check_db_setup(config)?;
if !Path::new(&config.database.path).exists() { if !Path::new(&config.database.path).exists() {
@ -306,21 +308,28 @@ impl KeyValueDatabase {
})?; })?;
} }
#[cfg_attr( let x: Arc<dyn KeyValueDatabaseEngine> = match config.database.backend {
not(any(feature = "rocksdb", feature = "sqlite")), #[cfg(feature = "sqlite")]
allow(unused_variables) DatabaseBackend::Sqlite => {
)] Arc::new(Arc::<abstraction::sqlite::Engine>::open(config)?)
let builder: Arc<dyn KeyValueDatabaseEngine> = }
match config.database.backend { #[cfg(feature = "rocksdb")]
#[cfg(feature = "sqlite")] DatabaseBackend::Rocksdb => {
DatabaseBackend::Sqlite => { Arc::new(Arc::<abstraction::rocksdb::Engine>::open(config)?)
Arc::new(Arc::<abstraction::sqlite::Engine>::open(config)?) }
} };
#[cfg(feature = "rocksdb")]
DatabaseBackend::Rocksdb => { #[cfg(any(feature = "rocksdb", feature = "sqlite"))]
Arc::new(Arc::<abstraction::rocksdb::Engine>::open(config)?) 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<KeyValueDatabase> {
let builder = Self::load_or_create_engine(config)?;
let db = Self { let db = Self {
db: builder.clone(), db: builder.clone(),