disintegrate_postgres/
lib.rs

1//! # PostgreSQL Disintegrate Backend Library
2mod error;
3mod event_store;
4#[cfg(feature = "listener")]
5mod listener;
6mod snapshotter;
7
8pub use crate::event_store::PgEventStore;
9#[cfg(feature = "listener")]
10pub use crate::listener::{
11    id_indexer::{Error as PgIdIndexerError, PgIdIndexer},
12    PgEventListener, PgEventListenerConfig,
13};
14pub use crate::snapshotter::PgSnapshotter;
15use disintegrate::{DecisionMaker, Event, EventSourcedStateStore, SnapshotConfig, WithSnapshot};
16use disintegrate_serde::Serde;
17pub use error::Error;
18
19pub type PgEventId = i64;
20
21/// An alias for [`DecisionMaker`], specialized for Postgres.
22pub type PgDecisionMaker<E, S, SN> =
23    DecisionMaker<EventSourcedStateStore<PgEventId, E, PgEventStore<E, S>, SN>>;
24
25/// An alias for [`WithSnapshot`], specialized for Postgres.
26pub type WithPgSnapshot = WithSnapshot<PgEventId, PgSnapshotter>;
27
28/// Creates a decision maker specialized for PostgreSQL.
29///
30/// # Arguments
31///
32/// - `event_store`: An instance of `PgEventStore`.
33/// - `snapshot_config`: The `SnapshotConfig` to be used for the snapshotting.
34///
35/// # Returns
36///
37/// A `PgDecisionMaker` with snapshotting configured according to the provided `snapshot_config`.
38pub fn decision_maker<
39    E: Event + Send + Sync + Clone,
40    S: Serde<E> + Clone + Sync + Send,
41    SN: SnapshotConfig + Clone,
42>(
43    event_store: PgEventStore<E, S>,
44    snapshot_config: SN,
45) -> PgDecisionMaker<E, S, SN> {
46    DecisionMaker::new(EventSourcedStateStore::new(event_store, snapshot_config))
47}