Fortune.scala 623 B

123456789101112131415161718192021
  1. package models
  2. import play.api.Play.current
  3. import play.api.db.slick.Config.driver.simple._
  4. import play.api.db.slick.DB
  5. class Fortunes(tag: Tag) extends Table[Fortune](tag, "Fortune") {
  6. def id = column[Long]("id", O.PrimaryKey)
  7. def message = column[String]("message")
  8. def * = (id, message) <> (Fortune.tupled, Fortune.unapply _)
  9. }
  10. class FortunesTableQuery extends TableQuery(new Fortunes(_)){
  11. val byId = this.findBy(_.id)
  12. val all = Compiled{this:Query[Fortunes,Fortune,Seq]}
  13. def getAll(): List[Fortune] = DB.withSession { implicit session =>
  14. all.list
  15. }
  16. }
  17. case class Fortune(id: Long, message: String)