0

Given a case class representation of a data row with a java.sql.Timestamp:

 case class ExampleRow(id: String, ts: Timestamp)

And query expecting an ExampleRow:

 import doobie._
 import doobie.implicits._
 import doobie.postgres.implicits._

 val queryExampleRows = 
   sql"select * from example".query[ExampleRow].to[List]

There is a resulting compile error:

Cannot find or construct a Read instance for type:

ExampleRow

This is surprising given that the documentation claims that Timestamp should work. Further, I know that the Timestamp is the cause because removing that member results in the code compiling.

How can a case class contain a Timestamp and capable of being queried by doobie?

There is a similar question but I cannot figure out if it applicable to my question since it involves a type parameter T and not a concrete type like Timestamp.

Thank you in advance for your consideration and response.

2
  • Try import doobie.implicits.javasql._ Commented Apr 15, 2023 at 4:47
  • 1
    Isn't java.sql.Timestamp a deprecated class that should not be used for years? Use java.time whenever possible.
    – Gaël J
    Commented Apr 15, 2023 at 7:52

1 Answer 1

1

Per the suggestion from the comments the problem was solved by transitioning the type from java.sql.Timestamp to java.time.Instant.

Not the answer you're looking for? Browse other questions tagged or ask your own question.