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
//! The text comparison: [`SqlTextComparison`], and one concrete lowering per dialect.
use PhantomData;
use Display;
// Gated with their only user, the shared slot walk below — which is itself gated with the
// per-dialect impls that call it. An import carries the cfg its consumer carries, and the run
// that catches a mismatch is the one where the family root is on and every dialect is off.
use ;
use crate;
use crate::;
comparison_kind!
/// The text kind answers for its two PLAIN operators alone, which is what makes the count the right
/// question here rather than a list: the kind carries twenty, seventeen of them matching shapes that
/// name no single child row, and any of them set raises the count past one.
///
/// # ONE impl over every dialect, where the LOWERING has three — and the open reading
///
/// The lowering is per-dialect because `LIKE` is: two of the three build a pattern and need
/// `V: AsRef<str>` for it. Nothing here renders, so this is the wire's own answer asked at the other
/// end and it holds wherever the wire's does.
///
/// What the dialect split WOULD be for, if it is ever wanted: the collapse moves a predicate off the
/// target's key column and onto the source's reference column, so it assumes the two compare text
/// alike. Under a schema whose two columns carry different collations they do not — MySQL's defaults
/// are the case to measure — and a dialect that wanted to decline would simply not have this row.
/// The framework's own DDL declares both columns from one type, so within a framework-emitted schema
/// they agree by construction; a hand-declared physical layout is where the question is live. It is
/// RECORDED rather than decided: the wire has answered `true` for every dialect since
/// `legacy/ingraph`, and narrowing it here would be a compile error for a declaration that works
/// today rather than a slower query.
/// The lowering promise is stated as the COMPARISON's own bound, because this kind has no other
/// spelling for it.
///
/// [`ToDatabaseComparison::Comparison`](crate::ToDatabaseComparison::Comparison) promises
/// [`ComplexComparison`], so a row proves it. The three kinds whose lowering is ONE generic impl
/// prove it by restating that impl's bound list; this kind's lowering is three CONCRETE impls whose
/// bounds disagree — SQLite asks `V: Carrier<Sqlite>` and the two `LIKE` dialects add
/// `V: AsRef<str>` to build a pattern — so there is no bound list to restate. What is true of all
/// three at once is exactly `SqlTextComparison<V, Db>: ComplexComparison<Db>`, and at a dialect
/// that resolves to whichever impl the dialect has.
///
/// `Db: sqlx::Database` is kept for the coherence reason
/// [`SqlScalarComparison`](super::SqlScalarComparison)'s row records, and `Db: Backend` because
/// naming [`ComplexComparison`] needs it and it is not elaborated from the crossing.
///
/// The READING parameter is carried but never read: what a crossing spends is the OPERANDS, and the
/// wire form they arrived under is spent by the time one is built. Generic over it so a declarer's
/// own text type — whose filter names a marker that crate owns — reaches storage exactly as
/// `TextFilter<String>` does.
/// The crossing with no declared converter — see [`SqlScalarComparison`](super::SqlScalarComparison)'s
/// for what the identity case buys. A `String` column stored as `String` is the common one, and it
/// reaches its comparison with an [`Infallible`](core::convert::Infallible) error.
/// The slot walk the three concrete impls share: the six comparison operators, the twelve affix
/// slots through `leaf`, then the two membership lists — in the order the struct declares them.
///
/// This is where the dialects genuinely agree, and it is shared for exactly that reason. `= ?`,
/// `> ?` and `IN (?, …)` reduce to a placeholder in every dialect and go through
/// [`Carrier`] and one `push_cmp` / `push_in`; the affixes do not, and `leaf` is the whole of what
/// the three impls differ by. A dialect answers a row of the table by READING its three components
/// as three arguments, which is what keeps a dialect at one leaf rather than at twelve.
///
/// `leaf` is taken as a type parameter rather than as a function POINTER so each impl monomorphizes
/// its own walk — and so the leaf's own bounds stay the leaf's, which is what lets SQLite's take
/// `V: Carrier<Sqlite>` while Postgres's takes `V: Carrier<Postgres> + AsRef<str>`.
// Gated with its only callers, the per-dialect impls below: with the family root on and no
// dialect there is no lowering, so there is no walk to share.
/// MySQL matches with `LIKE` too, and folds case by wrapping BOTH sides in `LOWER` rather than with
/// a second operator — collation-independent, which is what a `utf8mb4_bin` column needs.
///
/// It carries the same `V: AsRef<str>` Postgres's does, for the same reason and through the same
/// shared builder; the divergence between the two is one lexing rule, spelled at the leaf.
/// Postgres matches with `LIKE` / `ILIKE`, which is why its three affixes render BYTE-IDENTICAL SQL
/// and differ only in the bound pattern: a differential over the rendered text cannot tell
/// `starts_with` from `ends_with` here, and `dialect::tests` asserts the pattern instead.
///
/// `V: AsRef<str>` is what the pattern costs, and it is real: [`like_pattern`](super::like_pattern)
/// reads the operand's characters to escape them, and a carrier that binds an opaque encoding has no
/// characters to read. The same carrier SQLite lowers therefore has no lowering here, and the
/// omission is a bound naming the missing trait rather than a query that binds something plausible:
///
/// ```compile_fail,E0599
/// use ingraph::{
/// At, Carrier, ComplexComparison, FieldName, RecordAddress, TextFilter, TryFromFilter,
/// comparison::sql::{SqlConjunction, SqlTextComparison},
/// };
///
/// struct Opaque(String);
///
/// impl From<String> for Opaque {
/// fn from(text: String) -> Self {
/// Self(text)
/// }
/// }
///
/// impl Carrier<sqlx::Postgres> for Opaque {
/// fn push_bind(&self, qb: &mut sqlx::QueryBuilder<sqlx::Postgres>) {
/// qb.push_bind(self.0.as_str());
/// }
/// }
///
/// let c = SqlTextComparison::<Opaque, sqlx::Postgres>::try_from_filter(
/// TextFilter::<String>::new().with_contains("cam".to_owned()),
/// )
/// .unwrap();
/// let mut qb = sqlx::QueryBuilder::<sqlx::Postgres>::default();
/// const ROW: RecordAddress = RecordAddress::new(FieldName::new("t"), &[FieldName::new("id")]);
/// let out = SqlConjunction::with_lead(&mut qb, "");
/// let frame = At::new(&ROW).frame(FieldName::new("n"));
/// c.apply(frame.at(), out).unwrap();
/// ```
///
/// Its twin, which must COMPILE — stable rustdoc runs a `compile_fail` block just far enough to see
/// it fail and never checks why, so the pair shares its call shape and one half has to be positive:
///
/// ```
/// use ingraph::{
/// At, ComplexComparison, FieldName, RecordAddress, TextFilter, TryFromFilter,
/// comparison::sql::{SqlConjunction, SqlTextComparison},
/// };
///
/// let c = SqlTextComparison::<String, sqlx::Postgres>::try_from_filter(
/// TextFilter::<String>::new().with_contains("cam".to_owned()),
/// )
/// .unwrap();
/// let mut qb = sqlx::QueryBuilder::<sqlx::Postgres>::default();
/// const ROW: RecordAddress = RecordAddress::new(FieldName::new("t"), &[FieldName::new("id")]);
/// let out = SqlConjunction::with_lead(&mut qb, "");
/// let frame = At::new(&ROW).frame(FieldName::new("n"));
/// c.apply(frame.at(), out).unwrap();
/// assert_eq!(qb.sql(), "\"n\" LIKE $1 ESCAPE '\\'");
/// ```
/// SQLite matches with `instr`/`substr` and folds case with `lower`, so it renders every shape the
/// vocabulary declares and needs no pattern at all.
///
/// That is why its impl carries ONE bound where the two `LIKE` dialects carry two: nothing here
/// derives a value from the operand's text, so the operand binds through its own [`Carrier`] row and
/// `V: AsRef<str>` is never asked for. A stored text form that is not a Rust string — a newtype with
/// no `AsRef<str>`, a compact rope — is filterable with `contains` on this dialect and on neither
/// other, and that difference is what one impl over three dialects could not say.
///
/// The claim, from outside the crate, where a downstream storage type actually lives:
///
/// ```
/// use ingraph::{
/// At, Carrier, ComplexComparison, FieldName, RecordAddress, TextFilter, TryFromFilter,
/// comparison::sql::{SqlConjunction, SqlTextComparison},
/// };
///
/// /// A stored text form with no `AsRef<str>` — an interned handle, a compact rope.
/// struct Opaque(String);
///
/// impl From<String> for Opaque {
/// fn from(text: String) -> Self {
/// Self(text)
/// }
/// }
///
/// impl Carrier<sqlx::Sqlite> for Opaque {
/// fn push_bind(&self, qb: &mut sqlx::QueryBuilder<sqlx::Sqlite>) {
/// qb.push_bind(self.0.as_str());
/// }
/// }
///
/// let c = SqlTextComparison::<Opaque, sqlx::Sqlite>::try_from_filter(
/// TextFilter::<String>::new().with_contains("cam".to_owned()),
/// )
/// .unwrap();
/// let mut qb = sqlx::QueryBuilder::<sqlx::Sqlite>::default();
/// const ROW: RecordAddress = RecordAddress::new(FieldName::new("t"), &[FieldName::new("id")]);
/// let out = SqlConjunction::with_lead(&mut qb, "");
/// let frame = At::new(&ROW).frame(FieldName::new("n"));
/// c.apply(frame.at(), out).unwrap();
/// assert_eq!(qb.sql(), "instr(\"n\", ?) > 0");
/// ```