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
//! The statement types, each shaped by PostgreSQL's own grammar: the four core
//! ones, `MERGE`, and the two `SELECT` shorthands (`VALUES`, `TABLE`).
//!
//! Every one composes the shared clause structs as named fields, in the order the
//! reference manual lists them, and implements the `Has*` traits for the clauses it
//! actually has. *Not* implementing one is how "this statement has no such clause"
//! is said: `select::having(..)` will not compile against an `UpdateQuery`, because
//! `UpdateQuery` does not implement
//! [`HasHaving`](keelson_core::clause::HasHaving).
//!
//! # Which table a mod means
//!
//! Three statements have two tables, and the two `Has*` traits below are how they
//! are told apart:
//!
//! | statement | [`HasTableRef`](keelson_core::clause::HasTableRef) | [`HasTargetTable`] | [`HasExtraTables`] |
//! |---|---|---|---|
//! | `SELECT` | `FROM` item | — | further `FROM` items |
//! | `INSERT` | `INTO` target | — | — |
//! | `UPDATE` | `FROM` item | the updated table | further `FROM` items |
//! | `DELETE` | `USING` item | the deleted-from table | further `USING` items |
//! | `MERGE` | `USING` source | the merged-into table | — |
//! | `TABLE` | the table | — | — |
//!
//! So `HasTableRef` always means "the from-item", which is what makes one
//! `select::from` / `update::from` / `delete::using` / `merge::using` chain type
//! serve them all, and what puts joins in the right place — `HasJoins` reaches
//! the from-item's joins, never the target's.
pub use DeleteQuery;
pub use InsertQuery;
pub use ;
pub use SelectQuery;
pub use TableQuery;
pub use UpdateQuery;
pub use ValuesQuery;
use TableRef;
/// A statement whose *target* table is separate from its from-item: the table an
/// `UPDATE` writes to, or the one a `DELETE` removes from.
///
/// `SELECT` and `INSERT` have only one table each and use
/// [`HasTableRef`](keelson_core::clause::HasTableRef) for it, so they do not
/// implement this — which is precisely why `update::table(..)` cannot be applied to
/// them.
/// A statement whose from-item list may hold more than one entry.
///
/// PostgreSQL's `FROM from_item [, ...]` and `USING from_item [, ...]` are
/// comma-separated lists, and a comma there means the same thing as `CROSS JOIN`.
/// The first entry lives in [`HasTableRef`](keelson_core::clause::HasTableRef); the
/// rest are appended here.
/// Write `FROM`/`USING` and its comma-separated list, skipping absent entries.
///
/// An entry with no table renders nothing, so it must not contribute a comma
/// either; and if the leading item is absent the whole clause goes, because
/// `FROM , "x"` is not a repair of anything.
///
/// Two things must not go with it: joins and the extra items. Joins hang off
/// the leading item, so with no item they have nowhere to attach; extra items
/// are second and later entries of a list the leading item opens, so with no
/// item there is no list to be in. Dropping either one the caller asked for
/// would build *valid* SQL that silently means something else, which no
/// grammar or engine can catch after the fact. That is recorded as
/// [`Error::Incomplete`](keelson_core::Error::Incomplete) with `missing`
/// naming the absent item (`FROM` or `USING`, per statement).