5
votes

If I want a returning value when inserting a new row, I can do something like

val insertQuery = myTable returning myTable.map(_.id) += SomeData(someString)

How can I achieve the same effect when deleting?

I tried

val deleteQuery = myTable filter (_.id ===id) returning myTable.map(_.someColumn) delete

But apparently this does not compile.

I can resort to the for comprehension but I wonder if there is a shorter way.

1
The returning value of deleting is the number of rows deleted. I guess if you want to return the values itself, you need to select them first before you delete them.haffla

1 Answers

3
votes

The best way I know of to do this is to do something like:

val query = db.filter(....)
val action = for {
   results <- query.result
   _ <- query.delete
} yield results
db.run(action.withTransactionIsolation(TransactionIsolation.RepeatableRead))

Wish it was shorter.