How to use slick-joda-mapper with injected play.api.db.slick.DatabaseConfigProvider ?
See original GitHub issueI’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:
- Created 8 years ago
- Reactions:1
- Comments:12 (2 by maintainers)
Top 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 >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@jmcclell Released 2.2.0. Please try it.
@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?