0

I can't find postgres import for slick <> operator. I'm trying to create mapping for java.time.OffsetDateTime. The error is:

not found: value <>
  <> ((Bonus.apply _).tupled, Bonus.unapply _)

My * method:

override def * = (id, name, createdAt) <> ((Bonus.apply _).tupled, Bonus.unapply _)

My OffsetDateTime mapping:

  implicit def zoneDateTime: TypedType[OffsetDateTime]  =
    MappedColumnType.base[OffsetDateTime, String](
      zdt => zdt.toString,
      date => OffsetDateTime.parse(date)
    )

I believe import slick.jdbc.PostgresProfile.api._ should work, but it's not. Everything worked fine without OffsetDateTime and method

override def * = (id, name, createdAt).mapTo[Bonus]

karjan
  • 936
  • 1
  • 7
  • 17
  • Look here https://stackoverflow.com/questions/35840626/what-does-the-operator-do-in-slick – mgosk Sep 18 '18 at 08:11
  • I tried to import `import slick.lifted.ShapedValue._` and `import slick.lifted.ShapedValue`. Didn't work – karjan Sep 18 '18 at 08:18
  • @karjan can you post a complete example somewhere (e.g., github or similar). – Richard Dallaway Sep 19 '18 at 11:34
  • Code is pretty standard. The only issue were `Optionals` and `<>` method. Somehow everything is working now. I'm looking at changes in git and it's all the same. No new imports, nothing... No idea what was the issue. If it occurs again I'll upload the code – karjan Sep 19 '18 at 18:07

1 Answers1

0

You are missing mapping for OffsetDateTime. You have to provide an implicit JdbcType[OffsetDateTime] instance. AFAIR default postgres driver do not provide them for you, which is why many people use something like slick-pg.

E.g. you would need something like

import com.github.tminglei.slickpg._

trait MyPostgresProfile extends ExPostgresProfile with PgDate2Support {

  override val api = MyAPI

  object MyAPI extends API with DateTimeImplicits
}

object MyPostgresProfile extends MyPostgresProfile

Of course, you need to replace all usages of PostgresProfile with MyPostgresProfile.

Mateusz Kubuszok
  • 24,995
  • 4
  • 42
  • 64
  • Mapping was there, just updated post. I'll check out `slick-pg` but it would be better to solve it without extra dependency – karjan Sep 18 '18 at 08:39
  • If `<>` failed then either mapping was not there or it wasn't seen. This error is almost always about missing implicits. – Mateusz Kubuszok Sep 18 '18 at 08:46
  • You will almost definitively want to use `slick-pg`, since you then get proper mappings from Java-Time types to native types in Postgres. It also adds additional Postgres specific features to Slick, highly recommended when using Slick with Postgres. – ASamsig Sep 18 '18 at 11:39
  • Java Time, Arrays, enums, JSONs... Build-in driver is a kind of placeholder for start. As soon as you stop limiting yourself to primitives you need more mappings that slick-pg provides. – Mateusz Kubuszok Sep 18 '18 at 12:03
  • Ok, but still the issue stands. The same problem appears when I try to use `Optional` `value ? is not a member of slick.lifted.Rep[Option[String]]` – karjan Sep 18 '18 at 13:38
  • Also true - that would lift it to `Rep[Option[Option[String]]]` which cannot be constructed. – Mateusz Kubuszok Sep 18 '18 at 15:06