Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- trait QueryCommands {
- val records = TableQuery[T]
- val dbConfig = DatabaseConfigProvider.get[JdbcProfile](Play.current)
- def find(id: Long): Future[Option[TODO]] = {
- dbConfig.db.run(find_query(id).result.headOption)
- }
- def all = {
- dbConfig.db.run(records.result)
- }
- def destroy(id: Long) = {
- dbConfig.db.run(find_query(id).delete)
- }
- def update(id: Long, values: (String, Boolean)) = {
- var record = find_query(id).map(result => (result.text, result.is_performed))
- dbConfig.db.run(record.update(values))
- }
- private
- def find_query(id: Long): slick.lifted.Query[TODOTable, TODO, Seq] = {
- records.filter(_.id === id)
- }
- object TODOs extends QueryCommands {
- override val records = TableQuery[TODOTable]
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement