1use std::path::Path;
2
3use crate::error::GraphdError;
4
5pub struct Backend {
7 db: lbug::Database,
8}
9
10impl Backend {
11 pub fn open(path: &Path) -> Result<Self, GraphdError> {
13 Self::open_with_config(path, lbug::SystemConfig::default())
14 }
15
16 pub fn open_tenant(path: &Path, memory_mb: u64, max_threads: u64) -> Result<Self, GraphdError> {
20 let config = lbug::SystemConfig::default()
21 .buffer_pool_size(memory_mb * 1024 * 1024)
22 .max_num_threads(max_threads);
23 Self::open_with_config(path, config)
24 }
25
26 pub fn open_with_config(path: &Path, config: lbug::SystemConfig) -> Result<Self, GraphdError> {
28 let db = lbug::Database::new(path, config)
29 .map_err(|e| GraphdError::DatabaseError(format!("Failed to open database: {e}")))?;
30 Ok(Self { db })
31 }
32
33 pub fn connection(&self) -> Result<lbug::Connection<'_>, GraphdError> {
35 lbug::Connection::new(&self.db)
36 .map_err(|e| GraphdError::DatabaseError(format!("Connection failed: {e}")))
37 }
38}