Closed mandaputtra closed 1 year ago
Hey 👋
Have you tried setting an isolation level to your transaction? https://kysely-org.github.io/kysely/classes/TransactionBuilder.html#setIsolationLevel
The insert query might not be seeing uncommitted changes so acts on database state before the deletions.
Hi, silly me, you're correct 💯 setting it up to "read commited" resulted in correct result. I found a better solution since its key conflict I can use onConflict
await trx
.insertInto('plant_lifetime_energy_managements')
.values(updateInsertedPLTE)
.onConflict((oc) => {
return oc.columns(['plant_id', 'collect_time']).doUpdateSet({
inverter_yield_kwh_hour: (eb) =>
eb.ref('excluded.inverter_yield_kwh_hour'),
});
})
.execute();
Thanks!
I have some complex transaction. It looks like these
At the bottom of the code there are
await Promise.all
the problem with this code are thePromise.all
function never finishes before it run the insert so the insert table would error outduplicate unique key error
. How do I ensure that the function onPromise.all
finished running? Is there any technique like these where as it usingTask
andBatch
or it's just not possible to wait the delete statement finish before running the insert?