【问题标题】:How to write custom scala slick column mapping如何编写自定义 scala 光滑列映射
【发布时间】:2017-12-19 06:36:08
【问题描述】:

我的用例很简单。

我在 scala 中有围绕字符串的包装类,我想使用我的自定义 scala 映射器代码将其映射到数据库中的 String 类型(类是第 3 方,我无法修改它。

到目前为止,我发现的所有示例都指向 MappedColumnType,这似乎在 Slick 3 中不存在。

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

【问题讨论】:

标签: scala slick slick-3.0


【解决方案1】:

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

如需参考,请在此处查看我的示例:

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._
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2018-06-20
  • 2017-05-07
  • 1970-01-01
  • 1970-01-01
  • 2022-01-11
  • 2021-01-23
  • 1970-01-01
相关资源
最近更新 更多