From 804a70d83892841e07834e01498a685834421bf8 Mon Sep 17 00:00:00 2001 From: tuminglei Date: Tue, 24 Dec 2024 12:17:38 +0800 Subject: [PATCH] some code refactorings --- .../com/github/tminglei/slickpg/ScalaVersionShim.scala | 2 +- .../com/github/tminglei/slickpg/ScalaVersionShim.scala | 1 + .../com/github/tminglei/slickpg/PgEnumSupportSuite.scala | 4 ++-- 3 files changed, 4 insertions(+), 3 deletions(-) diff --git a/src/test/scala-2/com/github/tminglei/slickpg/ScalaVersionShim.scala b/src/test/scala-2/com/github/tminglei/slickpg/ScalaVersionShim.scala index 36c7f7e8..ed672966 100644 --- a/src/test/scala-2/com/github/tminglei/slickpg/ScalaVersionShim.scala +++ b/src/test/scala-2/com/github/tminglei/slickpg/ScalaVersionShim.scala @@ -1,12 +1,12 @@ package com.github.tminglei.slickpg -import com.github.tminglei.slickpg.PgCompositeSupportSuite.ts import org.postgresql.util.HStoreConverter import java.time.LocalDateTime import scala.jdk.CollectionConverters._ object ScalaVersionShim { + def ts(str: String) = LocalDateTime.parse(str.replace(' ', 'T')) def mapToString(m: Map[String, String]): String = HStoreConverter.toString((m).asJava) def stringToMap(s: String): Map[String, String] = (HStoreConverter.fromString(s) .asInstanceOf[java.util.Map[String, String]]).asScala.toMap diff --git a/src/test/scala-3/com/github/tminglei/slickpg/ScalaVersionShim.scala b/src/test/scala-3/com/github/tminglei/slickpg/ScalaVersionShim.scala index 9d2f16dd..4c66d978 100644 --- a/src/test/scala-3/com/github/tminglei/slickpg/ScalaVersionShim.scala +++ b/src/test/scala-3/com/github/tminglei/slickpg/ScalaVersionShim.scala @@ -12,6 +12,7 @@ object ScalaVersionShim { def mapToString(m: Map[String, String]): String = HStoreConverter.toString((m).asJava) def stringToMap(s: String): Map[String, String] = (HStoreConverter.fromString(s) .asInstanceOf[java.util.Map[String, String]]).asScala.toMap + implicit val StringToRange: RegisteredTypeConverter[String, Range[LocalDateTime]] = RegisteredTypeConverter(PgRangeSupportUtils.mkRangeFn(ts)) implicit val RangeToString: RegisteredTypeConverter[Range[LocalDateTime], String] = diff --git a/src/test/scala/com/github/tminglei/slickpg/PgEnumSupportSuite.scala b/src/test/scala/com/github/tminglei/slickpg/PgEnumSupportSuite.scala index 987f3ecf..5d3c9d59 100644 --- a/src/test/scala/com/github/tminglei/slickpg/PgEnumSupportSuite.scala +++ b/src/test/scala/com/github/tminglei/slickpg/PgEnumSupportSuite.scala @@ -66,8 +66,8 @@ class PgEnumSupportSuite extends AnyFunSuite with PostgresContainer { implicit def rainbowOptionColumnExtensionMethodsBuilder(rep: Rep[Option[Rainbows.Value]]): EnumColumnExtensionMethods[Rainbows.Value, Option[Rainbows.Value]] = createEnumOptionColumnExtensionMethodsBuilder[Rainbows.type](Rainbows).apply(rep) /// custom types of java enums and algebraic data type (ADT) - implicit val currencyTypeMapper: JdbcType[Currency] = createEnumJdbcType[Currency]("Currency", _.toString, Currency.values.get(_).get, quoteName = false) - implicit val currencyTypeListMapper: JdbcType[List[Currency]] = createEnumListJdbcType[Currency]("Currency", _.toString, Currency.values.get(_).get, quoteName = false) + implicit val currencyTypeMapper: JdbcType[Currency] = createEnumJdbcType[Currency]("Currency", _.toString, Currency.values(_), quoteName = false) + implicit val currencyTypeListMapper: JdbcType[List[Currency]] = createEnumListJdbcType[Currency]("Currency", _.toString, Currency.values(_), quoteName = false) implicit val languagesTypeMapper: JdbcType[Languages] = createEnumJdbcType[Languages]("Languages", _.name(), Languages.valueOf, quoteName = true) implicit val languagesTypeListMapper: JdbcType[List[Languages]] = createEnumListJdbcType[Languages]("Languages", _.name(), Languages.valueOf, quoteName = true) implicit val genderTypeMapper: JdbcType[Gender] = createEnumJdbcType[Gender]("Gender", _.repr, Gender.fromString, quoteName = false)