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
69
70
71
72
73
//! **SQL client** traits for `id_effect` — driver-agnostic database access inspired by
//! Effect.ts [`@effect/sql`](https://effect.website/docs/sql/introduction), on the
//! 0.7 kernel.
//!
//! - [`SqlClient`] returns `Effect`s; the capability is [`SqlClientService`]
//! ([`SqlClientEnv`]), read by [`query`] / [`execute`] / [`transaction`](fn@transaction).
//! - The client is a scoped `Layer`: [`sql_client_layer`] connects it when built and closes it
//! when the scope closes (`pg::PgSqlClient::layer` opens and closes a pool).
//! - A transaction is a bracket ([`with_transaction`], [`transaction`](fn@transaction)) or a
//! scoped `Layer` ([`transaction_layer`]): it commits on success and rolls back on failure,
//! defect or interrupt.
//!
//! Production PostgreSQL support is behind the `pg` feature (`pg` module, sqlx `PgPool`).
//! See [`docs/platform/adrs/adr-sql-driver-choice.md`](../../docs/platform/adrs/adr-sql-driver-choice.md).
//!
//! ## Example
//!
//! ```rust
//! use id_effect::Exit;
//! use id_effect::Effect;
//! use id_effect_sql::{
//! SqlClientEnv, SqlError, SqlParam, SqlRow, TestSqlClient, query, sql_client_layer, transaction,
//! };
//!
//! fn count_users() -> Effect<usize, SqlError, SqlClientEnv> {
//! query("SELECT id FROM users WHERE active = $1", vec![SqlParam::Bool(true)])
//! .map(|rows| rows.len())
//! }
//!
//! let test = TestSqlClient::new();
//! test.script_query(
//! "SELECT id FROM users WHERE active = $1",
//! vec![SqlRow::new(vec!["1".into()]), SqlRow::new(vec!["2".into()])],
//! );
//!
//! // Connected while the program runs, closed after it.
//! let program = count_users()
//! .flat_map(|n| {
//! let n = SqlParam::Int(n as i64);
//! transaction(move |tx| tx.execute("UPDATE stats SET n = $1", &[n]).narrow())
//! })
//! .provide_layer(sql_client_layer::<SqlError>(test.clone()));
//! assert!(matches!(program.block_on(), Exit::Success(0)));
//! assert_eq!((test.commits(), test.open_transactions(), test.closes()), (1, 0, 1));
//! ```
pub use ;
pub use SqlError;
pub use ;
/// Alias of [`with_transaction`] (the 0.6 name).
pub use with_transaction as transaction_scope;
/// Compiles and runs the README's quick start as a doctest.
;