hive 1.0.0

Dart CI Codecov Core version Flutter version Generator version

Hive is a lightweight and blazing fast key-value database written in pure Dart. Inspired by Bitcask.

Hive is stable now.

Flutter Web Demos πŸ•ΈοΈ #

Features #

Cross-platform ⚑ #

  • Runs on desktop, mobile & in browser
  • Very good performance (see benchmark)

Easy to use ❀️ #

  • Keys are of type String or uin32 and values are arbitrary objects
  • The basic operations are put(key, value), get(key), delete(key)
  • Strong encryption built in

Lightweight 🎈 #

  • Small runtime
  • Small disk space consumption
  • NO native dependencies

Benchmark #

Read 1000 entriesWrite 1000 entries
SharedPreferences is on par with Hive when it comes to read performance. SQLite performs much worse.Hive greatly outperforms SQLite and SharedPreferences when it comes to writing or deleting.

This benchmark was performed on a Oneplus 6T with Android Q. All entries are read and written one after another. You can run the benchmark yourself.

Add Hive to project #

Add the following to your pubspec.yaml. Use the latest version instead of [version].

Core version Generator version Build runner version

  hive: [version]

  hive_generator: [version]
  build_runner: [version]

Hive ❀️ Flutter #

Hive was written with Flutter in mind. It is a perfect fit if you need a lightweight datastore for your app. Here is a sample how that may look like:

class SettingsPage extends StatelessWidget {
  Widget build(BuildContext context) {
    return WatchBoxBuilder(
      builder: (context, box) {
        return Switch(
          value: box.get('darkMode'),
          onChanged: (val) {
            box.put('darkMode', val);

Boxes are cached and therefore fast enough to be used directly in the build() method of Flutter widgets.

Todo #

The work on Hive has just started. If you want to contribute, it would be amazing if you helped me with one of these:

  • [x] Good test coverage
  • [x] Many examples, especially for Flutter
  • [x] Benchmarks and comparison
  • [x] Finalize API
  • [x] Even more tests
  • [ ] Queries
  • [ ] Improve documentation
  • [ ] Write binary format spec
  • [ ] You can never have enough tests

Licence #

Copyright 2019 Simon Leier

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
See the License for the specific language governing permissions and
limitations under the License.

1.0.0 #

  • First stable release

0.5.1+1 #

  • Change keys parameter of deleteAll from List to Iterable
  • Fixed bug in BinaryWriter

0.5.1 #

  • Fixed Hive.init() bug in browser
  • Fixed a bug with large lists or strings
  • Improved box opening time in browser
  • Improved general write performance
  • Improved docs
  • Added integration tests

0.5.0 #

  • Added keyComparator parameter for custom key order
  • Added isEmpty and isNotEmpty getters to box
  • Added support for reading and writing subclasses
  • Removed length limitation for Lists, Maps and Strings
  • Greatly improved performance of storing Uint8Lists in browser
  • Removed CRC check in browser (not needed)
  • Improved documentation
  • TypeIds are now allowed in the range of 0-223
  • Fixed compaction
  • Fixed writing longer Strings
  • Breaking: Binary format changed

0.4.1+1 #

  • Document all public APIs
  • Fixed flutter_web error

0.4.1 #

  • Allow different versions of the path package

0.4.0 #

  • Added BigInt support
  • Added compactionStrategy parameter
  • Added automatic crash recovery
  • Added add() and addAll() for auto increment keys
  • Added getAt(), putAt() and deleteAt() for working with indices
  • Support for int (32 bit unsigned) keys
  • Non-lazy boxes now notify their listeners immediately about changes
  • Bugfixes
  • More tests
  • Breaking: Open boxes with openBox()
  • Breaking: Writing null is no longer equivalent to deleting a key
  • Breaking: Temporarily removed support for transactions. New API design needed. Will be coming back in a future version.
  • Breaking: Binary format changed
  • Breaking: API changes

0.3.0+1 #

  • Bugfix: Hive['yourBox'] didn't work with uppercase box names

0.3.0 #

  • Big step towards stable API
  • Support for transactions
  • Annotations for hive_generator
  • Bugfixes
  • Improved web support
  • Breaking: inMemory -> lazy
  • Breaking: Binary format changed

0.2.0 #

  • Support for dart2js
  • Improved performance
  • Added inMemory option
  • Breaking: Minor API changes
  • Breaking: Changed Endianness to little
  • Breaking: Removed Migrator

0.1.1 #

  • Downgrade to meta: ^1.1.6 to support flutter

0.1.0 #

  • First release


Hive samples #

Go here for samples using Hive.

Use this package as a library

1. Depend on it

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

  hive: ^1.0.0

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:hive/hive.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 Sep 20, 2019, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.5.0
  • pana: 0.12.21


Detected platforms: Flutter, other

Primary library: package:hive/hive.dart with components: io.

Health suggestions

Fix lib/src/backend/storage_backend_js.dart. (-0.50 points)

Analysis of lib/src/backend/storage_backend_js.dart reported 1 hint:

line 69 col 19: Unnecessary cast.

Fix lib/src/binary/binary_reader_impl.dart. (-0.50 points)

Analysis of lib/src/binary/binary_reader_impl.dart reported 1 hint:

line 137 col 12: Unnecessary cast.

Fix lib/src/io/synced_file.dart. (-0.50 points)

Analysis of lib/src/io/synced_file.dart reported 1 hint:

line 37 col 14: Unnecessary cast.


Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.2.2 <3.0.0
meta ^1.1.6 1.1.7
path >=1.6.0 <1.7.0 1.6.4
pointycastle ^1.0.1 1.0.1
Dev dependencies
mockito ^4.1.0
pedantic 1.7.0
test ^1.6.4