I insert a new row into a database and its id is auto-incremented ("serial"). How can I get the value of the id after insertion? Currently, I am using the following workaround:
inTransaction {
Schema.table.insert(new Entry(
content = "..."
))
def entries = from(Schema.table)(e => select(e) orderBy(e.id desc)).page(0, 1)
val id = entries.headOption match {
case Some(entry) => entry.id
case None => 0
}
}
If there is no easier way, how can I ensure this entire block will be an atomic operation?