config: convert database backend to enum

This reports a nice error when the config is loaded, rather than later
when the database is initialized.
This commit is contained in:
Lambda 2024-06-16 14:31:59 +00:00 committed by Charles Hall
parent d26b87a2f2
commit 8a30817930
No known key found for this signature in database
GPG key ID: 7B8E0645816E07CF
3 changed files with 40 additions and 11 deletions

View file

@ -153,9 +153,29 @@ impl Default for TurnConfig {
}
}
#[derive(Clone, Copy, Debug, Deserialize)]
#[serde(rename_all = "lowercase")]
pub(crate) enum DatabaseBackend {
#[cfg(feature = "rocksdb")]
Rocksdb,
#[cfg(feature = "sqlite")]
Sqlite,
}
impl Display for DatabaseBackend {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match *self {
#[cfg(feature = "rocksdb")]
DatabaseBackend::Rocksdb => write!(f, "RocksDB"),
#[cfg(feature = "sqlite")]
DatabaseBackend::Sqlite => write!(f, "SQLite"),
}
}
}
#[derive(Clone, Debug, Deserialize)]
pub(crate) struct DatabaseConfig {
pub(crate) backend: String,
pub(crate) backend: DatabaseBackend,
pub(crate) path: String,
#[serde(default = "default_db_cache_capacity_mb")]
pub(crate) cache_capacity_mb: f64,