t

play.api.db.slick

HasDatabaseConfig

trait HasDatabaseConfig[P <: BasicProfile] extends AnyRef

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).

Source
DatabaseConfigProvider.scala
Linear Supertypes
AnyRef, Any
Ordering
  1. Alphabetic
  2. By Inheritance
Inherited
  1. HasDatabaseConfig
  2. AnyRef
  3. Any
  1. Hide All
  2. Show All
Visibility
  1. Public
  2. Protected