mirror of
https://github.com/fawney19/Aether.git
synced 2026-10-08 10:27:46 +08:00
refactor: extract runtime state backends
This commit is contained in:
@@ -1,13 +1,11 @@
|
||||
use crate::database::SqlDatabaseConfig;
|
||||
use crate::driver::postgres::PostgresPoolConfig;
|
||||
use crate::driver::redis::RedisClientConfig;
|
||||
use crate::DataLayerError;
|
||||
|
||||
#[derive(Debug, Clone, Default, serde::Serialize, serde::Deserialize, PartialEq, Eq)]
|
||||
pub struct DataLayerConfig {
|
||||
pub database: Option<SqlDatabaseConfig>,
|
||||
pub postgres: Option<PostgresPoolConfig>,
|
||||
pub redis: Option<RedisClientConfig>,
|
||||
}
|
||||
|
||||
impl DataLayerConfig {
|
||||
@@ -15,7 +13,6 @@ impl DataLayerConfig {
|
||||
Self {
|
||||
database: Some(database),
|
||||
postgres: None,
|
||||
redis: None,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -23,7 +20,6 @@ impl DataLayerConfig {
|
||||
Self {
|
||||
database: Some(SqlDatabaseConfig::from_postgres_config(postgres)),
|
||||
postgres: None,
|
||||
redis: None,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -42,14 +38,11 @@ impl DataLayerConfig {
|
||||
if let Some(postgres) = &self.postgres {
|
||||
postgres.validate()?;
|
||||
}
|
||||
if let Some(redis) = &self.redis {
|
||||
redis.validate()?;
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub fn has_persistent_backends(&self) -> bool {
|
||||
self.effective_database().is_some() || self.redis.is_some()
|
||||
self.effective_database().is_some()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -58,7 +51,6 @@ mod tests {
|
||||
use super::DataLayerConfig;
|
||||
use crate::database::{DatabaseDriver, SqlDatabaseConfig, SqlPoolConfig};
|
||||
use crate::driver::postgres::PostgresPoolConfig;
|
||||
use crate::driver::redis::RedisClientConfig;
|
||||
|
||||
#[test]
|
||||
fn validates_nested_backend_configs() {
|
||||
@@ -74,10 +66,6 @@ mod tests {
|
||||
statement_cache_capacity: 64,
|
||||
require_ssl: false,
|
||||
}),
|
||||
redis: Some(RedisClientConfig {
|
||||
url: "redis://127.0.0.1/0".to_string(),
|
||||
key_prefix: Some("aether".to_string()),
|
||||
}),
|
||||
};
|
||||
|
||||
assert!(config.validate().is_ok());
|
||||
@@ -98,7 +86,6 @@ mod tests {
|
||||
statement_cache_capacity: 64,
|
||||
require_ssl: false,
|
||||
}),
|
||||
redis: None,
|
||||
};
|
||||
|
||||
assert!(config.validate().is_err());
|
||||
@@ -122,7 +109,6 @@ mod tests {
|
||||
statement_cache_capacity: 64,
|
||||
require_ssl: false,
|
||||
}),
|
||||
redis: None,
|
||||
};
|
||||
|
||||
let effective = config
|
||||
|
||||
Reference in New Issue
Block a user