Slick 3.0 Insert and then get Auto Increment Value

Here’s the relevant documentation page, according to which, you should construct a query like this:

val insertQuery = items returning items.map(_.id) into ((item, id) => item.copy(id = id))

def create(name: String, price: Double) : Future[Item] = {
  val action = insertQuery += Item(0, name, price)   
  db.run(action)
}

Leave a Comment