InsertOrUpdate in Slick - when not using primary key

Viewed 946

We are using Slick in a Scala Project. There's a module where we need to do Upsert operation ( Insert/Update) . One of the ways we know is to simply use SQL statements and do it, but for now we would like to stick to using Slick to do it instead.

Since Slick's version we use supports InsertOrUpdate() operation, we want to use that. Now here's an issue : -

Our table has one primary key, and that is the index which is set to auto-increment. And the upsert operation which we want to do is on a transaction id which though is expected to be unique but is not marked unique or primary key in the database.

How to handle this situation? I tried manually implementing Upsert by first checking the table, and then insert/update but that is failing in production environment when many requests are coming in every second and we are having 2 inserts for about 1% of the results.

0 Answers
Related