0

我已经尝试创建以下隐式,以便我可以从 postgreSQL 数据库获取/读取数据。我已经尝试添加推荐的隐式,但它们变成灰色并且似乎未使用。

implicit val get: Get[JobPostDetails] =
 Get[Json].temap(_.as[JobPostDetails].leftMap(_.show))

  def createTable: doobie.Update0 = {
    sql"""
         |CREATE TABLE IF NOT EXISTS jobs (
         |  id TEXT PRIMARY KEY,
         |  details JSON NOT NULL
         |)
       """.stripMargin
      .update
  }

case class JobPost(id: String, details: JobPostDetails)

case class JobPostDetails(title: String, description: String, salary: Double, employmentType: String, employer: String)

[warn] insecure HTTP request is deprecated 'http://repo.typesafe.com/typesafe/releases/'; switch to HTTPS or opt-in as ("Typesafe repository" at "http://repo.typesafe.com/typesafe/releases/").withAllowInsecureProtocol(true)
[info] Compiling 1 Scala source to /Users/ryanmcavoy/fullStackRyan/job-board/target/scala-2.13/classes ...
[error] /Users/ryanmcavoy/fullStackRyan/job-board/src/main/scala/io/github/jobboard/model/JobPost.scala:31:44: value leftMap is not a member of io.circe.Decoder.Result[io.github.jobboard.model.JobPostDetails]
[error]       Get[Json].temap(_.as[JobPostDetails].leftMap(_.show))
[error]                                            ^
[error] one error found
[error] (Compile / compileIncremental) Compilation failed
[error] Total time: 1 s, completed 3 Sep 2020, 16:41:02
sbt:job-board> 


[![enter image description here][1]][1]

[![enter image description here][2]][2]


  [1]: https://i.stack.imgur.com/PvKHJ.png
  [2]: https://i.stack.imgur.com/9QPz6.png
4

1 回答 1

2

旧版本的 Scala 提供.leftMapEither(因为这是 Circe Result 的别名),您使用的源代码中可能已经提到过。

但是,较新的版本对他们使用的 API 进行了一些清理,.left.right聚合了许多方法。如此.leftMap成为.left.map,但您也拥有.left.flatMap等,因此您Either不仅可以在与 Either 右偏一致的用例中轻松使用。

长话短说 -在新版本的 Scala 中.leftMap替换。.left.map

于 2020-09-04T14:40:04.233 回答