ingraph 0.1.0

A declaration-driven indexing framework: records and nodes are written as Rust types, and the storage rows, the dataflow between them and the GraphQL query surface are emitted from the declaration.
Documentation
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
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
use super::SqlNullable;
use crate::{
  Nullable, ScalarFilter,
  comparison::{TryFromFilter, sql::SqlScalarComparison},
};

type Column = SqlNullable<SqlScalarComparison<i64, ()>, i64>;

#[test]
fn the_wrapper_crosses_its_inner_and_keeps_the_null_test() {
  let filter = Nullable::new(ScalarFilter::<i64>::new().with_eq(1i64)).with_null(false);
  let crossed = Column::try_from_filter(filter).unwrap();

  assert_eq!(crossed.inner().eq(), Some(&1));
  assert_eq!(crossed.null(), Some(false));
  assert_eq!(crossed.inner().conjuncts(), 1);
}

/// The null test is the wrapper's own, so an inner comparison that is empty still leaves a
/// non-empty column comparison.
#[test]
fn the_null_test_alone_is_not_an_empty_comparison() {
  let crossed =
    Column::try_from_filter(Nullable::new(ScalarFilter::<i64>::new()).with_null(true)).unwrap();
  assert!(crossed.inner().is_empty());
  assert_eq!(crossed.null(), Some(true));
}

/// The empty comparison of an empty inner one, which is what a builder assembling a where struct
/// column by column starts from. Bounded on `C` where the flat kinds' [`Default`] is unbounded —
/// the wrapper owns an inner comparison and cannot invent one.
#[test]
fn the_default_is_the_empty_inner_comparison_with_no_null_test() {
  let empty = Column::default();

  assert_eq!(empty.null(), None);
  assert!(empty.inner().is_empty());
  assert_eq!(empty, Column::new(SqlScalarComparison::new()));
}

/// The `Option` a nullable column's storage type carries is placed by THIS wrapper and taken off on
/// the way down, so the inner comparison's operands are the bare storage type.
///
/// Written over a filter kind and a comparison declared here rather than over `ScalarFilter`,
/// because the claim is about the wrapper's own impl. It names a DIALECT where it used to name `()`,
/// and that is the crossing's item bound arriving rather than the claim changing: a row now promises
/// its comparison lowers, `ComplexComparison` is keyed on a [`Backend`](crate::Backend), and `()` is
/// not one. The kind and its comparison are still declared here, so what the equation is about is
/// unchanged.
#[cfg(feature = "sqlite")]
#[test]
fn the_column_option_lands_on_the_wrapper_and_not_on_the_operands() {
  use core::marker::PhantomData;

  use crate::{
    At, ComplexComparison,
    comparison::{
      ToDatabaseComparison,
      sql::{Carrier, SqlConjunction, SqlLoweringError, push_column},
    },
  };

  struct KeyFilter;
  struct KeyComparison<V>(Option<V>);

  impl<V: Carrier<sqlx::Sqlite>, Db> ToDatabaseComparison<V, Db> for KeyFilter
  where
    Db: sqlx::Database + crate::Backend,
    KeyComparison<V>: ComplexComparison<Db>,
  {
    type Comparison = KeyComparison<V>;
  }

  impl<V: Carrier<sqlx::Sqlite>> ComplexComparison<sqlx::Sqlite> for KeyComparison<V> {
    fn conjuncts(&self) -> usize {
      usize::from(self.0.is_some())
    }

    fn apply<'q>(
      &'q self,
      at: At<'_>,
      mut builder: SqlConjunction<'q, sqlx::Sqlite>,
    ) -> Result<SqlConjunction<'q, sqlx::Sqlite>, SqlLoweringError> {
      if let Some(value) = &self.0 {
        let qb = builder.open();
        push_column(qb, at);
        qb.push(" = ");
        value.push_bind(qb);
      }
      Ok(builder)
    }
  }

  fn same<A>(_: PhantomData<A>, _: PhantomData<A>) {}

  // The operand is `i64`, NOT `Option<i64>` — which is what makes `eq: Some(None)` a type that
  // does not exist rather than a second, unused spelling of the null test.
  same(
    PhantomData::<
      <Nullable<KeyFilter> as ToDatabaseComparison<Option<i64>, sqlx::Sqlite>>::Comparison,
    >,
    PhantomData::<SqlNullable<KeyComparison<i64>, i64>>,
  );
}

/// The TWO-FUNCTION entry: `f` takes the whole wrapped filter, so a caller whose two hops really
/// are two functions writes them out.
///
/// It was once claimed here that this shape is *what lets a nullable column use a declared
/// converter* — and that was false. A declaration names ONE operand leg, the record's crossing
/// spells one call with it, and this entry's argument is a filter, so the declared case could not
/// reach it at all. The nesting below is the composition
/// [`try_from_filter_with`](SqlNullable::try_from_filter_with) now does on the caller's behalf, and
/// pinning it here is what keeps the two entries agreeing about the answer.
#[test]
fn the_two_function_entry_nests_the_inner_kinds_own_crossing() {
  let filter = Nullable::new(ScalarFilter::<u8>::new().with_eq(3u8)).with_null(true);
  let crossed = SqlNullable::<_, i64>::try_from_filter_with_inner(filter, |inner| {
    SqlScalarComparison::<i64, ()>::try_from_filter_with(inner, |v: u8| {
      Ok::<_, core::convert::Infallible>(i64::from(v) * 10)
    })
  })
  .unwrap();

  assert_eq!(crossed.inner().eq(), Some(&30));
  assert_eq!(crossed.null(), Some(true));
}

/// **THE SINGLE-CONVERTER ENTRY, which is the one a DECLARED converter reaches** — one operand
/// function, and the wrapper composes it with the inner kind's own crossing.
///
/// The same conversion as the test above and the same answer, written the way `emit::cross` spells
/// it: `<held>::try_from_filter_with(filter, converter)`, with the converter taking ONE OPERAND —
/// the argument every flat kind's entry of this name takes.
#[test]
fn one_operand_converter_crosses_the_wrapper_the_way_every_flat_kind_takes_one() {
  let filter = Nullable::new(ScalarFilter::<u8>::new().with_eq(3u8)).with_null(true);
  let crossed =
    SqlNullable::<SqlScalarComparison<i64, ()>, i64>::try_from_filter_with(filter, |v: u8| {
      Ok::<_, core::convert::Infallible>(i64::from(v) * 10)
    })
    .unwrap();

  assert_eq!(crossed.inner().eq(), Some(&30));
  assert_eq!(
    crossed.null(),
    Some(true),
    "the null test names no value, so no converter is asked about it"
  );
}

#[cfg(feature = "sqlite")]
mod sqlite {
  use core::{cell::RefCell, convert::Infallible};

  use crate::{
    At, ColumnName, ColumnShape, ComplexComparison, FieldName, Nullable, ScalarFilter,
    comparison::{
      CompositeComparison, TryFromFilter,
      sql::{
        SqlConjunction, SqlLoweringError, SqlNullable, SqlScalarComparison,
        tests::{Probe, render, threaded},
      },
    },
  };

  type Column = SqlNullable<SqlScalarComparison<i64, sqlx::Sqlite>, i64>;

  /// The same equation as `the_column_option_lands_on_the_wrapper_and_not_on_the_operands`, over the
  /// crate's own kinds and a real dialect: a `Option<i64>` column crosses into a wrapper around an
  /// `i64` comparison, not around an `Option<i64>` one.
  ///
  /// The nested spelling is what a lowering could not read: `SqlScalarComparison<Option<i64>, _>`
  /// binds `None` as SQL `NULL` under `=`, which matches no row, so `eq: Some(None)` and
  /// `null: Some(true)` would be two spellings of one question with only one of them answerable.
  #[test]
  fn a_nullable_columns_operands_are_not_themselves_nullable() {
    use core::marker::PhantomData;

    use crate::comparison::ToDatabaseComparison;

    fn same<A>(_: PhantomData<A>, _: PhantomData<A>) {}

    same(
      PhantomData::<
        <Nullable<ScalarFilter<i64>> as ToDatabaseComparison<
          Option<i64>,
          sqlx::Sqlite,
        >>::Comparison,
      >,
      PhantomData::<Column>,
    );

    // And the operand reads back at the bare type, which is the value-level half of the same claim.
    let crossed = Column::try_from_filter(
      Nullable::new(ScalarFilter::<i64>::new().with_eq(1i64)).with_null(true),
    )
    .unwrap();
    let operand: Option<&i64> = crossed.inner().eq();
    assert_eq!(operand, Some(&1));
  }

  /// The null test is appended LAST and binds nothing — `IS NULL` takes no operand.
  #[test]
  fn the_null_test_closes_the_clause_and_binds_nothing() {
    let crossed = Column::try_from_filter(
      Nullable::new(ScalarFilter::<i64>::new().with_eq(1i64)).with_null(false),
    )
    .unwrap();

    assert_eq!(
      render::<sqlx::Sqlite, _>("n", &crossed),
      ("\"n\" = ? AND \"n\" IS NOT NULL".to_owned(), 1)
    );
  }

  /// Negation is the OPERATOR rather than a `NOT ( … )` wrap: under SQL's three-valued logic
  /// `NOT ( "n" = ? )` is UNKNOWN for a null row where `IS NOT NULL` is true, so the two spellings
  /// are different questions and only one of them is this one.
  #[test]
  fn the_null_test_negates_by_operator() {
    let is_null =
      Column::try_from_filter(Nullable::new(ScalarFilter::<i64>::new()).with_null(true)).unwrap();
    let is_not_null =
      Column::try_from_filter(Nullable::new(ScalarFilter::<i64>::new()).with_null(false)).unwrap();

    assert_eq!(
      render::<sqlx::Sqlite, _>("n", &is_null),
      ("\"n\" IS NULL".to_owned(), 0)
    );
    assert_eq!(
      render::<sqlx::Sqlite, _>("n", &is_not_null),
      ("\"n\" IS NOT NULL".to_owned(), 0)
    );
  }

  /// A `NOT NULL` column's comparison renders exactly what the wrapped one does minus the null test
  /// — the wrapper adds an operator and changes nothing else.
  #[test]
  fn the_wrapper_adds_only_the_null_test() {
    let bare = SqlScalarComparison::<i64, sqlx::Sqlite>::try_from_filter(
      ScalarFilter::<i64>::new().with_eq(1i64),
    )
    .unwrap();
    let wrapped =
      Column::try_from_filter(Nullable::new(ScalarFilter::<i64>::new().with_eq(1i64))).unwrap();

    assert_eq!(
      render::<sqlx::Sqlite, _>("n", &bare),
      render::<sqlx::Sqlite, _>("n", &wrapped)
    );
  }

  /// The first COMPOSITE, and what it proves: the wrapper hands its inner comparison exactly the
  /// accumulator it was handed, so the inner's conjuncts and the wrapper's own null test land in one
  /// clause, in that order. Recursion needs no state of its own because there is none to thread —
  /// the child receives what the parent held.
  #[test]
  fn the_wrapper_threads_its_inner_the_accumulator_it_was_handed() {
    let crossed = Column::try_from_filter(
      Nullable::new(ScalarFilter::<i64>::new().with_eq(1i64).with_gt(3i64)).with_null(false),
    )
    .unwrap();

    assert_eq!(
      threaded::<sqlx::Sqlite, _>("n", &crossed),
      "SELECT \"id\" FROM \"t\" WHERE \"n\" = ? AND \"n\" > ? AND \"n\" IS NOT NULL"
    );
  }

  /// Two levels deep, and each level appends AFTER its child: the scalar's conjunct, then the inner
  /// wrapper's null test, then the outer wrapper's. The predicate is deliberately unsatisfiable —
  /// what it pins is the ORDER, which is the only thing a second level can get wrong that a first
  /// cannot.
  #[test]
  fn nesting_composes_with_no_layer_knowing_the_depth() {
    let crossed = SqlNullable::<Column, i64>::try_from_filter(
      Nullable::new(Nullable::new(ScalarFilter::<i64>::new().with_eq(1i64)).with_null(true))
        .with_null(false),
    )
    .unwrap();

    assert_eq!(
      threaded::<sqlx::Sqlite, _>("n", &crossed),
      "SELECT \"id\" FROM \"t\" WHERE \"n\" = ? AND \"n\" IS NULL AND \"n\" IS NOT NULL"
    );
    assert_eq!(ComplexComparison::<sqlx::Sqlite>::conjuncts(&crossed), 3);
  }

  /// The count is the whole SUBTREE's, because the question a caller asks with it is whether
  /// anything at all will be rendered — and the wrapper is the first kind for which its own
  /// operators are not the answer.
  ///
  /// Fully qualified because it has to be: this type has a `conjuncts` on each of the two lowering
  /// traits and no inherent one, so an unqualified call is ambiguous.
  #[test]
  fn the_conjunct_count_is_the_whole_subtree() {
    let both = Column::try_from_filter(
      Nullable::new(ScalarFilter::<i64>::new().with_eq(1i64).with_gt(3i64)).with_null(false),
    )
    .unwrap();
    let inner_only =
      Column::try_from_filter(Nullable::new(ScalarFilter::<i64>::new().with_eq(1i64))).unwrap();
    let null_only =
      Column::try_from_filter(Nullable::new(ScalarFilter::<i64>::new()).with_null(true)).unwrap();
    let neither = Column::try_from_filter(Nullable::new(ScalarFilter::<i64>::new())).unwrap();

    assert_eq!(ComplexComparison::<sqlx::Sqlite>::conjuncts(&both), 3);
    assert_eq!(ComplexComparison::<sqlx::Sqlite>::conjuncts(&inner_only), 1);
    assert_eq!(ComplexComparison::<sqlx::Sqlite>::conjuncts(&null_only), 1);
    assert_eq!(ComplexComparison::<sqlx::Sqlite>::conjuncts(&neither), 0);
    assert!(ComplexComparison::<sqlx::Sqlite>::is_empty(&neither));
  }

  /// The operands are the INNER comparison's and the null test binds none of them, so a wrapper
  /// that dropped or reordered what it threads down is invisible in the text: two of these render
  /// byte-identically and bind in opposite order.
  #[test]
  fn the_wrapper_binds_its_inner_operands_and_adds_none() {
    let bound = RefCell::new(Vec::new());
    let crossed = SqlNullable::<_, i64>::try_from_filter_with_inner(
      Nullable::new(ScalarFilter::<i64>::new().with_eq(1i64).with_gt(3i64)).with_null(true),
      |inner| {
        SqlScalarComparison::<Probe<'_>, sqlx::Sqlite>::try_from_filter_with(inner, |value| {
          Ok::<_, Infallible>(Probe {
            value,
            bound: &bound,
          })
        })
      },
    )
    .unwrap();

    let sql = threaded::<sqlx::Sqlite, _>("n", &crossed);

    assert_eq!(
      sql,
      "SELECT \"id\" FROM \"t\" WHERE \"n\" = ? AND \"n\" > ? AND \"n\" IS NULL"
    );
    assert_eq!(*bound.borrow(), [1, 3]);
  }

  /// A comparison of two columns, declared here because no shipped kind is one: every kind in this
  /// crate occupies exactly one column, and the composite case is the RECORD's own comparison, which
  /// only an expansion writes.
  ///
  /// It pushes a frame per part, which is the whole of what makes it a composite.
  struct Ratio {
    num: SqlScalarComparison<i64, sqlx::Sqlite>,
    den: SqlScalarComparison<i64, sqlx::Sqlite>,
  }

  impl ComplexComparison<sqlx::Sqlite> for Ratio {
    fn conjuncts(&self) -> usize {
      ComplexComparison::<sqlx::Sqlite>::conjuncts(&self.num)
        + ComplexComparison::<sqlx::Sqlite>::conjuncts(&self.den)
    }

    fn apply<'q>(
      &'q self,
      at: At<'_>,
      builder: SqlConjunction<'q, sqlx::Sqlite>,
    ) -> Result<SqlConjunction<'q, sqlx::Sqlite>, SqlLoweringError> {
      let num = at.frame(FieldName::new("num"));
      let builder = self.num.apply(num.at(), builder)?;
      let den = at.frame(FieldName::new("den"));
      self.den.apply(den.at(), builder)
    }
  }

  impl CompositeComparison<sqlx::Sqlite> for Ratio {
    const SEGMENTS: &'static [ColumnShape] = &[
      ColumnShape::Plain(ColumnName::new("num")),
      ColumnShape::Plain(ColumnName::new("den")),
    ];
  }

  /// The VALUE the comparison above is over — the type a declaration would have written, and what
  /// the wrapper's second parameter is for.
  ///
  /// A separate type from [`Ratio`] because the two answer different questions: `Ratio` is HOW a
  /// filter lowers and this is WHAT the column holds. The null test reads this one, deliberately —
  /// the storage type's `SEGMENTS` is the same `const` the row's `COLUMNS` and its `CREATE TABLE`
  /// read, so a null test built from it cannot name a column the schema does not have.
  struct Aspect;

  impl crate::ColumnKind for Aspect {
    const SEGMENTS: &'static [ColumnShape] = <Ratio as CompositeComparison<sqlx::Sqlite>>::SEGMENTS;
  }

  /// The same VALUE with a DERIVED leaf beside its two — the shipped citizens' shape, in miniature.
  ///
  /// `norm` is what `at_nanos` is: an index the write computes, `NULL` for a value it cannot place,
  /// and no part of what the column holds.
  struct Reduced;

  impl crate::ColumnKind for Reduced {
    const SEGMENTS: &'static [ColumnShape] = &[
      ColumnShape::Plain(ColumnName::new("num")),
      ColumnShape::Plain(ColumnName::new("den")),
      ColumnShape::Nullable(ColumnName::new("norm")),
    ];
  }

  /// `Option<Timebase>` is flattenable exactly where `Timebase` is: the wrapper claims the refinement
  /// when its inner does, and reports the segments its inner reports.
  ///
  /// Nullability is orthogonal to how many columns a value occupies, and this row is what says so —
  /// without it a nullable composite would be unflattenable while the same type unwrapped was not.
  ///
  /// The forwarding cannot silently become a blanket: `SEGMENTS` is `C`'s, so an impl that dropped
  /// the bound would have no value to give and would not compile.
  #[test]
  fn the_wrapper_is_a_composite_when_its_inner_is_and_forwards_the_segments() {
    fn segments<C: CompositeComparison<sqlx::Sqlite>>() -> &'static [ColumnShape] {
      C::SEGMENTS
    }

    const PARTS: [ColumnShape; 2] = [
      ColumnShape::Plain(ColumnName::new("num")),
      ColumnShape::Plain(ColumnName::new("den")),
    ];
    assert_eq!(segments::<Ratio>(), PARTS);
    assert_eq!(segments::<SqlNullable<Ratio, Aspect>>(), PARTS);
  }

  fn ratio() -> Ratio {
    Ratio {
      num: SqlScalarComparison::try_from_filter(ScalarFilter::<i64>::new().with_eq(16i64)).unwrap(),
      den: SqlScalarComparison::try_from_filter(ScalarFilter::<i64>::new().with_eq(9i64)).unwrap(),
    }
  }

  /// **A COMPOSITE'S NULL TEST IS ITS VALUE COLUMNS', CONJUNCTIVELY** — and the identifier it used
  /// to render is the whole reason this changed.
  ///
  /// The wrapper once pushed the test at the address it was handed, which for a composite is the
  /// FIELD: `"aspect" IS NOT NULL`, naming a column no `CREATE TABLE` ever wrote. Nothing caught it
  /// because nothing could reach it — an optional composite had no read face, so no declaration
  /// could produce one. The moment `Option<Composite>` became loadable that predicate became
  /// reachable, and this is what it renders instead.
  ///
  /// Bracketed, because the test is ONE conjunct of the surrounding clause and `conjuncts` still
  /// counts it as one.
  #[test]
  fn a_nullable_composite_tests_every_one_of_its_value_columns() {
    let crossed = SqlNullable::<_, Aspect> {
      inner: ratio(),
      null: Some(false),
      value: core::marker::PhantomData,
    };

    assert_eq!(
      render::<sqlx::Sqlite, _>("aspect", &crossed),
      (
        "\"aspect_num\" = ? AND \"aspect_den\" = ? AND (\"aspect_num\" IS NOT NULL AND \
         \"aspect_den\" IS NOT NULL)"
          .to_owned(),
        2
      )
    );
  }

  /// **AND A DERIVED LEAF IS NOT ONE OF THEM.** `norm` is in the row, in the `SELECT` list and in
  /// the `CREATE TABLE`, and it is absent from both directions of the presence test.
  ///
  /// This is the interlock the two rulings meet at, asked of the filter rather than of the decode: a
  /// derived column is `NULL` for a value that IS there and cannot be placed, so `isNull: true` over
  /// a set including it would select rows holding values — and `isNull: false` over it would omit
  /// them. Both would disagree with the read, which answers `Some` for exactly those rows.
  #[test]
  fn a_derived_leaf_is_in_neither_direction_of_the_null_test() {
    let absent = SqlNullable::<_, Reduced> {
      inner: ratio(),
      null: Some(true),
      value: core::marker::PhantomData,
    };

    let (sql, _) = render::<sqlx::Sqlite, _>("aspect", &absent);
    assert!(
      sql.ends_with("(\"aspect_num\" IS NULL AND \"aspect_den\" IS NULL)"),
      "the test is the two VALUE columns and closes there: {sql}"
    );
    assert!(
      !sql.contains("aspect_norm"),
      "the derived column takes no part in whether the field is there: {sql}"
    );
  }

  /// **A SHAPE WITH NO VALUE COLUMN IS NEVER ABSENT, AND THE TWO DIRECTIONS SAY SO DIFFERENTLY.**
  ///
  /// No shipped type is one — a composite whose leaves were all derived would have no value to
  /// derive them FROM — but the walk can be handed a shape a person wrote, so it answers rather
  /// than assuming. `Assemble`'s own row calls such a value present, so asking for the ABSENT rows
  /// must select none and asking for the PRESENT ones must select all.
  ///
  /// Dropping the term instead is the trap this pins: an empty conjunct would make `isNull: true`
  /// mean *every row*, which is the opposite of the answer.
  #[test]
  fn a_shape_with_no_value_column_is_never_absent_and_always_present() {
    struct Indexed;

    impl crate::ColumnKind for Indexed {
      const SEGMENTS: &'static [ColumnShape] = &[ColumnShape::Nullable(ColumnName::new("norm"))];
    }

    let test = |null| {
      render::<sqlx::Sqlite, _>(
        "aspect",
        &SqlNullable::<_, Indexed> {
          inner: ratio(),
          null: Some(null),
          value: core::marker::PhantomData,
        },
      )
      .0
    };

    assert!(test(true).ends_with("(FALSE)"), "{}", test(true));
    assert!(test(false).ends_with("(TRUE)"), "{}", test(false));
  }

  /// A SCALAR renders exactly what it always did — one column, no brackets — which is what says the
  /// value parameter bought the composite case and cost the flat one nothing.
  #[test]
  fn a_scalar_null_test_is_unchanged() {
    let crossed =
      Column::try_from_filter(Nullable::new(ScalarFilter::<i64>::new()).with_null(true)).unwrap();

    assert_eq!(
      render::<sqlx::Sqlite, _>("n", &crossed),
      ("\"n\" IS NULL".to_owned(), 0)
    );
  }
}