Updating Retool Database Data Rows in JS

In an app I am building, I want to query one table in my Retool DB, loop through the rows, do some calculations on each row, and then store the calculation results in another table. I've read a bunch of Retool documentation and believe the best practice solution would be:

. Create a query to retrieve rows from Table1
. Create a query to upsert rows into Table2

. Write a JS query that is triggered by an event handler of a button click
. In the JS query, trigger the Table 1 query
. Then write a function that process each row of the .data result
. In the processing function, run the upsert query

Does this outline describe a recommended way to accomplish my objective?

Thanks.

Hi,

You're about right, that is possible, but you can also use the OnSucces eventhandlers in the Queries.

It would be then:

  • create SELECT query to retrieve data from Table1 (OnSucces, start next JSQuery)
  • Create JSquery to transform your data en 'return' data (OnSucces, start next Upsert query)
  • create UPSERT query to store data in table2
1 Like