idb_shim 1.10.2

  • Readme
  • Changelog
  • Example
  • Installing
  • 87

idb shim #

Pure dart indexed db like API on top of native, sembast implementation. Its goal is to support browsers that do not support the indexed_db api with very few changes as well as setting the base for a flutter implementation.

It also allows to test your database schema and access in vm unit tests.

Build Status

Usage #

Assume you have the existing:

import 'dart:indexed_db';, version: xxx, onUpgradeNeeded: yyy);

This can be replaced by:

import 'package:idb_shim/idb_browser.dart'
IdbFactory idbFactory = getIdbFactory();, version: xxx, onUpgradeNeeded: yyy);

All other existing code remains unchanged. Simple example below:

// define the store name
const String storeName = "records";

// open the database
Database db = await"my_records.db", version: 1,
    onUpgradeNeeded: (VersionChangeEvent event) {
  Database db = event.database;
  // create the store
  db.createObjectStore(storeName, autoIncrement: true);

// put some data
var txn = db.transaction(storeName, "readwrite");
var store = txn.objectStore(storeName);
var key = await store.put({"some": "data"});
await txn.completed;

// read some data
txn = db.transaction(storeName, "readonly");
store = txn.objectStore(storeName);
Map value = await store.getObject(key);
await txn.completed;

Example #

Simple notepad available here running on Flutter (iOS/Android/Web).

Flutter support #

While idb_shim over sembast is a solution on Flutter, there is an implementation idb_sqflite based on sqflite for mobile (iOS and Android)

Author #

Testing #

Testing with dartdevc #

pub serve test --web-compiler=dartdevc --port=8079
pub run test -p chrome --pub-serve=8079

Known limitations/issues #

Memory/Io implementation #

  • For autoincrement, if key is set, it cannot be set as a different type than int
  • Nextunique and prevunique not supported (for now)
  • No support for Cursor.source
  • No generic support for blocked. It is always possible to upgrade the database, however other tabs will get blocked in their future calls
  • Index.get: only by key is supported (no range yet)
Type of data #
  • Only stuff that can be JSON serialized/deserialized
  • DateTime is not supported, it should be converted to string using toIso8601String or int as milliseconds since epoch
  • Cyclic dependecy are not supported (per JSON serialization)
  • Large float are not converted to int (native indexeddb implementation does this)
Type of key #
  • String and num (int or double) are supported for keys

Native exception #

  • Native exception type have no match in dart so a custom DatabaseError object is created to wrap the exception

Ie limitation #

IE 11, Edge 12 has the following limitations:

  • no support for reading objectStore.autoIncrement properties
  • ObjectStore.count() without argument throw a 'DataError' exception...better avoid count() on IE...
  • it seems ie close the transaction 'sooner' then chrome/firefox, i.e. calling an sync function that wrap an idb calls makes the transaction terminate
  • IDBIndex.multiEntry not supported on ie

Safari limitation #

Safari has the following limitations (as of v 9.0)

  • no support for transactions on multiple stores
  • very short transaction life cycle (no await on sdk 1.12)

1.10.2 #

  • Pedantic 1.9

1.10.1 #

  • Add support for idb_sqflite, an implementation for flutter mobile on top of sqflite
  • Add support for service worker self.indexedDB

1.9.0 #

  • Deprecates old names (sorry) and websql
  • Fix update/delete in index cursor for sembast
  • Sdk 2.4 min

1.8.0+3 #

  • Sdk 2.5 support

1.7.6+1 #

  • add support for ObjectStore.openKeyCursor

1.7.5 #

  • Supports dart 2.3

1.7.4 #

  • Supports multiEntry for sembast implementation
  • Fix cursor update with keyPath for sembast

1.7.3 #

  • Fix dot support in keyPath to match native behavior

1.7.2 #

  • Dart 2.2 support, Dart 2.1 compatible

1.7.0 #

  • remove websql support
  • support keyPath as array

1.6.0 #

  • dart2 only, no websql yet

1.5.0 #

  • Dart2 compatible (except websql shim)
  • Depends on sembast 1.7.0

1.4.2 #

  • Add implicit-cast: false support

1.4.0 #

  • Depends on sembast 1.4.0

1.3.6 #

  • Add IdbFactory.cmp

1.3.5 #

  • Simulate multistore transaction on Safari

1.3.3 #

  • Add support for import/export (sembast export format)
  • Fix timing to mimic IE limitation
  • Add workaround for transaction bug in sdk 1.13

1.3.2 #

  • Fix implementation for IE/Edge where the transaction life-cycle is shorter

1.3.1 #

  • Add support for ObjectStore.deleteIndex

1.2.1 #

  • Fix openCursor for Index that included null key before (sembast)
  • Travis test integration

1.0.0 #

  • Initial revision


import 'package:idb_shim/idb.dart';
import 'package:idb_shim/idb_io.dart';

void main() async {
  final idbFactory = getIdbFactoryPersistent('test/tmp/out');

  // define the store name
  final storeName = 'records';

  // open the database
  final db = await'my_records.db', version: 1,
      onUpgradeNeeded: (VersionChangeEvent event) {
    final db = event.database;
    // create the store
    db.createObjectStore(storeName, autoIncrement: true);

  // put some data
  var txn = db.transaction(storeName, idbModeReadWrite);
  var store = txn.objectStore(storeName);
  var key = await store.put({'some': 'data'});
  await txn.completed;

  // read some data
  txn = db.transaction(storeName, idbModeReadOnly);
  store = txn.objectStore(storeName);
  final value = await store.getObject(key) as Map;
  await txn.completed;


Use this package as a library

1. Depend on it

Add this to your package's pubspec.yaml file:

  idb_shim: ^1.10.2

2. Install it

You can install packages from the command line:

with pub:

$ pub get

with Flutter:

$ flutter pub get

Alternatively, your editor might support pub get or flutter pub get. Check the docs for your editor to learn more.

3. Import it

Now in your Dart code, you can use:

import 'package:idb_shim/idb_shim.dart';
Describes how popular the package is relative to other packages. [more]
Code health derived from static analysis. [more]
Reflects how tidy and up-to-date the package is. [more]
Weighted score of the above. [more]
Learn more about scoring.

We analyzed this package on Jan 16, 2020, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.7.0
  • pana: 0.13.4


Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.5.0 <3.0.0
collection >=1.14.10 <3.0.0 1.14.12
js >=0.6.1 <2.0.0 0.6.1+1
path >=1.6.1 <3.0.0 1.6.4
sembast >=2.0.1 <3.0.0 2.1.2+3
Transitive dependencies
meta 1.1.8
synchronized 2.1.1
Dev dependencies
build_runner >=1.5.0
build_test >=0.10.2
build_web_compilers >=0.4.0
dev_test >=0.13.0
io any
logging any
pedantic >=1.4.0
process_run >=0.10.3
pub_semver any
stack_trace any
test >=1.2.0
yaml any