Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Import different db drivers in Slick

Tags:

scala

slick

Slick 3 has "import api" to use specific database driver. e.g.

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

or

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

How do I use postgresql in production and h2 in unit test?

like image 764
mmdc Avatar asked Jun 08 '16 22:06

mmdc


1 Answers

Use DatabaseConfig instead. As Slick documentation states:

On top of the configuration syntax for Database, there is another layer in the form of DatabaseConfig which allows you to configure a Slick driver plus a matching Database together. This makes it easy to abstract over different kinds of database systems by simply changing a configuration file.

Instead of importing database specific drivers, first obtain a DatabaseConfig:

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

And then import api from it:

import dbConfig.driver.api._
like image 58
Ali Dehghani Avatar answered Sep 29 '22 01:09

Ali Dehghani