stash_sembast 1.0.0-dev.1

  • Readme
  • Changelog
  • Example
  • Installing
  • new49

stash_sembast #

A stash storage extension for sembast

Pub Package Build Status Coverage Status Package Documentation GitHub License

Introduction #

This storage extension for stash provides a sembast based storage that relies on a highly performing binary serialization of the cache items through the use of msgpack serialization format.

Getting Started #

Add this to your pubspec.yaml (or create it):

dependencies:
    stash_sembast: ^1.0.0-dev.1

Run the following command to install dependencies:

pub install

Optionally use the following command to run the tests:

pub run test

Finally, to start developing import the library:

import 'package:stash_sembast/stash_sembast.dart';

Usage #

This storage extension for stash provides a hive based storage that relies on a highly performing binary serialization of the cache items through the use of msgpack serialization format.

import 'dart:io';

import 'package:stash_sembast/stash_sembast.dart';

class Task {
  final int id;
  final String title;
  final bool completed;

  Task({this.id, this.title, this.completed = false});

  /// Creates a [Task] from json map
  factory Task.fromJson(Map<String, dynamic> json) => Task(
      id: json['id'] as int,
      title: json['title'] as String,
      completed: json['completed'] as bool);

  /// Creates a json map from a [Task]
  Map<String, dynamic> toJson() =>
      <String, dynamic>{'id': id, 'title': title, 'completed': completed};

  @override
  String toString() {
    return 'Task ${id}: "${title}" is ${completed ? "completed" : "not completed"}';
  }
}

void main() async {
  // Temporary path
  final path = Directory.systemTemp.path;

  // Creates cache with a Sembast based storage backend with the capacity of 10 entries
  final cache = newSembastCache(path,
      maxEntries: 10, fromEncodable: (json) => Task.fromJson(json));

  // Adds a task with key 'task1' to the cache
  await cache.put('task1',
      Task(id: 1, title: 'Run stash_sembast example', completed: true));
  // Retrieves the value from the cache
  final value = await cache.get('task1');

  print(value);
}

Contributing #

This library is developed by best effort, in the motto of "Scratch your own itch!", meaning APIs that are meaningful for the author use cases.

If you would like to contribute with other parts of the API, feel free to make a Github pull request as I'm always looking for contributions for:

  • Tests
  • Documentation
  • New APIs

Features and Bugs #

Please file feature requests and bugs at the issue tracker.

License #

This project is licensed under the MIT License - see the LICENSE file for details

1.0.0-dev.1 #

  • Initial version

example/example.dart

import 'dart:io';

import 'package:stash_sembast/stash_sembast.dart';

class Task {
  final int id;
  final String title;
  final bool completed;

  Task({this.id, this.title, this.completed = false});

  /// Creates a [Task] from json map
  factory Task.fromJson(Map<String, dynamic> json) => Task(
      id: json['id'] as int,
      title: json['title'] as String,
      completed: json['completed'] as bool);

  /// Creates a json map from a [Task]
  Map<String, dynamic> toJson() =>
      <String, dynamic>{'id': id, 'title': title, 'completed': completed};

  @override
  String toString() {
    return 'Task ${id}: "${title}" is ${completed ? "completed" : "not completed"}';
  }
}

void main() async {
  // Temporary path
  final path = Directory.systemTemp.path;

  // Creates cache with a Sembast based storage backend with the capacity of 10 entries
  final cache = newSembastCache(path,
      maxEntries: 10, fromEncodable: (json) => Task.fromJson(json));

  // Adds a task with key 'task1' to the cache
  await cache.put('task1',
      Task(id: 1, title: 'Run stash_sembast example', completed: true));
  // Retrieves the value from the cache
  final value = await cache.get('task1');

  print(value);
}

Use this package as a library

1. Depend on it

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


dependencies:
  stash_sembast: ^1.0.0-dev.1

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:stash_sembast/stash_sembast.dart';
  
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]
95
Overall:
Weighted score of the above. [more]
49
Learn more about scoring.

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

  • Dart: 2.8.4
  • pana: 0.13.15

Maintenance suggestions

Package is pre-release. (-5 points)

Pre-release versions should be used with caution; their API can change in breaking ways.

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.8.4 <3.0.0
path ^1.7.0 1.7.0
sembast ^2.4.5 2.4.7+4
stash ^1.0.0-dev.1 1.0.0-dev.1
Transitive dependencies
charcode 1.1.3
collection 1.14.13 1.15.0-nullsafety
convert 2.1.1
crypto 2.1.5
equatable 1.2.2
matcher 0.12.8
meta 1.2.2 1.3.0-nullsafety
quiver 2.1.3
stack_trace 1.9.5
synchronized 2.2.0+1
time 1.3.0
typed_data 1.2.0 1.3.0-nullsafety
uuid 2.2.0
Dev dependencies
pedantic ^1.9.0
test ^1.15.1
test_coverage ^0.4.1