Fortune.scala 516 B

12345678910111213141516171819202122232425
  1. package models
  2. import play.api.db._
  3. import play.api.Play.current
  4. import anorm._
  5. import anorm.SqlParser._
  6. import scala.language.postfixOps
  7. case class Fortune(id: Long, message: String)
  8. object Fortune {
  9. val simpleRowParser = {
  10. get[Long]("fortune.id") ~
  11. get[String]("fortune.message") map {
  12. case id~message => Fortune(id, message)
  13. }
  14. }
  15. def getAll(): List[Fortune] = {
  16. DB.withConnection { implicit connection =>
  17. SQL("SELECT * FROM Fortune").as(Fortune.simpleRowParser *)
  18. }
  19. }
  20. }