Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

play 2.5.x Anorm Doc update with DI #129

Merged
merged 2 commits into from Oct 19, 2016
Merged
Changes from 1 commit
Commits
File filter...
Filter file types
Jump to…
Jump to file or symbol
Failed to load files and symbols.

Always

Just for now

@@ -56,7 +56,7 @@ libraryDependencies ++= Seq(

To start you need to learn how to execute SQL queries.

First, import `anorm._`, and then simply use the `SQL` object to create queries. You need a `Connection` to run a query, and you can retrieve one from the `play.api.db.DB` helper:
First, import `anorm._`, and then simply use the `SQL` object to create queries. You need a `Connection` to run a query, and you can retrieve one from the `play.api.db.DB` helper with the help of DI:

@[playdb](code/ScalaAnorm.scala)

@@ -1,23 +1,14 @@
package scalaguide.sql.anorm
package scalaGuide.main.sql

import org.specs2.mutable.Specification
import play.api.test._
import play.api.test.Helpers._
import play.api.db.Database
import anorm._
import com.google.inject.Inject
//#playdb
class ScalaAnorm @Inject () (db: Database) {

This comment has been minimized.

Copy link
@wsargent

wsargent Oct 19, 2016

Member

the imports should be available within the preview snippet


object ScalaAnorm extends Specification {
"Code samples" title
db.withConnection { implicit connection =>
val result: Boolean = SQL("Select 1").execute()

"Anorm" should {
"be usable in play" in new WithApplication(FakeApplication(additionalConfiguration = inMemoryDatabase())) {
//#playdb
import anorm._
import play.api.db.DB

DB.withConnection { implicit c =>
val result: Boolean = SQL("Select 1").execute()
}
//#playdb
ok
}
}
}

This comment has been minimized.

Copy link
@wsargent

wsargent Oct 19, 2016

Member

Included imports

//#playdb
ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.