Pastebin launched a little side project called VERYVIRAL.com, check it out ;-) Want more features on Pastebin? Sign Up, it's FREE!
Guest

Untitled

By: a guest on Mar 27th, 2013  |  syntax: Scala  |  size: 0.79 KB  |  views: 64  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  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. }
clone this paste RAW Paste Data