mirror of
https://gitlab.computer.surgery/matrix/grapevine.git
synced 2025-12-18 16:21: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(())
|
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() {
|
||||||
|
|
@ -329,21 +331,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(),
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue