-
Notifications
You must be signed in to change notification settings - Fork 163
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Cosmin Ciobanu
committed
Jun 13, 2023
1 parent
d21cffb
commit 5a16feb
Showing
1 changed file
with
63 additions
and
0 deletions.
There are no files selected for viewing
63 changes: 63 additions & 0 deletions
63
modules/tests/shared/src/test/scala/ExtendedQueryTest.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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") | ||
} | ||
|
||
} |