Skip to content

Commit

Permalink
some code refactorings
Browse files Browse the repository at this point in the history
  • Loading branch information
tminglei committed Dec 24, 2024
1 parent 0dcba20 commit 804a70d
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 3 deletions.
Original file line number Diff line number Diff line change
@@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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] =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 804a70d

Please sign in to comment.