tminglei/slick-pg

implicits not imported during Scala 3 mirgration

agolovenko opened this issue · 3 comments

Hi, I'm trying to migrate to Scala 3. Versions used: Scala 3.3.1 -source:3.0-migration, Slick 3.5.0-M5, Slick-PG 0.22.0-M5

Here's my code:

import com.github.tminglei.slickpg._

trait PostgresProfile extends ExPostgresProfile with PgArraySupport with PgDate2Support with PgCompositeSupport with PgHStoreSupport {
  type Predicate[Item, T <: Table[Item]] = T => Rep[Option[Boolean]]

  override val api = PostgresAPI

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

  object PostgresAPI extends ExtPostgresAPI with ArrayImplicits with Date2DateTimeImplicitsDuration with HStoreImplicits {
    implicit val dateArrayType: BaseColumnType[List[LocalDate]] =
      MappedColumnType.base[List[LocalDate], List[Date]](_.map(toSqlDate), _.map(_.toLocalDate))

    implicit def setArrayType[T: Ordering](implicit listArrayType: BaseColumnType[List[T]]): BaseColumnType[Set[T]] =
      MappedColumnType.base[Set[T], List[T]](_.toList.sorted, _.toSet)

    def optEq[T: BaseColumnType](column: Rep[Option[T]], value: Option[T]): Rep[Option[Boolean]] = value match {
      case Some(v) => column === v
      case None    => column.isEmpty.?
    }
  }
}

object PostgresProfile extends PostgresProfile
import PostgresProfile.api._

class BoostingCampaignTable(tag: Tag) extends Table[BoostingCampaign](tag, Some("marketing"), "boosting_campaigns") {
  def id                 = column[Int]("id", O.PrimaryKey)
  def partnerId          = column[Int]("partner_id")
  def includeCategoryIds = column[Set[Int]]("include_category_ids")
  def excludeCategoryIds = column[List[Int]]("exclude_category_ids")
  def startAt            = column[LocalDate]("start_at")
  def endAt              = column[LocalDate]("end_at")
  def nProducts          = column[Int]("n_products")
  def inFirstM           = column[Int]("in_first_m")

  override def * =
    (
      id,
      partnerId,
      includeCategoryIds,
      excludeCategoryIds,
      startAt,
      endAt,
      nProducts,
      inFirstM
    ) <> ((BoostingCampaign.apply _).tupled, BoostingCampaign.unapply)
}

These compile errors I get in Scala 3, but not whenever I rollback to Scala 2.13

No given instance of type slick.ast.TypedType[List[Int]]
No given instance of type slick.ast.TypedType[Set[Int]]

Do I miss anything here?

I changed everywhere to import the object instead of the api value as a workaround.
(import PostgresProfile.PostgresAPI._ instead of import PostgresProfile.api._)

Also ran into this with Scala 2.13 with slick-pg 0.21.1 when adding -Xsource:3.

Chaning import profile.api._ to import profile.MyApi._ helps, but does anyone have any idea as to why this happens?

To answer my own question above, ExPostgresProfile defines api as:

override val api: API = new API {}

So, in PostgresProfile above, it is not enough to write:

override val api = PostgresAPI

instead, this works for me (Scala 2.13 & -Xsource:3):

override val api: PostgresAPI.type = PostgresAPI