pub struct NodeStore;Expand description
Node storage operations.
NodeStore provides transactional CRUD operations for graph nodes (entities).
All operations work within a transaction context for ACID guarantees.
§Example
use manifoldb_graph::store::{NodeStore, IdGenerator};
// Create a node
let gen = IdGenerator::new();
let entity = NodeStore::create(&mut tx, &gen, |id| {
Entity::new(id)
.with_label("Person")
.with_property("name", "Alice")
})?;
// Read it back
let retrieved = NodeStore::get(&tx, entity.id)?;Implementations§
Source§impl NodeStore
impl NodeStore
Sourcepub fn create<T: Transaction, F>(
tx: &mut T,
id_gen: &IdGenerator,
builder: F,
) -> GraphResult<Entity>
pub fn create<T: Transaction, F>( tx: &mut T, id_gen: &IdGenerator, builder: F, ) -> GraphResult<Entity>
Create a new entity in the store.
The provided function receives a new unique ID and should return the entity to store. The entity’s ID will be set to the generated ID.
§Arguments
tx- The transaction to useid_gen- The ID generatorbuilder- A function that builds the entity given an ID
§Returns
The created entity with its assigned ID.
§Errors
Returns an error if the entity cannot be stored.
Sourcepub fn create_with_id<T: Transaction>(
tx: &mut T,
entity: &Entity,
) -> GraphResult<()>
pub fn create_with_id<T: Transaction>( tx: &mut T, entity: &Entity, ) -> GraphResult<()>
Create an entity with a specific ID.
This is useful when importing data or when you need to control IDs.
§Arguments
tx- The transaction to useentity- The entity to store (must have a valid ID)
§Errors
Returns GraphError::EntityAlreadyExists if an entity with this ID exists.
Sourcepub fn get<T: Transaction>(tx: &T, id: EntityId) -> GraphResult<Option<Entity>>
pub fn get<T: Transaction>(tx: &T, id: EntityId) -> GraphResult<Option<Entity>>
Sourcepub fn get_or_error<T: Transaction>(tx: &T, id: EntityId) -> GraphResult<Entity>
pub fn get_or_error<T: Transaction>(tx: &T, id: EntityId) -> GraphResult<Entity>
Get an entity by ID, returning an error if not found.
§Arguments
tx- The transaction to useid- The entity ID to look up
§Errors
Returns GraphError::EntityNotFound if the entity doesn’t exist.
Sourcepub fn exists<T: Transaction>(tx: &T, id: EntityId) -> GraphResult<bool>
pub fn exists<T: Transaction>(tx: &T, id: EntityId) -> GraphResult<bool>
Sourcepub fn update<T: Transaction>(tx: &mut T, entity: &Entity) -> GraphResult<()>
pub fn update<T: Transaction>(tx: &mut T, entity: &Entity) -> GraphResult<()>
Update an existing entity.
This replaces the entire entity. To update specific fields, first get the entity, modify it, then update.
§Arguments
tx- The transaction to useentity- The entity with updated data
§Errors
Returns GraphError::EntityNotFound if the entity doesn’t exist.
Sourcepub fn delete<T: Transaction>(tx: &mut T, id: EntityId) -> GraphResult<bool>
pub fn delete<T: Transaction>(tx: &mut T, id: EntityId) -> GraphResult<bool>
Delete an entity by ID.
This also removes all label index entries for the entity.
Note: This does NOT delete edges connected to this entity.
Use crate::store::EdgeStore::delete_edges_for_entity to clean up edges first.
§Arguments
tx- The transaction to useid- The entity ID to delete
§Returns
true if the entity was deleted, false if it didn’t exist.
Sourcepub fn find_by_label<T: Transaction>(
tx: &T,
label: &Label,
) -> GraphResult<Vec<EntityId>>
pub fn find_by_label<T: Transaction>( tx: &T, label: &Label, ) -> GraphResult<Vec<EntityId>>
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<()>
Sourcepub fn all<T: Transaction>(tx: &T) -> GraphResult<Vec<Entity>>
pub fn all<T: Transaction>(tx: &T) -> GraphResult<Vec<Entity>>
Get all entities as a vector.
Use with caution on large datasets - prefer Self::for_each for
processing entities without loading all into memory.
§Arguments
tx- The transaction to use