ScalaDatabaseOthers - opensas/Play20Es GitHub Wiki
Esta página todavía no ha sido traducida al castellano. Puedes ayudarnos con la tarea simplemente presionando el botón
Edit Page. Para más información puedes leer esta guía para el traductor. Aquí puedes ver cuánto nos falta para terminar la traducción.
You can use any SQL database access library you like with Play, as can easily retrieve either a Connection or a Datasource from the play.api.db.DB helper.
From here you can integrate any JDBC access layer that needs a JDBC data source. For example, to integrate with ScalaQuery:
import play.api.db._
import play.api.Play.current
import org.scalaquery.ql._
import org.scalaquery.ql.TypeMapper._
import org.scalaquery.ql.extended.{ExtendedTable => Table}
import org.scalaquery.ql.extended.H2Driver.Implicit._
import org.scalaquery.session._
object Task extends Table[(Long, String, Date, Boolean)]("tasks") {
lazy val database = Database.forDataSource(DB.getDataSource())
def id = column[Long]("id", O PrimaryKey, O AutoInc)
def name = column[String]("name", O NotNull)
def dueDate = column[Date]("due_date")
def done = column[Boolean]("done")
def * = id ~ name ~ dueDate ~ done
def findAll = database.withSession { implicit db:Session =>
(for(t <- this) yield t.id ~ t.name).list
}
}Some libraries expect to retrieve the Datasource reference from JNDI. You can expose any Play managed datasource via JNDI by adding this configuration in conf/application.conf:
db.default.driver=org.h2.Driver
db.default.url="jdbc:h2:mem:play"
db.default.jndiName=DefaultDS
Next: Using the Cache