Skip to content

Commit 5dcd45a

Browse files
committed
Fix translate spec
1 parent 7eeee32 commit 5dcd45a

File tree

2 files changed

+28
-29
lines changed

2 files changed

+28
-29
lines changed

quill-core/src/main/scala/io/getquill/context/ContextVerbTranslate.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -102,8 +102,8 @@ trait ContextTranslateProto {
102102
options: TranslateOptions = TranslateOptions()
103103
)(executionInfo: ExecutionInfo, dc: Runner): List[String] =
104104
groups.flatMap { group =>
105-
group.prepare.map { _ =>
106-
translateQuery(group.string, options = options)(executionInfo, dc)
105+
(group.prepare zip group.liftings).map { case (_, liftings) =>
106+
translateQuery(group.string, options = options, liftings = liftings)(executionInfo, dc)
107107
}
108108
}
109109

quill-core/src/test/scala/io/getquill/context/ActionMacroSpec.scala

Lines changed: 26 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -379,7 +379,6 @@ class ActionMacroSpec extends Spec {
379379
)
380380
}
381381
}
382-
383382
"translate non-batched action" - {
384383
"normal" in {
385384
val q = quote {
@@ -393,21 +392,21 @@ class ActionMacroSpec extends Spec {
393392
qr1.insert(t => t.i -> lift(1))
394393
}
395394
testContext.translate(q) mustEqual
396-
"""querySchema("TestEntity").insert(t => t.i -> 1)"""
395+
"""querySchema("TestEntity").insert(t => t.i -> lift(1))"""
397396
}
398397
"case class lifting" in {
399398
val q = quote {
400399
qr1.insertValue(lift(TestEntity("s", 1, 2L, None, true)))
401400
}
402401
testContext.translate(q) mustEqual
403-
"""querySchema("TestEntity").insert(v => v.s -> 's', v => v.i -> 1, v => v.l -> 2, v => v.o -> null, v => v.b -> true)"""
402+
"""querySchema("TestEntity").insert(v => v.s -> lift('s'), v => v.i -> lift(1), v => v.l -> lift(2), v => v.o -> lift(None), v => v.b -> lift(true))"""
404403
}
405404
"nested case class lifting" in {
406405
val q = quote { t: TestEntity =>
407406
qr1.insertValue(t)
408407
}
409408
testContext.translate(q(lift(TestEntity("s", 1, 2L, None, true)))) mustEqual
410-
"""querySchema("TestEntity").insert(v => v.s -> 's', v => v.i -> 1, v => v.l -> 2, v => v.o -> null, v => v.b -> true)"""
409+
"""querySchema("TestEntity").insert(v => v.s -> lift('s'), v => v.i -> lift(1), v => v.l -> lift(2), v => v.o -> lift(None), v => v.b -> lift(true))"""
411410
}
412411
"returning value" in {
413412
val q = quote {
@@ -421,21 +420,21 @@ class ActionMacroSpec extends Spec {
421420
qr1.insert(t => t.i -> lift(1)).returning(t => t.l)
422421
}
423422
testContext.translate(q) mustEqual
424-
"""querySchema("TestEntity").insert(t => t.i -> 1).returning((t) => t.l)"""
423+
"""querySchema("TestEntity").insert(t => t.i -> lift(1)).returning((t) => t.l)"""
425424
}
426425
"case class lifting + returning value" in {
427426
val q = quote {
428427
qr1.insertValue(lift(TestEntity("s", 1, 2L, None, true))).returning(t => t.l)
429428
}
430429
testContext.translate(q) mustEqual
431-
"""querySchema("TestEntity").insert(v => v.s -> 's', v => v.i -> 1, v => v.l -> 2, v => v.o -> null, v => v.b -> true).returning((t) => t.l)"""
430+
"""querySchema("TestEntity").insert(v => v.s -> lift('s'), v => v.i -> lift(1), v => v.l -> lift(2), v => v.o -> lift(None), v => v.b -> lift(true)).returning((t) => t.l)"""
432431
}
433432
"case class lifting + returning generated value" in {
434433
val q = quote {
435434
qr1.insertValue(lift(TestEntity("s", 1, 2L, None, true))).returningGenerated(t => t.l)
436435
}
437436
testContext.translate(q) mustEqual
438-
"""querySchema("TestEntity").insert(v => v.s -> 's', v => v.i -> 1, v => v.o -> null, v => v.b -> true).returningGenerated((t) => t.l)"""
437+
"""querySchema("TestEntity").insert(v => v.s -> lift('s'), v => v.i -> lift(1), v => v.o -> lift(None), v => v.b -> lift(true)).returningGenerated((t) => t.l)"""
439438
}
440439
}
441440

@@ -454,17 +453,17 @@ class ActionMacroSpec extends Spec {
454453
liftQuery(List(1, 2)).foreach((p: Int) => insert(p))
455454
}
456455
testContext.translate(q) mustEqual List(
457-
"""querySchema("TestEntity").insert(t => t.i -> 1)""",
458-
"""querySchema("TestEntity").insert(t => t.i -> 2)"""
456+
"""querySchema("TestEntity").insert(t => t.i -> lift(1))""",
457+
"""querySchema("TestEntity").insert(t => t.i -> lift(2))"""
459458
)
460459
}
461460
"case class" in {
462461
val q = quote {
463462
liftQuery(entities).foreach(p => qr1.insertValue(p))
464463
}
465464
testContext.translate(q) mustEqual List(
466-
"""querySchema("TestEntity").insert(v => v.s -> 's1', v => v.i -> 2, v => v.l -> 3, v => v.o -> 4, v => v.b -> true)""",
467-
"""querySchema("TestEntity").insert(v => v.s -> 's5', v => v.i -> 6, v => v.l -> 7, v => v.o -> 8, v => v.b -> false)"""
465+
"""querySchema("TestEntity").insert(v => v.s -> lift('s1'), v => v.i -> lift(2), v => v.l -> lift(3), v => v.o -> lift(Some(4)), v => v.b -> lift(true))""",
466+
"""querySchema("TestEntity").insert(v => v.s -> lift('s5'), v => v.i -> lift(6), v => v.l -> lift(7), v => v.o -> lift(Some(8)), v => v.b -> lift(false))"""
468467
)
469468
}
470469
"case class + nested action" in {
@@ -475,8 +474,8 @@ class ActionMacroSpec extends Spec {
475474
liftQuery(entities).foreach(p => nested(p))
476475
}
477476
testContext.translate(q) mustEqual List(
478-
"""querySchema("TestEntity").insert(v => v.s -> 's1', v => v.i -> 2, v => v.l -> 3, v => v.o -> 4, v => v.b -> true)""",
479-
"""querySchema("TestEntity").insert(v => v.s -> 's5', v => v.i -> 6, v => v.l -> 7, v => v.o -> 8, v => v.b -> false)"""
477+
"""querySchema("TestEntity").insert(v => v.s -> lift('s1'), v => v.i -> lift(2), v => v.l -> lift(3), v => v.o -> lift(Some(4)), v => v.b -> lift(true))""",
478+
"""querySchema("TestEntity").insert(v => v.s -> lift('s5'), v => v.i -> lift(6), v => v.l -> lift(7), v => v.o -> lift(Some(8)), v => v.b -> lift(false))"""
480479
)
481480
}
482481
"tuple + case class + nested action" in {
@@ -487,8 +486,8 @@ class ActionMacroSpec extends Spec {
487486
liftQuery(entities).foreach(p => nested(lift("s"), p))
488487
}
489488
testContext.translate(q) mustEqual List(
490-
"""querySchema("TestEntity").filter(t1 => t1.s == 's').update(v => v.s -> 's1', v => v.i -> 2, v => v.l -> 3, v => v.o -> 4, v => v.b -> true)""",
491-
"""querySchema("TestEntity").filter(t1 => t1.s == 's').update(v => v.s -> 's5', v => v.i -> 6, v => v.l -> 7, v => v.o -> 8, v => v.b -> false)"""
489+
"""querySchema("TestEntity").filter(t1 => t1.s == lift('s')).update(v => v.s -> lift('s1'), v => v.i -> lift(2), v => v.l -> lift(3), v => v.o -> lift(Some(4)), v => v.b -> lift(true))""",
490+
"""querySchema("TestEntity").filter(t1 => t1.s == lift('s')).update(v => v.s -> lift('s5'), v => v.i -> lift(6), v => v.l -> lift(7), v => v.o -> lift(Some(8)), v => v.b -> lift(false))"""
492491
)
493492
}
494493
"zipWithIndex" in {
@@ -499,8 +498,8 @@ class ActionMacroSpec extends Spec {
499498
liftQuery(entities.zipWithIndex).foreach(p => nested(p._1, p._2))
500499
}
501500
testContext.translate(q) mustEqual List(
502-
"""querySchema("TestEntity").filter(t1 => t1.i == 0).update(v => v.s -> 's1', v => v.i -> 2, v => v.l -> 3, v => v.o -> 4, v => v.b -> true)""",
503-
"""querySchema("TestEntity").filter(t1 => t1.i == 1).update(v => v.s -> 's5', v => v.i -> 6, v => v.l -> 7, v => v.o -> 8, v => v.b -> false)"""
501+
"""querySchema("TestEntity").filter(t1 => t1.i == lift(0)).update(v => v.s -> lift('s1'), v => v.i -> lift(2), v => v.l -> lift(3), v => v.o -> lift(Some(4)), v => v.b -> lift(true))""",
502+
"""querySchema("TestEntity").filter(t1 => t1.i == lift(1)).update(v => v.s -> lift('s5'), v => v.i -> lift(6), v => v.l -> lift(7), v => v.o -> lift(Some(8)), v => v.b -> lift(false))"""
504503
)
505504
}
506505
"scalar + returning" in {
@@ -511,44 +510,44 @@ class ActionMacroSpec extends Spec {
511510
liftQuery(List(1, 2)).foreach((p: Int) => insert(p))
512511
}
513512
testContext.translate(q) mustEqual List(
514-
"""querySchema("TestEntity").insert(t => t.i -> 1).returning((t) => t.l)""",
515-
"""querySchema("TestEntity").insert(t => t.i -> 2).returning((t) => t.l)"""
513+
"""querySchema("TestEntity").insert(t => t.i -> lift(1)).returning((t) => t.l)""",
514+
"""querySchema("TestEntity").insert(t => t.i -> lift(2)).returning((t) => t.l)"""
516515
)
517516
}
518517
"case class + returning" in {
519518
val q = quote {
520519
liftQuery(entities).foreach(p => qr1.insertValue(p).returning(t => t.l))
521520
}
522521
testContext.translate(q) mustEqual List(
523-
"""querySchema("TestEntity").insert(v => v.s -> 's1', v => v.i -> 2, v => v.l -> 3, v => v.o -> 4, v => v.b -> true).returning((t) => t.l)""",
524-
"""querySchema("TestEntity").insert(v => v.s -> 's5', v => v.i -> 6, v => v.l -> 7, v => v.o -> 8, v => v.b -> false).returning((t) => t.l)"""
522+
"""querySchema("TestEntity").insert(v => v.s -> lift('s1'), v => v.i -> lift(2), v => v.l -> lift(3), v => v.o -> lift(Some(4)), v => v.b -> lift(true)).returning((t) => t.l)""",
523+
"""querySchema("TestEntity").insert(v => v.s -> lift('s5'), v => v.i -> lift(6), v => v.l -> lift(7), v => v.o -> lift(Some(8)), v => v.b -> lift(false)).returning((t) => t.l)"""
525524
)
526525
}
527526
"case class + returning + nested action" in {
528527
val insert = quote { p: TestEntity =>
529528
qr1.insertValue(p).returning(t => t.l)
530529
}
531530
testContext.translate(liftQuery(entities).foreach(p => insert(p))) mustEqual List(
532-
"""querySchema("TestEntity").insert(v => v.s -> 's1', v => v.i -> 2, v => v.l -> 3, v => v.o -> 4, v => v.b -> true).returning((t) => t.l)""",
533-
"""querySchema("TestEntity").insert(v => v.s -> 's5', v => v.i -> 6, v => v.l -> 7, v => v.o -> 8, v => v.b -> false).returning((t) => t.l)"""
531+
"""querySchema("TestEntity").insert(v => v.s -> lift('s1'), v => v.i -> lift(2), v => v.l -> lift(3), v => v.o -> lift(Some(4)), v => v.b -> lift(true)).returning((t) => t.l)""",
532+
"""querySchema("TestEntity").insert(v => v.s -> lift('s5'), v => v.i -> lift(6), v => v.l -> lift(7), v => v.o -> lift(Some(8)), v => v.b -> lift(false)).returning((t) => t.l)"""
534533
)
535534
}
536535
"case class + returning generated" in {
537536
val q = quote {
538537
liftQuery(entities).foreach(p => qr1.insertValue(p).returningGenerated(t => t.l))
539538
}
540539
testContext.translate(q) mustEqual List(
541-
"""querySchema("TestEntity").insert(v => v.s -> 's1', v => v.i -> 2, v => v.o -> 4, v => v.b -> true).returningGenerated((t) => t.l)""",
542-
"""querySchema("TestEntity").insert(v => v.s -> 's5', v => v.i -> 6, v => v.o -> 8, v => v.b -> false).returningGenerated((t) => t.l)"""
540+
"""querySchema("TestEntity").insert(v => v.s -> lift('s1'), v => v.i -> lift(2), v => v.o -> lift(Some(4)), v => v.b -> lift(true)).returningGenerated((t) => t.l)""",
541+
"""querySchema("TestEntity").insert(v => v.s -> lift('s5'), v => v.i -> lift(6), v => v.o -> lift(Some(8)), v => v.b -> lift(false)).returningGenerated((t) => t.l)"""
543542
)
544543
}
545544
"case class + returning generated + nested action" in {
546545
val insert = quote { p: TestEntity =>
547546
qr1.insertValue(p).returningGenerated(t => t.l)
548547
}
549548
testContext.translate(liftQuery(entities).foreach(p => insert(p))) mustEqual List(
550-
"""querySchema("TestEntity").insert(v => v.s -> 's1', v => v.i -> 2, v => v.o -> 4, v => v.b -> true).returningGenerated((t) => t.l)""",
551-
"""querySchema("TestEntity").insert(v => v.s -> 's5', v => v.i -> 6, v => v.o -> 8, v => v.b -> false).returningGenerated((t) => t.l)"""
549+
"""querySchema("TestEntity").insert(v => v.s -> lift('s1'), v => v.i -> lift(2), v => v.o -> lift(Some(4)), v => v.b -> lift(true)).returningGenerated((t) => t.l)""",
550+
"""querySchema("TestEntity").insert(v => v.s -> lift('s5'), v => v.i -> lift(6), v => v.o -> lift(Some(8)), v => v.b -> lift(false)).returningGenerated((t) => t.l)"""
552551
)
553552
}
554553
}

0 commit comments

Comments
 (0)