Skip to content

Commit

Permalink
Fix liftQueryScalar
Browse files Browse the repository at this point in the history
  • Loading branch information
Matthew de Detrich committed Aug 13, 2019
1 parent 9b4f31e commit 60d1499
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,16 @@ class ContextInstanceSpec extends Spec {
}
testContext.run(q).extractor(Row("s")) mustEqual Entity(StringValue("s"))
}

"encoding with set" in {
implicit val testToString = MappedEncoding[StringValue, String](_.s)
implicit val stringToTest = MappedEncoding[String, StringValue](StringValue)
case class Entity(x: StringValue)
val q = quote {
query[Entity].filter(e => liftQueryScalar(Set(StringValue("1"))).contains(e.x))
}
testContext.run(q).prepareRow mustEqual Row("1")
}
}
"package-based" - {
import io.getquill.MappedEncoding
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,6 @@ class PeopleJdbcSpec extends PeopleSpec {
testContext.run(`Ex 2 rangeSimple`(lift(`Ex 2 param 1`), lift(`Ex 2 param 2`))) mustEqual `Ex 2 expected result`
}

"Example 3 - satisfies" in {
testContext.run(`Ex 3 satisfies`) mustEqual `Ex 3 expected result`
}

"Example 4 - satisfies" in {
testContext.run(`Ex 4 satisfies`) mustEqual `Ex 4 expected result`
}
Expand Down Expand Up @@ -57,4 +53,8 @@ class PeopleJdbcSpec extends PeopleSpec {
testContext.run(`Ex 10 page 1 query`) mustEqual `Ex 10 page 1 expected`
testContext.run(`Ex 10 page 2 query`) mustEqual `Ex 10 page 2 expected`
}

"Example 11 - contains non empty with custom encoder/decoder" in {
testContext.run(`Ex 11 contains`(`Ex 11 param`)) mustEqual `Ex 11 expected result`
}
}
19 changes: 19 additions & 0 deletions quill-sql/src/test/scala/io/getquill/context/sql/PeopleSpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,13 @@ trait PeopleSpec extends Spec {

import context._

case class CustomInt(value: Int)

implicit lazy val customIntDecoder = MappedEncoding[CustomInt, Int](_.value)
implicit lazy val customIntEncoder = MappedEncoding[Int, CustomInt](x => CustomInt(x))

case class Person(name: String, age: Int)
case class PersonWithCustomType(name: String, age: CustomInt)
case class Couple(her: String, him: String)

val peopleInsert =
Expand Down Expand Up @@ -131,6 +137,16 @@ trait PeopleSpec extends Spec {
query[Person].filter(p => set.contains(p.age))
}

def `Ex 11 contains`(set: Set[CustomInt]) =
quote {
querySchema[PersonWithCustomType]("public.Person").filter { p =>
if (liftQueryScalar(set).isEmpty)
true
else
liftQueryScalar(set).contains(p.age)
}
}

val `Ex 8 param` = Set.empty[Int]
val `Ex 8 expected result` = List.empty[Person]

Expand All @@ -145,4 +161,7 @@ trait PeopleSpec extends Spec {
query[Person].sortBy(p => p.name)(Ord.asc).drop(3).take(3)
}
val `Ex 10 page 2 expected` = peopleEntries.sortBy(_.name).slice(3, 6)

val `Ex 11 param` = Set(CustomInt(55), CustomInt(33))
val `Ex 11 expected result` = List(PersonWithCustomType("Bert", CustomInt(55)), PersonWithCustomType("Cora", CustomInt(33)))
}

0 comments on commit 60d1499

Please sign in to comment.