KnowledgeHub
Questions
Tags
Users
Search
Alex Rivera
|
Logout
Edit Question
Title
Body
I'm using Scala Play! framework with Anorm to persist the data model to the database. I followed the example code here : 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() } } } Trying to expand on it, I want to retrieve the primary key just created and store it in the case class. How can I retrieve the primary key?
Tags (comma-separated)
Save Edits
Cancel