Advertisement
Guest User

Untitled

a guest
May 2nd, 2016
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Scala 0.77 KB | None | 0 0
  1. trait QueryCommands {
  2.   val records = TableQuery[T]
  3.   val dbConfig = DatabaseConfigProvider.get[JdbcProfile](Play.current)
  4.  
  5.   def find(id: Long): Future[Option[TODO]] = {
  6.     dbConfig.db.run(find_query(id).result.headOption)
  7.   }
  8.  
  9.   def all = {
  10.     dbConfig.db.run(records.result)
  11.   }
  12.  
  13.   def destroy(id: Long) = {
  14.     dbConfig.db.run(find_query(id).delete)
  15.   }
  16.  
  17.   def update(id: Long, values: (String, Boolean)) = {
  18.     var record = find_query(id).map(result => (result.text, result.is_performed))
  19.  
  20.     dbConfig.db.run(record.update(values))
  21.   }
  22.  
  23.   private
  24.  
  25.   def find_query(id: Long): slick.lifted.Query[TODOTable, TODO, Seq] = {
  26.     records.filter(_.id === id)
  27.   }
  28.  
  29.  
  30.  
  31. object TODOs extends QueryCommands {
  32.   override val records = TableQuery[TODOTable]
  33. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement