joesan
joesan

Reputation: 15435

Scala Slick 3.0.0 Strange Error

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

Upvotes: 3

Views: 1950

Answers (2)

marko
marko

Reputation: 642

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._

Upvotes: 6

joesan
joesan

Reputation: 15435

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!

Upvotes: 2

Related Questions