Skip to main content

idb_shim 2.11.3 copy "idb_shim: ^2.11.3" to clipboard
idb_shim: ^2.11.3 copied to clipboard

indexed_db dart base interface with implementation for native (browser), file (io) and in memory.

example/example.dart

// ignore_for_file: avoid_print

/// idb_shim example on the Dart VM.
///
/// Only the factory depends on the platform: `idbFactoryWeb` on the web
/// (`package:idb_shim/idb_browser.dart`), `getIdbFactorySqflite(...)` from
/// `idb_sqflite` on Flutter mobile and desktop, `newIdbFactoryMemory()` in
/// tests.
library;

import 'package:idb_shim/idb_io.dart';

void main() async {
  // The databases are stored below test/tmp/out (sembast files).
  final idbFactory = getIdbFactoryPersistent('test/tmp/out');

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

  // open the database
  final db = await idbFactory.open(
    '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;

  print(value);
}
40
likes
160
points
282k
downloads

Documentation

API reference

Publisher

verified publishertekartik.com

Weekly Downloads

indexed_db dart base interface with implementation for native (browser), file (io) and in memory.

Repository (GitHub)
View/report issues

Topics

#nosql #database

License

BSD-2-Clause (license)

Dependencies

collection, meta, path, sembast, synchronized, web

More

Packages that depend on idb_shim