缺少方法的参数在 slick 中不适用

Missing arguments for method unapply in slick

我正在使用 Scala 和 Slick 开发应用程序。我有一个名为 table 的 CarAdvertisement,它有一个模型

case class CarAdvertisementModel(id: Int, title: String, fuel: String, price: Int, isNew: Boolean, mileage: Option[Int], firstRegistration : Option[LocalDate])

我正在尝试使用 slick 声明我的架构。我的代码如下

  private class CarAdvertisement(tag: Tag) extends Table[CarAdvertisementModel](tag, "CAR_ADVERTISEMENT") {

    def id = column[Int]("id", O.PrimaryKey, O.AutoInc)

    def title = column[String]("title")

    def fuel = column[String]("fuel")

    def price = column[Int]("price")

    def isNew = column[Boolean]("isNew")

    def mileage = column[Option[Int]]("mileage")

    def firstRegistration = column[Option[LocalDate]]("firstRegistration")

    def * = (id, title, fuel, price, isNew, mileage,firstRegistration) <> ((CarAdvertisementModel.apply _).tupled, CarAdvertisementModel.unapply)
  }

然而,最后一行

CarAdvertisementModel.unapply)

给我一个错误

Missing arguments for method unapply(CarAdvertisementModel)

你能告诉我我在这里遗漏了什么吗?

你确定你没有像

这样的错误吗

could not find implicit value for parameter tt: slick.ast.TypedType[Option[java.time.LocalDate]]
def firstRegistration = columnOption[LocalDate]

如果你有,请尝试在你的代码中添加类似这样的内容

private class CarAdvertisement(tag: Tag) extends Table[CarAdvertisementModel](tag, "CAR_ADVERTISEMENT") {

  // fast hack to support LocalDate
  implicit val localDateColumnType = MappedColumnType.base[LocalDate, java.sql.Date](java.sql.Date.valueOf, _.toLocalDate)

  // the rest of the code

或者您可以尝试使用 Slick 的最新代码并合并 PR #1349 Support java time。不幸的是,AFAIK 仍然没有包含这些更改的官方版本。