pub struct SqliteGraphStore { /* private fields */ }Expand description
SQLite implementation of GraphStore
Integrates with existing openfang-memory schema by adding two tables:
ainl_graph_nodes: stores node payloadsainl_graph_edges: stores graph edges
Implementations§
Source§impl SqliteGraphStore
impl SqliteGraphStore
pub fn query<'a>(&'a self, agent_id: &str) -> GraphQuery<'a>
Source§impl SqliteGraphStore
impl SqliteGraphStore
Sourcepub fn ensure_schema(conn: &Connection) -> Result<(), Error>
pub fn ensure_schema(conn: &Connection) -> Result<(), Error>
Ensure the AINL graph schema exists in the database
Sourcepub fn from_connection(conn: Connection) -> Result<Self, String>
pub fn from_connection(conn: Connection) -> Result<Self, String>
Create from an existing connection (for integration with openfang-memory pool)
Sourcepub fn insert_graph_edge(
&self,
from_id: Uuid,
to_id: Uuid,
label: &str,
) -> Result<(), String>
pub fn insert_graph_edge( &self, from_id: Uuid, to_id: Uuid, label: &str, ) -> Result<(), String>
Insert a directed edge between two node IDs (separate from per-node edge payloads).
Sourcepub fn insert_graph_edge_checked(
&self,
from_id: Uuid,
to_id: Uuid,
label: &str,
) -> Result<(), String>
pub fn insert_graph_edge_checked( &self, from_id: Uuid, to_id: Uuid, label: &str, ) -> Result<(), String>
Like Self::insert_graph_edge, but verifies both endpoints exist first (clear errors for strict runtime wiring).
Sourcepub fn insert_graph_edge_with_meta(
&self,
from_id: Uuid,
to_id: Uuid,
label: &str,
weight: f32,
metadata: Option<&Value>,
) -> Result<(), String>
pub fn insert_graph_edge_with_meta( &self, from_id: Uuid, to_id: Uuid, label: &str, weight: f32, metadata: Option<&Value>, ) -> Result<(), String>
Same as Self::insert_graph_edge, with optional edge weight and JSON metadata.
Sourcepub fn query_nodes_by_type_since(
&self,
node_type: &str,
since_timestamp: i64,
limit: usize,
) -> Result<Vec<AinlMemoryNode>, String>
pub fn query_nodes_by_type_since( &self, node_type: &str, since_timestamp: i64, limit: usize, ) -> Result<Vec<AinlMemoryNode>, String>
Nodes of a given node_type with timestamp >= since_timestamp, most recent first.
Sourcepub fn read_runtime_state(
&self,
agent_id: &str,
) -> Result<Option<RuntimeStateNode>, String>
pub fn read_runtime_state( &self, agent_id: &str, ) -> Result<Option<RuntimeStateNode>, String>
Read the most recent persisted RuntimeStateNode for agent_id, if any.
Rows are stored with node_type = 'runtime_state' and JSON $.node_type.runtime_state.agent_id matching the agent.
Sourcepub fn write_runtime_state(
&self,
state: &RuntimeStateNode,
) -> Result<(), String>
pub fn write_runtime_state( &self, state: &RuntimeStateNode, ) -> Result<(), String>
Upsert one RuntimeStateNode row per agent (stable id via Uuid::new_v5).
Sourcepub fn write_node_with_edges(
&mut self,
node: &AinlMemoryNode,
) -> Result<(), String>
pub fn write_node_with_edges( &mut self, node: &AinlMemoryNode, ) -> Result<(), String>
Write a node and its embedded edges in one transaction; fails if any edge target is missing.
Sourcepub fn validate_graph(
&self,
agent_id: &str,
) -> Result<GraphValidationReport, String>
pub fn validate_graph( &self, agent_id: &str, ) -> Result<GraphValidationReport, String>
Validate structural integrity for one agent’s induced subgraph.
Sourcepub fn agent_subgraph_edges(
&self,
agent_id: &str,
) -> Result<Vec<SnapshotEdge>, String>
pub fn agent_subgraph_edges( &self, agent_id: &str, ) -> Result<Vec<SnapshotEdge>, String>
Directed edges where both endpoints are nodes owned by agent_id (aligned with Self::export_graph edge set).
Sourcepub fn export_graph(&self, agent_id: &str) -> Result<AgentGraphSnapshot, String>
pub fn export_graph(&self, agent_id: &str) -> Result<AgentGraphSnapshot, String>
Export all nodes and interconnecting edges for agent_id.
Sourcepub fn import_graph(
&mut self,
snapshot: &AgentGraphSnapshot,
allow_dangling_edges: bool,
) -> Result<(), String>
pub fn import_graph( &mut self, snapshot: &AgentGraphSnapshot, allow_dangling_edges: bool, ) -> Result<(), String>
Import a snapshot in one transaction (INSERT OR IGNORE per row).
allow_dangling_edges == false(default / production):PRAGMA foreign_keysstays enabled; every edge must reference existing node rows after inserts (same invariants asSelf::write_node_with_edges).allow_dangling_edges == true(repair / forensic): FK checks are disabled only for this import so partially invalid snapshots can be loaded; runSelf::validate_graphafterward and repair before returning to normal writes.
Trait Implementations§
Source§impl GraphStore for SqliteGraphStore
impl GraphStore for SqliteGraphStore
Source§fn write_node(&self, node: &AinlMemoryNode) -> Result<(), String>
fn write_node(&self, node: &AinlMemoryNode) -> Result<(), String>
Persists the full node JSON under id via INSERT OR REPLACE (upsert).
Backfill pattern: read_node → patch fields (e.g. episodic signals) → write_node, preserving loaded edges.