sembast_sqflite 1.0.0

  • Readme
  • Changelog
  • Example
  • Installing
  • 79

sembast_sqflite #

sembast DB for flutter on top of sqflite.

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

See sembast for API usage

Setup #

Setup instructions for all platforms (Flutter/VM, iOS/Android/MacOS, Windows/Linux)

Quick usage #

Example for Flutter (iOS/Android/MacOS):

import 'package:sembast_sqflite/sembast_sqflite.dart';
import 'package:sembast_test/test_common.dart';
import 'package:sqflite/sqflite.dart' as sqflite;

export 'package:sembast/sembast.dart';

Future main() async {
  /// Sembast sqflite based database factory.
  ///
  /// Supports iOS/Android/MacOS for now.
  final factory = getDatabaseFactorySqflite(sqflite.databaseFactory);

  // Define the store, key is a string, value is a string
  var store = StoreRef<String, String>.main();
  // Define the record
  var record = store.record('my_key');

  // Open the database
  var db = await factory.openDatabase('test.db');

  // Write a record
  await record.put(db, 'my_value');

  // print store content
  print(await store.stream(db).first);

  // Close the database
  await db.close();
}

Why #

You might wonder why...sembast already has its own io format. However sembast io is not cross process safe and one might consider that it is not a well known robust database system.

Here sqflite is used as the based of a journal database that provides data to sembast, allowing a fast all-in-memory access and safe cross process database storage and transaction mechanism.

Usage #

  • sembast_sqflite should be used from the main isolate only
  • While being cross-process safe, you might encounter locked access when using multiple transactions are in progress, which could happen while debugging.
  • Applications should not rely on internal storage format

1.0.0 #

  • First stable version

0.2.0+2 #

  • Add Blob and Timestamp support

0.1.0 #

  • Initial revision

example/main.dart

import 'package:sembast/sembast.dart';
import 'package:sembast_sqflite/sembast_sqflite.dart';
import 'package:sqflite_common_ffi/sqflite_ffi.dart';

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

  var factory = getDatabaseFactorySqflite(databaseFactoryFfi);

  var db = await factory.openDatabase('example.db');
  // Use the main store for storing key values as String
  var store = StoreRef<String, String>.main();

  // Writing the data
  await store.record('username').put(db, 'my_username');
  await store.record('url').put(db, 'my_url');

  // Reading the data
  var url = await store.record('url').get(db);
  var username = await store.record('username').get(db);

  print('url: $url');
  print('username: $username');
}

Use this package as a library

1. Depend on it

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


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

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

  • Dart: 2.8.4
  • pana: 0.13.14

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.8.0 <3.0.0
meta >=1.1.6 <3.0.0 1.2.1
sembast >=2.4.7+3 <4.0.0 2.4.7+4
sqflite_common >=1.0.0+1 <3.0.0 1.0.2+1
Transitive dependencies
path 1.7.0
synchronized 2.2.0+1
Dev dependencies
pedantic >=1.8.0
process_run >=0.10.3
sqflite_common_ffi >=1.0.0 <3.0.0
test any