allframe_core/cqrs/
backend.rs1use async_trait::async_trait;
8
9use super::Event;
10
11#[async_trait]
13pub trait EventStoreBackend<E: Event>: Send + Sync {
14 async fn append(&self, aggregate_id: &str, events: Vec<E>) -> Result<(), String>;
16
17 async fn get_events(&self, aggregate_id: &str) -> Result<Vec<E>, String>;
19
20 async fn get_all_events(&self) -> Result<Vec<E>, String>;
22
23 async fn get_events_after(&self, aggregate_id: &str, version: u64) -> Result<Vec<E>, String>;
25
26 async fn save_snapshot(
28 &self,
29 aggregate_id: &str,
30 snapshot_data: Vec<u8>,
31 version: u64,
32 ) -> Result<(), String> {
33 let _ = (aggregate_id, snapshot_data, version);
34 Ok(()) }
36
37 async fn get_latest_snapshot(&self, aggregate_id: &str) -> Result<(Vec<u8>, u64), String> {
39 let _ = aggregate_id;
40 Err("Snapshots not supported by this backend".to_string())
41 }
42
43 async fn flush(&self) -> Result<(), String> {
45 Ok(()) }
47
48 async fn stats(&self) -> BackendStats {
50 BackendStats::default()
51 }
52}
53
54#[derive(Debug, Clone, Default)]
56pub struct BackendStats {
57 pub total_events: u64,
59 pub total_aggregates: u64,
61 pub total_snapshots: u64,
63 pub backend_specific: std::collections::HashMap<String, String>,
65}