我在数据库中插入一个新行,它的 id 是自动递增的(“串行”)。插入后如何获取 id 的值?目前,我正在使用以下解决方法:
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
  }
}
如果没有更简单的方法,我如何确保整个块都是原子操作?