azoth_core/traits/
projection.rs1use crate::error::Result;
2use crate::types::EventId;
3use std::path::Path;
4
5pub trait ProjectionTxn {
9 fn apply_event(&mut self, id: EventId, bytes: &[u8]) -> Result<()>;
11
12 fn apply_batch(&mut self, events: &[(EventId, Vec<u8>)]) -> Result<()> {
14 for (id, bytes) in events {
15 self.apply_event(*id, bytes)?;
16 }
17 Ok(())
18 }
19
20 fn commit(self: Box<Self>, new_cursor: EventId) -> Result<()>;
22
23 fn rollback(self: Box<Self>);
25}
26
27pub trait ProjectionStore: Send + Sync {
35 type Txn<'a>: ProjectionTxn
36 where
37 Self: 'a;
38
39 fn open(cfg: crate::config::ProjectionConfig) -> Result<Self>
41 where
42 Self: Sized;
43
44 fn close(&self) -> Result<()>;
46
47 fn begin_txn(&self) -> Result<Self::Txn<'_>>;
49
50 fn get_cursor(&self) -> Result<EventId>;
52
53 fn migrate(&self, target_version: u32) -> Result<()>;
55
56 fn backup_to(&self, path: &Path) -> Result<()>;
58
59 fn restore_from(path: &Path, cfg: crate::config::ProjectionConfig) -> Result<Self>
61 where
62 Self: Sized;
63
64 fn schema_version(&self) -> Result<u32>;
66}