contrag_core/data_sources/
mod.rs

1pub mod canister_state;
2pub mod stable_memory;
3
4use candid::CandidType;
5use crate::entity::RagEntity;
6use crate::error::Result;
7
8/// Trait for data sources that can provide entities
9/// 
10/// Implement this trait to create custom data sources for your canister.
11#[async_trait::async_trait]
12pub trait DataSource: Send + Sync {
13    /// Read a single entity by ID
14    async fn read_entity<T: RagEntity + CandidType>(
15        &self,
16        entity_type: &str,
17        entity_id: &str,
18    ) -> Result<T>;
19
20    /// Read multiple entities by IDs
21    async fn read_entities<T: RagEntity + CandidType + Send>(
22        &self,
23        entity_type: &str,
24        entity_ids: Vec<String>,
25    ) -> Result<Vec<T>>;
26
27    /// Query entities with optional filtering
28    /// This is optional and can be implemented for more advanced querying
29    async fn query_entities<T: RagEntity + CandidType>(
30        &self,
31        entity_type: &str,
32        filter: Option<String>,
33    ) -> Result<Vec<T>> {
34        // Default implementation returns empty
35        Ok(vec![])
36    }
37}