-
Notifications
You must be signed in to change notification settings - Fork 0
/
Parameters.scala
37 lines (29 loc) · 987 Bytes
/
Parameters.scala
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
package parameterizedQueries
import cats.effect.unsafe.implicits.global
import org.scalatest.funsuite.AnyFunSuite
class Parameters extends AnyFunSuite {
test("parameters") {
import skunk._
import skunk.implicits._
import skunk.codec.all._
import skunkrecipes.Setup
case class Country(code: String, name: String, pop: Int, gnp: Option[BigDecimal])
val country: Decoder[Country] = (bpchar(3) *: varchar *: int4 *: numeric(10, 2).opt).to[Country]
val f =
sql"""
select code, name, population, gnp
from country
where population > $int4
and population < $int4
""".query(country)
val mySelect = Setup.session.use(_.prepare(f).flatMap { ps =>
ps.stream((150000000 , 200000000), 64).take(2).compile.to(List)
})
assert(
mySelect.unsafeRunSync() == List(
Country("BRA", "Brazil", 170115000, Some(776739.0)),
Country("PAK", "Pakistan", 156483000, Some(61289.0))
)
)
}
}