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
impl EdgeStore
Sourcepub fn create<T: Transaction, F>(
tx: &mut T,
id_gen: &IdGenerator,
source: EntityId,
target: EntityId,
edge_type: impl Into<EdgeType>,
builder: F,
) -> GraphResult<Edge>
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>
Create a new edge in the store.
§Arguments
tx- The transaction to useid_gen- The ID generatorsource- The source entity IDtarget- The target entity IDedge_type- The edge typebuilder- 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.
Sourcepub fn create_with_id<T: Transaction>(
tx: &mut T,
edge: &Edge,
validate_refs: bool,
) -> GraphResult<()>
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 useedge- 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.
Sourcepub fn get<T: Transaction>(tx: &T, id: EdgeId) -> GraphResult<Option<Edge>>
pub fn get<T: Transaction>(tx: &T, id: EdgeId) -> GraphResult<Option<Edge>>
Sourcepub fn get_or_error<T: Transaction>(tx: &T, id: EdgeId) -> GraphResult<Edge>
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 useid- The edge ID to look up
§Errors
Returns GraphError::EdgeNotFound if the edge doesn’t exist.
Sourcepub fn exists<T: Transaction>(tx: &T, id: EdgeId) -> GraphResult<bool>
pub fn exists<T: Transaction>(tx: &T, id: EdgeId) -> GraphResult<bool>
Sourcepub fn update<T: Transaction>(tx: &mut T, edge: &Edge) -> GraphResult<()>
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 useedge- The edge with updated data
§Errors
Returns GraphError::EdgeNotFound if the edge doesn’t exist.
Sourcepub fn delete<T: Transaction>(tx: &mut T, id: EdgeId) -> GraphResult<bool>
pub fn delete<T: Transaction>(tx: &mut T, id: EdgeId) -> GraphResult<bool>
Sourcepub fn get_outgoing<T: Transaction>(
tx: &T,
source: EntityId,
) -> GraphResult<Vec<Edge>>
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 usesource- The source entity ID
Sourcepub fn get_outgoing_ids<T: Transaction>(
tx: &T,
source: EntityId,
) -> GraphResult<Vec<EdgeId>>
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 usesource- The source entity ID
Sourcepub fn get_outgoing_by_type<T: Transaction>(
tx: &T,
source: EntityId,
edge_type: &EdgeType,
) -> GraphResult<Vec<Edge>>
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 usesource- The source entity IDedge_type- The edge type to filter by
Sourcepub fn get_incoming<T: Transaction>(
tx: &T,
target: EntityId,
) -> GraphResult<Vec<Edge>>
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 usetarget- The target entity ID
Sourcepub fn get_incoming_ids<T: Transaction>(
tx: &T,
target: EntityId,
) -> GraphResult<Vec<EdgeId>>
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 usetarget- The target entity ID
Sourcepub fn get_incoming_by_type<T: Transaction>(
tx: &T,
target: EntityId,
edge_type: &EdgeType,
) -> GraphResult<Vec<Edge>>
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 usetarget- The target entity IDedge_type- The edge type to filter by
Sourcepub fn find_by_type<T: Transaction>(
tx: &T,
edge_type: &EdgeType,
) -> GraphResult<Vec<EdgeId>>
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 useedge_type- The edge type to search for
Sourcepub fn delete_edges_for_entity<T: Transaction>(
tx: &mut T,
entity_id: EntityId,
) -> GraphResult<usize>
pub fn delete_edges_for_entity<T: Transaction>( tx: &mut T, entity_id: EntityId, ) -> GraphResult<usize>
Sourcepub fn count<T: Transaction>(tx: &T) -> GraphResult<usize>
pub fn count<T: Transaction>(tx: &T) -> GraphResult<usize>
Sourcepub fn for_each<T: Transaction, F>(tx: &T, f: F) -> GraphResult<()>
pub fn for_each<T: Transaction, F>(tx: &T, f: F) -> GraphResult<()>
Iterate over all edges.
§Arguments
tx- The transaction to usef- A function to call for each edge. Returnfalseto stop iteration.
Sourcepub fn all<T: Transaction>(tx: &T) -> GraphResult<Vec<Edge>>
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