PostgreSQL



projects/build.scala
...
    val appDependencies = Seq(
      // Add your project dependencies here,
      // "org.squeryl" %% "squeryl" % "0.9.4"
      "org.scalaquery" % "scalaquery_2.9.0-1" % "0.9.5",
     "postgresql" % "postgresql" % "9.1-901-1.jdbc4"
    )
...


Maven - JDBC DRVIERS
$ conf/application.conf
# Database configuration
# ~~~~~ 
# You can declare as many datasources as you want.
# By convention, the default datasource is named `default`
#
 db.default.driver=org.h2.Driver
 db.default.url="jdbc:h2:mem:play"
 db.default.user=sa
# db.default.password=

# PostgreSQL
 db.play201.driver=org.postgresql.Driver
 db.play201.url="jdbc:postgresql://host:port/database"
 db.play201.user=yourAccount
 db.play201.password=



範例

package entities


//import org.scalaquery.ql._

//import org.scalaquery.ql.TypeMapper._

import org.scalaquery.ql.extended.{ ExtendedTable => Table }


//object Task extends Table[(Long, String, Date, Boolean)]("tasks") {

object Task extends Table[(Long, String, Boolean)]("tasks") {


  import play.api.db._

  import play.api.Play.current

  import org.scalaquery.session._

  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 ~ done


  def findAll = database.withSession {

    import org.scalaquery.ql.extended.H2Driver.Implicit._

    //  import org.scalaquery.ql.extended.PostgresDriver.Implicit._

    implicit db: Session =>

      (for (t <- thisyield t.id ~ t.name).list

  }


}





squeryl

Ref
Comments