Skip to content

Commit

Permalink
Define new ExtendedQueryTest suite
Browse files Browse the repository at this point in the history
  • Loading branch information
Cosmin Ciobanu committed Jun 13, 2023
1 parent d21cffb commit 5a16feb
Showing 1 changed file with 63 additions and 0 deletions.
63 changes: 63 additions & 0 deletions modules/tests/shared/src/test/scala/ExtendedQueryTest.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
// Copyright (c) 2018-2021 by Rob Norris
// This software is licensed under the MIT License (MIT).
// For more information see LICENSE or https://opensource.org/licenses/MIT

import fs2.Stream
import shapeless._
import skunk.codec.all._
import skunk.implicits._
import tests.SkunkTest

class ExtendedQueryTest extends SkunkTest {

sessionTest("parameterized simple") { s =>
val query =
sql"""
SELECT name, region FROM country
WHERE continent = $varchar
AND population > $int4
""".query(varchar *: varchar)

val countryStream = for {
preparedQuery <- Stream.eval(s.prepare(query))
country <- preparedQuery.stream("Europe" :: 10_000_000 :: HNil, chunkSize = 5)
} yield country

countryStream.compile.toList.map(_ => "ok")
}

sessionTest("parameterized w/ list (legacy twiddle)") { s =>
import skunk.feature.legacyCommandSyntax
val continents = List("Europe", "Asia")
val query =
sql"""
SELECT name, region FROM country
WHERE continent IN (${varchar.list(continents)})
AND population > $int4
""".query(varchar ~ varchar)

val countryStream = for {
preparedQuery <- Stream.eval(s.prepare(query))
country <- preparedQuery.stream((continents, 10_000_000), chunkSize = 5)
} yield country

countryStream.compile.toList.map(_ => "ok")
}

sessionTest("parameterized w/ list") { s =>
val continents = List("Europe", "Asia")
val query = sql"""
SELECT name, region FROM country
WHERE continent IN (${varchar.list(continents)})
AND population > $int4
""".query(varchar *: varchar)

val countryStream = for {
preparedQuery <- Stream.eval(s.prepare(query))
country <- preparedQuery.stream(continents :: 10_000_000 :: HNil, chunkSize = 5)
} yield country

countryStream.compile.toList.map(_ => "ok")
}

}

0 comments on commit 5a16feb

Please sign in to comment.