mirror of
https://gitlab.computer.surgery/matrix/grapevine.git
synced 2025-12-16 23:31:24 +01:00
break out function for opening unstructured db
This commit is contained in:
parent
b91aea687c
commit
7a228810e2
1 changed files with 30 additions and 21 deletions
|
|
@ -311,12 +311,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() {
|
||||
|
|
@ -329,21 +331,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