Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Extended query tests #898

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
65 changes: 65 additions & 0 deletions modules/tests/shared/src/test/scala/ExtendedQueryTest.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
// 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

package tests

import fs2.Stream
import skunk._
import skunk.codec.all._
import skunk.implicits._

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 *: EmptyTuple, 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")
}

// Uses import skunk._ for *: and EmptyTuple polyfills; can replace with :: and HNil if preferred
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(new *:(continents, 10_000_000 *: EmptyTuple), chunkSize = 5)
} yield country

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

}