pub struct Database<S> { /* private fields */ }Expand description
Owns the graph store and orchestrates parse → analyze → compile → execute.
Implementations§
Source§impl Database<InMemoryGraph>
impl Database<InMemoryGraph>
Source§impl<S> Database<S>where
S: GraphStorage + GraphStorageMut,
impl<S> Database<S>where
S: GraphStorage + GraphStorageMut,
Sourcepub fn from_graph(graph: S) -> Self
pub fn from_graph(graph: S) -> Self
Build a database by taking ownership of a bare graph store.
Sourcepub fn store(&self) -> &Arc<Mutex<S>>
pub fn store(&self) -> &Arc<Mutex<S>>
Handle to the underlying shared store — useful for callers that need to snapshot or share the graph across multiple databases.
Sourcepub fn parse(&self, query: &str) -> Result<Document>
pub fn parse(&self, query: &str) -> Result<Document>
Parse a query string into an AST without executing it.
Sourcepub fn execute(
&self,
query: &str,
options: Option<ExecuteOptions>,
) -> Result<QueryResult>
pub fn execute( &self, query: &str, options: Option<ExecuteOptions>, ) -> Result<QueryResult>
Execute a query and return its result.
Sourcepub fn execute_with_params(
&self,
query: &str,
options: Option<ExecuteOptions>,
params: BTreeMap<String, LoraValue>,
) -> Result<QueryResult>
pub fn execute_with_params( &self, query: &str, options: Option<ExecuteOptions>, params: BTreeMap<String, LoraValue>, ) -> Result<QueryResult>
Execute a query with bound parameters.
Sourcepub fn node_count(&self) -> usize
pub fn node_count(&self) -> usize
Number of nodes currently in the graph.
Sourcepub fn relationship_count(&self) -> usize
pub fn relationship_count(&self) -> usize
Number of relationships currently in the graph.
Sourcepub fn with_store<R>(&self, f: impl FnOnce(&S) -> R) -> R
pub fn with_store<R>(&self, f: impl FnOnce(&S) -> R) -> R
Run a closure with a shared borrow of the underlying store. Used by bindings to answer ad-hoc queries without locking the mutex themselves.
Sourcepub fn with_store_mut<R>(&self, f: impl FnOnce(&mut S) -> R) -> R
pub fn with_store_mut<R>(&self, f: impl FnOnce(&mut S) -> R) -> R
Run a closure with an exclusive borrow of the underlying store. Reserved
for admin paths (restore, bulk load); regular mutation goes through
execute_with_params.
Source§impl<S> Database<S>
impl<S> Database<S>
Sourcepub fn save_snapshot_to(&self, path: impl AsRef<Path>) -> Result<SnapshotMeta>
pub fn save_snapshot_to(&self, path: impl AsRef<Path>) -> Result<SnapshotMeta>
Serialize the current graph state to the given path. Writes are
atomic: the payload goes to <path>.tmp, is fsync’d, and then
renamed over the target; a torn write can never leave a half-written
file at path. If any step before the rename fails, the stale
<path>.tmp is removed so a crashed save never leaks scratch files.
Holds the store mutex for the duration of the save so concurrent queries see a consistent point-in-time snapshot.
Sourcepub fn load_snapshot_from(&self, path: impl AsRef<Path>) -> Result<SnapshotMeta>
pub fn load_snapshot_from(&self, path: impl AsRef<Path>) -> Result<SnapshotMeta>
Replace the current graph state with a snapshot loaded from path.
Holds the store mutex for the duration of the load; concurrent
queries block until restore completes.
Source§impl Database<InMemoryGraph>
impl Database<InMemoryGraph>
Sourcepub fn in_memory_from_snapshot(path: impl AsRef<Path>) -> Result<Self>
pub fn in_memory_from_snapshot(path: impl AsRef<Path>) -> Result<Self>
Convenience constructor: open (or create) an empty in-memory database
and immediately restore it from path. Errors if the file cannot be
opened or the snapshot is malformed.