私は次の方法でEnumsの問題を解決しました(例として値を取り上げます):
import play.api.db.slick.DB
import play.api.db.slick.Config.driver.simple._
sealed trait MyEnum
case object MyEnumA extends MyEnum
case object MyEnumB extends MyEnum
case object MyEnumC extends MyEnum
object MyEnumMapper {
val string_enum_mapping:Map[String,MyEnum] = Map(
"a" -> MyEnumA,
"b" -> MyEnumB,
"c" -> MyEnumC
)
val enum_string_mapping:Map[MyEnum,String] = string_enum_mapping.map(_.swap)
implicit val myEnumStringMapper = MappedTypeMapper.base[MyEnum,String](
e => enum_string_mapping(e),
s => string_enum_mapping(s)
)
}
import MyEnumMapper._
case class MyData(
......
enumValue: MyEnum,
.....
)
................
object MyDataTable extends Table[MyData]("<table_name>") {
......
def enumValue = column[MyEnum]("<field_name>")
.....
.... /* whatever lifted or direct slick calls you want */
}
Play2.1とPlay2.2の両方で機能する場合は、Slick1.0.0とMariaDB5.5(MySQLと同じ)