I have written couple of functions to manipulate data in indexedDB using Dexie wrapper. This is update method :
updateRow(documentId, rowId, row) {
this.db.transaction('rw', this.db.tableEntry, async () => {
await this.db.tableEntry.where({
documentId: documentId,
rowId: rowId
}).modify({row: row})
}).catch(e => {
console.log(e)
});
}
This function works perfectly as expected. Following function is implemented same way inside the same class :
getAllByDocumentId(documentId, callBack) {
this.db.transaction('rw', this.db.tableEntry, async () => {
await this.db.tableEntry.where({
documentId: documentId,
}).toArray((entries)=>callBack(entries))
}).catch(e => {
console.log(e)
});
}
Execution of this method gives the error :
name: "SubTransactionError"
message: "Table tableEntry not included in parent transaction."
How can I fix this? And what is the root cause behind the error?
I found the reason is that, Other calling classes execute multiple functions that include transactions. Therefore, these asynchronous functions overlaps their transactions. Only first function call is succeeded due to that reason. Simple approach I used were delaying the execution of the function when calling.
update(...);
setTimeout(getAllByDocumentId(...),200);
setTimeout(otherDBFunction(...),300);
Then It worked fine.