pub struct StorageEngine { /* private fields */ }Expand description
The main storage engine for CypherLite.
Provides high-level access to node/edge CRUD, transactions, WAL, and checkpoint operations.
Implementations§
Source§impl StorageEngine
impl StorageEngine
Sourcepub fn open(config: DatabaseConfig) -> Result<Self>
pub fn open(config: DatabaseConfig) -> Result<Self>
Open or create a CypherLite database.
Acquires an exclusive file lock (flock) on the .cyl file. If the lock
cannot be acquired (e.g. another process holds it), returns
CypherLiteError::DatabaseLocked.
Sourcepub fn create_node(
&mut self,
labels: Vec<u32>,
properties: Vec<(u32, PropertyValue)>,
) -> NodeId
pub fn create_node( &mut self, labels: Vec<u32>, properties: Vec<(u32, PropertyValue)>, ) -> NodeId
Create a new node.
Sourcepub fn get_node(&self, node_id: NodeId) -> Option<&NodeRecord>
pub fn get_node(&self, node_id: NodeId) -> Option<&NodeRecord>
Get a node by ID.
Sourcepub fn update_node(
&mut self,
node_id: NodeId,
properties: Vec<(u32, PropertyValue)>,
) -> Result<()>
pub fn update_node( &mut self, node_id: NodeId, properties: Vec<(u32, PropertyValue)>, ) -> Result<()>
Update a node’s properties.
Sourcepub fn delete_node(&mut self, node_id: NodeId) -> Result<NodeRecord>
pub fn delete_node(&mut self, node_id: NodeId) -> Result<NodeRecord>
Delete a node and all its connected edges. REQ-STORE-004: Delete all connected edges first.
Sourcepub fn create_edge(
&mut self,
start_node: NodeId,
end_node: NodeId,
rel_type_id: u32,
properties: Vec<(u32, PropertyValue)>,
) -> Result<EdgeId>
pub fn create_edge( &mut self, start_node: NodeId, end_node: NodeId, rel_type_id: u32, properties: Vec<(u32, PropertyValue)>, ) -> Result<EdgeId>
Create a new edge.
Sourcepub fn get_edge(&self, edge_id: EdgeId) -> Option<&RelationshipRecord>
pub fn get_edge(&self, edge_id: EdgeId) -> Option<&RelationshipRecord>
Get an edge by ID.
Sourcepub fn update_edge(
&mut self,
edge_id: EdgeId,
properties: Vec<(u32, PropertyValue)>,
) -> Result<()>
pub fn update_edge( &mut self, edge_id: EdgeId, properties: Vec<(u32, PropertyValue)>, ) -> Result<()>
Update an edge’s properties.
Sourcepub fn get_edges_for_node(&self, node_id: NodeId) -> Vec<&RelationshipRecord>
pub fn get_edges_for_node(&self, node_id: NodeId) -> Vec<&RelationshipRecord>
Get all edges connected to a node.
Sourcepub fn delete_edge(&mut self, edge_id: EdgeId) -> Result<RelationshipRecord>
pub fn delete_edge(&mut self, edge_id: EdgeId) -> Result<RelationshipRecord>
Delete an edge.
Sourcepub fn scan_nodes(&self) -> Vec<&NodeRecord>
pub fn scan_nodes(&self) -> Vec<&NodeRecord>
Scan all nodes in the database.
Sourcepub fn scan_nodes_by_label(&self, label_id: u32) -> Vec<&NodeRecord>
pub fn scan_nodes_by_label(&self, label_id: u32) -> Vec<&NodeRecord>
Scan nodes that have the given label.
Sourcepub fn scan_edges_by_type(&self, type_id: u32) -> Vec<&RelationshipRecord>
pub fn scan_edges_by_type(&self, type_id: u32) -> Vec<&RelationshipRecord>
Scan edges of the given relationship type.
Sourcepub fn begin_read(&self) -> ReadTransaction
pub fn begin_read(&self) -> ReadTransaction
Begin a read transaction.
Sourcepub fn begin_write(&self) -> Result<WriteTransaction>
pub fn begin_write(&self) -> Result<WriteTransaction>
Begin a write transaction.
Sourcepub fn wal_write_page(
&mut self,
page_id: PageId,
data: &[u8; 4096],
) -> Result<u64>
pub fn wal_write_page( &mut self, page_id: PageId, data: &[u8; 4096], ) -> Result<u64>
Write a page to the WAL (used internally).
Sourcepub fn wal_commit(&mut self) -> Result<u64>
pub fn wal_commit(&mut self) -> Result<u64>
Commit the current WAL transaction.
Sourcepub fn wal_discard(&mut self)
pub fn wal_discard(&mut self)
Discard uncommitted WAL frames.
Sourcepub fn checkpoint(&mut self) -> Result<u64>
pub fn checkpoint(&mut self) -> Result<u64>
Run a checkpoint: copy WAL frames to main file.
Sourcepub fn flush_header(&mut self) -> Result<()>
pub fn flush_header(&mut self) -> Result<()>
Flush the database header to disk.
Sourcepub fn node_count(&self) -> usize
pub fn node_count(&self) -> usize
Returns the number of nodes.
Sourcepub fn edge_count(&self) -> usize
pub fn edge_count(&self) -> usize
Returns the number of edges.
Sourcepub fn find_node(
&self,
label_ids: &[u32],
properties: &[(u32, PropertyValue)],
) -> Option<NodeId>
pub fn find_node( &self, label_ids: &[u32], properties: &[(u32, PropertyValue)], ) -> Option<NodeId>
Find the first node matching all given labels and properties.
Scans nodes by the first label (if any) for efficiency, then filters
by remaining labels and all property key-value pairs (exact equality).
Returns None if no match is found.
Sourcepub fn find_edge(
&self,
start: NodeId,
end: NodeId,
type_id: u32,
) -> Option<EdgeId>
pub fn find_edge( &self, start: NodeId, end: NodeId, type_id: u32, ) -> Option<EdgeId>
Find the first edge from start to end with the given relationship type.
Checks edges connected to the start node and returns the first one matching both the end node and relationship type.
Sourcepub fn config(&self) -> &DatabaseConfig
pub fn config(&self) -> &DatabaseConfig
Returns a reference to the config.
Sourcepub fn scan_nodes_by_property(
&self,
label_id: u32,
prop_key_id: u32,
value: &PropertyValue,
) -> Vec<NodeId>
pub fn scan_nodes_by_property( &self, label_id: u32, prop_key_id: u32, value: &PropertyValue, ) -> Vec<NodeId>
Scan nodes by (label, property_key, value) using index if available.
If an index exists for (label_id, prop_key_id), uses the fast index lookup. Otherwise falls back to linear scan.
Sourcepub fn scan_nodes_by_range(
&self,
label_id: u32,
prop_key_id: u32,
min: &PropertyValue,
max: &PropertyValue,
) -> Vec<NodeId>
pub fn scan_nodes_by_range( &self, label_id: u32, prop_key_id: u32, min: &PropertyValue, max: &PropertyValue, ) -> Vec<NodeId>
Range scan by (label, property_key, min, max) using index if available.
Returns node IDs where the property value is in [min, max] (inclusive). Uses index range query if available, otherwise falls back to linear scan.
Sourcepub fn index_manager(&self) -> &IndexManager
pub fn index_manager(&self) -> &IndexManager
Returns a reference to the index manager.
Sourcepub fn index_manager_mut(&mut self) -> &mut IndexManager
pub fn index_manager_mut(&mut self) -> &mut IndexManager
Returns a mutable reference to the index manager.
Sourcepub fn edge_index_manager(&self) -> &EdgeIndexManager
pub fn edge_index_manager(&self) -> &EdgeIndexManager
Returns a reference to the edge index manager.
Sourcepub fn edge_index_manager_mut(&mut self) -> &mut EdgeIndexManager
pub fn edge_index_manager_mut(&mut self) -> &mut EdgeIndexManager
Returns a mutable reference to the edge index manager.
Sourcepub fn scan_edges_by_property(
&self,
rel_type_id: u32,
prop_key_id: u32,
value: &PropertyValue,
) -> Vec<EdgeId>
pub fn scan_edges_by_property( &self, rel_type_id: u32, prop_key_id: u32, value: &PropertyValue, ) -> Vec<EdgeId>
Scan edges by (rel_type_id, prop_key_id, value) using index if available.
If an index exists for (rel_type_id, prop_key_id), uses the fast index lookup. Otherwise falls back to linear scan.
Sourcepub fn catalog_mut(&mut self) -> &mut Catalog
pub fn catalog_mut(&mut self) -> &mut Catalog
Returns a mutable reference to the catalog.
Sourcepub fn version_store(&self) -> &VersionStore
pub fn version_store(&self) -> &VersionStore
Returns a reference to the version store.
Sourcepub fn version_store_mut(&mut self) -> &mut VersionStore
pub fn version_store_mut(&mut self) -> &mut VersionStore
Returns a mutable reference to the version store.
Sourcepub fn create_subgraph(
&mut self,
properties: Vec<(u32, PropertyValue)>,
temporal_anchor: Option<i64>,
) -> SubgraphId
pub fn create_subgraph( &mut self, properties: Vec<(u32, PropertyValue)>, temporal_anchor: Option<i64>, ) -> SubgraphId
Create a new subgraph with the given properties and optional temporal anchor.
Sourcepub fn get_subgraph(&self, id: SubgraphId) -> Option<&SubgraphRecord>
pub fn get_subgraph(&self, id: SubgraphId) -> Option<&SubgraphRecord>
Get a subgraph record by ID.
Sourcepub fn delete_subgraph(&mut self, id: SubgraphId) -> Result<SubgraphRecord>
pub fn delete_subgraph(&mut self, id: SubgraphId) -> Result<SubgraphRecord>
Delete a subgraph by ID. Also removes all memberships.
Sourcepub fn add_member(
&mut self,
subgraph_id: SubgraphId,
node_id: NodeId,
) -> Result<()>
pub fn add_member( &mut self, subgraph_id: SubgraphId, node_id: NodeId, ) -> Result<()>
Add a node as a member of a subgraph.
Sourcepub fn remove_member(
&mut self,
subgraph_id: SubgraphId,
node_id: NodeId,
) -> Result<()>
pub fn remove_member( &mut self, subgraph_id: SubgraphId, node_id: NodeId, ) -> Result<()>
Remove a node from a subgraph.
Sourcepub fn list_members(&self, subgraph_id: SubgraphId) -> Vec<NodeId>
pub fn list_members(&self, subgraph_id: SubgraphId) -> Vec<NodeId>
List all node members of a subgraph.
Sourcepub fn get_subgraph_memberships(&self, node_id: NodeId) -> Vec<SubgraphId>
pub fn get_subgraph_memberships(&self, node_id: NodeId) -> Vec<SubgraphId>
Get all subgraphs that a node belongs to.
Sourcepub fn scan_subgraphs(&self) -> Vec<&SubgraphRecord>
pub fn scan_subgraphs(&self) -> Vec<&SubgraphRecord>
Scan all subgraph records.
Sourcepub fn create_hyperedge(
&mut self,
rel_type_id: u32,
sources: Vec<GraphEntity>,
targets: Vec<GraphEntity>,
properties: Vec<(u32, PropertyValue)>,
) -> HyperEdgeId
pub fn create_hyperedge( &mut self, rel_type_id: u32, sources: Vec<GraphEntity>, targets: Vec<GraphEntity>, properties: Vec<(u32, PropertyValue)>, ) -> HyperEdgeId
Create a new hyperedge with the given type, sources, targets, and properties.
Sourcepub fn get_hyperedge(&self, id: HyperEdgeId) -> Option<&HyperEdgeRecord>
pub fn get_hyperedge(&self, id: HyperEdgeId) -> Option<&HyperEdgeRecord>
Get a hyperedge record by ID.
Sourcepub fn delete_hyperedge(&mut self, id: HyperEdgeId) -> Result<HyperEdgeRecord>
pub fn delete_hyperedge(&mut self, id: HyperEdgeId) -> Result<HyperEdgeRecord>
Delete a hyperedge by ID. Also removes all reverse index entries.
Sourcepub fn scan_hyperedges(&self) -> Vec<&HyperEdgeRecord>
pub fn scan_hyperedges(&self) -> Vec<&HyperEdgeRecord>
Scan all hyperedge records.
Sourcepub fn hyperedges_for_entity(&self, raw_entity_id: u64) -> Vec<u64>
pub fn hyperedges_for_entity(&self, raw_entity_id: u64) -> Vec<u64>
Find all hyperedge IDs that an entity participates in (by raw entity ID).
Sourcepub fn node_data_root_page(&self) -> u32
pub fn node_data_root_page(&self) -> u32
Returns the node data root page ID from the database header.
Sourcepub fn edge_data_root_page(&self) -> u32
pub fn edge_data_root_page(&self) -> u32
Returns the edge data root page ID from the database header.
Sourcepub fn version_count(&self, entity_id: u64) -> u64
pub fn version_count(&self, entity_id: u64) -> u64
Returns the number of version snapshots for a given entity.
Sourcepub fn version_chain(&self, entity_id: u64) -> Vec<(u64, &VersionRecord)>
pub fn version_chain(&self, entity_id: u64) -> Vec<(u64, &VersionRecord)>
Returns the version chain for a given entity (oldest to newest).
Sourcepub fn read_data_page(&mut self, page_id: u32) -> Result<[u8; 4096]>
pub fn read_data_page(&mut self, page_id: u32) -> Result<[u8; 4096]>
Read a data page by page ID.
Returns the in-memory cached copy if the page is the current active data page (which may contain WAL-only writes not yet checkpointed). Otherwise reads from the main database file.
Sourcepub fn wal_frame_count(&self) -> u64
pub fn wal_frame_count(&self) -> u64
Returns the number of committed WAL frames.
Sourcepub fn node_data_page_count(&self) -> usize
pub fn node_data_page_count(&self) -> usize
Returns the number of node data pages currently allocated.