MikroORM update coallesce

25 Views Asked by At

In MikroORM, what would be the best/efficient way to implement update for specific values that are NOT NULL? For example, in Postgres there is the COALESCE() function:

UPDATE some_table SET some_column = COALESCE(nullish_value, some_column) WHERE id = some_id;

i.e. IF nullish_value === null THEN 'keep some_column' ELSE 'update nullish_value'.

Note, I believe this would be done in MySQL/MariaDB using IFNULL() and Oracle using NVL.

I understand the workaround could be done via code with a few extra calls. However, I'm looking for the best MikroORM-ish way to do things, for example, could it be done using @BeforeUpdate() or @BeforeUpsert() hooks in the Entity?

Thanks for all your help!

0

There are 0 best solutions below