@@ -10,7 +10,7 @@ import cats.{Apply, Show}
10
10
import dataprism .PlatformFunSuite .DbToTest
11
11
import dataprism .platform .sql .SqlQueryPlatform
12
12
import dataprism .platform .sql .value .SqlBitwiseOps
13
- import dataprism .sql .{NullabilityTypeChoice , SqlNull }
13
+ import dataprism .sql .{NullabilityTypeChoice , Nullable , SqlNull }
14
14
import org .scalacheck .cats .implicits .*
15
15
import org .scalacheck .{Arbitrary , Gen }
16
16
import perspective .Id
@@ -35,7 +35,7 @@ trait PlatformDbValueSuite[Codec0[_], Platform <: SqlQueryPlatform { type Codec[
35
35
def testEquality [A , N [_]: Apply ](
36
36
tpe : Type [N [A ]],
37
37
gen : Gen [N [A ]]
38
- )(using N : Nullability .Aux [N [A ], A , N ])(using Show [N [A ]]): Unit =
38
+ )(using N : Nullability .Aux [N [A ], N ])(using Show [N [A ]]): Unit =
39
39
typeTest(" Equality" , tpe):
40
40
configuredForall((gen, gen).tupled): (a : N [A ], b : N [A ]) =>
41
41
Select (
@@ -107,7 +107,6 @@ trait PlatformDbValueSuite[Codec0[_], Platform <: SqlQueryPlatform { type Codec[
107
107
testEquality[A , Id ](tpe, gen)
108
108
109
109
def testEqualityNullable [A : Show ](tpe : Type [A ], gen : Gen [A ])(using NotGiven [SqlNull <:< A ]): Unit =
110
- import dataprism .sql .sqlNullSyntax .given
111
110
testEquality[A , Nullable ](
112
111
tpe.choice.asInstanceOf [NullabilityTypeChoice [Codec , A , tpe.Dimension ]].nullable,
113
112
sqlNullGen(gen)
@@ -144,7 +143,7 @@ trait PlatformDbValueSuite[Codec0[_], Platform <: SqlQueryPlatform { type Codec[
144
143
SqlNumericSumAverage [N [A ], SumResult , AvgResult ],
145
144
Show [N [A ]]
146
145
)(
147
- using N : Nullability .Aux [N [A ], A , N ]
146
+ using N : Nullability .Aux [N [A ], N ]
148
147
): Unit =
149
148
import Numeric .Implicits .*
150
149
import Ordering .Implicits .*
@@ -176,8 +175,6 @@ trait PlatformDbValueSuite[Codec0[_], Platform <: SqlQueryPlatform { type Codec[
176
175
expect(((a * b) - abMul).abs <= delta),
177
176
expect(((b * a) - baMul).abs <= delta),
178
177
expect {
179
- import dataprism .sql .sqlNullSyntax .*
180
-
181
178
val lhs = if b == Numeric [N [A ]].zero then None else N .wrapOption(a / b)
182
179
val rhs : Option [A ] = N .nullableToOption(abDiv)
183
180
@@ -186,8 +183,6 @@ trait PlatformDbValueSuite[Codec0[_], Platform <: SqlQueryPlatform { type Codec[
186
183
.getOrElse(lhs.isEmpty && rhs.isEmpty)
187
184
},
188
185
expect {
189
- import dataprism .sql .sqlNullSyntax .*
190
-
191
186
val lhs = if a == Numeric [N [A ]].zero then None else N .wrapOption(b / a)
192
187
val rhs : Option [A ] = N .nullableToOption(baDiv)
193
188
@@ -241,7 +236,7 @@ trait PlatformDbValueSuite[Codec0[_], Platform <: SqlQueryPlatform { type Codec[
241
236
Ordering [N [A ]],
242
237
SqlOrdered [N [A ]],
243
238
Show [N [A ]]
244
- )(using N : Nullability .Aux [N [A ], A , N ]): Unit =
239
+ )(using N : Nullability .Aux [N [A ], N ]): Unit =
245
240
import Ordering .Implicits .*
246
241
typeTest(" Ordered" , tpe):
247
242
configuredForall((gen, gen).tupled): (a : N [A ], b : N [A ]) =>
@@ -274,14 +269,12 @@ trait PlatformDbValueSuite[Codec0[_], Platform <: SqlQueryPlatform { type Codec[
274
269
_ <- log.debug(s " Got max= ${maxMin._1} min= ${maxMin._2}" )
275
270
_ <- log.debug(s " Got greatest= ${greatestLeast._1} least= ${greatestLeast._2}" )
276
271
yield
277
- import dataprism .sql .sqlNullSyntax .*
278
-
279
272
val (max, min) = maxMin
280
273
val (greatest, least) = greatestLeast
281
274
val someVs = vs.toList.flatMap(N .wrapOption(_))
282
275
Seq (
283
- expect.same(someVs.maxOption, max.toOption),
284
- expect.same(someVs.minOption, min.toOption),
276
+ expect.same(someVs.maxOption, Nullable .syntax( max) .toOption),
277
+ expect.same(someVs.minOption, Nullable .syntax( min) .toOption),
285
278
expect.same(
286
279
if leastGreatestBubbleNulls && someVs.length != vs.length then None
287
280
else N .wrapOption(vs.toList.filter(_ != SqlNull ).max),
@@ -306,7 +299,6 @@ trait PlatformDbValueSuite[Codec0[_], Platform <: SqlQueryPlatform { type Codec[
306
299
cats.Order [Nullable [A ]],
307
300
SqlOrdered [Nullable [A ]]
308
301
): Unit =
309
- import dataprism .sql .sqlNullSyntax .given
310
302
testOrdered[A , Nullable ](
311
303
tpe.choice.asInstanceOf [NullabilityTypeChoice [Codec , A , tpe.Dimension ]].nullable,
312
304
sqlNullGen(gen)
@@ -338,10 +330,10 @@ trait PlatformDbValueSuite[Codec0[_], Platform <: SqlQueryPlatform { type Codec[
338
330
)
339
331
).runOne[F ]
340
332
.map: (abOr, baOr, abAnd, baAnd, aNot, bNot, abnOr, banOr, abnAnd, banAnd, anNot, bnNot) =>
341
- import dataprism .sql .sqlNullSyntax .{* , given }
342
333
import cats .syntax .all .*
343
334
344
- def sqlNullWhen [A ](cond : Boolean )(v : A ) = if cond then v else SqlNull
335
+ def sqlNullWhen [A ](cond : Boolean )(v : A )(using NotGiven [SqlNull <:< A ]): Nullable .NullableSyntax [A ] =
336
+ Nullable .unsafeSyntax(if cond then v else SqlNull )
345
337
346
338
Seq (
347
339
expect.same(a || b, abOr),
@@ -351,18 +343,28 @@ trait PlatformDbValueSuite[Codec0[_], Platform <: SqlQueryPlatform { type Codec[
351
343
expect.same(! a, aNot),
352
344
expect.same(! b, bNot),
353
345
//
354
- expect.same(sqlNullWhen(an.contains(true ) || bn.contains(true ))(true ).orElse(an.map2(bn)(_ || _)), abnOr),
355
- expect.same(sqlNullWhen(an.contains(true ) || bn.contains(true ))(true ).orElse(bn.map2(an)(_ || _)), banOr),
356
346
expect.same(
357
- sqlNullWhen(an.contains(false ) || bn.contains(false ))(false ).orElse(an.map2(bn)(_ && _)),
347
+ sqlNullWhen(Nullable .syntax(an).contains(true ) || Nullable .syntax(bn).contains(true ))(true )
348
+ .orElse(Nullable .syntax(an).map2(Nullable .syntax(bn))(_ || _)),
349
+ abnOr
350
+ ),
351
+ expect.same(
352
+ sqlNullWhen(Nullable .syntax(an).contains(true ) || Nullable .syntax(bn).contains(true ))(true )
353
+ .orElse(Nullable .syntax(bn).map2(Nullable .syntax(an))(_ || _)),
354
+ banOr
355
+ ),
356
+ expect.same(
357
+ sqlNullWhen(Nullable .syntax(an).contains(false ) || Nullable .syntax(bn).contains(false ))(false )
358
+ .orElse(Nullable .syntax(an).map2(Nullable .syntax(bn))(_ && _)),
358
359
abnAnd
359
360
),
360
361
expect.same(
361
- sqlNullWhen(an.contains(false ) || bn.contains(false ))(false ).orElse(bn.map2(an)(_ && _)),
362
+ sqlNullWhen(Nullable .syntax(an).contains(false ) || Nullable .syntax(bn).contains(false ))(false )
363
+ .orElse(Nullable .syntax(bn).map2(Nullable .syntax(an))(_ && _)),
362
364
banAnd
363
365
),
364
- expect.same(an .map(! _), anNot),
365
- expect.same(bn .map(! _), bnNot)
366
+ expect.same(Nullable .syntax(an) .map(! _), anNot),
367
+ expect.same(Nullable .syntax(bn) .map(! _), bnNot)
366
368
).combineAll
367
369
368
370
def testNullOps [A : Show ](t : Type [A | SqlNull ], gen : Gen [A ]): Unit = typeTest(" NullOps" , t):
@@ -385,16 +387,17 @@ trait PlatformDbValueSuite[Codec0[_], Platform <: SqlQueryPlatform { type Codec[
385
387
)
386
388
).runOne[F ]
387
389
.map: (r1, r2, r3, r4, r5, r6, r7, r8) =>
388
- import dataprism .sql .sqlNullSyntax .{* , given }
390
+ val o123 = (Nullable .syntax(o1), Nullable .syntax(o2), Nullable .syntax(o3))
391
+
389
392
Seq (
390
393
expect.same(o1, r1),
391
394
expect.same(o1, r2),
392
- expect.same(o1 .flatMap(_ => o2 ), r3),
395
+ expect.same(Nullable .syntax(o1) .flatMap(_ => Nullable .syntax(o2) ), r3),
393
396
expect.same(o1, r4),
394
397
expect.same(SqlNull , r5),
395
- expect.same((o1, o2, o3) .mapN((n1, _, _) => n1), r6),
396
- expect.same((o1, o2, o3) .mapN((_, n2, _) => n2), r7),
397
- expect.same((o1, o2, o3) .mapN((_, _, n3) => n3), r8)
398
+ expect.same(o123 .mapN((n1, _, _) => n1), r6),
399
+ expect.same(o123 .mapN((_, n2, _) => n2), r7),
400
+ expect.same(o123 .mapN((_, _, n3) => n3), r8)
398
401
).combineAll
399
402
400
403
dbTest(" CaseBoolean" ):
@@ -421,7 +424,7 @@ trait PlatformDbValueSuite[Codec0[_], Platform <: SqlQueryPlatform { type Codec[
421
424
)(
422
425
using show : Show [N [A ]],
423
426
bw : bitwisePlatform.Api .SqlBitwise [N [A ]],
424
- N : bitwisePlatform.Nullability .Aux [N [A ], A , N ],
427
+ N : bitwisePlatform.Nullability .Aux [N [A ], N ],
425
428
bool : algebra.lattice.Bool [A ]
426
429
): Unit = typeTest(" BitwiseOps" , tpe):
427
430
import bitwisePlatform .Api .*
0 commit comments