Reference
Compressed map of scoped work and store verbs. Pair with Lesson 3.
const tx = db.transaction(storeNameOrNames, mode);
// mode: "readonly" | "readwrite" (versionchange only from upgradeneeded)
const store = tx.objectStore("notes");
store.get(key);
store.getAll(query?, count?);
store.put(value, key?); // upsert
store.add(value, key?); // fail if key exists
store.delete(key);
store.clear();
tx.oncomplete = () => { /* durable for this tx */ };
tx.onerror = () => { /* aborted / failed */ };
tx.onabort = () => { /* aborted */ };
| Mode | Use |
|---|---|
readonly |
Loads; prefer by default |
readwrite |
Any mutation; keep short |
versionchange |
Schema only (upgrade path) |
await unrelated async mid-transaction and then
issue more store requests.
fetch / timers / user prompts between
transaction(...) and the last store request — classic
inactive/finished errors.
Prefer tx.oncomplete (or wrapper promise for the whole
transaction) over a single request’s onsuccess when
multiple ops must land together.