forked from playframework/playframework
-
Notifications
You must be signed in to change notification settings - Fork 0
ScalaDatabaseOthers
fmyhr edited this page Jun 5, 2012
·
6 revisions
You can use any SQL database access library you like with Play, and 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
- Configuring and using JDBC
- Using Anorm to access your database
- Integrating with other database access libraries
- HTTP programming
- Asynchronous HTTP programming
- The template engine
- HTTP form submission and validation
- Working with JSON
- Working with XML
- Handling file upload
- Accessing an SQL database
- Using the Cache
- Calling WebServices
- Integrating with Akka
- Internationalization
- The application Global object
- Testing your application