A map of the IndexedDB object graph
IndexedDB is a transactional, asynchronous, key-value store built into the browser for large structured data and offline apps. Its API spans several interfaces — a factory, the database, object stores, indexes, cursors and transactions — each with its own methods. This searchable reference lists the core members with their signatures so you can find the right call quickly.
How it works
You open a database, declare stores and indexes during an upgrade, then read and write inside transactions:
const req = indexedDB.open("app", 2);
req.onupgradeneeded = (e) => {
const db = e.target.result;
const store = db.createObjectStore("notes", { keyPath: "id" });
store.createIndex("by_tag", "tag", { unique: false });
};
req.onsuccess = (e) => {
const db = e.target.result;
const tx = db.transaction("notes", "readwrite");
tx.objectStore("notes").put({ id: 1, tag: "todo", body: "ship it" });
};
Every operation returns an IDBRequest whose onsuccess/onerror fire
asynchronously. Transactions auto-commit when control returns to the event loop
with no pending requests. Schema changes are confined to the special
versionchange transaction during upgradeneeded.
Tips and notes
- Use
keyPathfor in-line keys (the key lives in the value) orautoIncrementfor generated keys. - Cursors iterate in key order; pass
prevfor descending ornextuniqueto skip duplicate index keys. getAll()is faster than a cursor when you simply need every matching value as an array.- A thrown error or
tx.abort()rolls back every change made in that transaction — IndexedDB is fully atomic per transaction.