use std::path::Path;
pub use marsdb_query::{Literal, QueryResult, Value};
#[derive(Debug, thiserror::Error)]
pub enum Error {
#[error("graph error: {0}")]
Graph(#[from] marsdb_graph::GraphError),
#[error("query error: {0}")]
Query(#[from] marsdb_query::QueryError),
}
pub struct Database {
store: marsdb_graph::GraphStore,
}
impl Database {
pub fn open(path: impl AsRef<Path>) -> Result<Self, Error> {
Ok(Self {
store: marsdb_graph::GraphStore::open_file(path)?,
})
}
pub fn in_memory() -> Result<Self, Error> {
Ok(Self {
store: marsdb_graph::GraphStore::open_memory()?,
})
}
pub fn execute(&self, cypher: &str) -> Result<QueryResult, Error> {
let stmt = marsdb_query::parse(cypher)?;
let result = marsdb_query::Executor::new(&self.store).execute(&stmt)?;
Ok(result)
}
}