Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a new event onbeforecommit on the interface IDBTransaction #314

Closed
Jack-Works opened this issue Dec 18, 2019 · 6 comments
Closed

Add a new event onbeforecommit on the interface IDBTransaction #314

Jack-Works opened this issue Dec 18, 2019 · 6 comments
Labels
feature request TPAC2024 Topic for discussion at TPAC 2024

Comments

@Jack-Works
Copy link

Jack-Works commented Dec 18, 2019

By adding a onbeforecommit event, developers can suppress the bad transaction that make the db in an inconsistent state to be committed.

e.g.

transaction.onbeforecommit = (event) => {
   // when the transaction enter the `onbeforecommit` event, it becomes readonly.
   // it should be enough for consistency check
   if (dbIsConsistent(transaction)) { event.commit() }
   else { event.abort() } // db is inconsistent if we commit this transaction
}
@inexorabletash
Copy link
Member

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?

@inexorabletash
Copy link
Member

Also, would the discussion in #34 which allow for explicit control over transaction lifetime handle this?

@Jack-Works
Copy link
Author

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)
}

@Jack-Works
Copy link
Author

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.

@Jack-Works
Copy link
Author

It will also be nice to have a diff for what does this transaction changed to complete the check

@SteveBeckerMSFT SteveBeckerMSFT added the TPAC2024 Topic for discussion at TPAC 2024 label Sep 9, 2024
@SteveBeckerMSFT
Copy link

TPAC 2024: We discussed and believe that explicit control over transaction lifetime should support the scenarios discussed by this issue. I'm closing this issue, but please re-activate with example scenarios if we're mistaken.

@SteveBeckerMSFT SteveBeckerMSFT closed this as not planned Won't fix, can't repro, duplicate, stale Oct 1, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature request TPAC2024 Topic for discussion at TPAC 2024
Projects
None yet
Development

No branches or pull requests

3 participants