use super::{kinds::BackendKind, native::NativeConfig, sqlite::SqliteConfig};
#[derive(Clone, Debug)]
pub struct GraphConfig {
pub backend: BackendKind,
pub sqlite: SqliteConfig,
pub native: NativeConfig,
}
impl GraphConfig {
pub fn new(backend: BackendKind) -> Self {
let sqlite_config = match backend {
BackendKind::SQLite => SqliteConfig::default(),
BackendKind::Native => SqliteConfig {
without_migrations: true,
..Default::default()
},
};
Self {
backend,
sqlite: sqlite_config,
native: NativeConfig::default(),
}
}
pub fn sqlite() -> Self {
Self::new(BackendKind::SQLite)
}
pub fn native() -> Self {
Self::new(BackendKind::Native)
}
pub fn with_cpu_profile(mut self, profile: crate::backend::native::CpuProfile) -> Self {
self.native.cpu_profile = Some(profile);
self
}
pub fn with_parallel_recovery(mut self, degree: usize) -> Self {
self.native.max_parallel_transactions = degree;
self
}
pub fn with_sqlite_config<F>(mut self, config_fn: F) -> Self
where
F: FnOnce(SqliteConfig) -> SqliteConfig,
{
self.sqlite = config_fn(self.sqlite);
self
}
pub fn with_native_config<F>(mut self, config_fn: F) -> Self
where
F: FnOnce(NativeConfig) -> NativeConfig,
{
self.native = config_fn(self.native);
self
}
}
impl Default for GraphConfig {
fn default() -> Self {
Self::new(BackendKind::SQLite)
}
}