use super::{SheafGraph, SheafNode};
use crate::error::StorageResult;
use crate::types::{GraphId, NamespaceId, NodeId};
#[allow(async_fn_in_trait)]
pub trait SheafGraphRepository: Send + Sync {
async fn find_by_id(&self, id: GraphId) -> StorageResult<Option<SheafGraph>>;
async fn save(&self, graph: &SheafGraph) -> StorageResult<()>;
async fn delete(&self, id: GraphId) -> StorageResult<()>;
async fn find_nodes_by_namespace(&self, namespace: &NamespaceId) -> StorageResult<Vec<SheafNode>>;
async fn find_similar_nodes(
&self,
state: &[f32],
k: usize,
) -> StorageResult<Vec<(NodeId, f32)>>;
}
#[derive(Debug, Default)]
pub struct InMemoryGraphRepository {
graphs: parking_lot::RwLock<std::collections::HashMap<GraphId, SheafGraph>>,
}
impl InMemoryGraphRepository {
pub fn new() -> Self {
Self::default()
}
}
impl InMemoryGraphRepository {
pub fn find_by_id_sync(&self, id: GraphId) -> Option<SheafGraph> {
let _graphs = self.graphs.read();
None
}
}