diff --git a/build.sbt b/build.sbt index 7ddefaa2..2f01bbc9 100644 --- a/build.sbt +++ b/build.sbt @@ -102,6 +102,7 @@ lazy val commonSettings = Seq( "org.typelevel" %%% "munit-cats-effect" % munitCatsEffectVersion % "test", "io.circe" %%% "circe-literal" % circeVersion % "test", "io.circe" %%% "circe-jawn" % circeVersion % "test", + "io.circe" %%% "circe-parser" % circeVersion % "test", ) ++ Seq( compilerPlugin("org.typelevel" %% "kind-projector" % kindProjectorVersion cross CrossVersion.full), ).filterNot(_ => tlIsScala3.value), @@ -234,9 +235,7 @@ lazy val doobiecore = project libraryDependencies ++= Seq( "org.tpolecat" %% "doobie-core" % doobieVersion, "org.typelevel" %% "log4cats-core" % log4catsVersion, - "ch.qos.logback" % "logback-classic" % logbackVersion % "test", - // TODO: Needed temporarily for Metas in DoobieDatabaseSuite - "org.tpolecat" %% "doobie-postgres-circe" % doobieVersion % "test" + "ch.qos.logback" % "logback-classic" % logbackVersion % "test" ) ) diff --git a/modules/doobie-core/src/test/scala/DoobieDatabaseSuite.scala b/modules/doobie-core/src/test/scala/DoobieDatabaseSuite.scala index 245292b1..17797179 100644 --- a/modules/doobie-core/src/test/scala/DoobieDatabaseSuite.scala +++ b/modules/doobie-core/src/test/scala/DoobieDatabaseSuite.scala @@ -16,14 +16,9 @@ package grackle.doobie package test -import java.time.{Duration, LocalDate, LocalTime, OffsetDateTime} -import java.util.UUID +import java.time.Duration -// TODO: Postgres-specifics will have to move -import doobie.postgres.implicits._ -import doobie.postgres.circe.jsonb.implicits._ -import doobie.{Get, Meta, Put} -import io.circe.Json +import doobie.Meta import munit.CatsEffectSuite import grackle.sql.test._ @@ -36,7 +31,6 @@ trait DoobieDatabaseSuite extends CatsEffectSuite { def bool: TestCodec[Boolean] = (Meta[Boolean], false) def text: TestCodec[String] = (Meta[String], false) def varchar: TestCodec[String] = (Meta[String], false) - def nvarchar: TestCodec[String] = (Meta[String], false) def bpchar(len: Int): TestCodec[String] = (Meta[String], false) def int2: TestCodec[Int] = (Meta[Int], false) def int4: TestCodec[Int] = (Meta[Int], false) @@ -45,14 +39,8 @@ trait DoobieDatabaseSuite extends CatsEffectSuite { def float8: TestCodec[Double] = (Meta[Double], false) def numeric(precision: Int, scale: Int): TestCodec[BigDecimal] = (Meta[BigDecimal], false) - def uuid: TestCodec[UUID] = (Meta[UUID], false) - def localDate: TestCodec[LocalDate] = (Meta[LocalDate], false) - def localTime: TestCodec[LocalTime] = (Meta[LocalTime], false) - def offsetDateTime: TestCodec[OffsetDateTime] = (Meta[OffsetDateTime], false) def duration: TestCodec[Duration] = (Meta[Long].timap(Duration.ofMillis)(_.toMillis), false) - def jsonb: TestCodec[Json] = (new Meta(Get[Json], Put[Json]), false) - def nullable[T](c: TestCodec[T]): TestCodec[T] = (c._1, true) def list[T](c: TestCodec[T]): TestCodec[List[T]] = { diff --git a/modules/doobie-oracle/src/test/scala/DoobieOracleDatabaseSuite.scala b/modules/doobie-oracle/src/test/scala/DoobieOracleDatabaseSuite.scala index b2834a32..f4dfd89e 100644 --- a/modules/doobie-oracle/src/test/scala/DoobieOracleDatabaseSuite.scala +++ b/modules/doobie-oracle/src/test/scala/DoobieOracleDatabaseSuite.scala @@ -17,7 +17,7 @@ package grackle.doobie.oracle package test import java.sql.Timestamp -import java.time.{LocalTime, OffsetDateTime, ZoneId} +import java.time.{LocalDate, LocalTime, OffsetDateTime, ZoneId} import java.time.format.DateTimeFormatter import java.util.UUID import scala.util.Try @@ -28,6 +28,7 @@ import cats.syntax.all._ import doobie.{Meta, Transactor} import doobie.enumerated.JdbcType import doobie.util.Put +import doobie.util.meta.MetaConstructors.Basic import io.circe.Json import io.circe.parser.parse import munit.catseffect._ @@ -40,43 +41,40 @@ import grackle.sql.test._ trait DoobieOracleDatabaseSuite extends DoobieDatabaseSuite { abstract class DoobieOracleTestMapping[F[_]: Sync](transactor: Transactor[F], monitor: DoobieMonitor[F] = DoobieMonitor.noopMonitor[IO]) extends DoobieOracleMapping[F](transactor, monitor) with DoobieTestMapping[F] with SqlTestMapping[F] { - override val uuid: TestCodec[UUID] = ( - Meta[String].tiemap(s => Try(UUID.fromString(s)).toEither.leftMap(_.getMessage))(_.toString), - false - ) + def mkTestCodec[T](meta: Meta[T]): TestCodec[T] = (meta, false) - val localTimeFormat: DateTimeFormatter = DateTimeFormatter.ofPattern("0 H:m:s.S") - override val localTime: TestCodec[LocalTime] = ( - Meta[String].tiemap(s => Try(LocalTime.parse(s, localTimeFormat)).toEither.leftMap(_.getMessage))(_.format(localTimeFormat)), - false - ) + val uuid: TestCodec[UUID] = + mkTestCodec(Meta[String].tiemap(s => Try(UUID.fromString(s)).toEither.leftMap(_.getMessage))(_.toString)) - // Forget precise time zone for compatibility with Postgres. Nb. this is specific to this test suite. - override val offsetDateTime: TestCodec[OffsetDateTime] = ( - Meta[Timestamp].timap(t => OffsetDateTime.ofInstant(t.toInstant, ZoneId.of("UTC")))(o => Timestamp.from(o.toInstant)), - false - ) + val localTime: TestCodec[LocalTime] = { + val localTimeFormat: DateTimeFormatter = DateTimeFormatter.ofPattern("0 H:m:s.S") + mkTestCodec(Meta[String].tiemap(s => Try(LocalTime.parse(s, localTimeFormat)).toEither.leftMap(_.getMessage))(_.format(localTimeFormat))) + } - val nvarcharMeta: Meta[String] = { - import JdbcType._ - val oldGet = Meta[String].get - val oldPut = Meta[String].put - val newTargets = NonEmptyList.of(NChar, NVarChar, LongnVarChar) - val newPut = - Put.Basic(oldPut.typeStack, newTargets, oldPut.put, oldPut.update, oldPut.vendorTypeNames.headOption) + val localDate: TestCodec[LocalDate] = + (Basic.oneObject(JdbcType.Date, None, classOf[LocalDate]), false) - new Meta[String](oldGet, newPut) + // Forget precise time zone for compatibility with Postgres. Nb. this is specific to this test suite. + val offsetDateTime: TestCodec[OffsetDateTime] = + mkTestCodec(Meta[Timestamp].timap(t => OffsetDateTime.ofInstant(t.toInstant, ZoneId.of("UTC")))(o => Timestamp.from(o.toInstant))) + + val nvarchar: TestCodec[String] = { + val nvarcharMeta: Meta[String] = { + import JdbcType._ + val oldGet = Meta[String].get + val oldPut = Meta[String].put + val newTargets = NonEmptyList.of(NChar, NVarChar, LongnVarChar) + val newPut = + Put.Basic(oldPut.typeStack, newTargets, oldPut.put, oldPut.update, oldPut.vendorTypeNames.headOption) + + new Meta[String](oldGet, newPut) + } + + mkTestCodec(nvarcharMeta) } - override val nvarchar: TestCodec[String] = ( - nvarcharMeta, - false - ) - - override val jsonb: TestCodec[Json] = ( - Meta[String].tiemap(s => parse(s).leftMap(_.getMessage))(_.noSpaces), - false - ) + val jsonb: TestCodec[Json] = + mkTestCodec(Meta[String].tiemap(s => parse(s).leftMap(_.getMessage))(_.noSpaces)) } case class OracleConnectionInfo(host: String, port: Int) { @@ -86,11 +84,13 @@ trait DoobieOracleDatabaseSuite extends DoobieDatabaseSuite { val username = "test" val password = "test" } + object OracleConnectionInfo { val DefaultPort = 1521 } - val oracleConnectionInfo: OracleConnectionInfo = OracleConnectionInfo("localhost", OracleConnectionInfo.DefaultPort) + val oracleConnectionInfo: OracleConnectionInfo = + OracleConnectionInfo("localhost", OracleConnectionInfo.DefaultPort) def transactorResource: Resource[IO, Transactor[IO]] = { val connInfo = oracleConnectionInfo diff --git a/modules/doobie-pg/src/test/scala/DoobiePgDatabaseSuite.scala b/modules/doobie-pg/src/test/scala/DoobiePgDatabaseSuite.scala index e945ac7f..9f5ed80b 100644 --- a/modules/doobie-pg/src/test/scala/DoobiePgDatabaseSuite.scala +++ b/modules/doobie-pg/src/test/scala/DoobiePgDatabaseSuite.scala @@ -16,8 +16,14 @@ package grackle.doobie.postgres package test +import java.time.{LocalDate, LocalTime, OffsetDateTime} +import java.util.UUID + import cats.effect.{IO, Resource, Sync} -import doobie.Transactor +import doobie.{Get, Meta, Put, Transactor} +import doobie.postgres.implicits._ +import doobie.postgres.circe.jsonb.implicits._ +import io.circe.Json import munit.catseffect.IOFixture import grackle.doobie.DoobieMonitor @@ -27,7 +33,14 @@ import grackle.sqlpg.test._ trait DoobiePgDatabaseSuite extends DoobieDatabaseSuite with SqlPgDatabaseSuite { abstract class DoobiePgTestMapping[F[_]: Sync](transactor: Transactor[F], monitor: DoobieMonitor[F] = DoobieMonitor.noopMonitor[IO]) - extends DoobiePgMapping[F](transactor, monitor) with DoobieTestMapping[F] with SqlTestMapping[F] + extends DoobiePgMapping[F](transactor, monitor) with DoobieTestMapping[F] with SqlTestMapping[F] { + def uuid: TestCodec[UUID] = (Meta[UUID], false) + def localDate: TestCodec[LocalDate] = (Meta[LocalDate], false) + def localTime: TestCodec[LocalTime] = (Meta[LocalTime], false) + def offsetDateTime: TestCodec[OffsetDateTime] = (Meta[OffsetDateTime], false) + def jsonb: TestCodec[Json] = (new Meta(Get[Json], Put[Json]), false) + def nvarchar: TestCodec[String] = (Meta[String], false) + } def transactorResource: Resource[IO, Transactor[IO]] = { val connInfo = postgresConnectionInfo diff --git a/modules/sql-pg/js-jvm/src/test/scala/SqlPgDatabaseSuite.scala b/modules/sql-pg/js-jvm/src/test/scala/SqlPgDatabaseSuite.scala index 0c5d3fca..444ff552 100644 --- a/modules/sql-pg/js-jvm/src/test/scala/SqlPgDatabaseSuite.scala +++ b/modules/sql-pg/js-jvm/src/test/scala/SqlPgDatabaseSuite.scala @@ -31,5 +31,6 @@ trait SqlPgDatabaseSuite extends CatsEffectSuite { val DefaultPort = 5432 } - val postgresConnectionInfo: PostgresConnectionInfo = PostgresConnectionInfo("localhost", PostgresConnectionInfo.DefaultPort) + val postgresConnectionInfo: PostgresConnectionInfo = + PostgresConnectionInfo("localhost", PostgresConnectionInfo.DefaultPort) }