Skip to main content

GrafeoDB

Struct GrafeoDB 

Source
pub struct GrafeoDB { /* private fields */ }
Expand description

Your handle to a Grafeo database.

Start here. Create one with new_in_memory() for quick experiments, or open() for persistent storage. Then grab a session() to start querying.

§Examples

use grafeo_engine::GrafeoDB;

// Quick in-memory database
let db = GrafeoDB::new_in_memory();

// Add some data
db.create_node(&["Person"]);

// Query it
let session = db.session();
let result = session.execute("MATCH (p:Person) RETURN p")?;

Implementations§

Source§

impl GrafeoDB

Source

pub fn new_in_memory() -> Self

Creates an in-memory database - fast to create, gone when dropped.

Use this for tests, experiments, or when you don’t need persistence. For data that survives restarts, use open() instead.

§Examples
use grafeo_engine::GrafeoDB;

let db = GrafeoDB::new_in_memory();
let session = db.session();
session.execute("INSERT (:Person {name: 'Alice'})")?;
Source

pub fn open(path: impl AsRef<Path>) -> Result<Self>

Opens a database at the given path, creating it if it doesn’t exist.

If you’ve used this path before, Grafeo recovers your data from the write-ahead log automatically. First open on a new path creates an empty database.

§Errors

Returns an error if the path isn’t writable or recovery fails.

§Examples
use grafeo_engine::GrafeoDB;

let db = GrafeoDB::open("./my_social_network")?;
Source

pub fn with_config(config: Config) -> Result<Self>

Creates a database with custom configuration.

Use this when you need fine-grained control over memory limits, thread counts, or persistence settings. For most cases, new_in_memory() or open() are simpler.

§Errors

Returns an error if the database can’t be created or recovery fails.

§Examples
use grafeo_engine::{GrafeoDB, Config};

// In-memory with a 512MB limit
let config = Config::in_memory()
    .with_memory_limit(512 * 1024 * 1024);

let db = GrafeoDB::with_config(config)?;
Source

pub fn session(&self) -> Session

Opens a new session for running queries.

Sessions are cheap to create - spin up as many as you need. Each gets its own transaction context, so concurrent sessions won’t block each other on reads.

§Examples
use grafeo_engine::GrafeoDB;

let db = GrafeoDB::new_in_memory();
let session = db.session();

// Run queries through the session
let result = session.execute("MATCH (n) RETURN count(n)")?;
Source

pub fn adaptive_config(&self) -> &AdaptiveConfig

Returns the adaptive execution configuration.

Source

pub fn execute(&self, query: &str) -> Result<QueryResult>

Runs a query directly on the database.

A convenience method that creates a temporary session behind the scenes. If you’re running multiple queries, grab a session() instead to avoid the overhead.

§Errors

Returns an error if parsing or execution fails.

Source

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.

Source

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.

Source

pub fn config(&self) -> &Config

Returns the configuration.

Source

pub fn store(&self) -> &Arc<LpgStore>

Returns the underlying store.

This provides direct access to the LPG store for algorithm implementations.

Source

pub fn buffer_manager(&self) -> &Arc<BufferManager>

Returns the buffer manager for memory-aware operations.

Source

pub fn close(&self) -> Result<()>

Closes the database, flushing all pending writes.

For persistent databases, this ensures everything is safely on disk. Called automatically when the database is dropped, but you can call it explicitly if you need to guarantee durability at a specific point.

§Errors

Returns an error if the WAL can’t be flushed (check disk space/permissions).

Source

pub fn wal(&self) -> Option<&Arc<WalManager>>

Returns the WAL manager if available.

Source

pub fn node_count(&self) -> usize

Returns the number of nodes in the database.

Source

pub fn edge_count(&self) -> usize

Returns the number of edges in the database.

Source

pub fn label_count(&self) -> usize

Returns the number of distinct labels in the database.

Source

pub fn property_key_count(&self) -> usize

Returns the number of distinct property keys in the database.

Source

pub fn edge_type_count(&self) -> usize

Returns the number of distinct edge types in the database.

Source

pub fn create_node(&self, labels: &[&str]) -> NodeId

Creates a node with the given labels and returns its ID.

Labels categorize nodes - think of them like tags. A node can have multiple labels (e.g., ["Person", "Employee"]).

§Examples
use grafeo_engine::GrafeoDB;

let db = GrafeoDB::new_in_memory();
let alice = db.create_node(&["Person"]);
let company = db.create_node(&["Company", "Startup"]);
Source

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.

Source

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

Gets a node by ID.

Source

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.

Source

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.

Source

pub fn create_edge(&self, src: NodeId, dst: NodeId, edge_type: &str) -> EdgeId

Creates an edge (relationship) between two nodes.

Edges connect nodes and have a type that describes the relationship. They’re directed - the order of src and dst matters.

§Examples
use grafeo_engine::GrafeoDB;

let db = GrafeoDB::new_in_memory();
let alice = db.create_node(&["Person"]);
let bob = db.create_node(&["Person"]);

// Alice knows Bob (directed: Alice -> Bob)
let edge = db.create_edge(alice, bob, "KNOWS");
Source

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.

Source

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

Gets an edge by ID.

Source

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

Deletes an edge.

If WAL is enabled, the operation is logged for durability.

Source

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.

Source

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.

Source

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.

Source

pub fn is_persistent(&self) -> bool

Returns true if this database is backed by a file (persistent).

In-memory databases return false.

Source

pub fn path(&self) -> Option<&Path>

Returns the database file path, if persistent.

In-memory databases return None.

Source

pub fn info(&self) -> DatabaseInfo

Returns high-level database information.

Includes node/edge counts, persistence status, and mode (LPG/RDF).

Source

pub fn detailed_stats(&self) -> DatabaseStats

Returns detailed database statistics.

Includes counts, memory usage, and index information.

Source

pub fn schema(&self) -> SchemaInfo

Returns schema information (labels, edge types, property keys).

For LPG mode, returns label and edge type information. For RDF mode, returns predicate and named graph information.

Source

pub fn validate(&self) -> ValidationResult

Validates database integrity.

Checks for:

  • Dangling edge references (edges pointing to non-existent nodes)
  • Internal index consistency

Returns a list of errors and warnings. Empty errors = valid.

Source

pub fn wal_status(&self) -> WalStatus

Returns WAL (Write-Ahead Log) status.

Returns None if WAL is not enabled.

Source

pub fn wal_checkpoint(&self) -> Result<()>

Forces a WAL checkpoint.

Flushes all pending WAL records to the main storage.

§Errors

Returns an error if the checkpoint fails.

Source

pub fn save(&self, path: impl AsRef<Path>) -> Result<()>

Saves the database to a file path.

  • If in-memory: creates a new persistent database at path
  • If file-backed: creates a copy at the new path

The original database remains unchanged.

§Errors

Returns an error if the save operation fails.

Source

pub fn to_memory(&self) -> Result<Self>

Creates an in-memory copy of this database.

Returns a new database that is completely independent. Useful for:

  • Testing modifications without affecting the original
  • Faster operations when persistence isn’t needed
§Errors

Returns an error if the copy operation fails.

Source

pub fn open_in_memory(path: impl AsRef<Path>) -> Result<Self>

Opens a database file and loads it entirely into memory.

The returned database has no connection to the original file. Changes will NOT be written back to the file.

§Errors

Returns an error if the file can’t be opened or loaded.

Source

pub fn iter_nodes(&self) -> impl Iterator<Item = Node> + '_

Returns an iterator over all nodes in the database.

Useful for dump/export operations.

Source

pub fn iter_edges(&self) -> impl Iterator<Item = Edge> + '_

Returns an iterator over all edges in the database.

Useful for dump/export operations.

Trait Implementations§

Source§

impl Drop for GrafeoDB

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more

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> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
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.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more