Skip to main content

EdgeStore

Struct EdgeStore 

Source
pub struct EdgeStore;
Expand description

Edge storage operations.

EdgeStore provides transactional CRUD operations for graph edges. All operations work within a transaction context for ACID guarantees.

§Indexes

Edges are indexed by:

  • Source entity (for outgoing edge queries)
  • Target entity (for incoming edge queries)
  • Edge type (for type-based filtering)

§Example

use manifoldb_graph::store::{EdgeStore, NodeStore, IdGenerator};

// Create an edge between two nodes
let gen = IdGenerator::new();
let edge = EdgeStore::create(&mut tx, &gen, source_id, target_id, "FOLLOWS", |id| {
    Edge::new(id, source_id, target_id, "FOLLOWS")
        .with_property("since", "2024-01-01")
})?;

// Find all outgoing edges from a node
let outgoing = EdgeStore::get_outgoing(&tx, source_id)?;

Implementations§

Source§

impl EdgeStore

Source

pub fn create<T: Transaction, F>( tx: &mut T, id_gen: &IdGenerator, source: EntityId, target: EntityId, edge_type: impl Into<EdgeType>, builder: F, ) -> GraphResult<Edge>
where F: FnOnce(EdgeId) -> Edge,

Create a new edge in the store.

§Arguments
  • tx - The transaction to use
  • id_gen - The ID generator
  • source - The source entity ID
  • target - The target entity ID
  • edge_type - The edge type
  • builder - A function that builds the edge given an ID
§Returns

The created edge with its assigned ID.

§Errors

Returns GraphError::InvalidEntityReference if source or target doesn’t exist.

Source

pub fn create_with_id<T: Transaction>( tx: &mut T, edge: &Edge, validate_refs: bool, ) -> GraphResult<()>

Create an edge with a specific ID.

This is useful when importing data or when you need to control IDs.

§Arguments
  • tx - The transaction to use
  • edge - The edge to store (must have a valid ID)
  • validate_refs - Whether to validate that source/target entities exist
§Errors

Returns GraphError::EdgeAlreadyExists if an edge with this ID exists. Returns GraphError::InvalidEntityReference if validation is enabled and entities don’t exist.

Source

pub fn get<T: Transaction>(tx: &T, id: EdgeId) -> GraphResult<Option<Edge>>

Get an edge by ID.

§Arguments
  • tx - The transaction to use
  • id - The edge ID to look up
§Returns

The edge if found, or None if it doesn’t exist.

Source

pub fn get_or_error<T: Transaction>(tx: &T, id: EdgeId) -> GraphResult<Edge>

Get an edge by ID, returning an error if not found.

§Arguments
  • tx - The transaction to use
  • id - The edge ID to look up
§Errors

Returns GraphError::EdgeNotFound if the edge doesn’t exist.

Source

pub fn exists<T: Transaction>(tx: &T, id: EdgeId) -> GraphResult<bool>

Check if an edge exists.

§Arguments
  • tx - The transaction to use
  • id - The edge ID to check
Source

pub fn update<T: Transaction>(tx: &mut T, edge: &Edge) -> GraphResult<()>

Update an existing edge.

Note: The source, target, and edge type cannot be changed. To change these, delete the edge and create a new one.

§Arguments
  • tx - The transaction to use
  • edge - The edge with updated data
§Errors

Returns GraphError::EdgeNotFound if the edge doesn’t exist.

Source

pub fn delete<T: Transaction>(tx: &mut T, id: EdgeId) -> GraphResult<bool>

Delete an edge by ID.

§Arguments
  • tx - The transaction to use
  • id - The edge ID to delete
§Returns

true if the edge was deleted, false if it didn’t exist.

Source

pub fn get_outgoing<T: Transaction>( tx: &T, source: EntityId, ) -> GraphResult<Vec<Edge>>

Get all outgoing edges from an entity.

§Arguments
  • tx - The transaction to use
  • source - The source entity ID
Source

pub fn get_outgoing_ids<T: Transaction>( tx: &T, source: EntityId, ) -> GraphResult<Vec<EdgeId>>

Get IDs of all outgoing edges from an entity.

§Arguments
  • tx - The transaction to use
  • source - The source entity ID
Source

pub fn get_outgoing_by_type<T: Transaction>( tx: &T, source: EntityId, edge_type: &EdgeType, ) -> GraphResult<Vec<Edge>>

Get outgoing edges of a specific type from an entity.

§Arguments
  • tx - The transaction to use
  • source - The source entity ID
  • edge_type - The edge type to filter by
Source

pub fn get_incoming<T: Transaction>( tx: &T, target: EntityId, ) -> GraphResult<Vec<Edge>>

Get all incoming edges to an entity.

§Arguments
  • tx - The transaction to use
  • target - The target entity ID
Source

pub fn get_incoming_ids<T: Transaction>( tx: &T, target: EntityId, ) -> GraphResult<Vec<EdgeId>>

Get IDs of all incoming edges to an entity.

§Arguments
  • tx - The transaction to use
  • target - The target entity ID
Source

pub fn get_incoming_by_type<T: Transaction>( tx: &T, target: EntityId, edge_type: &EdgeType, ) -> GraphResult<Vec<Edge>>

Get incoming edges of a specific type to an entity.

§Arguments
  • tx - The transaction to use
  • target - The target entity ID
  • edge_type - The edge type to filter by
Source

pub fn find_by_type<T: Transaction>( tx: &T, edge_type: &EdgeType, ) -> GraphResult<Vec<EdgeId>>

Find all edges of a specific type.

§Arguments
  • tx - The transaction to use
  • edge_type - The edge type to search for
Source

pub fn delete_edges_for_entity<T: Transaction>( tx: &mut T, entity_id: EntityId, ) -> GraphResult<usize>

Delete all edges connected to an entity.

This removes all incoming and outgoing edges. Call this before deleting an entity to maintain graph consistency.

§Arguments
  • tx - The transaction to use
  • entity_id - The entity ID
§Returns

The number of edges deleted.

Source

pub fn count<T: Transaction>(tx: &T) -> GraphResult<usize>

Count all edges in the store.

§Arguments
  • tx - The transaction to use
Source

pub fn for_each<T: Transaction, F>(tx: &T, f: F) -> GraphResult<()>
where F: FnMut(&Edge) -> bool,

Iterate over all edges.

§Arguments
  • tx - The transaction to use
  • f - A function to call for each edge. Return false to stop iteration.
Source

pub fn all<T: Transaction>(tx: &T) -> GraphResult<Vec<Edge>>

Get all edges as a vector.

Use with caution on large datasets - prefer Self::for_each for processing edges without loading all into memory.

§Arguments
  • tx - The transaction to use
Source

pub fn max_id<T: Transaction>(tx: &T) -> GraphResult<Option<EdgeId>>

Find the highest edge ID in the store.

This is useful for initializing the ID generator after loading data.

§Arguments
  • tx - The transaction to use
§Returns

The highest edge ID, or None if there are no edges.

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, 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