This question might not strictly related to Elixir, but f someone could help me to learn I would really appreciate it!
So, I need to find a value in the DB and transform it based on a simple logic. Basically my fragment in select
looks like this:
fragment("
CASE
WHEN ? IS NOT NULL THEN ?
ELSE ? ->> 'key'
END
", id, t1.key, t2.object)
And it works, but I need to apply a conditional logic for ?
when I got the value following this logic or sudo code:
fragment("
CASE
WHEN id IS NOT NULL THEN
IF t1.key == "1", DO: "SUCCESS", ELSE: "FAIL"
ELSE
IF t2.object.key == "1", DO: "SUCCESS", ELSE: "FAIL"
END
", id, t1.key, t2.object)
I was trying different approaches but always getting errors related to mismatch of received argument(s) vs expected argument(s).
Obviously, I can do that later after Repo.all
, but I would like to put all load on DB level.
I would appreciate any help here!
Thanks a lot in advance!