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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
//! **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.
//!
//! - Parameters and column values are typed [`SqlValue`]s ([`params!`] encodes Rust values with
//! [`ToSqlValue`]); a [`SqlRow`] decodes its columns by name or index with
//! [`SqlRow::get`] ([`FromSqlValue`]), returning a [`SqlError`] naming the column.
//!
//! 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, fail, succeed};
//! use id_effect_sql::{
//! SqlClientEnv, SqlError, SqlRow, TestSqlClient, params, query, sql_client_layer, transaction,
//! };
//!
//! fn active_ids() -> Effect<Vec<i64>, SqlError, SqlClientEnv> {
//! query("SELECT id FROM users WHERE active = $1", params![true])
//! .flat_map(|rows| match rows.iter().map(|r| r.get::<i64>("id")).collect::<Result<_, _>>() {
//! Ok(ids) => succeed(ids),
//! Err(e) => fail(e),
//! })
//! }
//!
//! let test = TestSqlClient::new();
//! test.script_query(
//! "SELECT id FROM users WHERE active = $1",
//! vec![SqlRow::from_pairs([("id", 1i64)]), SqlRow::from_pairs([("id", 2i64)])],
//! );
//!
//! // Connected while the program runs, closed after it.
//! let program = active_ids()
//! .flat_map(|ids| {
//! let n = ids.len() as i64;
//! transaction(move |tx| tx.execute("UPDATE stats SET n = $1", ¶ms![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 SqlParam;
pub use ;
pub use SqlError;
pub use ;
/// Derive [`FromRow`] for a struct with named fields (see [`from_row`]).
pub use FromRow;
pub use ;
pub use ;
pub use ;
/// The value crates of the public API, re-exported so callers use the same versions.
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.
;
// Savepoints, isolation levels and streaming (E3.1a).
pub use ;
pub use ;
// sea-query statements bridged to `SqlValue` (E3.3, feature `query`). The module is
// `query_builder`: `query` is already the free function.
pub use ;
// SQLite driver (E3.1b, feature `sqlite`) and read-replica routing over any `SqlClient`.
pub use ;
// Hash-chained audit log appended in the caller's transaction (E5.5, feature `audit`).
// Entities and repositories: `#[derive(Entity)]`, `Repository<T>` CRUD with optimistic locking
// and global filters (E3.3, feature `repository` = `query` + the repository layer).
/// Derive [`Entity`] for a `#[derive(FromRow)]` struct (see [`repository`]).
pub use Entity;
pub use ;
// MySQL driver (E3.1b, feature `mysql`).