leveldb 5.0.1

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

Fast & simple storage - a Dart LevelDB wrapper

LevelDB LogoBuild Status

Introduction

LevelDB is a simple key/value data store built by Google, inspired by BigTable. It's used in Google Chrome and many other products. LevelDB supports arbitrary byte arrays as both keys and values, singular get, put and delete operations, batched put and delete, bi-directional iterators and simple compression using the very fast Snappy algorithm.

leveldb_dart aims to expose the features of LevelDB in a Dart-friendly way.

LevelDB stores entries sorted lexicographically by keys. This makes LevelDB.getItems a very powerful query mechanism.

Platform Support

Modern 64-bit Linux platforms should work fine. The following distributions are known to work:

  • [x] Fedora 26 64-bit
  • [x] Fedora 25 64-bit
  • [x] Ubuntu 14.04 64-bit
  • [x] Ubuntu 15.10 64-bit

Unsupported platforms:

Basic usage

Add leveldb to your pubspec.yaml file.

name: myproject
dependencies:
  leveldb:

Open a database and read/write some keys and values..

import 'dart:async';
import 'package:leveldb/leveldb.dart';

Future main() async {
  LevelDB<String, String> db = await LevelDB.openUtf8("/tmp/testdb");
  db.put("abc", "def");
  String value = db.get("abc");
  print("value is $value"); // value2 is def
}

Check out example/main.dart to see how to read, write and iterate over keys and values.

Documentation

API Documentation is available at https://www.dartdocs.org/documentation/leveldb/latest/

Isolates (Threads)

leveldb_dart supports access to a database from multiple isolates by passing shared: true to the LevelDB.open function. The LevelDB object returned by this function will share an underlying reference to the object in other isolates and changes will be visible between isolates.

See example/isolate.dart for an example of using a database from multiple isolates (OS threads).

Feature Support

  • [x] Read and write keys
  • [x] Forward iteration
  • [x] Multi-isolate
  • [ ] Backward iteration
  • [ ] Snapshots
  • [ ] Bulk get / put

Custom Encoding and Decoding

By default you can use LevelDB.openUtf8 to open a database with String keys and values which are encoded in UTF8. The dart:codec library can be used to create databases with custom encodings. See example/json.dart for an example which stores dart objects to the database via JSON encoding.

Changelog

5.0.1

Non-breaking changes

  • Add @required annotation to keyEncoding and valueEncoding in LevelDB.open
  • Improve docs

5.0.0

Breaking changes:

  • Remove LevelEncoding interface and use dart:codec directly. This better aligns the interface with the dart way of encoding and decoding and allows easily fusing new codecs.
  • Add new json.dart example to demonstrate encoding objects to the database (as JSON).

4.0.0

Minor API update for Sound Dart

Breaking changes:

  • The keyEncoding and valueEncoding parameters are now required when using the LevelDB.open function. When encoding utf8 keys and values LevelDB.openUtf8 is the recommended constructor.

3.0.0

Breaking changes:

  • Add generic parameters to LevelDB to improve type safety when using the API. Key/Value encoding parameters have been moved to the LevelDB.open function.
  • Minimum dart sdk version updated to 1.23.0

Non-breaking changes:

  • Upgrade to leveldb 1.20. This version is compatible with the previous on-disk format. See: https://github.com/google/leveldb/releases/tag/v1.20
  • Add shared parameter to LevelDB.open. This feature allows referencing the same underlying database from multiple isolates.
  • Add an example demonstrating how to use the shared parameter in muliple isolates.

2.0.3

  • Build leveldb with better compatibility.

example/main.dart

import 'dart:async';
import 'dart:typed_data';

import 'package:leveldb/leveldb.dart';

/// main example.
Future<dynamic> main() async {
  // Open a database. It is created if it does not already exist. Only one process can
  // open a database at a time.
  LevelDB<String, String> db = await LevelDB.openUtf8("/tmp/testdb");

  // By default keys and values are strings.
  db.put("abc", "def");

  // Now get the key
  String value = db.get("abc");
  print("value is $value"); // value2 is def

  // Delete the key
  db.delete("abc");

  // If a key does not exist we get null back
  String value3 = db.get("abc");
  print("value3 is $value3"); // value3 is null

  // Now lets add a few key-value pairs
  for (int i in new Iterable<int>.generate(5)) {
    db.put("key-$i", "value-$i");
  }

  // Iterate through the key-value pairs in key order.
  for (LevelItem<String, String> v in db.getItems()) {
    print(
        "Row: ${v.key} ${v.value}"); // prints Row: key-0 value-0, Row: key-1 value-1, ...
  }

  // Iterate keys between key-1 and key-3
  for (LevelItem<String, String> v in db.getItems(gte: "key-1", lte: "key-3")) {
    print(
        "Row: ${v.key} ${v.value}"); // prints Row: key-1 value-1, Row: key-2 value-2, Row: key-3 value-3
  }

  // Iterate explicitly. This avoids allocation of LevelItem objects if you never call it.current.
  LevelIterator<String, String> it = db.getItems(limit: 1).iterator;
  while (it.moveNext()) {
    print("${it.currentKey} ${it.currentValue}");
  }

  // Just key iteration
  for (dynamic key in db.getItems().keys) {
    print("Key $key"); // Prints Key key-0, Key key-1, ...
  }

  // Value iteration
  for (dynamic value in db.getItems().values) {
    print("Value $value"); // Prints Key value-0, Key value-1, ...
  }

  // Close the db. This free's all resources associated with the db.
  // All iterators will throw if used after this call.
  db.close();

  // Open a new db which will use raw UInt8List data. This is faster since it avoids any decoding.
  LevelDB<Uint8List, Uint8List> db2 =
      await LevelDB.openUint8List("/tmp/testdb");

  for (LevelItem<Uint8List, Uint8List> item in db2.getItems()) {
    print("${item.key}"); // Prints [107, 101, 121, 45, 48], ...
  }

  db2.close();
}

1. Depend on it

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


dependencies:
  leveldb: "^5.0.1"

2. Install it

You can install packages from the command line:

with pub:


$ pub get

Alternatively, your editor might support pub get. Check the docs for your editor to learn more.

3. Import it

Now in your Dart code, you can use:


import 'package:leveldb/leveldb.dart';
        
Version Uploaded Documentation Archive
5.0.1 Nov 29, 2017 Go to the documentation of leveldb 5.0.1 Download leveldb 5.0.1 archive
5.0.0 Oct 2, 2017 Go to the documentation of leveldb 5.0.0 Download leveldb 5.0.0 archive
4.0.0 Sep 13, 2017 Go to the documentation of leveldb 4.0.0 Download leveldb 4.0.0 archive
3.0.0 Apr 26, 2017 Go to the documentation of leveldb 3.0.0 Download leveldb 3.0.0 archive
2.0.3 Jan 24, 2017 Go to the documentation of leveldb 2.0.3 Download leveldb 2.0.3 archive
2.0.2 Jan 12, 2017 Go to the documentation of leveldb 2.0.2 Download leveldb 2.0.2 archive
2.0.1 Jan 12, 2017 Go to the documentation of leveldb 2.0.1 Download leveldb 2.0.1 archive
2.0.0 Jan 12, 2017 Go to the documentation of leveldb 2.0.0 Download leveldb 2.0.0 archive

Analysis

This feature is new.
We welcome feedback.
More details: scoring.

We analyzed this package, and provided a score, details, and suggestions below.

  • completed on Feb 3, 2018
  • Dart: 2.0.0-dev.20.0
  • pana: 0.10.1

Scores

Popularity:
Describes how popular the package is relative to other packages. [more]
65 / 100
Health:
Code health derived from static analysis. [more]
100 / 100
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
100 / 100
Overall score:
Weighted score of the above. [more]
82

Platforms

Detected platforms: other

Primary library: package:leveldb/leveldb.dart with components: nativewrappers.

Suggestions

  • The description is too short.

    Add more detail about the package, what it does and what is its target use case. Try to write at least 60 characters.

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=1.23.0
meta ^1.1.2 1.1.2
Dev dependencies
test ^0.12.20+10