Package

play.api.db

slick

Permalink

package slick

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

Type Members

  1. trait DatabaseConfigProvider extends AnyRef

    Permalink

    Generic interface for a provider of a DatabaseConfig instance.

    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) {
     // ...
    }
  2. final case class DbName(value: String) extends AnyVal with Product with Serializable

    Permalink

    The name used in the application's config file to reference a slick database configuration.

  3. final class DefaultSlickApi extends SlickApi

    Permalink
  4. trait HasDatabaseConfig[P <: BasicProfile] extends AnyRef

    Permalink

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

  5. trait HasDatabaseConfigProvider[P <: BasicProfile] extends HasDatabaseConfig[P]

    Permalink

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

  6. final class NamedDatabaseConfigProvider extends Provider[DatabaseConfigProvider]

    Permalink

    Inject provider for named databases.

  7. trait SlickApi extends AnyRef

    Permalink
  8. trait SlickComponents extends AnyRef

    Permalink
  9. final class SlickModule extends Module

    Permalink
    Annotations
    @Singleton()

Value Members

  1. object DatabaseConfigProvider

    Permalink

    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. 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)
  2. object DefaultSlickApi

    Permalink
  3. object SlickModule

    Permalink
  4. package evolutions

    Permalink

Inherited from AnyRef

Inherited from Any

Ungrouped