5

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.

Khanetor
  • 11,595
  • 8
  • 40
  • 76
  • 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 Dec 13 '15 at 19:42

1 Answers1

4

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.

Russell Cohen
  • 717
  • 4
  • 7
  • 1
    As mentioned in the question. Using `for` comprehension obviously works. I was looking for an inline solution. – Khanetor Nov 23 '16 at 21:27