Advertisement
Guest User

Untitled

a guest
Mar 27th, 2013
169
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Scala 0.79 KB | None | 0 0
  1. package models
  2.  
  3. import anorm._
  4. import anorm.SqlParser._
  5. import play.api.db._
  6. import play.api.Play.current
  7.  
  8. case class Task(id: Long, label: String)
  9.  
  10. object Task {
  11.   val task = {
  12.     get[Long]("id") ~
  13.       get[String]("label") map {
  14.       case id ~ label => Task(id, label)
  15.     }
  16.   }
  17.  
  18.   def all(): List[Task] = DB.withConnection {
  19.     implicit c =>
  20.       SQL("select * from task").as(task *)
  21.   }
  22.  
  23.   def create(label: String) {
  24.     DB.withConnection {
  25.       implicit c =>
  26.         SQL("insert into task (label) values ({label})").on(
  27.           'label -> label
  28.         ).executeUpdate()
  29.     }
  30.   }
  31.  
  32.   def delete(id: Long) {
  33.     DB.withConnection {
  34.       implicit c =>
  35.         SQL("delete from task where id = {id}").on(
  36.           'id -> id
  37.         ).executeUpdate()
  38.     }
  39.   }
  40. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement