Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Slick 3.0 delete and returning values

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.

like image 542
Khanetor Avatar asked Oct 19 '22 04:10

Khanetor


1 Answers

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.

like image 124
Russell Cohen Avatar answered Nov 15 '22 06:11

Russell Cohen