I find SORM very Interesting and promising but I cant find a way to Integrate It with play any guides?
问题:
回答1:
- Install Play >= 2.1.0.
- Generate a project using Play's guides
Add appropriate SORM's and chosen database's dependencies to the generated
project/Build.scala
, e.g.:val appDependencies = Seq( "org.sorm-framework" % "sorm" % "0.3.8", "com.h2database" % "h2" % "1.3.168" )
In the same file make sure that your project depends on the same Scala version, on which SORM depends (for SORM 0.3.8 it's Scala 2.10.1):
val main = play.Project(appName, appVersion, appDependencies).settings( scalaVersion := "2.10.1" )
If you miss that step, you may bump into this issue.
In
app/models/package.scala
place all your case classes and SORM's instance declaration, e.g.:package models case class A( name : String ) case class B( name : String ) import sorm._ object Db extends Instance( entities = Set(Entity[A](), Entity[B]()), url = "jdbc:h2:mem:test" )
Note that there is no requirement to follow these naming and location conventions - e.g., you can put your SORM instances in your controllers or elsewhere if you want.
In
app/controllers/Application.scala
place some controller actions utilizing SORM, e.g.:package controllers import play.api.mvc._ import models._ object Application extends Controller { def index = Action { val user = Db.save(A("test")) Ok(user.id.toString) } }
This will print out a generated id of the saved
A
case class value.Run your server using
play run
orplay start
command.
回答2:
Play was updated to use a new build file format
Ref : Build.scala is not created in play
You can continue from build.sbt file anymore
ForEx:
libraryDependencies ++= Seq(
jdbc,
cache,
"org.sorm-framework" % "sorm" % "0.3.8",
ws,
specs2 % Test
)
For new usage :
Using SORM with Play Framework 2.3.8
回答3:
libraryDependencies ++= Seq(
jdbc,
cache,
ws,
"org.sorm-framework" % "sorm" % "0.3.22",
"com.h2database" % "h2" % "1.3.168",
"org.scalatestplus.play" %% "scalatestplus-play" % "1.5.1" % Test
)