disintegrate_postgres/
lib.rsmod error;
mod event_store;
#[cfg(feature = "listener")]
mod listener;
mod snapshotter;
pub use crate::event_store::PgEventStore;
#[cfg(feature = "listener")]
pub use crate::listener::{PgEventListener, PgEventListenerConfig};
pub use crate::snapshotter::PgSnapshotter;
use disintegrate::{
DecisionMaker, Event, EventSourcedDecisionStateStore, NoSnapshot, WithSnapshot,
};
use disintegrate_serde::Serde;
pub use error::Error;
pub type PgEventId = i64;
pub type PgDecisionMaker<E, S, SN> =
DecisionMaker<EventSourcedDecisionStateStore<PgEventId, E, PgEventStore<E, S>, SN>>;
pub type WithPgSnapshot = WithSnapshot<PgEventId, PgSnapshotter>;
pub async fn decision_maker_with_snapshot<
E: Event + Send + Sync + Clone,
S: Serde<E> + Clone + Sync + Send,
>(
event_store: PgEventStore<E, S>,
every: u64,
) -> Result<PgDecisionMaker<E, S, WithPgSnapshot>, Error> {
let pool = event_store.pool.clone();
let snapshot = WithSnapshot::new(PgSnapshotter::new(pool, every).await?);
Ok(DecisionMaker::new(EventSourcedDecisionStateStore::new(
event_store,
snapshot,
)))
}
pub fn decision_maker<E: Event + Send + Sync + Clone, S: Serde<E> + Clone + Sync + Send>(
event_store: PgEventStore<E, S>,
) -> PgDecisionMaker<E, S, NoSnapshot> {
DecisionMaker::new(EventSourcedDecisionStateStore::new(event_store, NoSnapshot))
}