pub struct GraphosDB { /* private fields */ }Expand description
The main Graphos database.
Implementations§
Source§impl GraphosDB
impl GraphosDB
Sourcepub fn new_in_memory() -> Self
pub fn new_in_memory() -> Self
Creates a new in-memory database.
§Examples
use graphos_engine::GraphosDB;
let db = GraphosDB::new_in_memory();
let session = db.session();Sourcepub fn open(path: impl AsRef<Path>) -> Result<Self>
pub fn open(path: impl AsRef<Path>) -> Result<Self>
Opens or creates a database at the given path.
If the database exists, it will be recovered from the WAL. If the database does not exist, a new one will be created.
§Errors
Returns an error if the database cannot be opened or created.
§Examples
use graphos_engine::GraphosDB;
let db = GraphosDB::open("./my_database").expect("Failed to open database");Sourcepub fn with_config(config: Config) -> Result<Self>
pub fn with_config(config: Config) -> Result<Self>
Creates a database with the given configuration.
If WAL is enabled and a database exists at the configured path, the database will be recovered from the WAL.
§Errors
Returns an error if the database cannot be created or recovery fails.
§Examples
use graphos_engine::{GraphosDB, Config};
let config = Config::in_memory()
.with_memory_limit(512 * 1024 * 1024); // 512MB
let db = GraphosDB::with_config(config).unwrap();Sourcepub fn session(&self) -> Session
pub fn session(&self) -> Session
Creates a new session for interacting with the database.
§Examples
use graphos_engine::GraphosDB;
let db = GraphosDB::new_in_memory();
let session = db.session();
// Use session for queries and transactionsSourcepub fn execute(&self, query: &str) -> Result<QueryResult>
pub fn execute(&self, query: &str) -> Result<QueryResult>
Executes a query and returns the result.
This is a convenience method that creates a session, executes the query, and returns the result.
§Errors
Returns an error if the query fails.
Sourcepub fn execute_with_params(
&self,
query: &str,
params: HashMap<String, Value>,
) -> Result<QueryResult>
pub fn execute_with_params( &self, query: &str, params: HashMap<String, Value>, ) -> Result<QueryResult>
Executes a query with parameters and returns the result.
§Errors
Returns an error if the query fails.
Sourcepub fn query_scalar<T: FromValue>(&self, query: &str) -> Result<T>
pub fn query_scalar<T: FromValue>(&self, query: &str) -> Result<T>
Executes a query and returns a single scalar value.
§Errors
Returns an error if the query fails or doesn’t return exactly one row.
Sourcepub fn store(&self) -> &Arc<LpgStore>
pub fn store(&self) -> &Arc<LpgStore>
Returns the underlying store.
This provides direct access to the LPG store for algorithm implementations.
Sourcepub fn buffer_manager(&self) -> &Arc<BufferManager>
pub fn buffer_manager(&self) -> &Arc<BufferManager>
Returns the buffer manager for memory-aware operations.
Sourcepub fn close(&self) -> Result<()>
pub fn close(&self) -> Result<()>
Closes the database.
This will:
- Commit any pending WAL records
- Create a checkpoint
- Sync the WAL to disk
§Errors
Returns an error if the WAL cannot be flushed.
Sourcepub fn wal(&self) -> Option<&Arc<WalManager>>
pub fn wal(&self) -> Option<&Arc<WalManager>>
Returns the WAL manager if available.
Sourcepub fn node_count(&self) -> usize
pub fn node_count(&self) -> usize
Returns the number of nodes in the database.
Sourcepub fn edge_count(&self) -> usize
pub fn edge_count(&self) -> usize
Returns the number of edges in the database.
Sourcepub fn label_count(&self) -> usize
pub fn label_count(&self) -> usize
Returns the number of distinct labels in the database.
Sourcepub fn property_key_count(&self) -> usize
pub fn property_key_count(&self) -> usize
Returns the number of distinct property keys in the database.
Sourcepub fn edge_type_count(&self) -> usize
pub fn edge_type_count(&self) -> usize
Returns the number of distinct edge types in the database.
Sourcepub fn create_node(&self, labels: &[&str]) -> NodeId
pub fn create_node(&self, labels: &[&str]) -> NodeId
Creates a new node with the given labels.
If WAL is enabled, the operation is logged for durability.
Sourcepub fn create_node_with_props(
&self,
labels: &[&str],
properties: impl IntoIterator<Item = (impl Into<PropertyKey>, impl Into<Value>)>,
) -> NodeId
pub fn create_node_with_props( &self, labels: &[&str], properties: impl IntoIterator<Item = (impl Into<PropertyKey>, impl Into<Value>)>, ) -> NodeId
Creates a new node with labels and properties.
If WAL is enabled, the operation is logged for durability.
Sourcepub fn delete_node(&self, id: NodeId) -> bool
pub fn delete_node(&self, id: NodeId) -> bool
Deletes a node and all its edges.
If WAL is enabled, the operation is logged for durability.
Sourcepub fn set_node_property(&self, id: NodeId, key: &str, value: Value)
pub fn set_node_property(&self, id: NodeId, key: &str, value: Value)
Sets a property on a node.
If WAL is enabled, the operation is logged for durability.
Sourcepub fn create_edge(&self, src: NodeId, dst: NodeId, edge_type: &str) -> EdgeId
pub fn create_edge(&self, src: NodeId, dst: NodeId, edge_type: &str) -> EdgeId
Creates a new edge between two nodes.
If WAL is enabled, the operation is logged for durability.
Sourcepub fn create_edge_with_props(
&self,
src: NodeId,
dst: NodeId,
edge_type: &str,
properties: impl IntoIterator<Item = (impl Into<PropertyKey>, impl Into<Value>)>,
) -> EdgeId
pub fn create_edge_with_props( &self, src: NodeId, dst: NodeId, edge_type: &str, properties: impl IntoIterator<Item = (impl Into<PropertyKey>, impl Into<Value>)>, ) -> EdgeId
Creates a new edge with properties.
If WAL is enabled, the operation is logged for durability.
Sourcepub fn delete_edge(&self, id: EdgeId) -> bool
pub fn delete_edge(&self, id: EdgeId) -> bool
Deletes an edge.
If WAL is enabled, the operation is logged for durability.
Sourcepub fn set_edge_property(&self, id: EdgeId, key: &str, value: Value)
pub fn set_edge_property(&self, id: EdgeId, key: &str, value: Value)
Sets a property on an edge.
If WAL is enabled, the operation is logged for durability.
Sourcepub fn remove_node_property(&self, id: NodeId, key: &str) -> bool
pub fn remove_node_property(&self, id: NodeId, key: &str) -> bool
Removes a property from a node.
Returns true if the property existed and was removed, false otherwise.
Sourcepub fn remove_edge_property(&self, id: EdgeId, key: &str) -> bool
pub fn remove_edge_property(&self, id: EdgeId, key: &str) -> bool
Removes a property from an edge.
Returns true if the property existed and was removed, false otherwise.