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
//! The scalar comparison: [`SqlScalarComparison`].
use ;
use ;
use crate::;
comparison_kind!
/// Every SQL dialect takes the scalar filter to the scalar comparison; only the storage type and the
/// dialect vary, and both are parameters. The MongoDB family joins beside this over the same trait
/// — measured, not assumed: `impl<…, Db: sqlx::Database>` here and `impl<…> …<Mongo>` there do NOT
/// overlap, because `Mongo` would be local and nothing may implement `sqlx::Database` for it.
///
/// # The rest of the bounds are the LOWERING's, restated
///
/// [`ToDatabaseComparison::Comparison`](crate::ToDatabaseComparison::Comparison) promises
/// [`ComplexComparison`], so this row has to PROVE it rather than assume it, and what proves it is
/// the bound list the lowering below already carries — including [`ColumnKind`], which is the
/// operand's WIDTH and is what the lowering reads to know whether it is naming one column or
/// several. `Db: sqlx::Database` stays at the head of that list for the coherence reason above,
/// which the added bounds do not replace: `Backend` is a trait this crate declares, so a local
/// `Mongo` may implement it and the overlap argument would be gone if that were all the header said.
/// The scalar kind answers, and it is the kind an id column most often crosses into: an integer key
/// compared under `eq` is exactly the shape a relation collapses onto the foreign key.
///
/// ONE impl for every dialect, for [`ComplexComparison`]'s reason one layer simpler — nothing here
/// renders, so there is no dialect-varying SQL for the answer to depend on.
/// A scalar comparison re-stated over a different element is that comparison: the dialect keeps and
/// only the operand's storage type moves.
///
/// It is here because a COLLECTION re-states its element comparison through the same trait — see
/// [`StrategyOver`](super::StrategyOver) — and a scalar is the element kind every collection this
/// crate ships a wrapper row for holds. An element kind with no row here has no re-stated
/// collection, which is the same honest answer an element with no storage row gets.
/// The crossing with no declared converter: the storage type's own [`TryFrom`].
///
/// When the storage type IS the field's, `V: TryFrom<V>` resolves through std's reflexive
/// `From`/`Into` blankets and the error is [`Infallible`](core::convert::Infallible) — so the
/// identity crossing is provably unable to fail rather than merely always succeeding.
/// **THE CONFIDENCE KIND LOWERS ONTO THIS COMPARISON**, which is what a widthless operand costs and
/// what it buys.
///
/// [`ConfidenceFilter`] is one input object over every width a confidence measures in, so its
/// operands carry no width — and the width has to come from somewhere. It comes from HERE: `V` is
/// the column's own storage type, and `V: ScoreKind` is the row that says what one threshold means
/// AT that type. A `Confidence<f32>` column narrows the operand to binary32, a
/// `Confidence<rust_decimal::Decimal>` column reads its exact literal, and the client wrote one
/// threshold either way.
///
/// **The comparison is the ordinary scalar one**, and that is the deliverable rather than an
/// economy: the confidence needed a filter KIND because its OPERAND is different, and it needed no
/// comparison kind because its OPERATORS are not — six of the eight, over a total order, rendered by
/// the same `push_operand_cmp` every other scalar column renders through. `in`/`not_in` come out of
/// the crossing empty, this filter having no slot for either.
///
/// The bound is [`ScoreKind`] rather than the four widths written out, which is the FRAMEWORK-OPEN
/// posture stated as a where clause: a builtin that comes to serve as a score gets this lowering by
/// implementing that one trait, and no row here changes.
/// The confidence kind's storage-side answer, and it is [`ScalarFilter`]'s row above with one
/// parameter fewer: there is no `D` to carry, the operand being the same widthless
/// [`ConfidenceOperand`](crate::ConfidenceOperand) at every column.
///
/// Every bound is the row above's, unchanged, and for the same reasons — including `Db:
/// sqlx::Database` at the head, which is what keeps this from overlapping the MongoDB family's.
/// ONE impl for every dialect, and that is a POSITIVE finding rather than the absence of one.
///
/// The test this kind passes is not "no difference was found" — it is that the dialects agree on
/// both of the things a lowering can differ in:
///
/// - **The SQL is identical.** `"col" = ?`, `"col" > ?`, `"col" IN (?, …)`, the `1 = 0` an empty
/// list degenerates to, and the `NOT ( … )` wrap are one spelling in SQLite, Postgres and MySQL
/// alike. The placeholder is the only token that varies and it is
/// [`sqlx::QueryBuilder`]'s to vary, not this crate's — no string pushed on this path reads
/// differently in any dialect.
/// - **The bounds are identical, and so is the set of types they admit.** `V: Carrier<Db>` is the
/// whole requirement in every dialect. Nothing here needs a capability one engine has and another
/// does not — contrast [`SqlTextComparison`](super::SqlTextComparison), whose two `LIKE` dialects
/// need `V: AsRef<str>` to build a pattern and whose SQLite impl does not, and
/// [`SqlListComparison`](super::SqlListComparison), whose Postgres impl needs
/// [`PgHasArrayType`](sqlx::postgres::PgHasArrayType) and has no counterpart elsewhere.
///
/// What DOES vary per dialect is WHICH types have a [`Carrier`] row — `u64` has one on MySQL and not
/// on SQLite. That variation is the carrier table's, keyed on (storage type × dialect), and it
/// travels through this impl's bound rather than being flattened by it.
///
/// A fourth dialect is checked against those two statements. One whose equality, ordering or
/// membership differed in either respect would need a concrete impl of its own, exactly as the four
/// kinds that do have theirs.
///
/// # The bound that ties the dialect to its builder
///
/// `Db: for<'q> Backend<Builder<'q> = SqlConjunction<'q, Db>>` is what lets this body open a
/// conjunct at all: [`Backend::Builder`] is an associated type, so without the equality the builder
/// is opaque and the only thing an impl could do with it is give it back. Stating it as a bound
/// rather than writing one impl per dialect keeps the uniform kind uniform — a dialect that came to
/// need its own builder would simply not satisfy it, and would get a concrete impl.
///
/// # The buffer is a BOUND where the builder is an equality, and the difference is what each is for
///
/// This body hands its rendered names to [`sqlx::QueryBuilder::push`], which takes `impl Display`
/// and nothing more, so `Buffer: Display` is the whole of what the column path costs here — where
/// the builder has to be THE accumulator this family threads, because the body opens conjuncts on
/// it. Pinning the buffer to a type as well would close a question this impl never asks, and would
/// close it for every hand-written comparison generic over the dialect: such a comparison restates
/// this list to prove [`ComplexComparison`], so an equality here becomes an equality downstream.
///
/// Those two are the whole of what this impl asks of `Db`. The identifier is not spelled the same in
/// every dialect either, but this body never spells one: it hands the address to
/// [`push_column`](super::push_column), and which character brackets a column is the
/// [`Backend`]'s answer rather than a further bound here.
///
/// # `V: ColumnKind` is what makes a COMPOSITE operand nameable, and it is the third claim of a
/// storable type rather than a new one
///
/// A storage type already states three facts — its width ([`ColumnKind`]), its bind
/// ([`Carrier`]) and its read ([`Assemble`](crate::Assemble)) — and this impl reads the first two
/// TOGETHER, because a predicate is where they have to agree: an operand whose bind pushes two
/// placeholders under a left-hand side naming one column renders `"at" = ?, ?`, which no engine
/// parses. The width is a `const`, so the branch is resolved at compile time and the scalar path is
/// the same code and the same bytes it was before the bound existed — see
/// [`push_operand_cmp`](super::push_operand_cmp).
///
/// What it costs a DOWNSTREAM scalar is nothing it had not already paid: `impl ColumnKind for MyScalar
/// {}` is the whole row, the body being the default, and every storage type this crate ships has one.