1mod assignments;
32pub use assignments::{Assignment, Assignments};
33
34mod association;
35pub use association::Association;
36
37mod condition;
38pub use condition::Condition;
39
40mod cte;
41pub use cte::Cte;
42
43mod cx;
44pub use cx::{DerivedRef, ExprContext, ExprTarget, IntoExprTarget, Resolve, ResolvedRef};
45
46mod delete;
47pub use delete::Delete;
48
49mod direction;
50pub use direction::Direction;
51
52mod document_storage_text;
53pub use document_storage_text::DocumentStorageText;
54
55mod entry;
56pub use entry::Entry;
57
58mod entry_mut;
59pub use entry_mut::EntryMut;
60
61mod entry_path;
62pub use entry_path::EntryPath;
63
64mod eval;
65
66mod expr;
67pub use expr::Expr;
68
69mod expr_all_op;
70pub use expr_all_op::ExprAllOp;
71
72mod expr_and;
73pub use expr_and::ExprAnd;
74
75mod expr_between;
76pub use expr_between::ExprBetween;
77
78mod expr_any;
79pub use expr_any::ExprAny;
80
81mod expr_any_op;
82pub use expr_any_op::ExprAnyOp;
83
84mod expr_arg;
85pub use expr_arg::ExprArg;
86
87mod expr_binary_op;
88pub use expr_binary_op::ExprBinaryOp;
89
90mod expr_cast;
91pub use expr_cast::ExprCast;
92
93mod expr_error;
94pub use expr_error::ExprError;
95
96mod expr_exists;
97pub use expr_exists::ExprExists;
98
99mod expr_func;
100pub use expr_func::ExprFunc;
101
102mod expr_in_list;
103pub use expr_in_list::ExprInList;
104
105mod expr_in_subquery;
106pub use expr_in_subquery::ExprInSubquery;
107
108mod expr_incoming;
109pub use expr_incoming::ExprIncoming;
110
111mod expr_intersects;
112pub use expr_intersects::ExprIntersects;
113
114mod expr_is_null;
115pub use expr_is_null::ExprIsNull;
116
117mod expr_is_superset;
118pub use expr_is_superset::ExprIsSuperset;
119
120mod expr_is_variant;
121pub use expr_is_variant::ExprIsVariant;
122
123mod expr_length;
124pub use expr_length::ExprLength;
125
126mod expr_let;
127pub use expr_let::ExprLet;
128
129mod expr_like;
130pub use expr_like::ExprLike;
131
132mod expr_list;
133pub use expr_list::ExprList;
134
135mod expr_map;
136pub use expr_map::ExprMap;
137
138mod expr_match;
139pub use expr_match::{ExprMatch, MatchArm};
140
141mod expr_not;
142pub use expr_not::ExprNot;
143
144mod expr_or;
145pub use expr_or::ExprOr;
146
147mod expr_project;
148pub use expr_project::ExprProject;
149
150mod expr_record;
151pub use expr_record::ExprRecord;
152
153mod expr_reference;
154pub use expr_reference::{ExprColumn, ExprReference};
155
156mod expr_set;
157pub use expr_set::ExprSet;
158
159mod expr_set_op;
160pub use expr_set_op::ExprSetOp;
161
162mod expr_starts_with;
163pub use expr_starts_with::ExprStartsWith;
164
165mod expr_stmt;
166pub use expr_stmt::ExprStmt;
167
168mod filter;
169pub use filter::Filter;
170
171mod hash_index;
172pub use hash_index::HashIndex;
173
174mod sorted_index;
175pub use sorted_index::SortedIndex;
176
177mod func_count;
178pub use func_count::FuncCount;
179
180mod func_json_extract;
181pub use func_json_extract::FuncJsonExtract;
182
183mod func_last_insert_id;
184pub use func_last_insert_id::FuncLastInsertId;
185
186mod include;
187pub use include::Include;
188
189mod insert;
190pub use insert::{Insert, Upsert, UpsertAction, UpsertTarget};
191
192mod insert_table;
193pub use insert_table::InsertTable;
194
195mod insert_target;
196pub use insert_target::InsertTarget;
197
198mod input;
199pub(crate) use input::InputResolve;
200pub use input::{ConstInput, Input, TypedInput};
201
202mod join;
203pub use join::{Join, JoinOp};
204
205mod limit;
206pub use limit::{Limit, LimitCursor, LimitOffset};
207
208#[cfg(feature = "assert-struct")]
209mod like;
210
211mod node;
212pub use node::Node;
213
214mod num;
215
216mod op_binary;
217pub use op_binary::BinaryOp;
218
219mod order_by;
220pub use order_by::OrderBy;
221
222mod order_by_expr;
223pub use order_by_expr::OrderByExpr;
224
225mod op_set;
226pub use op_set::SetOp;
227
228mod path;
229pub use path::{Path, PathRoot};
230
231mod path_field_set;
232pub use path_field_set::PathFieldSet;
233
234mod projection;
235pub use projection::{Project, Projection};
236
237mod query;
238pub use query::{Lock, Query};
239
240mod returning;
241pub use returning::Returning;
242
243mod select;
244pub use select::Select;
245
246mod source;
247pub use source::{Source, SourceModel};
248
249mod source_table;
250pub use source_table::SourceTable;
251
252mod source_table_id;
253pub use source_table_id::SourceTableId;
254
255mod sparse_record;
256pub use sparse_record::SparseRecord;
257
258mod substitute;
259use substitute::Substitute;
260
261mod table_derived;
262pub use table_derived::TableDerived;
263
264mod table_ref;
265pub use table_ref::TableRef;
266
267mod table_factor;
268pub use table_factor::TableFactor;
269
270mod table_with_joins;
271pub use table_with_joins::TableWithJoins;
272
273mod ty;
274pub use ty::Type;
275
276#[cfg(feature = "bigdecimal")]
277pub use bigdecimal::BigDecimal;
278#[cfg(feature = "net")]
279pub use cidr::{IpCidr, IpInet};
280#[cfg(feature = "jiff")]
281pub use jiff::{
282 Timestamp, Zoned,
283 civil::{Date, DateTime, Time},
284};
285#[cfg(feature = "net")]
286pub use macaddr::{MacAddr6, MacAddr8};
287#[cfg(feature = "rust_decimal")]
288pub use rust_decimal::Decimal;
289pub use uuid::Uuid;
290
291mod ty_union;
292pub use ty_union::TypeUnion;
293
294#[cfg(feature = "jiff")]
295mod ty_jiff;
296
297#[cfg(feature = "net")]
298mod ty_net;
299
300mod update;
301pub use update::{Update, UpdateTarget};
302
303mod value;
304pub use value::Value;
305
306mod value_cmp;
307
308mod values;
309pub use values::Values;
310
311#[cfg(feature = "jiff")]
312mod value_jiff;
313
314#[cfg(feature = "net")]
315mod value_net;
316
317mod value_object;
318pub use value_object::ValueObject;
319
320mod value_record;
321pub use value_record::ValueRecord;
322
323mod value_set;
324pub use value_set::ValueSet;
325
326pub mod visit_mut;
328pub use visit_mut::VisitMut;
329
330mod value_list;
331
332mod value_stream;
333pub use value_stream::ValueStream;
334
335pub mod visit;
337pub use visit::Visit;
338
339mod with;
340pub use with::With;
341
342use crate::schema::db::TableId;
343use std::fmt;
344
345#[derive(Clone, PartialEq)]
362pub enum Statement {
363 Delete(Delete),
365
366 Insert(Insert),
368
369 Query(Query),
371
372 Update(Update),
374}
375
376impl Statement {
377 pub fn name(&self) -> &str {
379 match self {
380 Statement::Query(_) => "query",
381 Statement::Insert(_) => "insert",
382 Statement::Update(_) => "update",
383 Statement::Delete(_) => "delete",
384 }
385 }
386
387 pub fn substitute(&mut self, input: impl Input) {
390 Substitute::new(input).visit_stmt_mut(self);
391 }
392
393 pub fn is_const(&self) -> bool {
396 match self {
397 Statement::Query(query) => {
398 if query.with.is_some() {
399 return false;
400 }
401
402 query.body.is_const()
403 }
404 _ => false,
405 }
406 }
407
408 pub fn as_update(&self) -> Option<&Update> {
414 match self {
415 Self::Update(update) => Some(update),
416 _ => None,
417 }
418 }
419
420 pub fn into_update(self) -> Option<Update> {
426 match self {
427 Self::Update(update) => Some(update),
428 _ => None,
429 }
430 }
431
432 pub fn is_single(&self) -> bool {
434 match self {
435 Statement::Query(q) => q.single,
436 Statement::Insert(i) => i.source.single,
437 Statement::Update(i) => match &i.target {
438 UpdateTarget::Query(q) => q.single,
439 UpdateTarget::Model(_) => true,
440 _ => false,
441 },
442 Statement::Delete(d) => d.selection().single,
443 }
444 }
445
446 pub fn into_update_unwrap(self) -> Update {
452 match self {
453 Self::Update(update) => update,
454 v => panic!("expected `Update`, found {v:#?}"),
455 }
456 }
457}
458
459impl Node for Statement {
460 fn visit<V: Visit>(&self, mut visit: V) {
461 visit.visit_stmt(self);
462 }
463
464 fn visit_mut<V: VisitMut>(&mut self, mut visit: V) {
465 visit.visit_stmt_mut(self);
466 }
467}
468
469impl fmt::Debug for Statement {
470 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
471 match self {
472 Self::Delete(v) => v.fmt(f),
473 Self::Insert(v) => v.fmt(f),
474 Self::Query(v) => v.fmt(f),
475 Self::Update(v) => v.fmt(f),
476 }
477 }
478}