0

I've tried creating the below implicit so that I can GET/read data from the postgreSQL database. I've tried add in the recommended implicits but they turn grey and seem to be unused.

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
Ry2254
  • 859
  • 1
  • 10
  • 19
  • Generally speaking please compile the project and post the errors compiler gives you, not IntelliJ errors. IntelliJ infer things poorly very often. That being said 1) Have you checked the documentation? There is an entire section on this https://tpolecat.github.io/doobie/docs/12-Custom-Mappings.html#defining-get-and-put-for-exotic-types 2) Have you imported the necessary postgres imports ? – sinanspd Sep 03 '20 at 14:55
  • Thanks for the comment I have read the various documentation. Will update question with compile errors. – Ry2254 Sep 03 '20 at 15:02
  • 1
    Have you tried `.left.map`? `.leftMap` doesn't exists in recent versions of Scala. – Mateusz Kubuszok Sep 03 '20 at 17:53
  • @MateuszKubuszok Thank you so much, you've solved the problem. I been reading docs but struggling with this for ages. – Ry2254 Sep 03 '20 at 18:05

1 Answers1

2

Older versions of Scala provided .leftMap to Either (because this is what Circe Result aliases to), which might have been mentioned in the source that you used.

However, newer versions cleaned up API a bit to they used .left and .right to aggregate many of the methods. So .leftMap became .left.map, but you have also .left.flatMap etc, so that you can use Either easily not only in use cases that align with Either being Right-biased.

So long story short - replace .leftMap with .left.map in newer versions of Scala.

Mateusz Kubuszok
  • 24,995
  • 4
  • 42
  • 64