From 5a16feb400818bbe2ed81ad539cf79fd74fcaa90 Mon Sep 17 00:00:00 2001 From: Cosmin Ciobanu Date: Tue, 13 Jun 2023 14:28:20 +0300 Subject: [PATCH] Define new ExtendedQueryTest suite --- .../src/test/scala/ExtendedQueryTest.scala | 63 +++++++++++++++++++ 1 file changed, 63 insertions(+) create mode 100644 modules/tests/shared/src/test/scala/ExtendedQueryTest.scala diff --git a/modules/tests/shared/src/test/scala/ExtendedQueryTest.scala b/modules/tests/shared/src/test/scala/ExtendedQueryTest.scala new file mode 100644 index 00000000..6de46eb4 --- /dev/null +++ b/modules/tests/shared/src/test/scala/ExtendedQueryTest.scala @@ -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") + } + +}