flutter_storage 0.9.4

flutter_storage #

A commit-log-based database for flutter apps written in Dart.

Key Features #

  • Backend runs in a separate thread using an Isolate
  • Keys are indexed in memory, values are cached in memory
  • Commit-log with undo-support
  • Simple serialization and deserialization of models
  • Compaction-support
  • One file per database

Motivation #

Flutter and Dart are awesome. Why not having a database for document-oriented apps written in and for both.

API Reference #

The API Reference of flutter_storage can be found here.

Getting Started #

For help getting started with Flutter, view the online documentation.

[0.9.4] - 2019/03/10

  • Due to apparent changes in object serialization between isolates in the Dart VM and/or the native runtime, backend was renamed to directly expose it's API without being encapsulated by an isolate.
  • Thus this version is not concurrent anymore.

[0.9.3] - 2019/03/10

  • Asserting list type for Storage.addEntries(…).

[0.9.2] - 2019/02/07

  • Making Serializer.collection(…) accept Iterables.

[0.9.1] - 2019/01/15

  • Making closeAndOpen(…) returning this on conclude.

[0.9.0] - 2019/01/14

  • Making flushState(…) conditional, so that in case no change occurred, nothing will be written to disk.

[0.8.9] - 2019/01/14

  • Adding closeAndOpen(…) method, allowing for:
    • Reuse of storage and isolate.
    • Minimizing respawn-time if requirement is: 1 open storage at a time.

[0.8.8] - 2019/01/11

  • Discovering compaction error, extending test amd fixing error.

[0.8.7] - 2019/01/08

  • Renaming Storage.create(…) to Storage.open(…)
  • Renaming Storage.flushStateAndClose() to Storage.close()
  • Changing isolate kill priority to beforeNextEvent(…)

[0.8.6] - 2018/12/13

  • Adding Serializer.model(…) for chaining calls on a serializer.

[0.8.4] - 2018/12/09

  • Changing example lokation

[0.8.3] - 2018/12/09

  • Example added showcasing adding, retrieving and iterating values.
  • Exporting storag entities

[0.8.2] - 2018/12/08

  • First release with comprehensible documentation.

example/example.dart

// // import 'package:flutter_storage/src/serialization.dart';
// import 'package:flutter_storage/flutter_storage.dart';
// // import 'package:flutter_storage/src/frontend_entries.dart';
// import 'package:flutter_test/flutter_test.dart';
// import 'dart:math';

// // Run this example from parent directory flutter_storage like so:
// // flutter test example/example.dart

// void main() {
//   var rand = Random.secure();

//   test('Illustrate basic usage of flutter_storage', () {
//     // The database is backed by one file:
//     var storage = Storage('my-apps-database.scl');

//     // Generate the houses in the street
//     var houses = List<House>.generate(
//       100, 
//       (int index) => House(index + 1, rand.nextBool()),
//     );

//     // Create the street
//     var street = Street('Cento Case Lane', houses);

//     // Save the street to the database
//     storage.write((Writer writer) {
//       writer.putModel(street.name, street);
//     });

//     // Retrieve the saved street
//     storage.read((Reader reader) {
//       var deserialize = reader.getEntry(street.name);
//       var retrievedStreet = Street.decode(deserialize);
//       print('retrievedStreet.name: ${retrievedStreet.name}');
//       print('retrievedStreet.houses.length: ${retrievedStreet.houses.length}');
//     });

//     // Iterate all the entries
//     storage.read((Reader reader) {
//       for (Deserializer deserialize in reader.values) {
//         // A database can contain all kinds of entries,
//         // thus a type-check is necessary:
//         var info = deserialize.entryInfo as ModelInfo;
//         if (info.modelType == Street.staticType) {
//           var streetEntry = Street.decode(deserialize);
//           print('streetEntry.name: ${streetEntry.name}');
//           print('streetEntry.houses.length: ${streetEntry.houses.length}');
//         }
//       }
//     });
//   });
// }

// class Street implements Model {
//   // Each model needs to have a [type] field
//   // you can make it static to identify it's type for decoding:
//   static final String staticType = 'street';
//   final String type = staticType;
//   final int version = 0;
//   final String name;
//   final List<House> houses;

//   Street(this.name, this.houses);

//   // Models should encode themselves, the serialization-
//   // field-order must be repeated during decode.
//   // In case this model is contained in another one,
//   // an optional serializer should be reused:
//   Serializer encode(Serializer serialize) =>
//     serialize
//       .string(name)
//       .list<House>(houses, (House h) => h.encode(serialize));

//   // Models should decode themselves.
//   // The serialization-field-order must be 
//   // the same like during encode.
//   Street.decode(Deserializer deserialize)
//     : name = deserialize.string(),
//       houses = deserialize.list<House>(() => House.decode(deserialize));
// }

// class House implements Model {
//   // Each model needs to a [type] field
//   // to identify it's type before decoding:
//   final String type = 'house';
//   final int version = 0;
//   final bool singleStory;
//   final int number;

//   House(this.number, this.singleStory);

//   Serializer encode(Serializer serialize) =>
//     serialize
//       .integer(number)
//       .boolean(singleStory);

//   // This model is never serialized directl,
//   // so collection support is sufficient:

//   // static Serializer encodeHouse(
//   //   House house,
//   // ) => house.encode(serialize);

//   static House decode(Deserializer deserialize) =>
//     House(
//       deserialize.integer(),
//       deserialize.boolean(),
//     );
// }

Use this package as a library

1. Depend on it

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


dependencies:
  flutter_storage: ^0.9.4

2. Install it

You can install packages from the command line:

with Flutter:


$ flutter pub get

Alternatively, your editor might support 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:flutter_storage/flutter_storage.dart';
  
Popularity:
Describes how popular the package is relative to other packages. [more]
30
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]
65
Learn more about scoring.

We analyzed this package on Sep 13, 2019, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.5.0
  • pana: 0.12.21
  • Flutter: 1.9.1+hotfix.2

Platforms

Detected platforms: Flutter

References Flutter, and has no conflicting libraries.

Health suggestions

Fix lib/src/serialization/line_serializer.dart. (-0.50 points)

Analysis of lib/src/serialization/line_serializer.dart reported 1 hint:

line 1 col 8: Unused import: 'dart:io'.

Format lib/src/commit_file/byte_data.dart.

Run flutter format to format lib/src/commit_file/byte_data.dart.

Format lib/src/commit_file/byte_wise_transformer.dart.

Run flutter format to format lib/src/commit_file/byte_wise_transformer.dart.

Fix additional 19 files with analysis or formatting issues.

Additional issues in the following files:

  • lib/src/commit_file/commit_file.dart (Run flutter format to format lib/src/commit_file/commit_file.dart.)
  • lib/src/commit_file/line_data.dart (Run flutter format to format lib/src/commit_file/line_data.dart.)
  • lib/src/commit_file/line_wise_transformer.dart (Run flutter format to format lib/src/commit_file/line_wise_transformer.dart.)
  • lib/src/commit_file/reverse_lines_reader.dart (Run flutter format to format lib/src/commit_file/reverse_lines_reader.dart.)
  • lib/src/commit_file/till_eol_transformer.dart (Run flutter format to format lib/src/commit_file/till_eol_transformer.dart.)
  • lib/src/identifier.dart (Run flutter format to format lib/src/identifier.dart.)
  • lib/src/index.dart (Run flutter format to format lib/src/index.dart.)
  • lib/src/serialization/control_chars.dart (Run flutter format to format lib/src/serialization/control_chars.dart.)
  • lib/src/serialization/deserialize_index.dart (Run flutter format to format lib/src/serialization/deserialize_index.dart.)
  • lib/src/serialization/deserializer.dart (Run flutter format to format lib/src/serialization/deserializer.dart.)
  • lib/src/serialization/entry_info.dart (Run flutter format to format lib/src/serialization/entry_info.dart.)
  • lib/src/serialization/entry_info_private.dart (Run flutter format to format lib/src/serialization/entry_info_private.dart.)
  • lib/src/serialization/escaping.dart (Run flutter format to format lib/src/serialization/escaping.dart.)
  • lib/src/serialization/line_deserializer.dart (Run flutter format to format lib/src/serialization/line_deserializer.dart.)
  • lib/src/serialization/model.dart (Run flutter format to format lib/src/serialization/model.dart.)
  • lib/src/serialization/remove_serializer.dart (Run flutter format to format lib/src/serialization/remove_serializer.dart.)
  • lib/src/serialization/serializer.dart (Run flutter format to format lib/src/serialization/serializer.dart.)
  • lib/src/serialization/unescaping.dart (Run flutter format to format lib/src/serialization/unescaping.dart.)
  • lib/src/storage.dart (Run flutter format to format lib/src/storage.dart.)

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.0.0-dev.68.0 <3.0.0
flutter 0.0.0
path ^1.6.2 1.6.4
Transitive dependencies
collection 1.14.11 1.14.12
meta 1.1.7
sky_engine 0.0.99
typed_data 1.1.6
vector_math 2.0.8
Dev dependencies
flutter_test