eventsourced_postgres/
lib.rs

1//! [EventLog](eventsourced::event_log::EventLog) and
2//! [SnapshotStore](eventsourced::snapshot_store::SnapshotStore) implementations based upon [PostgreSQL](https://www.postgresql.org/).
3
4mod event_log;
5mod snapshot_store;
6
7pub use event_log::{Config as PostgresEventLogConfig, PostgresEventLog};
8pub use snapshot_store::{Config as PostgresSnapshotStoreConfig, PostgresSnapshotStore};
9
10use bb8_postgres::{
11    bb8::{Pool, PooledConnection},
12    PostgresConnectionManager,
13};
14use std::num::NonZeroU64;
15use thiserror::Error;
16
17type CnnPool<T> = Pool<PostgresConnectionManager<T>>;
18
19type Cnn<'a, T> = PooledConnection<'a, PostgresConnectionManager<T>>;
20
21/// Errors from the [PostgresEventLog] or [PostgresSnapshotStore].
22#[derive(Debug, Error)]
23pub enum Error {
24    /// Postgres error.
25    #[error("Postgres error: {0}")]
26    Postgres(String, #[source] tokio_postgres::Error),
27
28    /// Cannot get connection from pool.
29    #[error("cannot get connection from pool")]
30    GetConnection(#[source] bb8_postgres::bb8::RunError<tokio_postgres::Error>),
31
32    /// Cannot convert an event to bytes.
33    #[error("cannot convert an event to bytes")]
34    ToBytes(#[source] Box<dyn std::error::Error + Send + Sync + 'static>),
35
36    /// Cannot convert bytes to an event.
37    #[error("cannot convert bytes to an event")]
38    FromBytes(#[source] Box<dyn std::error::Error + Send + Sync + 'static>),
39
40    /// Sequence number must not be zero.
41    #[error("sequence number must not be zero")]
42    ZeroNonZeroU64,
43
44    /// Sequence number must not be zero.
45    #[error("invalid last sequence number: {0:?} {1:?}")]
46    InvalidLastNonZeroU64(Option<NonZeroU64>, Option<NonZeroU64>),
47}