use std::path::PathBuf;
use std::sync::Arc;
use super::config::{Storage, TreeConfig, WalCommit};
use super::tree::Tree;
use crate::api::errors::Result;
use crate::checkpoint::CheckpointConfig;
use crate::store::blob_store::BlobStore;
#[derive(Debug, Clone)]
#[must_use = "TreeBuilder is consumed by `.open()` / `.open_with_blob_store()`; chained setters return a fresh builder you must use"]
pub struct TreeBuilder {
cfg: TreeConfig,
}
impl TreeBuilder {
pub fn new<P: Into<PathBuf>>(data_dir: P) -> Self {
Self {
cfg: TreeConfig::new(data_dir),
}
}
pub fn memory(mut self) -> Self {
self.cfg.storage = Storage::Memory;
self
}
pub fn buffer_pool_size(mut self, n: usize) -> Self {
self.cfg.buffer_pool_size = n;
self
}
pub fn wal_commit(mut self, mode: WalCommit) -> Self {
self.cfg.wal_commit = mode;
self
}
pub fn checkpoint(mut self, cfg: CheckpointConfig) -> Self {
self.cfg.checkpoint = cfg;
self
}
pub fn open(self) -> Result<Tree> {
Tree::open(self.cfg)
}
pub fn open_with_blob_store(self, store: Arc<dyn BlobStore>) -> Result<Tree> {
Tree::open_with_blob_store(self.cfg, store)
}
}