Skip to main content

gossan_graph/store/
mod.rs

1//! Storage backends for the attack-surface graph.
2
3pub mod graphml;
4pub mod json;
5pub mod memory;
6pub mod sqlite;
7
8use crate::{schema::EdgeType, Edge, Node};
9
10/// Abstract storage backend for graph operations.
11pub trait GraphBackend {
12    /// Error type returned by this backend.
13    type Error: std::error::Error + Send + Sync + 'static;
14
15    /// Initialize the backend (create tables/files, run migrations).
16    fn init(&mut self) -> Result<(), Self::Error>;
17
18    /// Persist a batch of nodes.
19    fn write_nodes(&mut self, nodes: &[Node]) -> Result<(), Self::Error>;
20
21    /// Persist a batch of edges.
22    fn write_edges(&mut self, edges: &[Edge]) -> Result<(), Self::Error>;
23
24    /// Read all nodes.
25    fn read_nodes(&self) -> Result<Vec<Node>, Self::Error>;
26
27    /// Read all edges.
28    fn read_edges(&self) -> Result<Vec<Edge>, Self::Error>;
29
30    /// Find nodes by type.
31    fn find_nodes_by_type(&self, kind: crate::schema::NodeType) -> Result<Vec<Node>, Self::Error>;
32
33    /// Find outgoing edges from a node, optionally filtered by edge type.
34    fn neighbors(
35        &self,
36        node_id: &str,
37        edge_type: Option<EdgeType>,
38    ) -> Result<Vec<Edge>, Self::Error>;
39
40    /// Clear all data.
41    fn clear(&mut self) -> Result<(), Self::Error>;
42}