slick-pg icon indicating copy to clipboard operation
slick-pg copied to clipboard

slick.jdbc.PostgresProfile.api._ will be conflict with slickpg.ExPostgresProfile.api._

Open asdfping opened this issue 5 years ago • 2 comments

if you import com.github.tminglei.slickpg.ExPostgresProfile.api._, and import slick.jdbc.PostgresProfile.api._ meanwhile,you will compile error.

if you import com.github.tminglei.slickpg.ExPostgresProfile.api.Over, and import slick.jdbc.PostgresProfile.api._ meanwhile , you will get exception slick.SlickException: Unexpected node WindowFuncExpr.

So, you should import com.github.tminglei.slickpg.ExPostgresProfile.api._ instead of slick.jdbc.PostgresProfile.api._ if you want to use slick-pg

asdfping avatar Jan 15 '20 11:01 asdfping

Yes, ExPostgresProfile extended PostgresProfile, and PostgresProfile didn't know com.github.tminglei.slickpg.ExPostgresProfile.api.Over.

tminglei avatar Jan 16 '20 01:01 tminglei

I think this might be related, but I ran into issues with ExPostgresProfile and slick.jdbc.JdbcProfile in slick codegen. The implicits were not being used by the generated code with the default generated :

object MyTable extends {
  val profile = MySlickPgPostgresProfile
} with MyTable

trait MyTable {
  val profile: slick.jdbc.JdbcProfile
  import profile.api._
  ...
}

wasn't working as expected, but replacing slick.jdbc.JdbcProfile with my custom profile resolved the problem.

This can be added to a custom code generator using, e.g.:

      override def packageCode(profile: String, pkg: String, container: String, parentType: Option[String]): String = {
        val defaultProfileClassName = "slick.jdbc.JdbcProfile"
        super
          .packageCode(profile, pkg, container, parentType)
          .replace(
            defaultProfileClassName,
            jdbcProfile match {
              case _: ExPostgresProfile => jdbcProfile.getClass.getCanonicalName.replaceAll("\\$", "")
              case _                    => defaultProfileClassName
            }
          )
      }

where jdbcProfile is the custom profile

charlietsai avatar Apr 01 '20 10:04 charlietsai