1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
//! Shared PostgreSQL connection abstraction.
//!
//! Both the event store ([`crate::es::postgres`]) and the read side
//! ([`crate::read::postgres`]) acquire their connections through [`PgPool`], so
//! a single pool implementation serves the whole stack.
//!
//! The crate ships [`SharedClient`], a zero-cost wrapper around a single
//! `Arc<Client>`. Real pools (deadpool-postgres, bb8, …) are supported by
//! implementing [`PgConn`] and [`PgPool`] in the application:
//!
//! ```rust,ignore
//! use cqrs_rust_lib::prelude::postgres::{PgConn, PgPool};
//!
//! #[derive(Debug, Clone)]
//! struct DeadPool(deadpool_postgres::Pool);
//!
//! struct DeadConn(deadpool_postgres::Object);
//!
//! impl PgConn for DeadConn {
//! fn client(&self) -> &tokio_postgres::Client { &self.0 }
//! }
//!
//! cqrs_async_trait! {
//! impl PgPool for DeadPool {
//! type Connection = DeadConn;
//! async fn acquire(&self) -> Result<Self::Connection, CqrsError> {
//! self.0.get().await.map(DeadConn).map_err(CqrsError::database_error)
//! }
//! }
//! }
//! ```
use crateCqrsError;
use Debug;
use Arc;
use Client;
/// Access to a `tokio_postgres::Client`.
cqrs_async_trait!
/// Wraps a single `Arc<Client>`. NOT safe for concurrent transactions.
;
cqrs_async_trait!