如何编写自定义 Scala 光滑列映射

How to write custom scala slick column mapping

我的用例很简单。

我在 Scala 中对字符串进行了包装 class,我想使用我的自定义 Scala 映射器代码将其映射到数据库中的 String 类型(class 是第 3 方,我可以'修改它。

到目前为止我找到的所有示例都涉及 MappedColumnType,而 Slick 3 中似乎不存在。

感谢任何帮助和理想的工作示例。

看起来您可能缺少驱动程序 api import!

作为参考,请查看我的示例:

https://github.com/joesan/plant-simulator/blob/master/app/com/inland24/plantsim/services/database/DBSchema.scala

implicit def powerPlantTypeMapping =
    MappedColumnType.base[PowerPlantType, String](
      powerPlantType => PowerPlantType.toString(powerPlantType),
      powerPlantTypeStr => PowerPlantType.fromString(powerPlantTypeStr)
    )

您需要导入:

import driver.api._