tailor 0.2.3+2 copy "tailor: ^0.2.3+2" to clipboard
tailor: ^0.2.3+2 copied to clipboard

discontinued

A lightning-fast, synchronous, key-value database written in pure Dart.

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.clear();
  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.

16
likes
20
pub points
0%
popularity

Publisher

verified publisherkishoredev.live

A lightning-fast, synchronous, key-value database written in pure Dart.

Repository (GitHub)
View/report issues

License

unknown (LICENSE)

Dependencies

meta, path, steel_crypt

More

Packages that depend on tailor