Skip to main content

NodeStore

Struct NodeStore 

Source
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

Source

pub fn create<T: Transaction, F>( tx: &mut T, id_gen: &IdGenerator, builder: F, ) -> GraphResult<Entity>
where F: FnOnce(EntityId) -> 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 use
  • id_gen - The ID generator
  • builder - 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.

Source

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 use
  • entity - The entity to store (must have a valid ID)
§Errors

Returns GraphError::EntityAlreadyExists if an entity with this ID exists.

Source

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

Get an entity by ID.

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

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

§Errors

Returns an error if the entity cannot be decoded.

Source

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 use
  • id - The entity ID to look up
§Errors

Returns GraphError::EntityNotFound if the entity doesn’t exist.

Source

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

Check if an entity exists.

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

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 use
  • entity - The entity with updated data
§Errors

Returns GraphError::EntityNotFound if the entity doesn’t exist.

Source

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 use
  • id - The entity ID to delete
§Returns

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

Source

pub fn find_by_label<T: Transaction>( tx: &T, label: &Label, ) -> GraphResult<Vec<EntityId>>

Find all entities with a specific label.

§Arguments
  • tx - The transaction to use
  • label - The label to search for
§Returns

A vector of entity IDs that have the label.

Source

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

Count all entities 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(&Entity) -> bool,

Iterate over all entities.

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

Returns an error if iteration fails or if any entity cannot be decoded.

Source

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
Source

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

Find the highest entity ID in the store.

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

§Arguments
  • tx - The transaction to use
§Returns

The highest entity ID, or None if there are no entities.

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