If you are having trouble using Play Slick, check if the FAQ contains the answer. Otherwise, feel free to reach out to play-framework user group. Also, note that if you are seeking help on Slick, the slick user group may be a better place.

Finally, if you prefer to get an answer for your Play and Slick questions in a timely manner, and with a well-defined SLA, you may prefer to get in touch with Lightbend, as it offers commercial support for these technologies.

Users of previous versions of Play Slick will notice a number of major changes. Read the migration guide for details on upgrading from older versions of Play Slick.

First time users of Play Slick will appreciate the painless integration of Slick into Play. If you’re familiar with Play and Slick, configuring and interacting with the Play Slick module will be straightforward.

The above dependency will also bring along the Slick library as a transitive dependency. This implies you don’t need to add an explicit dependency on Slick, but you may if desired. You may explicitly define a dependency to Slick if you need to use a newer version than the one bundled with play-slick. Because Slick trailing dot releases are binary compatible, you won’t incur any risk in using a different Slick trailing point release than the one that was used to build play-slick.

The Play Slick module does not bundle any JDBC driver. Hence, you will need to explicitly add the JDBC driver(s) you want to use in your application. For instance, if you would like to use an in-memory database such as H2, you will have to add a dependency to it:

"com.h2database" % "h2" % "${H2_VERSION}" // replace `${H2_VERSION}` with an actual version number

To have the Play Slick module handling the lifecycle of Slick databases, it is important that you never create database instances explicitly in your code. Rather, you should provide a valid Slick driver and database configuration in your application.conf (by convention the default Slick database must be called default):

First, note that the above is a valid Slick configuration (for the complete list of configuration parameters that you can use to configure a database see the Slick ScalaDoc for Database.forConfig - make sure to expand the forConfig row in the doc).

Second, the slick.dbs prefix before the database’s name is configurable. In fact, you may change it by overriding the value of the configuration key play.slick.db.config.

Third, in the above configuration slick.dbs.default.driver is used to configure the Slick driver, while slick.dbs.default.db.driver is the underlying JDBC driver used by Slick’s backend. In the above configuration we are configuring Slick to use H2 database, but Slick supports several other databases. Check the Slick documentation for a complete list of supported databases, and to find a matching Slick driver.

Slick does not support the DATABASE_URL environment variable in the same way as the default Play JBDC connection pool. But starting in version 3.0.3, Slick provides a DatabaseUrlDataSource specifically for parsing the environment variable.

After having properly configured a Slick database, you can obtain a DatabaseConfig (which is a Slick type bundling a database and driver) by using dependency injection.

Note: A Slick database instance manages a thread pool and a connection pool. In general, you should not need to shut down a database explicitly in your code (by calling its close method), as the Play Slick module takes care of this already.

While you can get the DatabaseConfig instance manually by accessing the SlickApi, we’ve provided some helpers for runtime DI users (Guice, Scaldi, Spring, etc.) for obtaining specific instances within your controller.

Here is an example of how to inject a DatabaseConfig instance for the default database (i.e., the database named default in your configuration):

If you’re using compile-time DI, you can query the database config directly from the SlickApi using the slickApi.dbConfig(DbName(name)) method. The play.api.db.slick.SlickComponents provide access to the slickApi.

To run a database query in your controller, you will need both a Slick database and driver. Fortunately, from the above we now know how to obtain a Slick DatabaseConfig, hence we have what we need to run a database query.

You will need to import some types and implicits from the driver:

import dbConfig.profile.api._

And then you can define a controller’s method that will run a database query: