HasDatabaseConfig

play.api.db.slick.HasDatabaseConfig
trait HasDatabaseConfig[P <: BasicProfile]

Mix-in this trait if you need a Slick database and profile. This is useful if you need to define a Slick table or need to execute some operation in the database.

There is only one abstract field, dbConfig, which you can implement by calling DatabaseConfigProvider.get. If you are injecting DatabaseConfigProvider instances using dependency injection, prefer using the trait HasDatabaseConfigProvider instead of this one.

==Example==

// model definition
class Cat(name: String, color: String)
// DAO definition
class CatDAO extends HasDatabaseConfig[RelationalProfile] {
protected val dbConfig = DatabaseConfigProvider.get[RelationalProfile](Play.current)
import profile.api._

private val Cats = TableQuery[CatsTable]
def all() = db.run(Cats.result)
def insert(cat: Cat) = db.run(Cats += cat)

// Slick table definition
private class CatsTable(tag: Tag) extends Table[Cat](tag, "CAT") {
def name = column[String]("NAME", O.PrimaryKey)
def color = column[String]("COLOR")
def * = (name, color) <> (Cat.tupled, Cat.unapply _)
}
}

Of course, you do not need to define a DAO to use this trait (the above it is really just an example of usage).

Attributes

Graph
Supertypes
class Object
trait Matchable
class Any
Known subtypes

Members list

Value members

Concrete methods

final protected def db: Database

The Slick database extracted from dbConfig.

The Slick database extracted from dbConfig.

Attributes

Concrete fields

lazy protected val dbConfig: DatabaseConfig[P]

The Slick database configuration.

The Slick database configuration.

Attributes

final lazy protected val profile: P

The Slick profile extracted from dbConfig.

The Slick profile extracted from dbConfig.

Attributes

Deprecated fields

final lazy protected val driver: P

Attributes

Deprecated
true