tailor 0.2.3+2

  • Readme
  • Changelog
  • Example
  • Installing
  • 65

TailorDB #

Tailor is a lightning-speed persistent key-value store for Dart. Using a synchronous, convenient API and a caching system, it is able to write 50k objects, read 500k, and delete 200k, all in a single second.

Caching: Pros and Cons #

Tailor conducts its core operations off of a cached copy of the database. It asynchronously checks for changes to the cache every 250 milliseconds (this value can be changed). If changes have been made, it pushes the cache to a file. You can also manually initiate a push.

It is done this way because writing to files is expensive, so avoiding this cost allows core operations to be really fast.

However, there is some practical issues with this caching. First, the database can only be as big as the available short-term storage. Second, there is a possibility of data loss if you don't manually initiate the pushes, because there might be a gap between a write and a scheduled flush.

If these issues are too much, I'd highly recommend Hive for a more stable alternative.

Features and Performance #

  • You can use Tailor synchronously or asynchronously: the core methods (normally synchronous) are available in async form.
  • Tailor has strong AES-GCM encryption built in. Just use var db = TailorDB(file: fileHere, encryption: true, passkey: keyHere) and pass a key. You can generate a key using the genKey() method.
  • Tailor uses a LinkedHashMap structure internally, so insertion order is preserved.

Usage #

Take a look at the example below and the TailorDB docs to understand usage. Tailor is essentially a persistent map, with Strings as the main data type. Keys are all String, and Values are String, List<String>, or Map<String,String>.

import 'package:tailor/tailor.dart';

void main() {
  var db = TailorDB(
      file: File(join(Directory.current.path, 'example', 'db.json')),
      encryption: true, //Encryption is enabled.
      passkey: '6hUzyvUiXsf652tPHXLW2K-Fx6ZHEU_r', //This is a key for encryption.
      refreshInterval: 200, //This is how often the cache will be written to storage (in ms).
  db.add(key: 'String', value: 'value');
  db.add(key: 'List', value: ['here', 'are', 'values']);
  db.add(key: 'Map', value: {'key1': 'value1', 'key2': 'value2'});
  print(Map.fromIterables(db.keys, db.values));

// Check out the persistent storage in the db.json file in the example folder!

// There's a lot more methods than these. Removing, getting, and tons of utilities/checks 
// are also available. Take a look at the TailorDB dartdocs!

Normal and Flutter Usage #

  • In the constructor, you may notice a file parameter. This is because Tailor requires a JSON file to write to.
  • Normally, you can just specify the path to where the db should be (File('pathtodb/db.json')). If that is inconvenient you can create it in the current directory (File(join(Directory.current.path, 'db.json')).
  • In Flutter, you will need the path provider library. Use it to get a library directory (var dir = await getLibraryDirectory()). Then, create a JSON file there (File(join(dir.path, 'db.json')).
  • Note: the above uses methods from the dart:io and path libraries. These methods from dart:io and path are bundled with this library; you don't need to import them separately. If you need to import only the core library (and not dart:io/path methods), use import 'package:tailor/tailor.dart' show TailorDB.

Bugs #

Please file feature requests and bugs at the issue tracker.

0.2.3 - 0.2.3+2 #

  • Made option for writeCache(): can be synchronous or async
  • Improved benchmarks (test folder)
  • README updates
  • Cleaned up exports (and API reference)

0.2.2 #

  • Made write operations asynchronous to avoid blocking app

0.2.1+1 #

  • Better test suite, deleted unfair benchmark
  • Include explanation of caching system
  • Updated stats in README to include persistent-write
  • Made links function properly in README

0.2.1 #

  • Added option to change persistent push rate
  • Increased default persistent push rate
  • Added checks for Map equality to push mechanism

0.1.2 - 0.1.2+1 #

  • Relicensed from AGPL to MPL 2.0
  • Slightly improved accuracy of tests
  • Updated README with more links

0.1.1 - 0.1.1+4 #

  • Initial version, created the entire repo
  • Wrote viable database which is confirmed to run really fast
  • Added encryption, tests, and example
  • Refined README


import 'package:tailor/tailor.dart';

void main() {
  var db = TailorDB(
      file: File(join(Directory.current.path, 'example', 'db.json')),
      encryption: true,
      passkey: '6hUzyvUiXsf652tPHXLW2K-Fx6ZHEU_r');
  db.add(key: 'String', value: 'value');
  db.add(key: 'List', value: ['here', 'are', 'values']);
  db.add(key: 'Map', value: {'key1': 'value1', 'key2': 'value2'});
  print(Map.fromIterables(db.keys, db.values));

//Check out the persistent storage in the db.json file in the example folder!

Use this package as a library

1. Depend on it

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

  tailor: ^0.2.3+2

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

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

  • Dart: 2.7.1
  • pana: 0.13.6

Health suggestions

Format lib/src/business/encryption.dart.

Run dartfmt to format lib/src/business/encryption.dart.

Format lib/src/tailor_base.dart.

Run dartfmt to format lib/src/tailor_base.dart.

Format lib/tailor.dart.

Run dartfmt to format lib/tailor.dart.


Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.1.0 <3.0.0
meta ^1.1.8 1.1.8
path ^1.6.0 1.6.4
steel_crypt ^1.5.4 1.7.1+1
Transitive dependencies
args 1.6.0
asn1lib 0.6.4
Dev dependencies
hive any
instant any
pedantic ^1.8.0
test ^1.6.0