我尝试创建下面的隐式,这样我就可以从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发布于 2020-09-04 22:40:04
旧版本的Scala为Either提供了.leftMap (因为这就是Circe产生的别名),这在您使用的源代码中可能已经提到过。
然而,较新的版本对API进行了一些清理,他们使用.left和.right来聚合许多方法。所以.leftMap变成了.left.map,但你也有了.left.flatMap等,这样你就可以很容易地使用Either,不仅仅是在那些偏向右派的用例中。
所以长话短说-在新版本的Scala中用.left.map替换.leftMap。
https://stackoverflow.com/questions/63726122
复制相似问题