question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

How to use slick-joda-mapper with injected play.api.db.slick.DatabaseConfigProvider ?

See original GitHub issue

I’d like to use dependency injection to make my choice of database configurable. In other words, I don’t want to hard code the database by doing something like

import com.github.tototoshi.slick.H2JodaSupport._

However, the example in the readme does not work with the latest Play 2.4.x, Slick 3.1.0 and slick-joda-mapper 2.1.0

import javax.inject.Inject
import com.github.tototoshi.slick.GenericJodaSupport
import org.joda.time.DateTime
import play.api.db.slick.DatabaseConfigProvider
import slick.driver.JdbcProfile

class MyRepository @Inject()(dbConfigProvider: DatabaseConfigProvider) {

  val dbConfig = dbConfigProvider.get[JdbcProfile]
  import dbConfig.driver.api._

  // Incompatible types !!
  // dbConfig.driver is an instance of JdbcProfile, not JdbcDriver
  private object PortableJodaSupport extends GenericJodaSupport(dbConfig.driver)

  import PortableJodaSupport._

  class MyTable(tag: Tag) extends Table[(Long, String, DateTime)](tag, "my_table") {
     def id = column[Long]("id", O.PrimaryKey)
     def name = column[String]("name")
     def time = column[DateTime]("date_time")
     def * = (id, name, time)
  }
  // ...
}

I don’t see an elegant way to get hold of Slick driver. Ugly workaround would be to read the configuration and try to find the Slick driver object in the classpath.

Issue Analytics

  • State:closed
  • Created 8 years ago
  • Reactions:1
  • Comments:12 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
tototoshicommented, Apr 13, 2016

@jmcclell Released 2.2.0. Please try it.

0reactions
jmcclellcommented, Apr 12, 2016

@tototoshi Any word on the status of getting a stable 2.2 release for the switch to JdbcProfile from JdbcDriver? Do you have anything you need completed/tested/working before you release?

Read more comments on GitHub >

github_iconTop Results From Across the Web

scala - No implementation for play.api.db.slick. ...
My DAO looks like: @Singleton class UserDAO @Inject() (protected val dbConfigProvider: DatabaseConfigProvider) ...
Read more >
DatabaseConfigProvider - extends - AnyRef
A DatabaseConfig is Slick type that bundles a database and profile. ... how you can use dependency injection to obtain an instance of...
Read more >
Need help fixing "No implementation for play.api.db.slick. ...
Hi all this is my first post. I am learning Scala and Play Framework and I'm attempting to write my first database backed...
Read more >
play.api.db.slick.DatabaseConfigProvider Scala Example
The following examples show how to use play.api.db.slick.DatabaseConfigProvider ... Future class PasswordInfoDAO @Inject() ( protected val dbConfigProvider: ...
Read more >
Best way to inject Slick DB · Issue #29
Hi, What's the best way to inject the default Slick DB ? I know some possible options: Use the play-slick HasDatabaseConfigProvider trait ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found