tminglei / slick-pg

Slick extensions for PostgreSQL
BSD 2-Clause "Simplified" License
839 stars 180 forks source link

Cannot use `PlayJsonPlainImplicits` with generated source code Tables.scala #378

Open mattfeury opened 6 years ago

mattfeury commented 6 years ago

Hello,

I am attempting to to write a compiled query that returns a json_object as one of the fields. however, i'm getting a message could not find implicit value for parameter e: slick.jdbc.GetResult[(Int, Int, String, org.joda.time.DateTime, String, Boolean, play.api.libs.json.JsValue)]

I've noticed there is a similar error message defined in https://github.com/tminglei/slick-pg/blob/56ad9e0b4576e9410243249c367f45310d882328/src/test/scala/com/github/tminglei/slickpg/PgTsqlSupportSuite.scala but it seems related to typed components. any ideas why i could be seeing this message?

My api is imported and contains the following:

trait MyPostgresDriver extends ExPostgresDriver
  with PgArraySupport
  with PgEnumSupport
  with PgPlayJsonSupport
  with PgRangeSupport
  with PgDateSupport
  with PgDateSupportJoda
  with PgDate2Support
  with PgJsonSupport
  with PgHStoreSupport
  with PgSearchSupport
  with PgNetSupport
  with PgLTreeSupport {

  override val api = MyAPI
  override val pgjson = "jsonb"

  object MyAPI extends API with ArrayImplicits
    with SimpleArrayPlainImplicits
    with SimpleDateTimeImplicits
    with Date2DateTimeImplicitsDuration
    with Date2DateTimePlainImplicits
    with DateTimeImplicits
    with JodaDateTimeImplicits
    with LTreeImplicits
    with NetImplicits
    with SimpleJsonImplicits
    with PlayJsonImplicits
    with RangeImplicits
    with HStoreImplicits
    with SearchImplicits
    with SearchAssistants {
        // some custom implicits for my custom db enums
    }
}

thanks!

mattfeury commented 6 years ago

ok I was able to fix this by adding with PlayJsonPlainImplicits to my api, but that is now having trouble with my generated code Tables.scala.

[error] /projects/app/models/db/Tables.scala:206: ambiguous implicit values:
[error]  both value getJsonOption in trait PlayJsonPlainImplicits of type => slick.jdbc.GetResult[Option[play.api.libs.json.JsValue]]
[error]  and value e4 of type slick.jdbc.GetResult[Option[play.api.libs.json.JsValue]]
[error]  match expected type slick.jdbc.GetResult[Option[play.api.libs.json.JsValue]]
[error]     CamerasRow.tupled((<<[Int], <<[models.db.CameraTypes.Value], <<[String], <<[Int], <<[org.joda.time.DateTime], <<[String], <<?[play.api.libs.json.JsValue], <<[Boolean]))

this is because the source code generator passes an implicit GetResult so it gets confused:

  implicit def GetResultCamerasRow(implicit e0: GR[Int], e1: GR[models.db.CameraTypes.Value], e2: GR[String], e3: GR[org.joda.time.DateTime], e4: GR[Option[play.api.libs.json.JsValue]], e5: GR[Boolean]): GR[CamerasRow] = GR{
    prs => import prs._
    CamerasRow.tupled((<<[Int], <<[models.db.CameraTypes.Value], <<[String], <<[Int], <<[org.joda.time.DateTime], <<[String], <<?[play.api.libs.json.JsValue], <<[Boolean]))
  }

temporarily i've removed PlayJsonPlainImplicits and just added my own JsValue implicits to my controllers to take care of the GRs

mrwillis commented 6 years ago

I am also having this issue with Date2DateTimePlainImplicits using the source code generator. Is there anything that can be done to fix it?

tminglei commented 6 years ago

pls ref #406