Skip to content

Instantly share code, notes, and snippets.

@mocyuto
Created October 9, 2014 15:31
Show Gist options
  • Save mocyuto/4b8b007ce36a24732fff to your computer and use it in GitHub Desktop.
Save mocyuto/4b8b007ce36a24732fff to your computer and use it in GitHub Desktop.
update を普通に実装した場合
case class Coffees(id: Int, name: String, supId:Int, price: Double)
class CoffeesTable(tag: Tag) extends Table[(String, Int, Double, Int, Int)](tag, "coffees") {
def id = column[Int]("COF_NAME", O.PrimaryKey)
def name = column[String]("name")
def supID = column[Int]("SUP_ID")
def price = column[Double]("PRICE")
def * = (id, name, supID, price) <> (Coffees.tupled, Coffees.unapply)
// A reified foreign key relation that can be navigated to create a join
}
val query = TableQuery[Coffees]
def update (coffee: Coffees) = {
Database.forURL("jdbc:h2:mem:test1", driver = "org.h2.Driver") withSession {
implicit session =>
query.filter(id===coffee.id).update(coffee)
}
}
def main(args: Array[String]) {
update(coffee(1,"starbacks",1,540))
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment