idb_shim
2.11.3, released 11 days ago by tekartik.com
Cross-platform IndexedDB implementation for Dart and Flutter.
WASM-readyRock solid
What it does
Provides a browser-compatible IndexedDB API that works on the web (real IndexedDB), Dart VM (IO via sembast), and in-memory for tests. It exposes standard IndexedDB concepts like databases, transactions, object stores, indexes, and key ranges.
AI-written summary of version 2.11.2, based on the package's README and metadata. Report an inaccuracy
Use it when
- You need structured, transactional storage and indexed queries across multiple platforms including the web.
- You want IndexedDB-compatible semantics outside the browser for unit testing your database schema and access.
Skip it when
- You prefer an ORM or a simpler key-value/SQL abstraction where you do not want to deal directly with IndexedDB database upgrades and transactions.
Strengths
- Cross-platform support (Web, Dart VM, mobile, desktop).
- Mirrors native IndexedDB semantics allowing easy code sharing.
- Provides in-memory factories for fast unit testing.
Weaknesses
- Requires manual handling of schema migrations inside onUpgradeNeeded callbacks.
- IO implementation over Sembast has some limitations compared to native browser IndexedDB.
Setup
- Kind
- Pure Dart
- Effort
- Low
- Code generation
- No
- Direct dependencies
- 6
import 'package:idb_shim/idb.dart';
import 'package:idb_shim/idb_browser.dart';
Future<void> main() async {
final factory = getIdbFactory();
final db = await factory.open(
'my_database',
version: 1,
onUpgradeNeeded: (VersionChangeEvent e) {
final db = e.database;
if (!db.objectStoreNames.contains('users')) {
db.createObjectStore('users', autoIncrement: true);
}
},
);
final txn = db.transaction('users', idbModeReadWrite);
final store = txn.objectStore('users');
await store.add({'name': 'Alice'});
await txn.completed;
}Alternatives
Packages that do the same job and could replace idb_shim.
Works with
Packages commonly used together with idb_shim: ones it builds on, ones built on it, and its own family.
- webidb_shim depends on itLightweight bindings for browser APIs via JS interop
- synchronizedidb_shim depends on itLock mechanism to prevent concurrent access to asynchronous code.
- sembastidb_shim depends on itA NoSQL persistent embedded document-based database for Dart and Flutter.
- sqflite_commonSame familyDart wrapper on SQLite providing the common API for sqflite and desktop FFI implementations.
- sqflite_common_ffiSame familyFFI-based implementation of sqflite for desktop platforms and unit tests.
- process_runSame familyRun shell scripts and locate executables across Linux, Windows and macOS.
- sqflite_common_ffi_webSame familySqflite web implementation using sqlite3 ffi and sqlite3 wasm.
- sembast_sqfliteSame familySembast NoSQL database support built on top of sqflite for cross-process safety.