PageRenderTime 67ms CodeModel.GetById 24ms RepoModel.GetById 0ms app.codeStats 0ms

/app/models/Task.scala

http://github.com/Mironor/Play-2.0-Scala-MongoDb-Salat-exemple
Scala | 38 lines | 25 code | 13 blank | 0 comment | 0 complexity | 2a41199bb7f4c5f965657504ebee9680 MD5 | raw file
  1. package models
  2. import play.api.Play.current
  3. import play.api.PlayException
  4. import com.novus.salat._
  5. import com.novus.salat.dao._
  6. import com.mongodb.casbah.commons.Imports._
  7. import com.mongodb.casbah.MongoConnection
  8. import com.novus.salat.Context
  9. import mongoContext._
  10. case class Task(_id: ObjectId = new ObjectId, label: String)
  11. object TaskDAO extends SalatDAO[Task, ObjectId](
  12. collection = MongoConnection()(
  13. current.configuration.getString("mongodb.default.db")
  14. .getOrElse(throw new PlayException("Configuration error",
  15. "Could not find mongodb.default.db in settings"))
  16. )("tasks"))
  17. object Task {
  18. def all(): List[Task] = TaskDAO.find(MongoDBObject.empty).toList
  19. def create(label: String): Option[ObjectId] = {
  20. TaskDAO.insert(Task(label = label))
  21. }
  22. def delete(id: String) {
  23. TaskDAO.remove(MongoDBObject("_id" -> new ObjectId(id)))
  24. }
  25. }