3
votes

I'm having some issues when trying to use different drivers for different environments:

Error:(44, 39) value schema is not a member of slick.lifted.TableQuery[MyserviceTests.this.myService.MyTable]
      myTableQuery.schema.create,

I followed this tutorial to actually implement a multi database communication layer:

http://www.typesafe.com/activator/template/slick-multidb

How to get around this? I'm using Slick 3.0.0

2
That template actually uses Slick 2.x github.com/typesafehub/activator-slick-multidb/blob/master/… Slick 3.0 is implemented in a separate branch...sap1ens
Yes, I know that, and I'm using the corresponding imports that come from the 3.0.0 Slick library. Strangely, there is also no ddl method found and the Slick documentation suggests using schema on the TableQuery while that GitHub source uses schemajoesan
Hm, strange, for example this snippet works for me with Slick 3.0 gist.github.com/sap1ens/37001f5cf3ac6161a4e5sap1ens
Could you post actual code that causes the error?sap1ens

2 Answers

6
votes

The answer posted by sparkr works for me.

The driver api._ import cause the correct implicit conversions to be included in scope.

So, if you can use static driver binding an import like this does the trick:

import slick.driver.H2Driver.api._

or you can import dynamically if you need the code to work with multiple drivers

import scala.reflect.runtime.universe
val rtm = universe.runtimeMirror(getClass.getClassLoader)
val obj = rtm.reflectModule(rtm.staticModule("slick.driver.H2Driver"))

val driver = obj.instance.asInstanceOf[slick.driver.JdbcDriver]
import driver.api._
2
votes

Alright, I found what the issue was. Here is the complete source code to my problem.

https://groups.google.com/forum/#!topic/scalaquery/FgRuPhyuGpc

As you can see in my tests that I'm using H2Driver in the imports and using the JdbcProfile import in the actual service class, this caused the problem. All I had to do is the following in my test class:

    //import slick.driver.H2Driver.api._

    val db = Database.forURL("jdbc:h2:mem:assetConfigDb;DATABASE_TO_UPPER=false;DB_CLOSE_DELAY=-1", driver="org.h2.Driver")
    val myService = MyService.apply(DBConfig(db, driver = slick.driver.H2Driver))

    import myService.driverProfile.api._

Notice the imports as this is very important!