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
//! Statement effect classification.
//!
//! [`classify`] walks a [`Statement`] AST and returns whether the
//! statement can be retried transparently on `connection_lost`. The
//! pool consults this before attempting a retry; downstream consumers
//! (e.g. a runtime-checked read-only API surface) read the same
//! classification.
//!
//! See [`docs/dev/design/retry-safe-recovery.md`] for the full
//! contract.
//!
//! [`Statement`]: toasty_core::stmt::Statement
//! [`docs/dev/design/retry-safe-recovery.md`]: ../../../docs/dev/design/retry-safe-recovery.md
use ;
/// Whether a statement mutates database state.
///
/// A statement is [`Effect::ReadOnly`] if it is a [`Statement::Query`]
/// and contains no `Insert`, `Update`, or `Delete` anywhere in its
/// tree. Otherwise it is [`Effect::Mutating`].
///
/// CTE-with-mutation queries (e.g.
/// `WITH ins AS (INSERT ... RETURNING *) SELECT * FROM ins`) parse as
/// `Statement::Query` values whose `WITH` clauses contain an
/// `ExprSet::Insert`, `ExprSet::Update`, or `ExprSet::Delete` and are
/// correctly classified as `Mutating`.
pub
/// Classify a statement's effect on database state.
///
/// O(n) in the size of the statement tree; no schema access.
pub