Created
May 31, 2016 15:17
-
-
Save anonymous/ad726fd48cd41e47df3b608fd33b1233 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import play.api.db.slick.HasDatabaseConfig | |
import slick.driver.JdbcProfile | |
import slick.lifted.AbstractTable | |
case class Coffee (name: String, id: Option[Int]) | |
abstract class CoffeeDao extends Dao { | |
import driver.api._ | |
class Coffees(tag: Tag) extends Table[Coffee](tag, "COFFEES") { | |
def name = column[String]("COF_NAME") | |
def id = column[Int]("ID", O.PrimaryKey) | |
def * = (name, id.?) <> (Coffee.tupled, Coffee.unapply) | |
} | |
val coffees = TableQuery[Coffees] | |
def saveCoffee(coffee: Coffee) = { | |
save (coffee, coffees) | |
} | |
def listCoffees = { | |
list(coffees) | |
} | |
} | |
trait Dao extends HasDatabaseConfig[JdbcProfile] { | |
import driver.api._ | |
def save[A <: AbstractTable[_]](newItem: A#TableElementType, tableQuery: TableQuery[A]) = { | |
db.run(tableQuery.insertOrUpdate(newItem)) | |
} | |
def list[A <: AbstractTable[_]](tableQuery: TableQuery[A]) = { | |
db.run(tableQuery.result) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment