Skip to main content

GraphosDB

Struct GraphosDB 

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

The main Graphos database.

Implementations§

Source§

impl GraphosDB

Source

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();
Source

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");
Source

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();
Source

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 transactions
Source

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.

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.

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.

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 new node with the given labels.

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

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 a new edge between two nodes.

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

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.

Trait Implementations§

Source§

impl Drop for GraphosDB

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