Skip to main content

nova_boot_graphdb/
traits.rs

1use crate::{error::GraphDbError, types::*};
2use async_trait::async_trait;
3use serde_json::Value as JsonValue;
4
5/// Adapter trait for graph database backends.
6///
7/// Implement this trait to support a new graph backend (Neo4j, Surreal, in-memory).
8#[async_trait]
9pub trait GraphStore: Send + Sync {
10    /// Execute a query and return JSON results.
11    async fn execute(&self, query: GraphQuery) -> Result<JsonValue, GraphDbError>;
12
13    /// Upsert a node into the store.
14    async fn upsert_node(&self, node: GraphNode) -> Result<(), GraphDbError>;
15
16    /// Upsert an edge into the store.
17    async fn upsert_edge(&self, edge: GraphEdge) -> Result<(), GraphDbError>;
18
19    /// Get a node by id.
20    async fn get_node(&self, node_id: &str) -> Result<Option<GraphNode>, GraphDbError>;
21
22    /// Return immediate neighbor nodes for `node_id`.
23    async fn neighbors(&self, node_id: &str) -> Result<Vec<GraphNode>, GraphDbError>;
24
25    /// Traverse from `start` and return a `GraphSubgraph` up to `max_depth`.
26    async fn traverse(&self, start: &str, max_depth: usize) -> Result<GraphSubgraph, GraphDbError>;
27}