Vistritium
Vistritium

Reputation: 26

In Slick 3.0 is there a way to declare Tables without using a Specific JDBC Driver

In slick 2.0 it was possible using something like this:

import driver.simple._

It was also asked here: In Slick is there a way to declar Tables without using a Specific JDBC Driver

However this seems to be no longer case for Slick 3.0. In their upgrade guide there is:

The JdbcDriver object has been deprecated. You should always use the correct driver for your database system. ~ http://slick.lightbend.com/doc/3.0.0/upgrade.html

But I still need to be able to switch between Postgress driver and H2. Is there anything I can do? For example is it possible to have the import-config in one place (for specific driver) and generic imports elsewhere. When I need to switch dbs, I just change import in one place. There may happen compilation errors because of driver switch but it's fine. But I don't want to go to every driver-related class and change the imports everytime I want to switch DB..

Upvotes: 2

Views: 64

Answers (1)

Chobeat
Chobeat

Reputation: 3535

Sure, the usual pattern is something like this.

object DriverRepository{
val defaultDriver: DatabaseConfig[JdbcProfile] = DatabaseConfig.forConfig("slick.dbs.default")
}

There you have a single place with a unique reference to the type of driver you want to use.

Then you will just need to:

import DriverRepository.defaultDriver.driver.api._

to access all your methods

Upvotes: 3

Related Questions