use alopex_core::StorageMode;
use std::path::Path;
#[derive(Debug, Clone, Default)]
pub struct DatabaseOptions {
memory_mode: bool,
memory_limit: Option<usize>,
}
impl DatabaseOptions {
pub fn new() -> Self {
Self::default()
}
pub fn in_memory() -> Self {
Self {
memory_mode: true,
memory_limit: None,
}
}
pub fn with_memory_limit(mut self, bytes: usize) -> Self {
self.memory_mode = true;
self.memory_limit = Some(bytes);
self
}
pub fn memory_mode(&self) -> bool {
self.memory_mode
}
pub fn memory_limit(&self) -> Option<usize> {
self.memory_limit
}
pub(crate) fn to_storage_mode(&self, path: Option<&Path>) -> StorageMode {
if self.memory_mode {
StorageMode::Memory {
max_size: self.memory_limit,
}
} else {
let disk_path = path.expect("disk mode requires a path");
StorageMode::Disk {
path: crate::disk_data_dir_path(disk_path),
config: None,
}
}
}
}