play.api.db.slick
Members list
Type members
Classlikes
Generic interface for a provider of a DatabaseConfig
instance. A DatabaseConfig
is Slick type that bundles a database and profile.
Generic interface for a provider of a DatabaseConfig
instance. A DatabaseConfig
is Slick type that bundles a database and profile.
Usually, you shouldn't need to create instances of DatabaseConfigProvider
explicitly. Rather, you should rely on dependency injection. If you don't want to use dependency injection, then use the companion object and call DatabaseConfigProvider.get
.
==Example==
Here is an example of how you can use dependency injection to obtain an instance of DatabaseConfigProvider
, for the database named default
in your application.conf.
class Application @Inject()(protected val dbConfigProvider: DatabaseConfigProvider) {
// ...
}
While here is an example for injecting a DatabaseConfigProvider
for a database named orders
in your application.conf.
import play.db.NamedDatabase
class Application @Inject()(@NamedDatabase("orders") protected val dbConfigProvider: DatabaseConfigProvider) {
// ...
}
Attributes
- Companion
- object
- Supertypes
-
class Objecttrait Matchableclass Any
Look up a DatabaseConfig
(which is Slick type that bundles a database and profile) for the passed database name. The DatabaseConfig
instance is created using the database's configuration you have provided in your application.conf, for the passed database name.
Look up a DatabaseConfig
(which is Slick type that bundles a database and profile) for the passed database name. The DatabaseConfig
instance is created using the database's configuration you have provided in your application.conf, for the passed database name.
Note that if no database name is passed, default
is used, and hence the configuration slick.dbs.default
is used to create the DatabaseConfig
instance.
==Example==
Here is an example for obtaining a DatabaseConfig
instance for the database named default
in your application.conf.
import play.api.Play
import play.api.db.slick.DatabaseConfigProvider
import slick.profile.RelationalProfile
val dbConfig = DatabaseConfigProvider.get[RelationalProfile](Play.current)
While here is an example for obtaining a DatabaseConfig
instance for the database named orders
in your application.conf.
import play.api.Play
import play.api.db.slick.DatabaseConfigProvider
import slick.profile.RelationalProfile
val dbConfig = DatabaseConfigProvider.get[RelationalProfile]("orders")(Play.current)
Attributes
- Companion
- trait
- Supertypes
-
class Objecttrait Matchableclass Any
- Self type
The name used in the application's config file to reference a slick database configuration.
The name used in the application's config file to reference a slick database configuration.
Attributes
- Supertypes
-
trait Serializabletrait Producttrait Equalsclass AnyValtrait Matchableclass AnyShow all
Attributes
- Companion
- class
- Supertypes
-
class Objecttrait Matchableclass Any
- Self type
-
DefaultSlickApi.type
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.
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
- Supertypes
-
class Objecttrait Matchableclass Any
- Known subtypes
-
trait HasDatabaseConfigProvider[P]
Mix-in this trait if you need a Slick database and profile, and you are using dependency injection for obtaining an instance of DatabaseConfigProvider
. If you are not using dependency injection, then prefer mixing HasDatabaseConfig
instead.
Mix-in this trait if you need a Slick database and profile, and you are using dependency injection for obtaining an instance of DatabaseConfigProvider
. If you are not using dependency injection, then prefer mixing HasDatabaseConfig
instead.
This trait is useful if you need to define a Slick table or need to execute some operation in the database.
==Example==
// model definition
class Cat(name: String, color: String)
// DAO definition
class CatDAO @Inject()(protected val dbConfigProvider: DatabaseConfigProvider) extends HasDatabaseConfigProvider[RelationalProfile] {
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
- Supertypes
Inject provider for named databases.
Inject provider for named databases.
Attributes
- Supertypes
Attributes
- Supertypes
-
class Objecttrait Matchableclass Any
- Known subtypes
-
class DefaultSlickApi
Attributes
- Supertypes
-
class Objecttrait Matchableclass Any
Attributes
- Companion
- class
- Supertypes
-
class Objecttrait Matchableclass Any
- Self type
-
SlickModule.type
Attributes
- Companion
- object
- Supertypes
-
class Moduleclass Objecttrait Matchableclass Any