In the following code, I can just insert my records. But I would really like to return the identifier of the inserted value, then to return the object as part of my response.
def postEntry = DBAction { request => request.body.asJson.map {json => json.validate[(String, Long, String)].map { case (name, age, lang) => { implicit val session = request.dbSession val something = Entries += Entry(None, name, age, lang) Ok("Hello!!!: " + something) } }.recoverTotal { e => BadRequest("Detected error: " + JsError.toFlatJson(e)) } }.getOrElse { BadRequest("Expecting Json data") } }
So I tried changing the insert to:
val something = (Entries returning Entries.map(_.id)) += Entry(None, name, age, lang)
But I get the following exception:
SlickException: This DBMS allows only a single AutoInc column to be returned from an INSERT
There is a note here: http://slick.typesafe.com/doc/2.1.0/queries.html
"Note that many database systems allow you to return only one column, which should be the primary key for automatic table growth. If you request other columns, then a SlickException is thrown at run time (if the database does not support it).
But he does not say how simple it is to request an identifier column.
source share