IndexedDB API Reference

IDBDatabase, IDBObjectStore, IDBIndex and IDBCursor methods with transaction modes.

Searchable IndexedDB API reference covering IDBFactory, IDBDatabase, IDBObjectStore, IDBIndex, IDBCursor and IDBTransaction methods, plus readonly, readwrite and versionchange transaction modes.

What are the three IndexedDB transaction modes?

readonly allows concurrent reads with no writes and is the default. readwrite permits reads and writes but serialises against other writers on the same store. versionchange is created automatically during upgradeneeded and is the only mode that can add or remove stores and indexes.

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 keyPath for in-line keys (the key lives in the value) or autoIncrement for generated keys.
  • Cursors iterate in key order; pass prev for descending or nextunique to 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.