package slick
- Source
- package.scala
- Alphabetic
- By Inheritance
- slick
- AnyRef
- Any
- Hide All
- Show All
- Public
- All
Package Members
- package evolutions
Type Members
- trait DatabaseConfigProvider extends AnyRef
Generic interface for a provider of a
DatabaseConfig
instance.Generic interface for a provider of a
DatabaseConfig
instance. ADatabaseConfig
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 callDatabaseConfigProvider.get
.Example
Here is an example of how you can use dependency injection to obtain an instance of
DatabaseConfigProvider
, for the database nameddefault
in your **application.conf**.class Application @Inject()(protected val dbConfigProvider: DatabaseConfigProvider) { // ... }
While here is an example for injecting a
DatabaseConfigProvider
for a database namedorders
in your **application.conf**.import play.db.NamedDatabase class Application @Inject()(@NamedDatabase("orders") protected val dbConfigProvider: DatabaseConfigProvider) { // ... }
- final case class DbName(value: String) extends AnyVal with Product with Serializable
The name used in the application's config file to reference a slick database configuration.
- final class DefaultSlickApi extends SlickApi
- trait HasDatabaseConfig[P <: BasicProfile] extends AnyRef
Mix-in this trait if you need a Slick database and profile.
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 callingDatabaseConfigProvider.get
. If you are injectingDatabaseConfigProvider
instances using dependency injection, prefer using the traitHasDatabaseConfigProvider
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).
- trait HasDatabaseConfigProvider[P <: BasicProfile] extends HasDatabaseConfig[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
.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 mixingHasDatabaseConfig
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).
- final class NamedDatabaseConfigProvider extends Provider[DatabaseConfigProvider]
Inject provider for named databases.
- trait SlickApi extends AnyRef
- trait SlickComponents extends AnyRef
- final class SlickModule extends Module
- Annotations
- @Singleton()
Value Members
- object DatabaseConfigProvider
Look up a
DatabaseConfig
(which is Slick type that bundles a database and profile) for the passed database name.Look up a
DatabaseConfig
(which is Slick type that bundles a database and profile) for the passed database name. TheDatabaseConfig
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 configurationslick.dbs.default
is used to create theDatabaseConfig
instance.Example
Here is an example for obtaining a
DatabaseConfig
instance for the database nameddefault
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 namedorders
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)
- object DefaultSlickApi
- object SlickModule