3
votes

Using Slick 3, I want to update my row depending on the property provided by the user. Say, I have 2 properties email and name. If email and name are provided I will update both properties in the database. If either one is provided I will only update the one provided and leave the other untouch.

I found what I want here,

Conditonally UPDATE fields with Slick String interpolation

but I do not want to manipulate the query string directly. Is this the only way? I prefer to use filter and update methods. Thanks

2

2 Answers

0
votes

I could not find an answer fast enough and I relented. I use multiple update configurations instead of a generalized composing update. This is bad as the number of configurations depend on 2 power of the number of parameters variant. It will become unwieldy and explode. Fortunately, at the moment, I have 2 parameters to manage.

0
votes

One possible workaround for this is to get the record first, update its fields in-memory, and then pass it to Slick update. It'll generate an SQL UPDATE for all the fields.

Notice that it should be done in transaction and might have different semantics depending on your transaction isolation level.