package slick
- Source
- package.scala
- Alphabetic
- By Inheritance
- slick
- AnyRef
- Any
- Hide All
- Show All
- Public
- Protected
Package Members
- package evolutions
Type Members
- trait DatabaseConfigProvider extends AnyRef
Generic interface for a provider of a
DatabaseConfiginstance.Generic interface for a provider of a
DatabaseConfiginstance. ADatabaseConfigis Slick type that bundles a database and profile.Usually, you shouldn't need to create instances of
DatabaseConfigProviderexplicitly. 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 nameddefaultin your **application.conf**.class Application @Inject()(protected val dbConfigProvider: DatabaseConfigProvider) { // ... }
While here is an example for injecting a
DatabaseConfigProviderfor a database namedordersin 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 injectingDatabaseConfigProviderinstances using dependency injection, prefer using the traitHasDatabaseConfigProviderinstead 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 mixingHasDatabaseConfiginstead.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. TheDatabaseConfiginstance 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,
defaultis used, and hence the configurationslick.dbs.defaultis used to create theDatabaseConfiginstance.Example
Here is an example for obtaining a
DatabaseConfiginstance for the database nameddefaultin 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
DatabaseConfiginstance for the database namedordersin 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