Skip to main content

StorageEngine

Trait StorageEngine 

Source
pub trait StorageEngine: Send + Sync {
    // Required methods
    fn put_node(&self, node: &Node) -> Result<()>;
    fn get_node(&self, id: NodeId) -> Result<Option<Node>>;
    fn delete_node(&self, id: NodeId) -> Result<bool>;
    fn put_edge(&self, edge: &Edge) -> Result<()>;
    fn get_edge(&self, id: EdgeId) -> Result<Option<Edge>>;
    fn delete_edge(&self, id: EdgeId) -> Result<bool>;
    fn get_edges(
        &self,
        node_id: NodeId,
        direction: Direction,
    ) -> Result<Vec<Edge>>;
    fn flush(&self) -> Result<()>;

    // Provided methods
    fn find_nodes_by_label(&self, _label: &str) -> Result<Vec<NodeId>> { ... }
    fn find_edges_by_type(
        &self,
        _edge_type: &str,
    ) -> Result<Vec<(EdgeId, NodeId, NodeId)>> { ... }
    fn list_all_nodes(&self) -> Result<Vec<NodeId>> { ... }
}
Expand description

Low-level storage engine trait for persisting and retrieving nodes and edges.

Implementations handle the page-based storage, buffer pool, and disk I/O. This trait intentionally does NOT handle transactions — that is layered on top.

Required Methods§

Source

fn put_node(&self, node: &Node) -> Result<()>

Store a node. Overwrites if the node ID already exists.

Source

fn get_node(&self, id: NodeId) -> Result<Option<Node>>

Retrieve a node by ID.

Source

fn delete_node(&self, id: NodeId) -> Result<bool>

Delete a node by ID. Returns true if the node existed.

Source

fn put_edge(&self, edge: &Edge) -> Result<()>

Store an edge. Overwrites if the edge ID already exists.

Source

fn get_edge(&self, id: EdgeId) -> Result<Option<Edge>>

Retrieve an edge by ID.

Source

fn delete_edge(&self, id: EdgeId) -> Result<bool>

Delete an edge by ID. Returns true if the edge existed.

Source

fn get_edges(&self, node_id: NodeId, direction: Direction) -> Result<Vec<Edge>>

Get all edges connected to a node in the given direction.

Source

fn flush(&self) -> Result<()>

Flush all dirty data to disk.

Provided Methods§

Source

fn find_nodes_by_label(&self, _label: &str) -> Result<Vec<NodeId>>

Find all node IDs that carry the given label.

The default implementation returns an empty vector. Storage engines that maintain a label index should override this for O(1) lookups.

Source

fn find_edges_by_type( &self, _edge_type: &str, ) -> Result<Vec<(EdgeId, NodeId, NodeId)>>

Find all edges whose edge_type matches the given string.

Returns a list of (EdgeId, source NodeId, target NodeId) triples. The default implementation returns an empty vector. Storage engines that maintain an edge index should override this.

Source

fn list_all_nodes(&self) -> Result<Vec<NodeId>>

List all node IDs currently stored in the engine.

The default implementation returns an empty vector. Storage engines that maintain a node index should override this to return every stored node ID. Used by Graph::rebuild_vector_index to repopulate an in-memory HNSW index after a WAL replay / restart.

Dyn Compatibility§

This trait is dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§