如何获取使用 Slick 插入的记录的自动递增值?以下代码打印 1111。我本来希望它打印 1234
import scala.slick.driver.H2Driver.simple._
object TestMappedTable extends App{
case class User(id: Option[Int], first: String, last: String)
object Users extends Table[User]("users") {
def id = column[Int]("id", O.PrimaryKey, O.AutoInc)
def first = column[String]("first")
def last = column[String]("last")
def * = id.? ~ first ~ last <> (User, User.unapply _)
}
implicit val session = Database.forURL("jdbc:h2:mem:test1", driver = "org.h2.Driver").createSession()
session.withTransaction{
Users.ddl.create
print(Users.insert(User(None, "Jack", "Green" )))
print(Users.insert(User(None, "Joe", "Blue" )))
print(Users.insert(User(None, "John", "Purple" )))
print(Users.insert(User(None, "Jim", "Yellow" )))
}
}
我正在为 Scala 2.10.0-RC1 使用 Slick 0.11.2