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
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
//! The INTERFACE's own vocabulary: which member a row came from, what each arm projects, and the
//! refusal a discriminant nobody declared gets.
//!
//! An interface names no table and mints no id, so its query layer reads its MEMBERS' tables — one
//! `SELECT` per member, joined by `UNION ALL`, every arm projecting the shared columns under the
//! interface's own names. Two facts have to travel with that statement and neither is a member's:
//! WHICH member each row came from, and what that member calls each shared column.
//!
//! # The discriminant is a WORD the interface owns, and never a table's name
//!
//! An interface's total order ends `…, kind, id`, so the discriminant is a sort key: the sequence
//! rows come back in depends on how the engine compares two of these strings, and a cursor freezes
//! one. A member's TABLE cannot be that string, for two reasons that are each on their own decisive
//! — it is per DATABASE (`persist(sqlite(table = "…"), postgres(table = "…"))` names two), so one
//! interface's cursor would not be portable between two deployments of one schema; and it is
//! RENAMEABLE, so moving a member's table would silently re-sort every page of every interface it
//! belongs to.
//!
//! So the word is the member's own VARIANT, snake-cased — `video`, `audio` — which the interface's
//! declaration writes and nothing about storage can move. Lower-case ASCII is not decoration
//! either: a discriminant is compared by the ENGINE's collation, and the three shipped dialects'
//! defaults (SQLite `BINARY`, PostgreSQL's `C`/`en_US.utf8`, MySQL's `utf8mb4_0900_ai_ci`) agree on
//! the ordering of lower-case ASCII and do NOT agree on how it sorts against upper case. A word
//! that cannot contain a case distinction cannot be sorted two ways.
//!
//! # `Ord` is deliberately NOT on [`InterfaceKind`]
//!
//! A derived `Ord` over the emitted enum would run in DECLARATION order, and the statement sorts by
//! the projected STRING. Two orderings that agree only while a declaration happens to be written
//! alphabetically is exactly the shape that pages wrongly with no error anywhere, so the comparison
//! every party makes is over [`as_str`](InterfaceKind::as_str) and the enum carries no ordering at
//! all.
use fmt;
use Utf8Bytes;
use crateFieldName;
/// The alias every arm of a union projects its discriminant under.
///
/// ONE name, shared by the party that WRITES it into the statement and the party that DECODES it
/// off the row — the discipline a sort value's alias and a gathered element's already follow.
///
/// # `__ig_…__` is the SYNTHESIZED-COLUMN law, and it is what makes `kind` an ordinary field name
///
/// A column the framework invents wears `__ig_` at the front and `__` at the end. That shape is
/// inside the fence `ingraph-derive` already refuses a declared column for — *a name with `__` at
/// both ends is reserved* — so a declaration CANNOT spell this name, and an interface promising a
/// shared field called `kind` collides with nothing. A synthesized column named `kind` would have
/// made the framework's own vocabulary compete with the declaration's, which is the one thing the
/// fence exists to prevent.
pub const KIND: &FieldName = new;
/// The name every arm of a union projects its member's ADDRESS column under.
///
/// A REAL column and therefore an ordinary name: what each arm selects is that member's own address
/// column, which is `id` in one table and `audio_id` in the next, so the union needs one output name
/// for them and `id` is what it is. It is not synthesized — the value is a member's own, where the
/// discriminant beside it is the framework's invention — so it wears no fence, and a shared field
/// called `id` collides with it exactly as two columns of one name collide anywhere.
pub const ID: &FieldName = new;
/// The name the outer query gives the union it selects from.
///
/// A union is a DERIVED TABLE and a derived table must be named, so this is the name the shared
/// predicate and the `ORDER BY` qualify their columns with. Synthesized, therefore fenced: nothing
/// a declaration can spell, so a member's own table called `union` collides with nothing.
pub const SOURCE: &FieldName = new;
/// Which member a row came from, as the interface's own closed vocabulary.
///
/// A CAPABILITY rather than a member of the query binding, because the answer is one per INTERFACE
/// where the binding is one per (interface, database): the word a row carries is the same word in
/// every database the interface is about, which is the whole of what makes a cursor minted against
/// SQLite replayable against the Postgres deployment of one schema.
///
/// # [`parse`](Self::parse) is DEFAULTED, and there is no second body to write
///
/// It is a scan of [`ALL`](Self::ALL) comparing [`as_str`](Self::as_str), which is the only
/// implementation the two items admit. An emitted vocabulary states the two facts and inherits the
/// crossing; a hand-written one does the same.
/// A discriminant naming no member of the interface that read it.
///
/// It carries the word VERBATIM rather than a summary, because the word is the whole evidence: a
/// row from a table the union does not join and a cursor minted under another interface are told
/// apart by reading it.
/// What HYDRATING an interface's page refuses with: the union answered, and the members' own tables
/// did not.
///
/// # It is the COHERENCE refusal, and it exists because two statements are two moments
///
/// A page is a union over the members' tables and a hydration is one gather per member, so a row the
/// union returned can be gone by the time its member's table is read. Inside one read transaction
/// that cannot happen — which is what [`BeginRead`](crate::query::sql::BeginRead)'s passthrough is
/// for — and outside one it can, so the gap is REPORTED rather than papered over with a shorter
/// list. A page that silently loses rows is a page whose `hasNextPage` is a lie.
///
/// # It carries the WORD and a count, and never an id
///
/// The members need not agree about what an id is, so a refusal naming one would be generic in the
/// member — and this type is what a declared error unifies through, which a generic one could not
/// be. The member's word and how many of its rows went missing is the whole evidence a caller acts
/// on.
/// ONE shared column, as one arm of a union projects it.
///
/// TWO names rather than one, and they differ exactly where a member block moved the column: the
/// interface promises `created_at` and `Audio` carries it as `imported_at`, so that arm renders
/// `"imported_at" AS "created_at"` and every other arm renders the name twice over. Which is why
/// the pair is carried rather than an `Option`: the arm that renames and the arm that does not are
/// one rendering, and a branch on absence would be a second one.
/// ONE arm of a union: which member it reads, and how that member's row spells the shared columns.
///
/// The TABLE is not here, and its absence is the point: a member's table is its own declaration's
/// and is reached through the member's query binding rather than restated by the interface —
/// see [`SqlInterface::table`](crate::query::sql::SqlInterface::table), which asks the member's own
/// `ADDRESS` for it. An arm carrying a copy would be a second spelling of a name a
/// `persist(<db>(table = "…"))` can move.