I want to have a SQL UPDATE run whenever any switch in a group of switches is flipped. I setup a "Run query automatically when inputs changes" query, and use a transformer to turn the switch group values into an update statement
conditionsStates Transformer
var conditions = {{conditionsSwitches.values}}
var conditionsThatAreTrue = {{conditionsSwitches.value}}
return conditions.map( v => `${v} = ${conditionsThatAreTrue.includes(v) ? "'true'":"'false'"}`).join(', ')
SQL
UPDATE list
SET {{conditionsStates.value}}
WHERE id = {{entity_id.value}}
However, when I preview the above query it says syntax error at or near "$1"
. I have a feeling that it's because the transformer is returning a string, and that is quoted? To check my theory, I previewed the transformer, grab it's output and pasted it into the SQL. It works great.
So two questions
- How can I use a transformer inside an update query
- If I do, and the values inside the transformer change, will the query automatically run?