idb_sqflite 0.3.0

  • Readme
  • Changelog
  • Example
  • Installing
  • 81

idb_sqflite #

Indexed DB for flutter on top of sqflite.

  • Supports both iOS and Android
  • Supports Flutter Web through idb_shim.
  • Supports Dart VM (Desktop) through idb_shim

Example #

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

Getting Started #

import 'package:idb_sqflite/idb_sqflite.dart';

Future main() async {
  // The sqflite base factory

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

  // open the database
  Database db = await factory.open("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, 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);
  var value = await store.getObject(key);

  print(value);
  await txn.completed;
}

See idb_shim for API usage or more generally the W3C reference

0.3.0 #

  • No longer depends on flutter, sqflite must be explicitly added as a dependency.
  • Add support for DateTime and Uint8List

0.2.0 #

  • deprecate idbFactorySqflite to allow non-flutter support in the future

0.1.0+6 #

  • Initial revision

example/main.dart

import 'package:idb_sqflite/idb_sqflite.dart';
import 'package:sqflite_common_ffi/sqflite_ffi.dart';

Future main() async {
  // The sqflite base factory

  var factory = getIdbFactorySqflite(databaseFactoryFfi);
  // define the store name
  const storeName = 'records';

  // open the database
  var db = await factory.open('my_records.db', version: 1,
      onUpgradeNeeded: (VersionChangeEvent event) {
    var 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);
  var value = await store.getObject(key);

  print(value);
  await txn.completed;
}

Use this package as a library

1. Depend on it

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


dependencies:
  idb_sqflite: ^0.3.0

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_sqflite/idb_sqflite.dart';
  
Popularity:
Describes how popular the package is relative to other packages. [more]
66
Health:
Code health derived from static analysis. [more]
100
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
88
Overall:
Weighted score of the above. [more]
81
Learn more about scoring.

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

  • Dart: 2.7.1
  • pana: 0.13.6

Maintenance suggestions

The package description is too short. (-12 points)

Add more detail to the description field of pubspec.yaml. Use 60 to 180 characters to describe the package, what it does, and its target use case.

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.7.0-dev.0 <3.0.0
idb_shim >=1.11.0-dev.1 <3.0.0 1.11.0
meta >=1.1.6 <3.0.0 1.1.8
sqflite_common >=1.0.0+1 <3.0.0 1.0.0+1
Transitive dependencies
collection 1.14.12
js 0.6.1+1
path 1.6.4
sembast 2.4.1+1
synchronized 2.2.0
Dev dependencies
pedantic >=1.8.0
process_run >=0.10.3
sqflite_common_ffi >=1.0.0 <3.0.0
test any