HasDatabaseConfig
play.api.db.slick.HasDatabaseConfig
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 Objecttrait Matchableclass Any
- Known subtypes
-
trait HasDatabaseConfigProvider[P]
Members list
In this article