use std::collections::HashMap;
#[derive(Clone, Debug, Default)]
pub struct SqliteConfig {
pub without_migrations: bool,
pub cache_size: Option<usize>,
pub pool_size: Option<usize>,
pub pragma_settings: HashMap<String, String>,
}
impl SqliteConfig {
pub fn new() -> Self {
Self::default()
}
pub fn with_migrations_disabled(mut self, without_migrations: bool) -> Self {
self.without_migrations = without_migrations;
self
}
pub fn with_cache_size(mut self, cache_size: usize) -> Self {
self.cache_size = Some(cache_size);
self
}
pub fn with_pragma(mut self, key: &str, value: &str) -> Self {
self.pragma_settings
.insert(key.to_string(), value.to_string());
self
}
pub fn with_wal_mode(mut self) -> Self {
self.pragma_settings
.insert("journal_mode".to_string(), "WAL".to_string());
self
}
pub fn with_performance_mode(mut self) -> Self {
self.pragma_settings
.insert("journal_mode".to_string(), "WAL".to_string());
self.pragma_settings
.insert("synchronous".to_string(), "NORMAL".to_string());
self
}
pub fn with_pool_size(mut self, size: usize) -> Self {
self.pool_size = Some(size);
self
}
pub fn with_max_connections(mut self, max: usize) -> Self {
self.pool_size = Some(max);
self
}
}