SQL query with for each

Hello! I have a table with 1 changeable field, for example, I wanna change 4 rows, and do for each UPDATE.

Example:

function runQuery(){
  channels.recordUpdates.forEach((element) =>{
  console.log(element)
	localStorage.setValue("channelID",element.channel_id)
	localStorage.setValue("isHidden",element.is_hidden)
	update_is_hidden.trigger()})

	localStorage.clear()
}

runQuery()

That query trigger SQL query:
UPDATE channel_extended_data SET is_hidden = {{localStorage.values.isHidden}} where channel_extended_data.channel_id ={{localStorage.values.channelID}}

No idea why, but sometimes it works and sometimes not. And, not sure that use localstorage for this good solution, how can I pass placeholders to SQL query?

Hey there @Jeyb and welcome to the community! You definitely have the right idea. You can pass additionalScope to your query, so you don't need to use localStorage. More on that in our docs here:

https://docs.retool.com/docs/scripting-retool#triggering-a-query

The basic syntax looks like this:

query.trigger({
  additionalScope: {
    name: 'hi',
  },
})

The keys you use in the additional scope get assigned to variables at run time, so you can reference them in your SQL query even though they'll throw errors before it runs.