Search code examples
postgresqlscalaslick

Slick 3.2 with Postgresql?


The official Slick 3.2 docs (http://slick.lightbend.com/doc/3.2.0/database.html) says that Slick can be configured with a normal javax.sql.DataSource such as PGSimpleDataSource or PGPoolingDataSource with this:

val db = Database.forDataSource(dataSource: javax.sql.DataSource, Some(size: Int))

I can't find a Database object to import.

That Database singleton object doesn't even exist in the official ScalaDoc: http://slick.lightbend.com/doc/3.2.0/api/index.html

I include the following dependencies in my build.sbt. Am I missing a slick-postgresql binding or some other dependency that has the missing Database object specified in the documentation?

"com.typesafe.slick" %% "slick" % "3.2.0"
"org.postgresql" % "postgresql" % "42.0.0"

Solution

  • The Quick Intro section says

    // Use H2Profile to connect to an H2 database
    import slick.jdbc.H2Profile.api._
    

    Since we are using H2 as our database system, we need to import features from Slick’s H2Profile. A profile’s api object contains all commonly needed imports from the profile and other parts of Slick such as database handling.

    So I believe you want to import the PostgresProfile api:

    import slick.jdbc.PostgresProfile.api._