mirror of
https://gitlab.computer.surgery/matrix/grapevine.git
synced 2025-12-17 15:51: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(())
|
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,12 +308,7 @@ impl KeyValueDatabase {
|
||||||
})?;
|
})?;
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg_attr(
|
let x: Arc<dyn KeyValueDatabaseEngine> = match config.database.backend {
|
||||||
not(any(feature = "rocksdb", feature = "sqlite")),
|
|
||||||
allow(unused_variables)
|
|
||||||
)]
|
|
||||||
let builder: Arc<dyn KeyValueDatabaseEngine> =
|
|
||||||
match config.database.backend {
|
|
||||||
#[cfg(feature = "sqlite")]
|
#[cfg(feature = "sqlite")]
|
||||||
DatabaseBackend::Sqlite => {
|
DatabaseBackend::Sqlite => {
|
||||||
Arc::new(Arc::<abstraction::sqlite::Engine>::open(config)?)
|
Arc::new(Arc::<abstraction::sqlite::Engine>::open(config)?)
|
||||||
|
|
@ -322,6 +319,18 @@ impl KeyValueDatabase {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
#[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 {
|
let db = Self {
|
||||||
db: builder.clone(),
|
db: builder.clone(),
|
||||||
userid_password: builder.open_tree("userid_password")?,
|
userid_password: builder.open_tree("userid_password")?,
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue