flutter_storage 0.8.5

  • README.md
  • CHANGELOG.md
  • Example
  • Installing
  • Versions
  • new50

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.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/src/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', () async {
    // The database is backed by one file:
    var storage = await Storage.create('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
    await storage.setValue(street.name, street);

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

    // Iterate all the entries
    await for (StorageDecodeEntry entry in storage.entries) {
      // A database can contain all kinds of entries,
      // thus a type-check is necessary:
      if (entry.value.meta.type == Street.type) {
        var streetEntry = Street.decode(entry.value);
        print('streetEntry.name: ${streetEntry.name}');
        print('streetEntry.houses.length: ${streetEntry.houses.length}');
      }
    }
  });
}

class Street implements Model {
  // Each model needs to have static [type] field
  // to identify it's type before decoding:
  static final String type = 'street';
  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 ?? Serializer(type))
      .string(name)
      .collection<House>(houses, House.encodeHouse);

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

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

  House(this.number, this.singleStory);

  Serializer encode([Serializer serialize]) => 
    (serialize ?? Serializer(type))
      .integer(number)
      .boolean(singleStory);

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

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

  static House decodeHouse(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.8.5

2. Install it

You can install packages from the command line:

with Flutter:


$ flutter packages get

Alternatively, your editor might support flutter packages 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';
  
Version Uploaded Documentation Archive
0.8.5 Dec 10, 2018 Go to the documentation of flutter_storage 0.8.5 Download flutter_storage 0.8.5 archive
0.8.4 Dec 9, 2018 Go to the documentation of flutter_storage 0.8.4 Download flutter_storage 0.8.4 archive
0.8.3 Dec 9, 2018 Go to the documentation of flutter_storage 0.8.3 Download flutter_storage 0.8.3 archive
0.8.2 Dec 8, 2018 Go to the documentation of flutter_storage 0.8.2 Download flutter_storage 0.8.2 archive
0.8.1 Dec 8, 2018 Go to the documentation of flutter_storage 0.8.1 Download flutter_storage 0.8.1 archive
0.8.0 Dec 8, 2018 Go to the documentation of flutter_storage 0.8.0 Download flutter_storage 0.8.0 archive
0.7.9 Dec 8, 2018 Go to the documentation of flutter_storage 0.7.9 Download flutter_storage 0.7.9 archive
0.7.8 Dec 8, 2018 Go to the documentation of flutter_storage 0.7.8 Download flutter_storage 0.7.8 archive
0.7.7 Dec 8, 2018 Go to the documentation of flutter_storage 0.7.7 Download flutter_storage 0.7.7 archive
0.7.6 Dec 8, 2018 Go to the documentation of flutter_storage 0.7.6 Download flutter_storage 0.7.6 archive

All 12 versions...

Popularity:
Describes how popular the package is relative to other packages. [more]
0
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]
50
Learn more about scoring.

We analyzed this package on Dec 10, 2018, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.1.0
  • pana: 0.12.7
  • Flutter: 1.0.0

Platforms

Detected platforms: Flutter

References Flutter, and has no conflicting libraries.

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.2
Transitive dependencies
collection 1.14.11
meta 1.1.6
sky_engine 0.0.99
typed_data 1.1.6
vector_math 2.0.8
Dev dependencies
flutter_test