Conditionally updating fields
How would i go about doing something like
UPDATE table SET field = IF(condition, trueValue, falseValue) WHERE someCondition;
, i can't exactly seem to find that in the docs
Driver used: MySQL2 Replies
actually, this can be done with
<ExpressionBuilder>.case()
, but is it possible to write smth like id = id - 1
or would i be sticking to raw sql for scenarios like these?Solution
Hey 👋
Something like:
https://kyse.link/mqB8C
eb.lit
is optional here, you could just pass the 1s and have them parametrized.
eb(...)
allows creating all sorts of binary operations, where by default, the LHS is a column reference, and RHS is a value.