【问题标题】:Slick 3.0.3 error: could not find implicit value for parameter rconvSlick 3.0.3 错误:找不到参数 rconv 的隐式值
【发布时间】:2015-09-29 16:56:28
【问题描述】:

我使用 Slick 3.0.3 生成的模型为 Tables.scala,其中包括来自我的所有模型类的结果集的 GetResult 隐式转换,例如

implicit def GetResultInstrumentRow(implicit e0: GR[Int], e1: GR[String], e2: GR[Option[String]], e3: GR[Char], e4: GR[Option[Int]]): GR[InstrumentRow] = GR{
  prs => import prs._
  InstrumentRow.tupled((<<[Int], <<[String], <<?[String], <<[Char], <<?[Int], <<?[Int], <<[Int]))
}

但以下代码仍然会产生错误could not find implicit value for parameter rconv: slick.jdbc.GetResult[models.Tables.InstrumentRow]

import play.api.db.DB
import slick.driver.PostgresDriver.backend.Database._
import slick.jdbc.{StaticQuery => Q}
import play.api.Play.current

import models.Tables._

class InstrumentDao {
  /**
   * Returns all available instruments.
   *
   * @return all available instruments.
   */
  def findInstruments() : List[InstrumentRow] = DB.withConnection() { implicit conn =>
    Q.queryNA[InstrumentRow](s"""select * from "${Instrument.baseTableRow.tableName}"""").list
  }   
}

【问题讨论】:

    标签: scala playframework slick


    【解决方案1】:

    哦,发现问题了,它与 OP 上的代码无关,该代码是正确的并且可以正常工作。问题出在代码生成器/隐式实现上,即它不喜欢 Char 类型的属性,即 Postgres 数据库 CHAR(1)

    CHAR(1) 更改为VARCHAR(3) 并重新运行代码生成器解决了以下问题:

     case class InstrumentRow(id: Int, `type`: Char)
     implicit def GetResultInstrumentRow(implicit e0: GR[Int], e1: GR[Char]): GR[InstrumentRow] = GR{
         prs => import prs._
         InstrumentRow.tupled((<<[Int], <<[Char]))
     }
    

     case class InstrumentRow(id: Int, `type`: String)
     implicit def GetResultInstrumentRow(implicit e0: GR[Int], e1: GR[String]): GR[InstrumentRow] = GR{
         prs => import prs._
         InstrumentRow.tupled((<<[Int], <<[String]))
     }
    

    这似乎是隐式转换和/或生成器中的错误。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2015-05-14
      • 1970-01-01
      • 1970-01-01
      • 2016-02-13
      • 2022-08-05
      • 2017-02-02
      • 2016-01-17
      相关资源
      最近更新 更多