Open Jack-Works opened 4 years ago
Can you give examples of the problems you are trying to address with this idea?
Where have you seen the lack of this functionality be a problem?
Also, would the discussion in #34 which allow for explicit control over transaction lifetime handle this?
Here is my usage:
(I'm using the library idb
to wrap raw indexeddb as Promise version)
const t = getTransaction('objectStore', 'readwrite')
await doDangerousAction1(t)
await doDangerousAction2(t)
I need a way to do a data consistency check before the transaction end. If the check failed, I want to drop the transaction to prevent my db goes into a inconsistent state.
Currently I use this way to do the job:
async function consistentDBWriteAccess(action: (t: TransactionType) => Promise<void>) {
const t = (await db()).transaction(['objectStore'], 'readwrite')
await action(t)
await assertDBConsistency(t)
}
It will be nicer to append the check like this:
function doDangerousAction1(t) {
// ....
t.addEventListener('beforecommit', e => assertDBConsistency(e, t))
}
Therefore I can enforce a consistency check before the transaction commit then abort the transaction if it goes into a invalid state.
It will also be nice to have a diff
for what does this transaction changed to complete the check
By adding a
onbeforecommit
event, developers can suppress the bad transaction that make the db in an inconsistent state to be committed.e.g.