Skip to content

Commit

Permalink
slick scala3 support (#378)
Browse files Browse the repository at this point in the history
* slick scala3

* Update build.sbt to reference final version of Slick 3.5.0

---------

Co-authored-by: Lloyd <[email protected]>
Co-authored-by: Greg Barrett <[email protected]>
  • Loading branch information
3 people authored Mar 23, 2024
1 parent 75fffbb commit 9ea252a
Show file tree
Hide file tree
Showing 5 changed files with 78 additions and 53 deletions.
6 changes: 2 additions & 4 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -585,9 +585,10 @@ lazy val enumeratumSlick =
version := "1.7.5-SNAPSHOT",
crossScalaVersions := scalaVersionsAll,
libraryDependencies ++= Seq(
("com.typesafe.slick" %% "slick" % "3.4.1").cross(CrossVersion.for3Use2_13),
("com.typesafe.slick" %% "slick" % "3.5.0"),
"com.h2database" % "h2" % "1.4.197" % Test
),
libraryDependencies += scalaXmlTest,
libraryDependencies ++= {
if (useLocalVersion) {
Seq.empty
Expand All @@ -596,9 +597,6 @@ lazy val enumeratumSlick =
}
}
)
.settings( // TODO: Remove once Slick is published for Dotty
disabledSettings
)
.configure(configureWithLocal(coreJVM))

// Cats
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ trait SlickEnumPlainSqlSupport {
find: String => E
): GetResult[E] = {
new GetResult[E] {
override def apply(pr: PositionedResult): E = find(pr.nextString)
override def apply(pr: PositionedResult): E = find(pr.nextString())
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -127,51 +127,51 @@ trait SlickValueEnumPlainSqlSupport {

def getResultForIntEnum[E <: IntEnumEntry](
@deprecatedName(Symbol("enum")) e: IntEnum[E]
): GetResult[E] = _makeGetResult[Int, E](e, _.nextInt)
): GetResult[E] = _makeGetResult[Int, E](e, _.nextInt())

def optionalGetResultForIntEnum[E <: IntEnumEntry](
@deprecatedName(Symbol("enum")) e: IntEnum[E]
): GetResult[Option[E]] = _makeOptionalGetResult[Int, E](e, _.nextIntOption)
): GetResult[Option[E]] = _makeOptionalGetResult[Int, E](e, _.nextIntOption())

def getResultForLongEnum[E <: LongEnumEntry](
@deprecatedName(Symbol("enum")) e: LongEnum[E]
): GetResult[E] = _makeGetResult[Long, E](e, _.nextLong)
): GetResult[E] = _makeGetResult[Long, E](e, _.nextLong())

def optionalGetResultForLongEnum[E <: LongEnumEntry](
@deprecatedName(Symbol("enum")) e: LongEnum[E]
): GetResult[Option[E]] = _makeOptionalGetResult[Long, E](e, _.nextLongOption)
): GetResult[Option[E]] = _makeOptionalGetResult[Long, E](e, _.nextLongOption())

def getResultForShortEnum[E <: ShortEnumEntry](
@deprecatedName(Symbol("enum")) e: ShortEnum[E]
): GetResult[E] = _makeGetResult[Short, E](e, { _.nextShort })
): GetResult[E] = _makeGetResult[Short, E](e, { _.nextShort() })

def optionalGetResultForShortEnum[E <: ShortEnumEntry](
@deprecatedName(Symbol("enum")) e: ShortEnum[E]
): GetResult[Option[E]] = _makeOptionalGetResult[Short, E](e, { _.nextShortOption })
): GetResult[Option[E]] = _makeOptionalGetResult[Short, E](e, { _.nextShortOption() })

def getResultForStringEnum[E <: StringEnumEntry](
@deprecatedName(Symbol("enum")) e: StringEnum[E]
): GetResult[E] = _makeGetResult[String, E](e, { _.nextString })
): GetResult[E] = _makeGetResult[String, E](e, { _.nextString() })

def optionalGetResultForStringEnum[E <: StringEnumEntry](
@deprecatedName(Symbol("enum")) e: StringEnum[E]
): GetResult[Option[E]] = _makeOptionalGetResult[String, E](e, { _.nextStringOption })
): GetResult[Option[E]] = _makeOptionalGetResult[String, E](e, { _.nextStringOption() })

def getResultForByteEnum[E <: ByteEnumEntry](
@deprecatedName(Symbol("enum")) e: ByteEnum[E]
): GetResult[E] = _makeGetResult[Byte, E](e, { _.nextByte })
): GetResult[E] = _makeGetResult[Byte, E](e, { _.nextByte() })

def optionalGetResultForByteEnum[E <: ByteEnumEntry](
@deprecatedName(Symbol("enum")) e: ByteEnum[E]
): GetResult[Option[E]] = _makeOptionalGetResult[Byte, E](e, { _.nextByteOption })
): GetResult[Option[E]] = _makeOptionalGetResult[Byte, E](e, { _.nextByteOption() })

def getResultForCharEnum[E <: CharEnumEntry](
@deprecatedName(Symbol("enum")) e: CharEnum[E]
): GetResult[E] =
_makeGetResult[Char, E](
e,
{ pr =>
pr.nextString.head
pr.nextString().head
}
)

Expand All @@ -181,7 +181,7 @@ trait SlickValueEnumPlainSqlSupport {
_makeOptionalGetResult[Char, E](
e,
{ pr =>
pr.nextStringOption.map(_.head)
pr.nextStringOption().map(_.head)
}
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,10 @@ class SlickEnumSupportSpec

import profile.api._

implicit val trafficLightColumnType = mappedColumnTypeForEnum(TrafficLight)
val trafficLightUpperColumnType = mappedColumnTypeForUppercaseEnum(TrafficLight)
val trafficLightLowerColumnType = mappedColumnTypeForLowercaseEnum(TrafficLight)
implicit val trafficLightColumnType: profile.BaseColumnType[TrafficLight] =
mappedColumnTypeForEnum(TrafficLight)
val trafficLightUpperColumnType = mappedColumnTypeForUppercaseEnum(TrafficLight)
val trafficLightLowerColumnType = mappedColumnTypeForLowercaseEnum(TrafficLight)

val trafficLightSetParamName = setParameterForEnum(TrafficLight)
val trafficLightGetResultName = getResultForEnum(TrafficLight)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import org.scalatest.freespec.AnyFreeSpec
import org.scalatest.matchers.should.Matchers
import org.scalatest.concurrent.ScalaFutures
import org.scalatest.time._
import slick.jdbc.{GetResult, SetParameter}

class SlickValueEnumSupportSpec
extends AnyFreeSpec
Expand Down Expand Up @@ -47,36 +48,61 @@ class SlickValueEnumSupportSpec

import profile.api._

implicit val intValueColumn = mappedColumnTypeForValueEnum(IntValueExample)
implicit val intSetParam = setParameterForIntEnum(IntValueExample)
implicit val intOptionalSetParam = optionalSetParameterForIntEnum(IntValueExample)
implicit val intGetResult = getResultForIntEnum(IntValueExample)
implicit val intOptionalGetResult = optionalGetResultForIntEnum(IntValueExample)

implicit val longValueColumn = mappedColumnTypeForValueEnum(LongValueExample)
implicit val longSetParam = setParameterForLongEnum(LongValueExample)
implicit val longOptionalSetParam = optionalSetParameterForLongEnum(LongValueExample)
implicit val longGetResult = getResultForLongEnum(LongValueExample)

implicit val shortValueColumn = mappedColumnTypeForValueEnum(ShortValueExample)
implicit val shortSetParam = setParameterForShortEnum(ShortValueExample)
implicit val shortGetResult = getResultForShortEnum(ShortValueExample)
implicit val shortOptionalSetParam = optionalSetParameterForShortEnum(ShortValueExample)

implicit val stringValueColumn = mappedColumnTypeForValueEnum(StringValueExample)
implicit val stringSetParam = setParameterForStringEnum(StringValueExample)
implicit val stringOptionalSetParam = optionalSetParameterForStringEnum(StringValueExample)
implicit val stringGetResult = getResultForStringEnum(StringValueExample)

implicit val byteValueColumn = mappedColumnTypeForValueEnum(ByteValueExample)
implicit val byteSetParam = setParameterForByteEnum(ByteValueExample)
implicit val byteGetResult = getResultForByteEnum(ByteValueExample)
implicit val byteOptionalSetParam = optionalSetParameterForByteEnum(ByteValueExample)

implicit val charValueColumn = mappedColumnTypeForValueEnum(CharValueExample)
implicit val charSetParam = setParameterForCharEnum(CharValueExample)
implicit val charGetResult = getResultForCharEnum(CharValueExample)
implicit val charOptionalSetParam = optionalSetParameterForCharEnum(CharValueExample)
implicit val intValueColumn: profile.BaseColumnType[IntValueExample] =
mappedColumnTypeForValueEnum(IntValueExample)
implicit val intSetParam: SetParameter[IntValueExample] =
setParameterForIntEnum(IntValueExample)
implicit val intOptionalSetParam: SetParameter[Option[IntValueExample]] =
optionalSetParameterForIntEnum(IntValueExample)
implicit val intGetResult: GetResult[IntValueExample] =
getResultForIntEnum(IntValueExample)
implicit val intOptionalGetResult: GetResult[Option[IntValueExample]] =
optionalGetResultForIntEnum(IntValueExample)

implicit val longValueColumn: profile.BaseColumnType[LongValueExample] =
mappedColumnTypeForValueEnum(LongValueExample)
implicit val longSetParam: SetParameter[LongValueExample] =
setParameterForLongEnum(LongValueExample)
implicit val longOptionalSetParam: SetParameter[Option[LongValueExample]] =
optionalSetParameterForLongEnum(LongValueExample)
implicit val longGetResult: GetResult[LongValueExample] =
getResultForLongEnum(LongValueExample)

implicit val shortValueColumn: profile.BaseColumnType[ShortValueExample] =
mappedColumnTypeForValueEnum(ShortValueExample)
implicit val shortSetParam: SetParameter[ShortValueExample] =
setParameterForShortEnum(ShortValueExample)
implicit val shortGetResult: GetResult[ShortValueExample] =
getResultForShortEnum(ShortValueExample)
implicit val shortOptionalSetParam: SetParameter[Option[ShortValueExample]] =
optionalSetParameterForShortEnum(ShortValueExample)

implicit val stringValueColumn: profile.BaseColumnType[StringValueExample] =
mappedColumnTypeForValueEnum(StringValueExample)
implicit val stringSetParam: SetParameter[StringValueExample] =
setParameterForStringEnum(StringValueExample)
implicit val stringOptionalSetParam: SetParameter[Option[StringValueExample]] =
optionalSetParameterForStringEnum(StringValueExample)
implicit val stringGetResult: GetResult[StringValueExample] =
getResultForStringEnum(StringValueExample)

implicit val byteValueColumn: profile.BaseColumnType[ByteValueExample] =
mappedColumnTypeForValueEnum(ByteValueExample)
implicit val byteSetParam: SetParameter[ByteValueExample] =
setParameterForByteEnum(ByteValueExample)
implicit val byteGetResult: GetResult[ByteValueExample] =
getResultForByteEnum(ByteValueExample)
implicit val byteOptionalSetParam: SetParameter[Option[ByteValueExample]] =
optionalSetParameterForByteEnum(ByteValueExample)

implicit val charValueColumn: profile.BaseColumnType[CharValueExample] =
mappedColumnTypeForValueEnum(CharValueExample)
implicit val charSetParam: SetParameter[CharValueExample] =
setParameterForCharEnum(CharValueExample)
implicit val charGetResult: GetResult[CharValueExample] =
getResultForCharEnum(CharValueExample)
implicit val charOptionalSetParam: SetParameter[Option[CharValueExample]] =
optionalSetParameterForCharEnum(CharValueExample)

class ValueEnumTable(tag: Tag) extends Table[ValueEnumRow](tag, "value_enum") {
def id =
Expand Down Expand Up @@ -108,9 +134,9 @@ class SlickValueEnumSupportSpec
}
val valueEnums = TableQuery[ValueEnumTable]
}
class ConcreteRepository(val profile: slick.driver.H2Driver) extends ValueEnumRepository
class ConcreteRepository(val profile: slick.jdbc.H2Profile) extends ValueEnumRepository

val repo = new ConcreteRepository(slick.driver.H2Driver)
val repo = new ConcreteRepository(slick.jdbc.H2Profile)
import repo.profile.api._
import repo.valueEnums
val db = Database.forURL(
Expand All @@ -119,7 +145,7 @@ class SlickValueEnumSupportSpec
keepAliveConnection = true
)

implicit val defaultPatience = PatienceConfig(timeout = Span(1, Second))
implicit val defaultPatience: PatienceConfig = PatienceConfig(timeout = Span(1, Second))

override def beforeAll(): Unit = {
db.run(valueEnums.schema.create).futureValue(Timeout(Span(3, Seconds)))
Expand Down

0 comments on commit 9ea252a

Please sign in to comment.