Library / SDK
jakearchibald/idb avatar
jakearchibald/idb

idb: IndexedDB with promises, and the one transaction rule that still bites

IndexedDB, but with promises

7,443 stars385 forksTypeScriptISC

At a glance

What is it?
jakearchibald/idb is a roughly 1.19kB brotli'd wrapper that turns IDBRequest objects into promises and adds event callbacks to openDB. It does not hide IndexedDB's transaction lifetime, so an await on something else can close your transaction.
Who is it for?
Choose idb if you want the IndexedDB data model you already know, with promises and a cleaner upgrade path, in about 1.19kB brotli'd. Do not choose it if you want a key-value or query abstraction, because it mirrors IndexedDB on purpose, and do not target Internet Explorer.
Can I use it commercially?
Yes. ISC is a permissive licence: you can use, modify and sell software built on it, as long as you keep its copyright and licence notices.
Is it still maintained?
Yes. The repository last received commits 51 days ago.
What is it written in?
Mainly TypeScript, according to GitHub's language statistics.

Answers come from the project's GitHub data, last synced on November 25, 2026, and from our analysis. They are not legal advice.

From daily snapshots

Star history

  • jakearchibald/idb7,443 ★ · +21
Star history
Repository2026-10-112026-11-25
jakearchibald/idb7.4k7.4k

21 Stars in the last 45 days, measured from the daily GitHub snapshot. Compare with other projects

Editorial analysis

A thin mirror of IndexedDB, with the same stores, cursors and transactions

The README describes idb as a tiny library of about 1.19kB brotli'd that mostly mirrors the IndexedDB API, with small improvements that make a big difference to usability. After you open the database, the API is the same as IndexedDB, except for a few changes.

The main change: any method that usually returns an `IDBRequest` object now returns a promise for the result. A read looks like this:

js
const store = db.transaction(storeName).objectStore(storeName);
const value = await store.get(key);

The design choice matters for what you learn. Because idb keeps the original model of databases, object stores, transactions and cursors, knowledge of plain IndexedDB transfers, and so does the MDN documentation the README links for each event. The package description reads: A small wrapper that makes IndexedDB usable. It is not a storage abstraction with its own query language.

openDB takes four callbacks that map to four IndexedDB events

`openDB(name, version, { upgrade, blocked, blocking, terminated })` returns a promise for an enhanced `IDBDatabase`. The name is the database name. The version is optional, and passing `undefined` opens the current version.

Each callback replaces a plain IndexedDB event. `upgrade(db, oldVersion, newVersion, transaction, event)` runs if this version has never been opened and is where you define the schema, like the `upgradeneeded` event. Its `transaction` argument is an enhanced transaction, useful for reading other stores during a migration. `blocked(currentVersion, blockedVersion, event)` fires when older versions are open on the origin, so this one cannot open. `blocking(currentVersion, blockedVersion, event)` fires when your connection is blocking a future version, like `versionchange`. `terminated()` fires when the browser abnormally terminates the connection, and not on a regular `db.close()`.

An auto-closing transaction makes awaiting a fetch mid-transaction a bug

The README puts the key warning in capitals: do not await other things between the start and end of your transaction, otherwise the transaction will close before you are done. An IDB transaction auto-closes if it has nothing left to do once microtasks have been processed.

This works, because every await is on the transaction's own requests:

js
const tx = db.transaction('keyval', 'readwrite');
const store = tx.objectStore('keyval');
const val = (await store.get('counter')) || 0;
await store.put(val + 1, 'counter');
await tx.done;

This does not, since the fetch yields to the network:

js
const tx = db.transaction('keyval', 'readwrite');
const store = tx.objectStore('keyval');
const val = (await store.get('counter')) || 0;
// This is where things go wrong:
const newVal = await (await fetch('/increment?val=' + val)).json();
// And this throws an error:
await store.put(newVal, 'counter');
await tx.done;

The transaction can close while the browser is fetching, so `store.put` fails. If the network request needs the stored value, read it first, perform the request, then open a new transaction for the write. Those separate transactions are not an atomic read-modify-write: account for concurrent changes when designing the update.

Some methods throw synchronously instead of returning a rejected promise

The library turns all `IDBRequest` objects into promises, but it does not know in advance which methods may return promises. As a result, a method such as `store.put` may throw instead of returning a promise.

Inside an async function, there is no observable difference: a thrown error and a rejected promise both land in your `catch`. Outside one, the difference is real. Code like `store.put(x).catch(handler)` will not reach the handler if `put` throws before returning.

The practical rule is to call the library from async functions and wrap the block in try and catch. That keeps the behavior uniform, and it matches how the README's own examples are written.

Also note the `tx.done` promise in the examples above. Awaiting it tells you the whole transaction has completed, which is a separate event from any single request inside it.

wrap and unwrap move objects across the library boundary

Two functions let you mix idb with code that does not use it. `wrap(unwrapped)` takes an IDB object and returns a version enhanced by this library. The README suggests it for the case where third-party code hands you an `IDBDatabase` and you want the library's features on it.

`unwrap(wrapped)` goes the other way. It takes an enhanced object and returns the plain unmodified one, which is useful if you want to drop back into plain IndexedDB for some reason. Promises are converted back into `IDBRequest` objects as well.

Both appear in the module import line, `import { openDB, deleteDB, wrap, unwrap } from 'idb';`. `deleteDB(name, { blocked })` deletes a database and calls `blocked` if open connections do not close in response to a versionchange event, in which case the request waits until they all close.

npm, a jsdelivr module import or a global idb object

With npm, the install is `npm install idb`, followed by an import in any module-compatible system such as webpack or Rollup.

In a browser without a bundler, there are two forms. The module form imports from jsdelivr:

html
<script type="module">
  import { openDB, deleteDB, wrap, unwrap } from 'https://cdn.jsdelivr.net/npm/idb@8/+esm';

  async function doDatabaseStuff() {
    const db = await openDB(…);
  }
</script>

The script-tag form loads `https://cdn.jsdelivr.net/npm/idb@8/build/umd.js` and creates a global named `idb` that contains all exports of the module version, so you call `idb.openDB(…)`.

Both CDN URLs pin major version 8. The package.json shows version 8.0.4, ships files from build, and declares exports for types, import and a CommonJS default.

Modern browsers only, no GitHub releases, and the last push was on 2026-10-06

Browser support is stated in one sentence. The library targets modern browsers, meaning Chrome, Firefox, Safari and other browsers that use those engines, such as Edge. Internet Explorer is not supported, so there is no fallback build for it.

The README keeps breaking changes in CHANGELOG.md, linked as potentially breaking changes. Read it before bumping a major version.

The repository has no GitHub releases, so versions live on npm under the name idb. The project is not archived, and the last push was on 2026-10-06. The license is ISC. The top level includes a size-tests directory and a build script that runs a size report, which backs the small-size claim. The README also has a TypeScript section.

Editorial conclusion

Choose idb if you want the IndexedDB data model you already know, with promises and a cleaner upgrade path, in about 1.19kB brotli'd. Do not choose it if you want a key-value or query abstraction, because it mirrors IndexedDB on purpose, and do not target Internet Explorer. Before shipping, write one transaction that awaits a fetch between a get and a put, and confirm that you understand why the put throws.

Frequently asked questions

What does idb do that plain IndexedDB does not?

It returns promises instead of IDBRequest objects and adds openDB callbacks for upgrade, blocked, blocking and terminated. The README also lists IDBDatabase, IDBTransaction and IDBCursor enhancements and async iterators; otherwise the API is the same as IndexedDB.

Does idb support Internet Explorer?

No. The README says the library targets modern browsers such as Chrome, Firefox, Safari and engines based on them, including Edge, and that IE is not supported.

How do I add idb without a bundler?

Import from https://cdn.jsdelivr.net/npm/idb@8/+esm in a module script, or load https://cdn.jsdelivr.net/npm/idb@8/build/umd.js to get a global named idb.

Official sources

  1. Issues
  2. jakearchibald/idb on GitHub
  3. License: ISC
  4. Project website
  5. README
Add this badge to your README

If you maintain this project, the badge below links readers to this analysis and shows its maintenance status from the daily GitHub snapshot. Paste the markdown into your README; add ?metric=license or ?metric=stars to the image URL for a different field.

Add this badge to your README

markdown
[![Hysen Labs](https://hysenlabs.com/badge/jakearchibald-idb.svg)](https://hysenlabs.com/projects/jakearchibald-idb)

Star history chart for your README

markdown
[![Star history](https://hysenlabs.com/chart/jakearchibald-idb.svg)](https://hysenlabs.com/projects/jakearchibald-idb)

Was this useful?