Skip to content

Commit

Permalink
Merge pull request #641 from amumurst/chore/scala3-implicit-explicit
Browse files Browse the repository at this point in the history
Scala 3 explicit implicits
  • Loading branch information
tminglei authored Jun 5, 2023
2 parents d1b380b + 5d51354 commit 39e85d6
Show file tree
Hide file tree
Showing 22 changed files with 348 additions and 340 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.github.tminglei.slickpg

import slick.jdbc.{JdbcType, PositionedResult, PostgresProfile}
import slick.jdbc.{GetResult, JdbcType, PositionedResult, PostgresProfile, SetParameter}

import scala.reflect.classTag

trait PgArgonautSupport extends json.PgJsonExtensions with utils.PgCommonJdbcTypes { driver: PostgresProfile =>
Expand Down Expand Up @@ -32,10 +33,10 @@ trait PgArgonautSupport extends json.PgJsonExtensions with utils.PgCommonJdbcTyp
hasLiteralForm = false
)

implicit def argonautJsonColumnExtensionMethods(c: Rep[Json]) = {
implicit def argonautJsonColumnExtensionMethods(c: Rep[Json]): JsonColumnExtensionMethods[Json, Json] = {
new JsonColumnExtensionMethods[Json, Json](c)
}
implicit def argonautJsonOptionColumnExtensionMethods(c: Rep[Option[Json]]) = {
implicit def argonautJsonOptionColumnExtensionMethods(c: Rep[Option[Json]]): JsonColumnExtensionMethods[Json, Option[Json]] = {
new JsonColumnExtensionMethods[Json, Option[Json]](c)
}
}
Expand All @@ -49,9 +50,9 @@ trait PgArgonautSupport extends json.PgJsonExtensions with utils.PgCommonJdbcTyp
}

///////////////////////////////////////////////////////////
implicit val getJson = mkGetResult(_.nextJson())
implicit val getJsonOption = mkGetResult(_.nextJsonOption())
implicit val setJson = mkSetParameter[Json](pgjson, _.nospaces)
implicit val setJsonOption = mkOptionSetParameter[Json](pgjson, _.nospaces)
implicit val getJson: GetResult[Json] = mkGetResult(_.nextJson())
implicit val getJsonOption: GetResult[Option[Json]] = mkGetResult(_.nextJsonOption())
implicit val setJson: SetParameter[Json] = mkSetParameter[Json](pgjson, _.nospaces)
implicit val setJsonOption: SetParameter[Option[Json]] = mkOptionSetParameter[Json](pgjson, _.nospaces)
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
package com.github.tminglei.slickpg

import cats.syntax.either._
import slick.jdbc.{JdbcType, PositionedResult, PostgresProfile}
import slick.jdbc.{GetResult, JdbcType, PositionedResult, PostgresProfile, SetParameter}

import scala.reflect.classTag

trait PgCirceJsonSupport extends json.PgJsonExtensions with utils.PgCommonJdbcTypes { driver: PostgresProfile =>
Expand Down Expand Up @@ -34,11 +35,11 @@ trait PgCirceJsonSupport extends json.PgJsonExtensions with utils.PgCommonJdbcTy
hasLiteralForm = false
)

implicit def circeJsonColumnExtensionMethods(c: Rep[Json]) = {
implicit def circeJsonColumnExtensionMethods(c: Rep[Json]): JsonColumnExtensionMethods[Json, Json] = {
new JsonColumnExtensionMethods[Json, Json](c)
}

implicit def circeJsonOptionColumnExtensionMethods(c: Rep[Option[Json]]) = {
implicit def circeJsonOptionColumnExtensionMethods(c: Rep[Option[Json]]): JsonColumnExtensionMethods[Json, Option[Json]] = {
new JsonColumnExtensionMethods[Json, Option[Json]](c)
}
}
Expand All @@ -51,9 +52,9 @@ trait PgCirceJsonSupport extends json.PgJsonExtensions with utils.PgCommonJdbcTy
def nextJsonOption() = r.nextStringOption().map(parse(_).getOrElse(Json.Null))
}

implicit val getJson = mkGetResult(_.nextJson())
implicit val getJsonOption = mkGetResult(_.nextJsonOption())
implicit val setJson = mkSetParameter[Json](pgjson, _.asJson.spaces2)
implicit val setJsonOption = mkOptionSetParameter[Json](pgjson, _.asJson.spaces2)
implicit val getJson: GetResult[Json] = mkGetResult(_.nextJson())
implicit val getJsonOption: GetResult[Option[Json]] = mkGetResult(_.nextJsonOption())
implicit val setJson: SetParameter[Json] = mkSetParameter[Json](pgjson, _.asJson.spaces2)
implicit val setJsonOption: SetParameter[Option[Json]] = mkOptionSetParameter[Json](pgjson, _.asJson.spaces2)
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.github.tminglei.slickpg

import slick.jdbc.{JdbcType, PositionedResult, PostgresProfile}
import slick.jdbc.{GetResult, JdbcType, PositionedResult, PostgresProfile, SetParameter}

import scala.reflect.classTag

trait PgJawnJsonSupport extends json.PgJsonExtensions with utils.PgCommonJdbcTypes { driver: PostgresProfile =>
Expand Down Expand Up @@ -32,10 +33,10 @@ trait PgJawnJsonSupport extends json.PgJsonExtensions with utils.PgCommonJdbcTyp
hasLiteralForm = false
)

implicit def playJsonColumnExtensionMethods(c: Rep[JValue]) = {
implicit def playJsonColumnExtensionMethods(c: Rep[JValue]): JsonColumnExtensionMethods[JValue, JValue] = {
new JsonColumnExtensionMethods[JValue, JValue](c)
}
implicit def playJsonOptionColumnExtensionMethods(c: Rep[Option[JValue]]) = {
implicit def playJsonOptionColumnExtensionMethods(c: Rep[Option[JValue]]): JsonColumnExtensionMethods[JValue, Option[JValue]] = {
new JsonColumnExtensionMethods[JValue, Option[JValue]](c)
}
}
Expand All @@ -49,9 +50,9 @@ trait PgJawnJsonSupport extends json.PgJsonExtensions with utils.PgCommonJdbcTyp
}

////////////////////////////////////////////////////////////
implicit val getJson = mkGetResult(_.nextJson())
implicit val getJsonOption = mkGetResult(_.nextJsonOption())
implicit val setJson = mkSetParameter[JValue](pgjson, CanonicalRenderer.render)
implicit val setJsonOption = mkOptionSetParameter[JValue](pgjson, CanonicalRenderer.render)
implicit val getJson: GetResult[JValue] = mkGetResult(_.nextJson())
implicit val getJsonOption: GetResult[Option[JValue]] = mkGetResult(_.nextJsonOption())
implicit val setJson: SetParameter[JValue] = mkSetParameter[JValue](pgjson, CanonicalRenderer.render)
implicit val setJsonOption: SetParameter[Option[JValue]] = mkOptionSetParameter[JValue](pgjson, CanonicalRenderer.render)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ package com.github.tminglei.slickpg
import org.joda.time._
import org.joda.time.format.{DateTimeFormat, ISODateTimeFormat}
import org.postgresql.util.PGInterval
import slick.jdbc.{JdbcType, PositionedResult, PostgresProfile}
import slick.jdbc.{GetResult, JdbcType, PositionedResult, PostgresProfile, SetParameter}

import scala.reflect.classTag

trait PgDateSupportJoda extends date.PgDateExtensions with utils.PgCommonJdbcTypes { driver: PostgresProfile =>
Expand Down Expand Up @@ -69,34 +70,34 @@ trait PgDateSupportJoda extends date.PgDateExtensions with utils.PgCommonJdbcTyp
hasLiteralForm = false)

///
implicit def jodaDateColumnExtensionMethods(c: Rep[LocalDate]) =
implicit def jodaDateColumnExtensionMethods(c: Rep[LocalDate]): DateColumnExtensionMethods[LocalDate, LocalTime, LocalDateTime, Period, LocalDate] =
new DateColumnExtensionMethods[LocalDate, LocalTime, LocalDateTime, Period, LocalDate](c)
implicit def jodaDateOptColumnExtensionMethods(c: Rep[Option[LocalDate]]) =
implicit def jodaDateOptColumnExtensionMethods(c: Rep[Option[LocalDate]]): DateColumnExtensionMethods[LocalDate, LocalTime, LocalDateTime, Period, Option[LocalDate]] =
new DateColumnExtensionMethods[LocalDate, LocalTime, LocalDateTime, Period, Option[LocalDate]](c)

implicit def jodaTimeColumnExtensionMethods(c: Rep[LocalTime]) =
implicit def jodaTimeColumnExtensionMethods(c: Rep[LocalTime]): TimeColumnExtensionMethods[LocalDate, LocalTime, LocalDateTime, DateTime, Period, LocalTime] =
new TimeColumnExtensionMethods[LocalDate, LocalTime, LocalDateTime, DateTime, Period, LocalTime](c)
implicit def jodaTimeOptColumnExtensionMethods(c: Rep[Option[LocalTime]]) =
implicit def jodaTimeOptColumnExtensionMethods(c: Rep[Option[LocalTime]]): TimeColumnExtensionMethods[LocalDate, LocalTime, LocalDateTime, DateTime, Period, Option[LocalTime]] =
new TimeColumnExtensionMethods[LocalDate, LocalTime, LocalDateTime, DateTime, Period, Option[LocalTime]](c)

implicit def jodaTimestampColumnExtensionMethods(c: Rep[LocalDateTime]) =
implicit def jodaTimestampColumnExtensionMethods(c: Rep[LocalDateTime]): TimestampColumnExtensionMethods[LocalDate, LocalTime, LocalDateTime, DateTime, Period, LocalDateTime] =
new TimestampColumnExtensionMethods[LocalDate, LocalTime, LocalDateTime, DateTime, Period, LocalDateTime](c)
implicit def jodaTimestampOptColumnExtensionMethods(c: Rep[Option[LocalDateTime]]) =
implicit def jodaTimestampOptColumnExtensionMethods(c: Rep[Option[LocalDateTime]]): TimestampColumnExtensionMethods[LocalDate, LocalTime, LocalDateTime, DateTime, Period, Option[LocalDateTime]] =
new TimestampColumnExtensionMethods[LocalDate, LocalTime, LocalDateTime, DateTime, Period, Option[LocalDateTime]](c)

implicit def jodaIntervalColumnExtensionMethods(c: Rep[Period]) =
implicit def jodaIntervalColumnExtensionMethods(c: Rep[Period]): IntervalColumnExtensionMethods[LocalDate, LocalTime, LocalDateTime, Period, Period] =
new IntervalColumnExtensionMethods[LocalDate, LocalTime, LocalDateTime, Period, Period](c)
implicit def jodaIntervalOptColumnExtensionMethods(c: Rep[Option[Period]]) =
implicit def jodaIntervalOptColumnExtensionMethods(c: Rep[Option[Period]]): IntervalColumnExtensionMethods[LocalDate, LocalTime, LocalDateTime, Period, Option[Period]] =
new IntervalColumnExtensionMethods[LocalDate, LocalTime, LocalDateTime, Period, Option[Period]](c)

implicit def jodaTzTimestampColumnExtensionMethods(c: Rep[DateTime]) =
implicit def jodaTzTimestampColumnExtensionMethods(c: Rep[DateTime]): TimestampColumnExtensionMethods[LocalDate, LocalTime, DateTime, LocalDateTime, Period, DateTime] =
new TimestampColumnExtensionMethods[LocalDate, LocalTime, DateTime, LocalDateTime, Period, DateTime](c)
implicit def jodaTzTimestampOptColumnExtensionMethods(c: Rep[Option[DateTime]]) =
implicit def jodaTzTimestampOptColumnExtensionMethods(c: Rep[Option[DateTime]]): TimestampColumnExtensionMethods[LocalDate, LocalTime, DateTime, LocalDateTime, Period, Option[DateTime]] =
new TimestampColumnExtensionMethods[LocalDate, LocalTime, DateTime, LocalDateTime, Period, Option[DateTime]](c)

implicit def jodaTimestamp1ColumnExtensionMethods(c: Rep[Instant]) =
implicit def jodaTimestamp1ColumnExtensionMethods(c: Rep[Instant]): TimestampColumnExtensionMethods[LocalDate, LocalTime, Instant, LocalDateTime, Period, Instant] =
new TimestampColumnExtensionMethods[LocalDate, LocalTime, Instant, LocalDateTime, Period, Instant](c)
implicit def jodaTimestamp1OptColumnExtensionMethods(c: Rep[Option[Instant]]) =
implicit def jodaTimestamp1OptColumnExtensionMethods(c: Rep[Option[Instant]]): TimestampColumnExtensionMethods[LocalDate, LocalTime, Instant, LocalDateTime, Period, Option[Instant]] =
new TimestampColumnExtensionMethods[LocalDate, LocalTime, Instant, LocalDateTime, Period, Option[Instant]](c)
}

Expand All @@ -120,38 +121,38 @@ trait PgDateSupportJoda extends date.PgDateExtensions with utils.PgCommonJdbcTyp
}

/////////////////////////////////////////////////////////////////////////////
implicit val getLocalDate = mkGetResult(_.nextLocalDate())
implicit val getLocalDateOption = mkGetResult(_.nextLocalDateOption())
implicit val setLocalDate = mkSetParameter[LocalDate]("date", _.toString(jodaDateFormatter), sqlType = Types.DATE)
implicit val setLocalDateOption = mkOptionSetParameter[LocalDate]("date", _.toString(jodaDateFormatter), sqlType = Types.DATE)

implicit val getLocalTime = mkGetResult(_.nextLocalTime())
implicit val getLocalTimeOption = mkGetResult(_.nextLocalTimeOption())
implicit val setLocalTime = mkSetParameter[LocalTime]("time", _.toString(jodaTimeFormatter), sqlType = Types.TIME)
implicit val setLocalTimeOption = mkOptionSetParameter[LocalTime]("time", _.toString(jodaTimeFormatter), sqlType = Types.TIME)

implicit val getLocalDateTime = mkGetResult(_.nextLocalDateTime())
implicit val getLocalDateTimeOption = mkGetResult(_.nextLocalDateTimeOption())
implicit val setLocalDateTime = mkSetParameter[LocalDateTime]("timestamp", _.toString(jodaDateTimeFormatter), sqlType = Types.TIMESTAMP)
implicit val setLocalDateTimeOption = mkOptionSetParameter[LocalDateTime]("timestamp", _.toString(jodaDateTimeFormatter), sqlType = Types.TIMESTAMP)

implicit val getZonedDateTime = mkGetResult(_.nextZonedDateTime())
implicit val getZonedDateTimeOption = mkGetResult(_.nextZonedDateTimeOption())
implicit val setZonedDateTime = mkSetParameter[DateTime]("timestamptz", _.toString(jodaTzDateTimeFormatter), sqlType = Types.TIMESTAMP /*Types.TIMESTAMP_WITH_TIMEZONE*/)
implicit val setZonedDateTimeOption = mkOptionSetParameter[DateTime]("timestamptz", _.toString(jodaTzDateTimeFormatter), sqlType = Types.TIMESTAMP /*Types.TIMESTAMP_WITH_TIMEZONE*/)

implicit val getInstant = mkGetResult(_.nextInstant())
implicit val getInstantOption = mkGetResult(_.nextInstantOption())
implicit val setInstant = mkSetParameter[Instant]("timestamptz", _.toString(jodaTzDateTimeFormatter), sqlType = Types.TIMESTAMP /*Types.TIMESTAMP_WITH_TIMEZONE*/)
implicit val setInstantOption = mkOptionSetParameter[Instant]("timestamptz", _.toString(jodaTzDateTimeFormatter), sqlType = Types.TIMESTAMP /*Types.TIMESTAMP_WITH_TIMEZONE*/)

implicit val getPeriod = mkGetResult(_.nextPeriod())
implicit val getPeriodOption = mkGetResult(_.nextPeriodOption())
implicit val setPeriod = mkSetParameter[Period]("interval")
implicit val setPeriodOption = mkOptionSetParameter[Period]("interval")

implicit val setDuration = mkSetParameter[Duration]("interval")
implicit val setDurationOption = mkOptionSetParameter[Duration]("interval")
implicit val getLocalDate: GetResult[LocalDate] = mkGetResult(_.nextLocalDate())
implicit val getLocalDateOption: GetResult[Option[LocalDate]] = mkGetResult(_.nextLocalDateOption())
implicit val setLocalDate: SetParameter[LocalDate] = mkSetParameter[LocalDate]("date", _.toString(jodaDateFormatter), sqlType = Types.DATE)
implicit val setLocalDateOption: SetParameter[Option[LocalDate]] = mkOptionSetParameter[LocalDate]("date", _.toString(jodaDateFormatter), sqlType = Types.DATE)

implicit val getLocalTime: GetResult[LocalTime] = mkGetResult(_.nextLocalTime())
implicit val getLocalTimeOption: GetResult[Option[LocalTime]] = mkGetResult(_.nextLocalTimeOption())
implicit val setLocalTime: SetParameter[LocalTime] = mkSetParameter[LocalTime]("time", _.toString(jodaTimeFormatter), sqlType = Types.TIME)
implicit val setLocalTimeOption: SetParameter[Option[LocalTime]] = mkOptionSetParameter[LocalTime]("time", _.toString(jodaTimeFormatter), sqlType = Types.TIME)

implicit val getLocalDateTime: GetResult[LocalDateTime] = mkGetResult(_.nextLocalDateTime())
implicit val getLocalDateTimeOption: GetResult[Option[LocalDateTime]] = mkGetResult(_.nextLocalDateTimeOption())
implicit val setLocalDateTime: SetParameter[LocalDateTime] = mkSetParameter[LocalDateTime]("timestamp", _.toString(jodaDateTimeFormatter), sqlType = Types.TIMESTAMP)
implicit val setLocalDateTimeOption: SetParameter[Option[LocalDateTime]] = mkOptionSetParameter[LocalDateTime]("timestamp", _.toString(jodaDateTimeFormatter), sqlType = Types.TIMESTAMP)

implicit val getZonedDateTime: GetResult[DateTime] = mkGetResult(_.nextZonedDateTime())
implicit val getZonedDateTimeOption: GetResult[Option[DateTime]] = mkGetResult(_.nextZonedDateTimeOption())
implicit val setZonedDateTime: SetParameter[DateTime] = mkSetParameter[DateTime]("timestamptz", _.toString(jodaTzDateTimeFormatter), sqlType = Types.TIMESTAMP /*Types.TIMESTAMP_WITH_TIMEZONE*/)
implicit val setZonedDateTimeOption: SetParameter[Option[DateTime]] = mkOptionSetParameter[DateTime]("timestamptz", _.toString(jodaTzDateTimeFormatter), sqlType = Types.TIMESTAMP /*Types.TIMESTAMP_WITH_TIMEZONE*/)

implicit val getInstant: GetResult[Instant] = mkGetResult(_.nextInstant())
implicit val getInstantOption: GetResult[Option[Instant]] = mkGetResult(_.nextInstantOption())
implicit val setInstant: SetParameter[Instant] = mkSetParameter[Instant]("timestamptz", _.toString(jodaTzDateTimeFormatter), sqlType = Types.TIMESTAMP /*Types.TIMESTAMP_WITH_TIMEZONE*/)
implicit val setInstantOption: SetParameter[Option[Instant]] = mkOptionSetParameter[Instant]("timestamptz", _.toString(jodaTzDateTimeFormatter), sqlType = Types.TIMESTAMP /*Types.TIMESTAMP_WITH_TIMEZONE*/)

implicit val getPeriod: GetResult[Period] = mkGetResult(_.nextPeriod())
implicit val getPeriodOption: GetResult[Option[Period]] = mkGetResult(_.nextPeriodOption())
implicit val setPeriod: SetParameter[Period] = mkSetParameter[Period]("interval")
implicit val setPeriodOption: SetParameter[Option[Period]] = mkOptionSetParameter[Period]("interval")

implicit val setDuration: SetParameter[Duration] = mkSetParameter[Duration]("interval")
implicit val setDurationOption: SetParameter[Option[Duration]] = mkOptionSetParameter[Duration]("interval")
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.github.tminglei.slickpg

import slick.jdbc.{JdbcType, PositionedResult, PostgresProfile}
import slick.jdbc.{GetResult, JdbcType, PositionedResult, PostgresProfile, SetParameter}

import scala.reflect.classTag

trait PgJson4sSupport extends json.PgJsonExtensions with utils.PgCommonJdbcTypes { driver: PostgresProfile =>
Expand Down Expand Up @@ -35,10 +36,10 @@ trait PgJson4sSupport extends json.PgJsonExtensions with utils.PgCommonJdbcTypes
hasLiteralForm = false
)

implicit def json4sJsonColumnExtensionMethods(c: Rep[JValue]) = {
implicit def json4sJsonColumnExtensionMethods(c: Rep[JValue]): JsonColumnExtensionMethods[JValue, JValue] = {
new JsonColumnExtensionMethods[JValue, JValue](c)
}
implicit def json4sJsonOptionColumnExtensionMethods(c: Rep[Option[JValue]]) = {
implicit def json4sJsonOptionColumnExtensionMethods(c: Rep[Option[JValue]]): JsonColumnExtensionMethods[JValue, Option[JValue]] = {
new JsonColumnExtensionMethods[JValue, Option[JValue]](c)
}
}
Expand All @@ -52,9 +53,9 @@ trait PgJson4sSupport extends json.PgJsonExtensions with utils.PgCommonJdbcTypes
}

//////////////////////////////////////////////////////////
implicit val getJson = mkGetResult(_.nextJson())
implicit val getJsonOption = mkGetResult(_.nextJsonOption())
implicit val setJson = mkSetParameter[JValue](pgjson, (v) => jsonMethods.compact(jsonMethods.render(v)))
implicit val setJsonOption = mkOptionSetParameter[JValue](pgjson, (v) => jsonMethods.compact(jsonMethods.render(v)))
implicit val getJson: GetResult[JValue] = mkGetResult(_.nextJson())
implicit val getJsonOption: GetResult[Option[JValue]] = mkGetResult(_.nextJsonOption())
implicit val setJson: SetParameter[JValue] = mkSetParameter[JValue](pgjson, (v) => jsonMethods.compact(jsonMethods.render(v)))
implicit val setJsonOption: SetParameter[Option[JValue]] = mkOptionSetParameter[JValue](pgjson, (v) => jsonMethods.compact(jsonMethods.render(v)))
}
}
Loading

0 comments on commit 39e85d6

Please sign in to comment.