0

I currently have a patch endpoint which allows users to supply a field/value to update. I handle the update for a single named field/value with the following query.

 val query = sqlu"""UPDATE issues
                       SET    #$column=$value,
                              UPDATED_AT=NOW(),
                              VERSION=VERSION+1
                       WHERE  ID=$issueId
                       LIMIT  1"""

Now I need to extend the expoint to allow multiple updates in a single http request. So the user can supply for example two

[ {"op":"update","field":"name","value":"test"}, {"op":"update","field":"age","value":"99"} ]

I have managed to make this work by essentially doing the query above twice but that is obviously two hits to the DB.

Is there a way to update multiple unknown column/values in slick?

Ben Flowers
  • 1,434
  • 7
  • 21
  • 49
  • is this a duplication of http://stackoverflow.com/questions/16757368/how-do-you-update-multiple-columns-using-slick-lifted-embedding ? – ryan Aug 15 '16 at 17:06
  • @ryan no as this person seems to know which columns they want at compile time. I only know which columns I need to update at runtime – Ben Flowers Aug 16 '16 at 08:52
  • I see. though it's not a direct answer to this, maybe you want to consider using json object in the table to store the data that may change. AFAIK, Postgres has a very nice support for this. – ryan Aug 16 '16 at 16:40

0 Answers0