Thanks, cvogt for the help in the discussion. I think it would be useful to submit PR, since this is a very common and useful functionality that should not be absent in slick plainSQL queries .
Finally, I found a workaround to replace the missing built-in function as follows.
During the same session, I resolve two requests. The first is the INSERT , the second is the SELECT LAST_INSERT_ID() , which returns the new automatically generated value that was set for the AUTO_INCREMENT column by the recently executed INSERT (1). More details here: MySQL Reference - LAST_INSERT_ID ()
Database.forDataSource(dataSource).withDynSession { sqlu"""INSERT INTO `users`(`email`) VALUES (" theEmailAdress@test.de ") """.firstOption match { case Some(num) if num == 1 => sql"SELECT LAST_INSERT_ID()".as[Long].firstOption() case None => None } }
It works for me right now. If there are any improvements, feel free to post your decision.
source share