Demo app using the Scala Play framework
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
This repo is archived. You can view files and clone it, but cannot push or open issues/pull-requests.

38 lines
739 B

  1. package models
  2. import anorm._
  3. import anorm.SqlParser._
  4. import play.api.db._
  5. import play.api.Play.current
  6. case class Task(id:Long, label:String)
  7. object Task {
  8. val task = {
  9. get[Long]("id") ~
  10. get[String]("label") map {
  11. case id~label => Task(id, label)
  12. }
  13. }
  14. def all(): List[Task] = DB.withConnection { implicit c =>
  15. SQL("select * from task").as(task *)
  16. }
  17. def create(label:String) {
  18. DB.withConnection { implicit c =>
  19. SQL("insert into task (label) values ({label})").on(
  20. 'label -> label
  21. ).executeUpdate()
  22. }
  23. }
  24. def delete(id:Long) {
  25. DB.withConnection { implicit c =>
  26. SQL("delete from task where id = {id}").on(
  27. 'id -> id
  28. ).executeUpdate()
  29. }
  30. }
  31. }