Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Unable to import play.api.db.databases

I am developing an application in Scala Play 2.5.4. I want to test my database interactions, and am attempting to do so by the method recommended in this page.

The trouble is, I am unable to import the object play.api.db.Databases. I suspect that I may need to add something to my build.sbt file, but since this is part of the Play API, I'm not so sure that this is the case.

There are some things available, but not what is shown in the API doc

Image

like image 879
Anon Ymous Avatar asked Oct 14 '25 16:10

Anon Ymous


1 Answers

Yes, you need to add in your build.sbt file this:

libraryDependencies += jdbc

After that, reload activator and update your dependencies (activator update/sbt update).

Note that after this you will need also to add the jdbc driver of the database you intend to use. See more info in https://www.playframework.com/documentation/2.5.x/ScalaDatabase

Edit

As stated in the comments, this may cause problems with Slick. Unfortunately the classes you need to use are provided by that module, so if this causes you problems, you can try two things:

  • Extract the class/methods you need and put them in your project: you can get the Databases class code in https://github.com/playframework/playframework/blob/2.5.x/framework/src/play-jdbc/src/main/scala/play/api/db/Databases.scala
  • Try to disable the DBModule. I'm not quite sure about the syntax, so try each one of those:

    play.modules.enabled -= "play.api.db.DBModule" 
    play.modules.disabled += "play.api.db.DBModule" 
    
like image 51
Salem Avatar answered Oct 17 '25 11:10

Salem