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
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
//! The SQL engine: what a stored row answers a query with, what a dialect has to be able to do, and
//! the statement the three lanes render.
//!
//! # The binding is on the ROW, because a row is what one database IS here
//!
//! A declaration storing a record in two databases emits two row types, and everything a query
//! needs that varies — the column names, the stored types, the table — varies with exactly that.
//! So [`SqlQuery`] is implemented on the row and names the record it stores, which is the same key
//! `ToDatabaseComparison<Row, Db>` already turns: one record, one comparison per database, told
//! apart by naming the row.
//!
//! The DIALECT stays a type parameter on top of that, and it is not decoration. An expansion may
//! not name `sqlx::Sqlite`, because a declaration storing one dialect would then need that
//! dialect's feature to COMPILE; the row's own name is what picks which column names are rendered,
//! and the dialect that brackets them is chosen by the pool a caller passes.
//!
//! # Two traits, because ordering is a capability and not a part of being queryable
//!
//! [`SqlQuery`] is the whole of what `get`, an unordered `fetch` and a `limit` need. [`SqlOrdering`]
//! adds the ordering terms a client may write, the cursor values a row projects into, and the
//! address tail that completes a written order — and a record that has no order-by type to name
//! simply does not implement it, so `.order(…)` is a missing impl rather than a runtime refusal.
//!
//! # What is measured here, and what is measured against an engine
//!
//! The tests beside this module assert on the STATEMENT, because rendering is what this module
//! does. Whether the statement pages correctly is not visible in its text — a keyset that skips a
//! row is valid SQL that answers without an error — so that half is measured against real engines
//! and recorded where it was measured; see [`crate::comparison::sql::SqlKeyset`] for the walk and
//! [`find`](self::find) for this layer's own.
use Display;
pub use ;
// CRATE-INTERNAL, and reached by the one other literal in this crate that claims the reserved
// namespace — the retirement ledger's table prefix. See `ddl::leads_with` for why it is shared
// rather than copied.
pub use leads_with;
pub use ;
pub use ;
pub use ;
pub use ;
pub use ;
pub use ;
use crate::;
/// What a record ⇄ row crossing refuses with — the QUERY layer's
/// [`CrossingError`](crate::query::CrossingError), re-exported here.
///
/// It was declared in this module while SQL was the only engine, and it moved up the moment a
/// second one needed it: a declared conversion refuses the same way whichever database the row came
/// out of. The re-export is what keeps `query::sql::CrossingError` — the path an emitted binding
/// writes, through the shelf — resolving to the same type it always did.
pub use CrossingError;
/// The shape an edge table keeps a collection in, re-exported from [`schema`](crate::schema).
///
/// It was declared in this module while a MATERIALIZATION was the only party asking, and it moved to
/// the descriptor layer the moment the DDL needed it: a build with no SQL family still describes a
/// table, and this module is not compiled there. The re-export is what keeps `query::sql::EdgeShape`
/// — the path a collection plan is written through — resolving to the same type it always did.
pub use crateEdgeShape;
/// Everything a page needs of a SQL dialect, in ONE name.
///
/// # A bundle rather than six bounds at every signature
///
/// Each member is already a per-dialect capability with its own home and its own reason —
/// [`QuoteIdent`] states the bracket, [`NullOrder`] states how the framework's pinned `NULL`
/// position is reached, [`BindCeiling`] states the wire's parameter limit, and [`Backend`] states
/// the accumulator, the refusal and the buffer. What this adds is nothing of its own: the blanket
/// impl below is the whole of it, so a dialect this crate does not ship joins by implementing the
/// PARTS and never this.
///
/// # Three predicates are deliberately NOT in it, and the reason was measured
///
/// A statement is executable only where `i64` binds — `LIMIT` and `OFFSET` take a signed 64-bit
/// integer — where the dialect's arguments cross into `Execute`, and where `&mut` its connection is
/// an [`Executor`](sqlx::Executor). All three are predicates whose SUBJECT is not the dialect, so
/// none of them can be a supertrait, and putting them in this trait's `where` clause is worse than
/// leaving them out: **a `where` predicate on a trait is an obligation at every USE of the bound
/// and is not implied by having it.** Written there, `Db: SqlDialect` obliges a caller to prove all
/// three and then hands none of them back — so every signature pays for all of them whether it
/// spends one or none. Measured, on this crate, before they were moved out.
///
/// So they travel with the signatures that spend them, each restating the ones it uses and no
/// more. It costs the ENGINE and not its callers: a concrete dialect satisfies all three, so an
/// emitted face constructing a builder never names them and a caller's `fetch` discharges them by
/// having a real pool.
/// The nesting ceiling, which is the QUERY layer's rather than this family's — a filter that nests
/// too deep for one backend must be refused by both. Re-exported so that
/// `query::sql::DEPTH_CEILING`, which is the path an expansion writes and this family's own note
/// spells, keeps resolving.
pub use DEPTH_CEILING;
/// One database's stored row, as the engine queries it.
///
/// # What a query needs, and nothing more
///
/// The table and key columns it selects from, the columns it selects, the predicate type a filter
/// crosses into, the predicate that names ONE row, and the way back to the record. Ordering is not
/// here — see [`SqlOrdering`], which is what a page needs on top.
///
/// # The address is a `const`, so nothing builds one per query
///
/// [`RecordAddress::new`] is `const` and its key list is `&'static`, which is the shape that makes a
/// row's address an ITEM. An emitted binding states it once beside the row it describes.
///
/// # The dialect is an `sqlx::Database` here, and the COLLECTION PLAN is what made it one
///
/// A query needs a backend and nothing more, which is what this bound used to say. What it cannot
/// say is [`COLLECTIONS`](Self::COLLECTIONS): a materialization crosses the dialect's own ROW type
/// at both ends, so the plan's type names `Db::Row` and the trait has to be able to. Every party
/// affected already had it — the engine's lanes are `Db: SqlDialect` and an emitted binding states
/// `Db: sqlx::Database` for its cursor value's carrier — so the tightening costs the callers
/// nothing and is what keeps hydration a defaulted item here rather than a fourth trait a row would
/// have to remember to implement.
///
/// The plan is also a `&'static` list, so a row is `'static` too — which it already was, being the
/// OWNED shape a `FromRow` decode produces rather than a borrow of one. It is stated in the
/// supertrait list rather than as a `where` predicate, so a caller holding `Row: SqlQuery<Db>` is
/// GIVEN it instead of having to prove it.
/// A row that can be ORDERED, and therefore paged.
///
/// # It is a second trait, and the split is what makes the gap structural
///
/// A record with no order-by type has nothing to write a term with, so it implements this and
/// nothing here can be called on it — `.order(…)` fails to resolve rather than refusing at runtime.
/// Every other lane stays open to it: `get`, an unordered `fetch`, and a `limit`.
///
/// # Four functions, and one list drives every half of a page
///
/// [`complete`](Self::complete) turns a client's written terms into the total order the page runs
/// in; [`term`](Self::term) renders one of those into the [`OrderTerm`] this database spells;
/// [`subjects`](Self::subjects) says what each of them COMPARES; and [`value`](Self::value) reads
/// the row at that same term. So the `ORDER BY`, the keyset `WHERE`, the SELECT-list projection and
/// the cursor are four readings of ONE list, which is what keeps them from disagreeing about a
/// column, an expression or a direction — the failure that skips or repeats exactly the rows at a
/// page boundary.