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

Usage question: how to use slick-pg with an existing Profile? #559

Open
nemoo opened this issue May 19, 2022 · 2 comments
Open

Usage question: how to use slick-pg with an existing Profile? #559

nemoo opened this issue May 19, 2022 · 2 comments

Comments

@nemoo
Copy link

nemoo commented May 19, 2022

I want to use slick-pg with the great https://github.com/gitbucket/blocking-slick

It provides its own api and is used like this: import com.github.takezoe.slick.blocking.BlockingPostgresDriver.blockingApi._

I am strugling to combine the slick-pg with blocking-slick. My first naive approach looks like this:

import com.github.takezoe.slick.blocking.BlockingJdbcProfile
import com.github.tminglei.slickpg._

//trait MyPostgresDriver extends ExPostgresProfile with PgDate2Support {
trait MyPostgresDriver extends BlockingJdbcProfile with PgDate2Support {

  override val api = new API with DateTimeImplicits {}
}

object MyPostgresDriver extends MyPostgresDriver

This fails with Illegal inheritance, self-type MyPostgresDriver does not conform to PgDate2Support with PostgresProfile.
I created feature branch for this experiment: https://github.com/nemoo/play-slick-synchronous-example/blob/slick-pg/app/util/MyPostgresDriver.scala

Is there a way to use slick-pg with external Profiles, like the one mentioned above?

@nemoo
Copy link
Author

nemoo commented May 20, 2022

ok, got it to compile by extending both.

import com.github.takezoe.slick.blocking.BlockingJdbcProfile
import com.github.tminglei.slickpg._

trait MyPostgresDriver extends ExPostgresProfile with BlockingJdbcProfile with PgDate2Support {

  override val api = new API with DateTimeImplicits {}
}

object MyPostgresDriver extends MyPostgresDriver

and then using it like this:
import util.MyPostgresDriver.blockingApi._

@nemoo
Copy link
Author

nemoo commented May 20, 2022

My simple test case for the use of OffsetDateTime ( https://github.com/nemoo/play-slick-synchronous-example/blob/slick-pg/test/models/ModelScalaTestSpec.scala#L55 )

  "An timestamp " should {
    "be persisted correctly" in {
      db.withSession { implicit session =>
        val projectId = projectRepo.create("A")

        val timestamp = OffsetDateTime.now()
        val taskId = taskRepo.insert(Task(0, "blue", TaskStatus.ready, projectId, timestamp))
        taskRepo.findById(taskId).lastModification mustBe timestamp
      }
    }
  }

is still failing with:

- should be persisted correctly *** FAILED ***
[info]   org.postgresql.util.PSQLException: ERROR: column "last_modification" is of type timestamp with time zone but expression is of type character varying
[info]   Hint: You will need to rewrite or cast the expression.
[info]   Position: 87

Where could I look for the error?

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

1 participant