Import different db drivers in Slick

Slick 3 has an "import api" to use a specific database driver. eg.

import slick.driver.H2Driver.api._ ...DAO implementation... 

or

 import slick.driver.PostgresDriver.api._ ...DAO implementation... 

How to use postgresql in production and h2 in unit test?

+6
source share
1 answer

Use DatabaseConfig . Since the Slick documentation says:

In addition to the configuration syntax for Database , there is another layer in the form of DatabaseConfig , which allows you to configure the Slick driver along with the corresponding database. This simplifies the abstract across various types of database systems with the help of simply modifying the configuration file.

Instead of importing specific database drivers, first get DatabaseConfig :

 val dbConfig = DatabaseConfig.forConfig[JdbcProfile]("<db_name>") 

And then import the api from it:

 import dbConfig.driver.api._ 
+6
source

All Articles