Quill onconflictupdate multiple values

1.4k Views Asked by At

Is it in quill somehow possible to update multiple values on a conflict? E.g like this:

val a = quote {
  query[Product]
    .insert(_.id -> 1, _.sku -> 10)
    .onConflictUpdate((t, e) => t.sku -> (t.sku + e.sku), t.abc -> e.abc)
}

I tried it like the way above and always got a "not found: value t" error when I had two values. The documentation also does not answer questions into this direction.

1

There are 1 best solutions below

2
On

Yes, you can update multiple values on insert conflict. To do this, just provide multiple lambdas with mappings, like this

val q = quote {
  query[Product]
    .insert(lift(product))
    .onConflictUpdate(
      (t, e) => t.sku -> (t.sku + e.sku),
      (t, e) => t.abc -> e.abc)
}

This will produce the following SQL for MySQL:

INSERT INTO product (id,sku,abc) VALUES (?, ?, ?) 
ON DUPLICATE KEY UPDATE sku = (sku + VALUES(sku)), abc = VALUES(abc)