Skip to main content

Crate nova_boot_graphdb

Crate nova_boot_graphdb 

Source
Expand description

Graph database abstractions and store implementations for Nova.

This crate provides a small adapter layer over different graph database backends (Neo4j, Surreal, in-memory). It exposes a NovaGraphDb wrapper that application handlers can extract to execute queries, upsert nodes and edges, and traverse subgraphs. The crate also supplies lightweight builders and types used across adapters.

§Example: simple

use nova_boot_graphdb::{GraphEdge, GraphNode, NovaGraphDb};
use std::collections::HashMap;

#[tokio::main]
async fn main() {
    // Construct an in-memory graph store and upsert a couple of nodes/edges.
    let graph = NovaGraphDb::in_memory();

    let mut props = HashMap::new();
    props.insert("name".to_string(), serde_json::json!("Alice"));
    let node = GraphNode {
        id: "n1".to_string(),
        labels: vec!["Person".to_string()],
        properties: props,
    };

    graph.upsert_node(node).await.unwrap();

    let mut props2 = HashMap::new();
    props2.insert("name".to_string(), serde_json::json!("Bob"));
    let node2 = GraphNode {
        id: "n2".to_string(),
        labels: vec!["Person".to_string()],
        properties: props2,
    };

    graph.upsert_node(node2).await.unwrap();

    let edge = GraphEdge {
        id: "e1".to_string(),
        from: "n1".to_string(),
        to: "n2".to_string(),
        rel_type: "FRIEND".to_string(),
        properties: HashMap::new(),
    };

    graph.upsert_edge(edge).await.unwrap();

    let sub = graph.traverse_json("n1", 2).await.unwrap();
    println!("subgraph: {}", sub);
}

Re-exports§

pub use builders::CypherQueryBuilder;
pub use builders::GraphQlQueryBuilder;
pub use error::GraphDbError;
pub use memory::InMemoryGraphStore;
pub use neo4j::Neo4jGraphStore;
pub use surreal::SurrealGraphStore;
pub use traits::GraphStore;
pub use types::GraphEdge;
pub use types::GraphNode;
pub use types::GraphQuery;
pub use types::GraphSubgraph;
pub use wrapper::NovaGraphDb;
pub use wrapper::graph_to_json;

Modules§

builders
error
memory
neo4j
plugin
surreal
traits
types
wrapper

Structs§

NovaGraph
Nova graph database extractor.