How do I use the SORM framework with the Play Framework?

I find SORM very interesting and promising, but I can't find a way to integrate it with the game in any tutorials?

+3


source to share


3 answers


  • Install Play> = 2.1.0.
  • Create a Project Using the Replay Guides
  • Add the appropriate SORM and selected database dependencies to the generated one project/Build.scala

    , for example:

    val appDependencies = Seq(
      "org.sorm-framework" % "sorm" % "0.3.8",
      "com.h2database" % "h2" % "1.3.168"
    )
    
          

  • In the same file, make sure your project depends on the same version of Scala that SORM depends on (for SORM 0.3.8 it Scala 2.10.1):

    val main = play.Project(appName, appVersion, appDependencies).settings(
      scalaVersion := "2.10.1"
    )
    
          

    If you skip this step, you may encounter this problem .

  • In app/models/package.scala

    place all your case classes and the SORM instance declaration, for example:

    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 need to follow these naming and location conventions - for example, you can put your SORM instances in your controllers or elsewhere if you like.

  • In app/controllers/Application.scala

    put some controller actions using SORM like:

    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 output the generated ID of the stored case class value A

    .

  • Start the server with the command play run

    or play start

    .



+11


source


Play has been updated to use the new build file format

Link: Build.scala is not generated in the game

You can continue with the build.sbt file for more

ForEx:



libraryDependencies ++= Seq(
  jdbc,
  cache,
  "org.sorm-framework" % "sorm" % "0.3.8",
  ws,
  specs2 % Test
)

      

For new use:

Using SORM with Play Framework 2.3.8

+2


source


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
)

      

0


source







All Articles