toasty_core/
stmt.rs

1mod assignments;
2pub use assignments::{Assignment, AssignmentOp, Assignments};
3
4mod association;
5pub use association::Association;
6
7mod condition;
8pub use condition::Condition;
9
10mod cte;
11pub use cte::Cte;
12
13mod cx;
14pub use cx::{DerivedRef, ExprContext, ExprTarget, IntoExprTarget, Resolve, ResolvedRef};
15
16mod delete;
17pub use delete::Delete;
18
19mod direction;
20pub use direction::Direction;
21
22mod entry;
23pub use entry::Entry;
24
25mod entry_mut;
26pub use entry_mut::EntryMut;
27
28mod entry_path;
29pub use entry_path::EntryPath;
30
31mod eval;
32
33mod expr;
34pub use expr::Expr;
35
36mod expr_and;
37pub use expr_and::ExprAnd;
38
39mod expr_any;
40pub use expr_any::ExprAny;
41
42mod expr_arg;
43pub use expr_arg::ExprArg;
44
45mod expr_binary_op;
46pub use expr_binary_op::ExprBinaryOp;
47
48mod expr_cast;
49pub use expr_cast::ExprCast;
50
51mod expr_error;
52pub use expr_error::ExprError;
53
54mod expr_exists;
55pub use expr_exists::ExprExists;
56
57mod expr_func;
58pub use expr_func::ExprFunc;
59
60mod expr_in_list;
61pub use expr_in_list::ExprInList;
62
63mod expr_in_subquery;
64pub use expr_in_subquery::ExprInSubquery;
65
66mod expr_is_null;
67pub use expr_is_null::ExprIsNull;
68
69mod expr_is_variant;
70pub use expr_is_variant::ExprIsVariant;
71
72mod expr_let;
73pub use expr_let::ExprLet;
74
75mod expr_list;
76pub use expr_list::ExprList;
77
78mod expr_map;
79pub use expr_map::ExprMap;
80
81mod expr_match;
82pub use expr_match::{ExprMatch, MatchArm};
83
84mod expr_not;
85pub use expr_not::ExprNot;
86
87mod expr_or;
88pub use expr_or::ExprOr;
89
90mod expr_project;
91pub use expr_project::ExprProject;
92
93mod expr_record;
94pub use expr_record::ExprRecord;
95
96mod expr_reference;
97pub use expr_reference::{ExprColumn, ExprReference};
98
99mod expr_set;
100pub use expr_set::ExprSet;
101
102mod expr_set_op;
103pub use expr_set_op::ExprSetOp;
104
105mod expr_stmt;
106pub use expr_stmt::ExprStmt;
107
108mod filter;
109pub use filter::Filter;
110
111mod hash_index;
112pub use hash_index::HashIndex;
113
114mod sorted_index;
115pub use sorted_index::SortedIndex;
116
117mod func_count;
118pub use func_count::FuncCount;
119
120mod func_last_insert_id;
121pub use func_last_insert_id::FuncLastInsertId;
122
123mod insert;
124pub use insert::Insert;
125
126mod insert_table;
127pub use insert_table::InsertTable;
128
129mod insert_target;
130pub use insert_target::InsertTarget;
131
132mod input;
133pub use input::{ConstInput, Input, TypedInput};
134
135mod join;
136pub use join::{Join, JoinOp};
137
138mod limit;
139pub use limit::Limit;
140
141#[cfg(feature = "assert-struct")]
142mod like;
143
144mod node;
145pub use node::Node;
146
147mod num;
148
149mod offset;
150pub use offset::Offset;
151
152mod op_binary;
153pub use op_binary::BinaryOp;
154
155mod order_by;
156pub use order_by::OrderBy;
157
158mod order_by_expr;
159pub use order_by_expr::OrderByExpr;
160
161mod op_set;
162pub use op_set::SetOp;
163
164mod path;
165pub use path::{Path, PathRoot};
166
167mod path_field_set;
168pub use path_field_set::PathFieldSet;
169
170mod projection;
171pub use projection::{Project, Projection};
172
173mod query;
174pub use query::{Lock, Query};
175
176mod returning;
177pub use returning::Returning;
178
179mod select;
180pub use select::Select;
181
182mod source;
183pub use source::{Source, SourceModel};
184
185mod source_table;
186pub use source_table::SourceTable;
187
188mod source_table_id;
189pub use source_table_id::SourceTableId;
190
191mod sparse_record;
192pub use sparse_record::SparseRecord;
193
194mod substitute;
195use substitute::Substitute;
196
197mod table_derived;
198pub use table_derived::TableDerived;
199
200mod table_ref;
201pub use table_ref::TableRef;
202
203mod table_factor;
204pub use table_factor::TableFactor;
205
206mod table_with_joins;
207pub use table_with_joins::TableWithJoins;
208
209mod ty;
210pub use ty::Type;
211
212mod ty_union;
213pub use ty_union::TypeUnion;
214
215#[cfg(feature = "jiff")]
216mod ty_jiff;
217
218mod update;
219pub use update::{Update, UpdateTarget};
220
221mod value;
222pub use value::Value;
223
224mod value_cmp;
225
226mod values;
227pub use values::Values;
228
229#[cfg(feature = "jiff")]
230mod value_jiff;
231
232mod value_record;
233pub use value_record::ValueRecord;
234
235pub mod visit_mut;
236pub use visit_mut::VisitMut;
237
238mod value_list;
239
240mod value_stream;
241pub use value_stream::ValueStream;
242
243pub mod visit;
244pub use visit::Visit;
245
246mod with;
247pub use with::With;
248
249use crate::schema::db::TableId;
250use std::fmt;
251
252#[derive(Clone, PartialEq)]
253pub enum Statement {
254    /// Delete one or more existing records
255    Delete(Delete),
256
257    /// Create one or more instances of a model
258    Insert(Insert),
259
260    /// Query the database
261    Query(Query),
262
263    /// Update one or more existing records
264    Update(Update),
265}
266
267impl Statement {
268    pub fn substitute(&mut self, input: impl Input) {
269        Substitute::new(input).visit_stmt_mut(self);
270    }
271
272    pub fn is_const(&self) -> bool {
273        match self {
274            Statement::Query(query) => {
275                if query.with.is_some() {
276                    return false;
277                }
278
279                query.body.is_const()
280            }
281            _ => false,
282        }
283    }
284
285    /// Attempts to return a reference to an inner [`Update`].
286    ///
287    /// * If `self` is a [`Statement::Update`], a reference to the inner [`Update`] is
288    ///   returned wrapped in [`Some`].
289    /// * Else, [`None`] is returned.
290    pub fn as_update(&self) -> Option<&Update> {
291        match self {
292            Self::Update(update) => Some(update),
293            _ => None,
294        }
295    }
296
297    /// Consumes `self` and attempts to return the inner [`Update`].
298    ///
299    /// * If `self` is a [`Statement::Update`], inner [`Update`] is returned wrapped in
300    ///   [`Some`].
301    /// * Else, [`None`] is returned.
302    pub fn into_update(self) -> Option<Update> {
303        match self {
304            Self::Update(update) => Some(update),
305            _ => None,
306        }
307    }
308
309    /// Consumes `self` and returns the inner [`Update`].
310    ///
311    /// # Panics
312    ///
313    /// If `self` is not a [`Statement::Update`].
314    pub fn unwrap_update(self) -> Update {
315        match self {
316            Self::Update(update) => update,
317            v => panic!("expected `Update`, found {v:#?}"),
318        }
319    }
320}
321
322impl Node for Statement {
323    fn visit<V: Visit>(&self, mut visit: V) {
324        visit.visit_stmt(self);
325    }
326
327    fn visit_mut<V: VisitMut>(&mut self, mut visit: V) {
328        visit.visit_stmt_mut(self);
329    }
330}
331
332impl fmt::Debug for Statement {
333    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
334        match self {
335            Self::Delete(v) => v.fmt(f),
336            Self::Insert(v) => v.fmt(f),
337            Self::Query(v) => v.fmt(f),
338            Self::Update(v) => v.fmt(f),
339        }
340    }
341}