Scala Playを使用しています!データモデルをデータベースに永続化するためのAnormを使用したフレームワーク。私はここのサンプルコードに従いました:
case class Bar(id: Pk[Long], name: String)
object Bar {
val simple = {
get[Pk[Long]]("id") ~
get[String]("name") map {
case id~name => Bar(id, name)
}
}
def findAll(): Seq[Bar] = {
DB.withConnection { implicit connection =>
SQL("select * from bar").as(Bar.simple *)
}
}
def create(bar: Bar): Unit = {
DB.withConnection { implicit connection =>
SQL("insert into bar(name) values ({name})").on(
'name -> bar.name
).executeUpdate()
}
}
}
それを拡張しようとして、作成したばかりの主キーを取得して、ケースクラスに保存したいと思います。
主キーを取得するにはどうすればよいですか?