Skip to content

Commit cbc1515

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

File tree

1 file changed

+65
-0
lines changed

1 file changed

+65
-0
lines changed
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
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+
package tests
6+
7+
import fs2.Stream
8+
import skunk._
9+
import skunk.codec.all._
10+
import skunk.implicits._
11+
12+
class ExtendedQueryTest extends SkunkTest {
13+
14+
sessionTest("parameterized simple") { s =>
15+
val query =
16+
sql"""
17+
SELECT name, region FROM country
18+
WHERE continent = $varchar
19+
AND population > $int4
20+
""".query(varchar *: varchar)
21+
22+
val countryStream = for {
23+
preparedQuery <- Stream.eval(s.prepare(query))
24+
country <- preparedQuery.stream("Europe" *: 10_000_000 *: EmptyTuple, chunkSize = 5)
25+
} yield country
26+
27+
countryStream.compile.toList.map(_ => "ok")
28+
}
29+
30+
sessionTest("parameterized w/ list (legacy twiddle)") { s =>
31+
import skunk.feature.legacyCommandSyntax
32+
val continents = List("Europe", "Asia")
33+
val query =
34+
sql"""
35+
SELECT name, region FROM country
36+
WHERE continent IN (${varchar.list(continents)})
37+
AND population > $int4
38+
""".query(varchar ~ varchar)
39+
40+
val countryStream = for {
41+
preparedQuery <- Stream.eval(s.prepare(query))
42+
country <- preparedQuery.stream((continents, 10_000_000), chunkSize = 5)
43+
} yield country
44+
45+
countryStream.compile.toList.map(_ => "ok")
46+
}
47+
48+
// Uses import skunk._ for *: and EmptyTuple polyfills; can replace with :: and HNil if preferred
49+
sessionTest("parameterized w/ list") { s =>
50+
val continents = List("Europe", "Asia")
51+
val query = sql"""
52+
SELECT name, region FROM country
53+
WHERE continent IN (${varchar.list(continents)})
54+
AND population > $int4
55+
""".query(varchar *: varchar)
56+
57+
val countryStream = for {
58+
preparedQuery <- Stream.eval(s.prepare(query))
59+
country <- preparedQuery.stream(new *:(continents, 10_000_000 *: EmptyTuple), chunkSize = 5)
60+
} yield country
61+
62+
countryStream.compile.toList.map(_ => "ok")
63+
}
64+
65+
}

0 commit comments

Comments
 (0)