GithubHelp home page GithubHelp logo

tchigher / hive Goto Github PK

View Code? Open in Web Editor NEW

This project forked from isar/hive

0.0 0.0 0.0 278 KB

Lightweight and blazing fast key-value store written in pure Dart.

Home Page: https://leisim.github.io/hive/

License: Apache License 2.0

Dart 99.57% Shell 0.43%

hive's Introduction

Travis Codecov Core version Flutter version Generator version

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

Hive is not ready for production yet. I'm working hard on a stable version.

Features

Blazing Fast โšก

  • More than twice the speed of other datastores
  • Binary data format

Simple to use โค๏ธ

  • Supports all types
  • Strong encryption built in
  • Runs on desktop, mobile & in browser

Lightweight ๐ŸŽˆ

  • Small runtime
  • NO native dependencies

Benchmark

Read 1000 entries Write 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.

Getting Started

Initialize

Hive needs a directory where it can store its data. Call Hive.init() the first time you use Hive.

Hive.init('path/to/hive');

In the browser you don't have to call init().

Open a Box

All of your data is stored in boxes.

var box = await Hive.openBox('testBox');

Just provide an encryptionKey to encrypt a box:

var key = Hive.generateSecureKey();
var box = await Hive.openBox('secureBox', encryptionKey: key);

Read & Write

Hive supports all primitive types, List, Map, DateTime and Uint8List. Any object can be can stored using TypeAdapters

var dog = Dog(name: 'Nero', age: 4);

box.put('myDog', dog);

Dog myDog = box.get('myDog');

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 {
  @override
  Widget build(BuildContext context) {
    return HiveBuilder.openBox(
      openBox: () {
        return Hive.openBox('settings');
      },
      builder: (context, box) {
        return Switch(
          value: box.get('darkMode'),
          onChanged: (val) {
            box.put('darkMode', val);
          }
        )
      },
      child: Center(
        // Shown when app starts until Hive is ready
        child: Text('Please wait...'), 
      ),
    );
  }
}

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:

  • Good test coverage
  • Many examples, especially for Flutter
  • Finalize API
  • Improve documentation
  • Write binary format spec
  • Even more tests
  • Benchmarks and comparison

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

   http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

hive's People

Contributors

simc avatar aswinmohanme avatar michael77 avatar nipodemos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.