disintegrate_postgres/
lib.rs

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