Skip to main content

StorageEngine

Struct StorageEngine 

Source
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

Source

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.

Source

pub fn create_node( &mut self, labels: Vec<u32>, properties: Vec<(u32, PropertyValue)>, ) -> NodeId

Create a new node.

Source

pub fn get_node(&self, node_id: NodeId) -> Option<&NodeRecord>

Get a node by ID.

Source

pub fn update_node( &mut self, node_id: NodeId, properties: Vec<(u32, PropertyValue)>, ) -> Result<()>

Update a node’s properties.

Source

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.

Source

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.

Source

pub fn get_edge(&self, edge_id: EdgeId) -> Option<&RelationshipRecord>

Get an edge by ID.

Source

pub fn update_edge( &mut self, edge_id: EdgeId, properties: Vec<(u32, PropertyValue)>, ) -> Result<()>

Update an edge’s properties.

Source

pub fn get_edges_for_node(&self, node_id: NodeId) -> Vec<&RelationshipRecord>

Get all edges connected to a node.

Source

pub fn delete_edge(&mut self, edge_id: EdgeId) -> Result<RelationshipRecord>

Delete an edge.

Source

pub fn scan_nodes(&self) -> Vec<&NodeRecord>

Scan all nodes in the database.

Source

pub fn scan_nodes_by_label(&self, label_id: u32) -> Vec<&NodeRecord>

Scan nodes that have the given label.

Source

pub fn scan_edges_by_type(&self, type_id: u32) -> Vec<&RelationshipRecord>

Scan edges of the given relationship type.

Source

pub fn begin_read(&self) -> ReadTransaction

Begin a read transaction.

Source

pub fn begin_write(&self) -> Result<WriteTransaction>

Begin a write transaction.

Source

pub fn wal_write_page( &mut self, page_id: PageId, data: &[u8; 4096], ) -> Result<u64>

Write a page to the WAL (used internally).

Source

pub fn wal_commit(&mut self) -> Result<u64>

Commit the current WAL transaction.

Source

pub fn wal_discard(&mut self)

Discard uncommitted WAL frames.

Source

pub fn checkpoint(&mut self) -> Result<u64>

Run a checkpoint: copy WAL frames to main file.

Source

pub fn flush_header(&mut self) -> Result<()>

Flush the database header to disk.

Source

pub fn node_count(&self) -> usize

Returns the number of nodes.

Source

pub fn edge_count(&self) -> usize

Returns the number of edges.

Source

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.

Source

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.

Source

pub fn config(&self) -> &DatabaseConfig

Returns a reference to the config.

Source

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.

Source

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.

Source

pub fn index_manager(&self) -> &IndexManager

Returns a reference to the index manager.

Source

pub fn index_manager_mut(&mut self) -> &mut IndexManager

Returns a mutable reference to the index manager.

Source

pub fn edge_index_manager(&self) -> &EdgeIndexManager

Returns a reference to the edge index manager.

Source

pub fn edge_index_manager_mut(&mut self) -> &mut EdgeIndexManager

Returns a mutable reference to the edge index manager.

Source

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.

Source

pub fn catalog(&self) -> &Catalog

Returns a reference to the catalog.

Source

pub fn catalog_mut(&mut self) -> &mut Catalog

Returns a mutable reference to the catalog.

Source

pub fn version_store(&self) -> &VersionStore

Returns a reference to the version store.

Source

pub fn version_store_mut(&mut self) -> &mut VersionStore

Returns a mutable reference to the version store.

Source

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.

Source

pub fn get_subgraph(&self, id: SubgraphId) -> Option<&SubgraphRecord>

Get a subgraph record by ID.

Source

pub fn delete_subgraph(&mut self, id: SubgraphId) -> Result<SubgraphRecord>

Delete a subgraph by ID. Also removes all memberships.

Source

pub fn add_member( &mut self, subgraph_id: SubgraphId, node_id: NodeId, ) -> Result<()>

Add a node as a member of a subgraph.

Source

pub fn remove_member( &mut self, subgraph_id: SubgraphId, node_id: NodeId, ) -> Result<()>

Remove a node from a subgraph.

Source

pub fn list_members(&self, subgraph_id: SubgraphId) -> Vec<NodeId>

List all node members of a subgraph.

Source

pub fn get_subgraph_memberships(&self, node_id: NodeId) -> Vec<SubgraphId>

Get all subgraphs that a node belongs to.

Source

pub fn scan_subgraphs(&self) -> Vec<&SubgraphRecord>

Scan all subgraph records.

Source

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.

Source

pub fn get_hyperedge(&self, id: HyperEdgeId) -> Option<&HyperEdgeRecord>

Get a hyperedge record by ID.

Source

pub fn delete_hyperedge(&mut self, id: HyperEdgeId) -> Result<HyperEdgeRecord>

Delete a hyperedge by ID. Also removes all reverse index entries.

Source

pub fn scan_hyperedges(&self) -> Vec<&HyperEdgeRecord>

Scan all hyperedge records.

Source

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).

Source

pub fn node_data_root_page(&self) -> u32

Returns the node data root page ID from the database header.

Source

pub fn edge_data_root_page(&self) -> u32

Returns the edge data root page ID from the database header.

Source

pub fn version_count(&self, entity_id: u64) -> u64

Returns the number of version snapshots for a given entity.

Source

pub fn version_chain(&self, entity_id: u64) -> Vec<(u64, &VersionRecord)>

Returns the version chain for a given entity (oldest to newest).

Source

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.

Source

pub fn wal_frame_count(&self) -> u64

Returns the number of committed WAL frames.

Source

pub fn node_data_page_count(&self) -> usize

Returns the number of node data pages currently allocated.

Trait Implementations§

Source§

impl Drop for StorageEngine

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more
Source§

impl LabelRegistry for StorageEngine

Source§

fn get_or_create_label(&mut self, name: &str) -> u32

Get or create a label ID for the given name.
Source§

fn label_id(&self, name: &str) -> Option<u32>

Look up a label ID by name (returns None if not found).
Source§

fn label_name(&self, id: u32) -> Option<&str>

Look up a label name by ID (returns None if not found).
Source§

fn get_or_create_rel_type(&mut self, name: &str) -> u32

Get or create a relationship type ID.
Source§

fn rel_type_id(&self, name: &str) -> Option<u32>

Look up a relationship type ID by name.
Source§

fn rel_type_name(&self, id: u32) -> Option<&str>

Look up a relationship type name by ID.
Source§

fn get_or_create_prop_key(&mut self, name: &str) -> u32

Get or create a property key ID.
Source§

fn prop_key_id(&self, name: &str) -> Option<u32>

Look up a property key ID by name.
Source§

fn prop_key_name(&self, id: u32) -> Option<&str>

Look up a property key name by ID.

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.