Permalink
Browse files

merged

  • Loading branch information...
2 parents 43290c7 + b33e316 commit 45ff8c60371d19a39d649e0569f7a6b7d4a641e7 @jamesward committed Apr 28, 2012
Showing with 23 additions and 42 deletions.
  1. +1 −1 Procfile
  2. +3 −6 app/controllers/Application.scala
  3. +15 −20 app/models/Bar.scala
  4. +3 −2 conf/application.conf
  5. +0 −12 conf/evolutions/default/1.sql
  6. +1 −1 project/Build.scala
View
2 Procfile
@@ -1 +1 @@
-web: target/start -Dhttp.port=$PORT -DapplyEvolutions.default=true -Ddb.default.driver=org.postgresql.Driver -Ddb.default.url=$DATABASE_URL
+web: target/start -Dhttp.port=$PORT -Dmongodb.uri=$MONGOHQ_URL
View
9 app/controllers/Application.scala
@@ -1,27 +1,24 @@
package controllers
import play.api.data.Form
-import play.api.data.Forms.{single, nonEmptyText}
+import play.api.data.Forms.{single, text}
import play.api.mvc.{Action, Controller}
-import anorm.NotAssigned
import com.codahale.jerkson.Json
import models.Bar
object Application extends Controller {
- val barForm = Form(
- single("name" -> nonEmptyText)
- )
+ val barForm = Form(single("name" -> text))
def index = Action {
Ok(views.html.index(barForm))
}
def addBar() = Action { implicit request =>
barForm.bindFromRequest.value map { name =>
- Bar.create(Bar(NotAssigned, name))
+ Bar.create(new Bar(null, name))
Redirect(routes.Application.index())
} getOrElse BadRequest
}
View
35 app/models/Bar.scala
@@ -2,33 +2,28 @@ package models
import play.api.db._
import play.api.Play.current
+import net.vz.mongodb.jackson.{Id, ObjectId}
+import org.codehaus.jackson.annotate.JsonProperty
+import play.modules.mongodb.jackson.MongoDB
+import reflect.BeanProperty
-import anorm._
-import anorm.SqlParser._
-case class Bar(id: Pk[Long], name: String)
+class Bar(@ObjectId @Id val id: String,
+ @BeanProperty @JsonProperty("name") val name: String) {
+ @ObjectId @Id def getId = id;
+}
object Bar {
+ private lazy val db = MongoDB.collection("bars", classOf[Bar], classOf[String])
- val simple = {
- get[Pk[Long]]("id") ~
- get[String]("name") map {
- case id~name => Bar(id, name)
- }
- }
+ def create(bar: Bar) { db.save(bar) }
+ def findAll() = { db.find().toArray }
- def findAll(): Seq[Bar] = {
- DB.withConnection { implicit connection =>
- SQL("select * from bar").as(Bar.simple *)
- }
- }
+ def apply() = {
- def create(bar: Bar): Unit = {
- DB.withConnection { implicit connection =>
- SQL("insert into bar(name) values ({name})").on(
- 'name -> bar.name
- ).executeUpdate()
- }
}
+ def unapply() = {
+
+ }
}
View
5 conf/application.conf
@@ -22,8 +22,8 @@ application.langs="en"
# 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.driver=org.h2.Driver
+# db.default.url="jdbc:h2:mem:play"
# db.default.user=sa
# db.default.password=
@@ -45,3 +45,4 @@ logger.play=INFO
# Logger provided to your application:
logger.application=DEBUG
+mongodb.uri="mongodb://127.0.0.1:27017/play2bars-scala"
View
12 conf/evolutions/default/1.sql
@@ -1,12 +0,0 @@
-# --- First database schema
-
-# --- !Ups
-
-create table bar (
- id SERIAL PRIMARY KEY,
- name varchar(255) not null
-);
-
-# --- !Downs
-
-drop table if exists bar;
View
2 project/Build.scala
@@ -8,7 +8,7 @@ object ApplicationBuild extends Build {
val appVersion = "1.0-SNAPSHOT"
val appDependencies = Seq(
- "postgresql" % "postgresql" % "9.0-801.jdbc3"
+ "net.vz.mongodb.jackson" %% "play-mongo-jackson-mapper" % "1.0.0-SNAPSHOT"
)
val main = PlayProject(appName, appVersion, appDependencies, mainLang = SCALA).settings(

0 comments on commit 45ff8c6

Please sign in to comment.