0

I'm using scala slick + slick-pg (v0.21.1) for my db integration with my play application. Following the documentation: https://github.com/tminglei/slick-pg/tree/v0.21.1 I set up MyPostgresProfile as shown in the documentation.

However, I still can't get a column of List[Int] to compile.

In my code I have something like:

import com.nbcuas.promo.common.db.PromoPostgresProfile.api._

class MyTable(tag: Tag) extends Table[MyObject](tag, "my_table") {
  def id: Rep[Int] = column[Int]("id")
  def numbers:Rep[List[Int]] = column[List[Int]]("id")
} 

and this fails with error: could not find implicit value for parameter tt: slick.ast.TypedType[List[Int]]

I tried looking into other objects to import from slick-pg to see if it'd work, but couldn't get anything to compile.

CJC
  • 21
  • 2
  • 1
    Could you add more context? I guess your `PromoPostgresProfile` is the `companion object` that extends the traits with the same name that has `PgArraySupport` mixed. It also has a `val api` that extends `API with ArrayImplicits`. Doing that should be enough. If that is not the case, please provide a [minimal reproducible example](https://stackoverflow.com/help/minimal-reproducible-example) – Gastón Schabas Jun 06 '23 at 21:43
  • Everything should be working fine! Take a look at it working properly on [scastie](https://scastie.scala-lang.org/2r0MSpIBTRSyFNz8E3Ue6w) – AminMal Jun 07 '23 at 07:42
  • Ope. I looked into my code carefully again. It's legacy code, and I didn't want to mess with the existing Profile, but the api was set up differently. Instead of having `override val api = MyAPI`, it was set up like: `val api: API = new API with ArrayImplicits with ...`. For some reason, changing to the pattern in the documentation is breaking my code a lot with errors that says: `No matching Shape found. Possible causes: T in Table[T] does not match your * projection, you use an unsupported type in a Query (e.g. scala List), or you forgot to import a driver api into scope.` – CJC Jun 07 '23 at 20:02

1 Answers1

1

So, the code I was working on was legacy code.

For some reason my code had: override val api: API = new API with ArrayImplicits with ...

instead of following the convention of:

override val api: API = MyAPI
object MyAPI extends API with ArrayImplicits with ... 

In the comments, I noted that I still had issues. I was missing the explicit type declaration of api: API. This is really important, and without it created a lot of runtime exceptions.

CJC
  • 21
  • 2