mirror of
https://gitlab.computer.surgery/matrix/grapevine.git
synced 2025-12-17 07:41:23 +01:00
break out function for opening unstructured db
This commit is contained in:
parent
27dcb83c7e
commit
4dd7e13f41
1 changed files with 30 additions and 21 deletions
|
|
@ -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<KeyValueDatabase> {
|
||||
pub(crate) fn load_or_create_engine(
|
||||
config: &Config,
|
||||
) -> Result<Arc<dyn KeyValueDatabaseEngine>> {
|
||||
#[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<dyn KeyValueDatabaseEngine> =
|
||||
match config.database.backend {
|
||||
#[cfg(feature = "sqlite")]
|
||||
DatabaseBackend::Sqlite => {
|
||||
Arc::new(Arc::<abstraction::sqlite::Engine>::open(config)?)
|
||||
}
|
||||
#[cfg(feature = "rocksdb")]
|
||||
DatabaseBackend::Rocksdb => {
|
||||
Arc::new(Arc::<abstraction::rocksdb::Engine>::open(config)?)
|
||||
}
|
||||
};
|
||||
let x: Arc<dyn KeyValueDatabaseEngine> = match config.database.backend {
|
||||
#[cfg(feature = "sqlite")]
|
||||
DatabaseBackend::Sqlite => {
|
||||
Arc::new(Arc::<abstraction::sqlite::Engine>::open(config)?)
|
||||
}
|
||||
#[cfg(feature = "rocksdb")]
|
||||
DatabaseBackend::Rocksdb => {
|
||||
Arc::new(Arc::<abstraction::rocksdb::Engine>::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<KeyValueDatabase> {
|
||||
let builder = Self::load_or_create_engine(config)?;
|
||||
|
||||
let db = Self {
|
||||
db: builder.clone(),
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue