Skip to content

Commit 5a16feb

Browse files
author
Cosmin Ciobanu
committed
Define new ExtendedQueryTest suite
1 parent d21cffb commit 5a16feb

File tree

1 file changed

+63
-0
lines changed

1 file changed

+63
-0
lines changed
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
// Copyright (c) 2018-2021 by Rob Norris
2+
// This software is licensed under the MIT License (MIT).
3+
// For more information see LICENSE or https://opensource.org/licenses/MIT
4+
5+
import fs2.Stream
6+
import shapeless._
7+
import skunk.codec.all._
8+
import skunk.implicits._
9+
import tests.SkunkTest
10+
11+
class ExtendedQueryTest extends SkunkTest {
12+
13+
sessionTest("parameterized simple") { s =>
14+
val query =
15+
sql"""
16+
SELECT name, region FROM country
17+
WHERE continent = $varchar
18+
AND population > $int4
19+
""".query(varchar *: varchar)
20+
21+
val countryStream = for {
22+
preparedQuery <- Stream.eval(s.prepare(query))
23+
country <- preparedQuery.stream("Europe" :: 10_000_000 :: HNil, chunkSize = 5)
24+
} yield country
25+
26+
countryStream.compile.toList.map(_ => "ok")
27+
}
28+
29+
sessionTest("parameterized w/ list (legacy twiddle)") { s =>
30+
import skunk.feature.legacyCommandSyntax
31+
val continents = List("Europe", "Asia")
32+
val query =
33+
sql"""
34+
SELECT name, region FROM country
35+
WHERE continent IN (${varchar.list(continents)})
36+
AND population > $int4
37+
""".query(varchar ~ varchar)
38+
39+
val countryStream = for {
40+
preparedQuery <- Stream.eval(s.prepare(query))
41+
country <- preparedQuery.stream((continents, 10_000_000), chunkSize = 5)
42+
} yield country
43+
44+
countryStream.compile.toList.map(_ => "ok")
45+
}
46+
47+
sessionTest("parameterized w/ list") { s =>
48+
val continents = List("Europe", "Asia")
49+
val query = sql"""
50+
SELECT name, region FROM country
51+
WHERE continent IN (${varchar.list(continents)})
52+
AND population > $int4
53+
""".query(varchar *: varchar)
54+
55+
val countryStream = for {
56+
preparedQuery <- Stream.eval(s.prepare(query))
57+
country <- preparedQuery.stream(continents :: 10_000_000 :: HNil, chunkSize = 5)
58+
} yield country
59+
60+
countryStream.compile.toList.map(_ => "ok")
61+
}
62+
63+
}

0 commit comments

Comments
 (0)