Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Could not find implicit value for parameter tt: slick.ast.TypedType[play.api.libs.json.JsValue] #485

Open
Vishnugmavelil opened this issue Jul 27, 2020 · 4 comments

Comments

@Vishnugmavelil
Copy link

I'm new to scala and I'm trying to integrate a PostgreSQL database to a Lagom application written in scala.I'm trying to utilise the persistence API of Lagom. Lagom has inbuilt support for slick.

My table has 3 fields id of type int, name of type string, data of type jsonb

Since Slick doesn't support json format I'm trying to use slick-pg .

Below is my implementation

My custom profile class

import com.github.tminglei.slickpg.{ExPostgresProfile, PgPlayJsonSupport}
import play.api.libs.json.JsValue
import slick.basic.Capability
import slick.jdbc.{JdbcCapabilities, PostgresProfile}

trait CustomPostgresProfile extends ExPostgresProfile with PgPlayJsonSupport {
  def pgjson = "jsonb"

  override protected def computeCapabilities: Set[Capability] =
    super.computeCapabilities + JdbcCapabilities.insertOrUpdate

  override val api = PostgresJsonSupportAPI

  object PostgresJsonSupportAPI extends API with JsonImplicits {}
}

object CustomPostgresProfile extends PostgresProfile

My table definition

import com.custom.persistence.profile.CustomPostgresProfile.api._
import play.api.libs.json._


case class CustomDataEntity(id:int,name: String, data: JsValue)

object CustomDataTableDef {
  val data = TableQuery[CustomDataTableDef]
}
class CustomDataTableDef(tag: Tag) extends Table[CustomDataEntity](tag, "custom"){
  

  def id = column[Int]("id", O.PrimaryKey)

  def name = column[String]("name")
  def data = column[JsValue]("data")

  override def * =
    (id,name,data) <> (CustomDataEntity.tupled,CustomDataEntity.unapply(_))

}

when I'm trying to compile the code, I get the below 2 errors

could not find implicit value for parameter tt: slick.ast.TypedType[play.api.libs.json.JsValue]
[error]   def data = column[JsValue]("data")
Cannot resolve symbol <>

Please help me to resolve this
Thanks in advance

@tminglei
Copy link
Owner

@Vishnugmavelil when defining CustomPostgresProfile, try like this,

trait CustomPostgresProfile extends ExPostgresProfile with PgPlayJsonSupport {
  ...

  override val api: PostgresJsonSupportAPI = new PostgresJsonSupportAPI {}

  trait PostgresJsonSupportAPI extends API with JsonImplicits
}

object CustomPostgresProfile extends PostgresProfile

@Fritzybois
Copy link

have you made an implicit mapper for your JsValue type?

implicit def mapper: BaseColumnType[Foo] =
    MappedColumnType.base[Foo, String](
      bar => bar.toString,
      bar => Foo(bar)
    )

@thedevd
Copy link

thedevd commented Sep 15, 2022

PostgresJsonSupportAPI

This is not working for simple type as well

trait MyPostgresProfile extends ExPostgresProfile with PgArraySupport {
  override val api: API = new MyAPI {}

  trait MyAPI extends API with ArrayImplicits
}

object MyPostgresProfile extends PostgresProfile
import MyPostgresProfile.api._

trait AnalysisTable {
   class MyTableStructure(tag: Tag) extends Table[MyTable](tag, "MyTable" {
       def childernNames: Rep[List[String]] = column[List[String]]("childs") // this always gives compile time error
   }
}

@deabreu

This comment was marked as resolved.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants