pub struct GraphStore { /* private fields */ }Expand description
The main storage engine for the graph database.
GraphStore provides a transactional interface for inserting, deleting,
and querying triples, while managing the underlying storage backend and
in-memory indexes for efficient lookups.
Implementations§
Source§impl GraphStore
impl GraphStore
Sourcepub fn new(backend: Box<dyn StorageBackend>) -> Result<Self>
pub fn new(backend: Box<dyn StorageBackend>) -> Result<Self>
Creates a new GraphStore with the given storage backend.
This will also build the initial in-memory indexes from the data already present in the backend.
Sourcepub fn insert(&self, triple: Triple) -> Result<TripleId>
pub fn insert(&self, triple: Triple) -> Result<TripleId>
Inserts a single Triple into the store.
§Errors
Returns an Error::Duplicate if a triple with the same content already exists.
Sourcepub fn insert_batch(&self, triples: Vec<Triple>) -> Result<Vec<TripleId>>
pub fn insert_batch(&self, triples: Vec<Triple>) -> Result<Vec<TripleId>>
Inserts a batch of Triples into the store.
In batch mode, duplicates are silently skipped instead of returning an error. Uses an atomic batch write when supported by the backend (e.g., Sled).
Sourcepub fn delete(&self, id: &TripleId) -> Result<bool>
pub fn delete(&self, id: &TripleId) -> Result<bool>
Deletes a Triple by its TripleId.
§Returns
Ok(true) if the triple was found and deleted, Ok(false) otherwise.
Sourcepub fn find(&self, pattern: TriplePattern) -> Result<Vec<Triple>>
pub fn find(&self, pattern: TriplePattern) -> Result<Vec<Triple>>
Finds all triples that match a given TriplePattern.
The store will attempt to use the most efficient index based on the components specified in the pattern.
Sourcepub fn contains(&self, triple: &Triple) -> Result<bool>
pub fn contains(&self, triple: &Triple) -> Result<bool>
Returns true if a triple with the same content already exists in the store.
Sourcepub fn traverse(
&self,
start: &NodeId,
predicates: &[Predicate],
) -> Result<Vec<NodeId>>
pub fn traverse( &self, start: &NodeId, predicates: &[Predicate], ) -> Result<Vec<NodeId>>
Traverses the graph starting from a node and following a set of predicates.
Sourcepub fn backend_as_any(&self) -> &dyn Any
pub fn backend_as_any(&self) -> &dyn Any
Access the underlying storage backend as Any for downcasting
(e.g. to reach the Sled Db for the shared persistent DAG).
Sourcepub fn flush(&self) -> Result<()>
pub fn flush(&self) -> Result<()>
Flushes any buffered writes to the underlying storage backend.
For persistent backends (e.g., Sled), this ensures all data is written to disk. For in-memory backends, this is a no-op.
Sourcepub fn stats(&self) -> GraphStats
pub fn stats(&self) -> GraphStats
Returns statistics about the graph, such as triple and node counts.