use crate::error::Result;
use crate::types::EventId;
use std::path::Path;
pub trait ProjectionTxn {
fn apply_event(&mut self, id: EventId, bytes: &[u8]) -> Result<()>;
fn apply_batch(&mut self, events: &[(EventId, Vec<u8>)]) -> Result<()> {
for (id, bytes) in events {
self.apply_event(*id, bytes)?;
}
Ok(())
}
fn commit(self: Box<Self>, new_cursor: EventId) -> Result<()>;
fn rollback(self: Box<Self>);
}
pub trait ProjectionStore: Send + Sync {
type Txn<'a>: ProjectionTxn
where
Self: 'a;
fn open(cfg: crate::config::ProjectionConfig) -> Result<Self>
where
Self: Sized;
fn close(&self) -> Result<()>;
fn begin_txn(&self) -> Result<Self::Txn<'_>>;
fn get_cursor(&self) -> Result<EventId>;
fn migrate(&self, target_version: u32) -> Result<()>;
fn backup_to(&self, path: &Path) -> Result<()>;
fn restore_from(path: &Path, cfg: crate::config::ProjectionConfig) -> Result<Self>
where
Self: Sized;
fn schema_version(&self) -> Result<u32>;
}