简体   繁体   English

Scala Slick:MappedColumnType找不到BaseColumlnType [String]的隐式值

[英]Scala Slick: MappedColumnType cannot find implicit value for BaseColumlnType[String]

I'm trying to set up database columns in Slick with non-primitive objects. 我正在尝试使用非基本对象在Slick中设置数据库列。 I've spent the past day researching MappedColumnType for mapping custom objects to columns, and as far as I can tell I'm implementing them as people recommend. 我花了一天时间研究MappedColumnType来将自定义对象映射到列,据我所知,我正在按照人们的推荐实现它们。 Unfortunately, the following code produces an error: 不幸的是,以下代码产生错误:

  implicit val localDateMapper = MappedColumnType.base[LocalDate, String]
    (
    //map date to String
    d => d.toString,
    //map String to date
    s => LocalDate.parse(s)
    )

And here is the error: 这是错误:

could not find implicit value for evidence parameter of type slick.driver.H2Driver.BaseColumnType[String]

I've seen multiple examples where people map custom objects to and from Strings. 我已经看过多个人们将自定义对象映射到字符串和从字符串映射的示例。 I figure there must be something I'm missing? 我认为必须有一些我想念的东西?

For reference, I'm using Play Slick 1.1.1 and Scala 2.11.6. 作为参考,我正在使用Play Slick 1.1.1和Scala 2.11.6。 The former supports Slick 3.1. 前者支持Slick 3.1。

您可以使用以下命令导入BaseColumnType[String]

import slick.driver.H2Driver.api.stringColumnType

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM