How to dynamically set a row value using data from a JS object? (onConflictDoUpdate)

I am:
  • Checking if a row already exists
  • If it doesn't: Insert the data array's object
  • If it exists: Update the price column - The issue is I'm not sure how to set a row to the relevant object in my data array
    ```js
    const data = [
    {organisationId: "ABCD", accountId: "001", price: "120000"},
    {organisationId: "EFGH", accountId: "002", price: "59000"},
    ];
await db
.insert(myTable)
.values(data)
.onConflictDoUpdate({
target: [myTable.organisationId, myTable.financialAccountId],
set: data[0], // Putting [0] works but how to dynamically set the value to the relevant object in data array?
});
```
Was this page helpful?