Open enriquemolinari opened 2 years ago
I had to do this to have the atomic behaviour:
let tx;
try {
tx = db.transaction([STORE_DB, STORE_QUEUE], "readwrite");
await tx.objectStore(STORE_DB).add({ id: 511, bla: 1 });
await tx.objectStore(STORE_QUEUE).add({ queuedTime: Date.now(), id: 11 });
await tx.done;
} catch (e) {
tx.abort();
}
Hi ! I pasted a pretty simple example using transactions with two object stores. After creating the stores on the openIndexedDb() function, the code opens a Tx and add an object to one store (STORE_DB) and then tries to add other object to the other store (STORE_QUEUE). That lines fails due to there is a typo in the name of the key (it is declared as
queueTime
and the object to add has a property calledqueuedTime
). The thing is that even when these statements are in a Tx, the first line is commit into the object store (STORE_DB). Why? anything wrong am I doing?