如果我在插入新行时想要一个返回值,我可以做类似的事情
val insertQuery = myTable returning myTable.map(_.id) += SomeData(someString)
删除时如何达到同样的效果?
我试过
val deleteQuery = myTable filter (_.id ===id) returning myTable.map(_.someColumn) delete
但显然这不能编译。
我可以求助于
for
理解,但我想知道是否有更短的方法。
最佳答案
我所知道的最好的方法是执行以下操作:
val query = db.filter(....)
val action = for {
results <- query.result
_ <- query.delete
} yield results
db.run(action.withTransactionIsolation(TransactionIsolation.RepeatableRead))
希望它更短。
关于scala - Slick 3.0 删除和返回值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32123804/