`browser-level` is a JavaScript library providing an `abstract-level` compliant database interface designed specifically for web browsers, utilizing IndexedDB as its backend. The current stable version is 3.0.0. It serves as the spiritual successor to `level-js`, offering a modern, `abstract-level`-compatible API for client-side data persistence. Releases typically align with major upgrades to its underlying `abstract-level` dependency, ensuring compatibility with the broader Level ecosystem. A key differentiator is its seamless integration with browser environments, providing first-class support for both Uint8Array and Buffer (via an optional shim) for keys and values. However, due to IndexedDB's inherent limitations, `browser-level` iterators do not offer strict snapshot guarantees across multiple `next()` or `nextv()` calls, which means concurrent writes might be visible to an ongoing iteration. This necessitates careful handling for applications requiring strict transactional isolation during iteration.
npm install browser-levelVerified import paths — ran on the pinned version, not inferred.
This quickstart demonstrates how to create a `BrowserLevel` database, perform basic `put`, `batch`, `get`, and `iterator` operations, and properly open and close the database in a browser environment using TypeScript.
Consult the `UPGRADING.md` guides for both `browser-level` and `abstract-level` to understand necessary API adjustments and potential behavior changes.
Refer to the `UPGRADING.md` documents for `browser-level` v2 and `abstract-level` v2 to adapt your application code.
If strict snapshotting is critical, use `iterator.all()` immediately after creation to fetch all relevant entries within a single, atomic operation.
Always use the asynchronous `db.get(key)` method and `await` its result.
Remove `createIfMissing` and `errorIfExists` from your `BrowserLevel` constructor options. IndexedDB inherently handles database creation and existence.
Replace `db.getSync(key)` with `await db.get(key)` for asynchronous retrieval.
Remove these options from the `BrowserLevel` constructor. IndexedDB manages database creation internally without these specific flags.
Ensure that `db.open()` is called and awaited before any database operations, and that `db.close()` is called only when all operations are complete. Avoid performing operations during database shutdown.