{"id":13504361,"url":"https://github.com/isar/hive","last_synced_at":"2025-05-14T13:05:51.830Z","repository":{"id":38834253,"uuid":"195895847","full_name":"isar/hive","owner":"isar","description":"Lightweight and blazing fast key-value database written in pure Dart.","archived":false,"fork":false,"pushed_at":"2024-06-28T11:57:48.000Z","size":1159,"stargazers_count":4229,"open_issues_count":562,"forks_count":419,"subscribers_count":63,"default_branch":"main","last_synced_at":"2025-04-20T19:03:52.828Z","etag":null,"topics":["dart","database","encryption","flutter","hive","key-value","nosql"],"latest_commit_sha":null,"homepage":"","language":"Dart","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/isar.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2019-07-08T22:47:01.000Z","updated_at":"2025-04-18T16:52:33.000Z","dependencies_parsed_at":"2023-12-16T06:41:07.457Z","dependency_job_id":"ca336310-a526-4e7a-a948-b9cc6c44e6b8","html_url":"https://github.com/isar/hive","commit_stats":{"total_commits":588,"total_committers":59,"mean_commits":9.966101694915254,"dds":0.5017006802721089,"last_synced_commit":"1b4febe967370f790759823a5e154adc383e53d3"},"previous_names":["isar/hive","hivedb/hive","leisim/hive"],"tags_count":48,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/isar%2Fhive","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/isar%2Fhive/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/isar%2Fhive/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/isar%2Fhive/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/isar","download_url":"https://codeload.github.com/isar/hive/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254149920,"owners_count":22022851,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["dart","database","encryption","flutter","hive","key-value","nosql"],"created_at":"2024-08-01T00:00:35.355Z","updated_at":"2025-05-14T13:05:51.799Z","avatar_url":"https://github.com/isar.png","language":"Dart","readme":"\u003cp align=\"center\"\u003e\n  \u003cimg src=\"https://raw.githubusercontent.com/hivedb/hive/master/.github/hive.svg?sanitize=true\" width=\"300px\"\u003e\n\u003c/p\u003e\n\u003ch2 align=\"center\"\u003eFast, Enjoyable \u0026 Secure NoSQL Database\u003c/h2\u003e\n\n\u003cp align=\"center\"\u003e\n  \u003ca href=\"https://pub.dev/packages/hive\"\u003e\n    \u003cimg src=\"https://img.shields.io/pub/v/hive?label=pub.dev\u0026labelColor=333940\u0026logo=dart\"\u003e\n  \u003c/a\u003e\n  \u003ca href=\"https://github.com/isar/hive/actions/workflows/Dart CI.yaml\"\u003e\n    \u003cimg src=\"https://img.shields.io/github/actions/workflow/status/isar/hive/test.yml?branch=main\u0026label=tests\u0026labelColor=333940\u0026logo=github\"\u003e\n  \u003c/a\u003e\n  \u003ca href=\"https://app.codecov.io/gh/isar/hive\"\u003e\n    \u003cimg src=\"https://img.shields.io/codecov/c/github/isar/hive?logo=codecov\u0026logoColor=fff\u0026labelColor=333940\"\u003e\n  \u003c/a\u003e\n  \u003ca href=\"https://t.me/isardb\"\u003e\n    \u003cimg src=\"https://img.shields.io/static/v1?label=join\u0026message=Isar%20%26%20Hive\u0026labelColor=333940\u0026logo=telegram\u0026logoColor=white\u0026color=229ED9\"\u003e\n  \u003c/a\u003e\n  \u003ca href=\"https://twitter.com/simcdev\"\u003e\n    \u003cimg src=\"https://img.shields.io/twitter/follow/simcdev?style=social\"\u003e\n  \u003c/a\u003e\n\u003c/p\u003e\n\nHive is a lightweight and buzzing-fast key-value database made for Flutter and Dart.\n\n## Features 🌟\n\n- 🌍 Bee everywhere: mobile, desktop, browser\n- 🚀 Buzzing speed: Faster than a bee on caffeine!\n- 💡 Sweet, powerful, \u0026 intuitive API\n- 🔐 Queen's Guard: Encryption built right in.\n- 🧠 Thinking in swarms: Multi-isolate support.\n- 🍯 Everything a bee needs and more!\n\n\u003e Bee fact: A single bee can visit 5,000 flowers in a day!\n\n## Buzz into Action 🐝\n\nFeeling the excitement? Great! Let's help you take your first flight with Hive.\n\n#### 🔗 Add dependencies\n\nTo kickstart the journey add `hive`, `isar_flutter_libs` and `path_provider` to your `pubspec.yaml`.\n\n```yaml\ndependencies:\n  hive: ^4.0.0\n  isar_flutter_libs: ^4.0.0-dev.13\n  path_provider: ^2.1.0\n```\n\nPssst! 🤫 `path_provider` will help you to find the optimal directory for each platform.\n\n#### 🏡 Designate a Home\n\nHive needs a place to call home. Using `path_provider` we can find a valid directory.\n\n```dart\nvoid main() async {\n  WidgetsFlutterBinding.ensureInitialized();\n  final dir = await getApplicationDocumentsDirectory();\n  Hive.defaultDirectory = dir.path;\n\n  // ...\n}\n```\n\n#### 🏁 And... Action!\n\nWoohoo! You're all set. Jump in and let your Hive adventure begin!\n\n```dart\nimport 'package:hive/hive.dart';\n\nfinal box = Hive.box();\nbox.put('name', 'David');\n\nfinal name = box.get('name');\nprint('Name: $name');\n```\n\n\u003e Bee fact: Honeybees can fly at a speed of up to 30 kilometers per hour!\n\n# 📚 Hive Handbook\n\nIn Hive, data is neatly organized into containers known as boxes. Think of boxes as tables you'd find in SQL, but far more flexible — they don't stick to a set structure and can contain a variety of data. Boxes can be encrypted to store sensitive data.\n\n## Table of Contents\n\nWant to jump to a specific section? Here's a handy table of contents:\n\n- [Opening Boxes](#-opening-boxes)\n- [Closing Boxes](#-bidding-adieu-closing-boxes)\n- [Inserting](#-filling-the-honeycomb-inserting-data)\n- [Reading](#-extracting-honey-i-mean-data)\n- [Deleting](#-deleting-data)\n- [Using Boxes like Lists](#-using-boxes-like-lists)\n- [Type safety](#-type-safety)\n- [Non-primitive Objects](#-bee-yond-the-basics-non-primitive-objects)\n- [Transactions](#-transactions)\n- [Isolates](#-the-isolate-dance)\n- [FAQ](#-buzzworthy-questions)\n\n\u003e Bee fact: Bees have five eyes – three simple eyes on top of the head, and two compound eyes, with numerous hexagonal facets.\n\n### 📦 Opening Boxes\n\nYour journey with Hive begins with opening your first box. Trust me, it's unbee-lievably easy:\n\n```dart\nfinal box = Hive.box(name: 'myBox');\n```\n\nWhen you call `Hive.box(name: 'myBox')` for the first time with a given name, Hive will create a new box for you. If you call it again with the same name, Hive will return the already existing box.\n\nYou can also use `Hive.box()` without providing a name. In this case, Hive will return the default box.\n\nThere are optional parameters you can pass to `Hive.box()`:\n\n| Parameter       | Description                                                               |\n| --------------- | ------------------------------------------------------------------------- |\n| `name`          | Label your box with a distinct name                                       |\n| `directory`     | Select a home for your box. If omitted, Hive uses the `defaultDirectory`. |\n| `encryptionKey` | Hand over this key, and Hive will encrypt your box. Keep it safe!         |\n| `maxSizeMiB`    | The maximum size of the box in MiB. Go for a modest number.               |\n\n\u003e Bee fact: Beeswax, which is secreted from the abdomen of worker bees, is used to construct the honeycomb.\n\n### 🌂 Bidding Adieu: Closing Boxes\n\nIt's not advised to close boxes that might be accessed again. This prevents unnecessary overhead of reopening the box and ensures smooth data retrieval.\n\nTo close a box just call `box.close()`. Wipe the box from the face of the earth with `box.deleteFromDisk()`.\n\n\u003e Bee fact: When a bee finds a good source of nectar, it flies back to the hive and shows its friends where the nectar source is by doing a dance.\n\n### ✍️ Filling the Honeycomb: Inserting Data\n\nOnce we have a box, it's time to fill it with sweet data! At its core, a box is just a key-value store. String keys are mapped to arbitrary primitive values. You can think of a box as a persisted `Map\u003cString, dynamic\u003e`.\n\n```dart\nfinal box = Hive.box();\nbox.put('danceMoves', 'Waggle Dance');\nbox.put('wingSpeed', 200);\n```\n\nUpdating values? If a particular key already exists, Hive simply updates its corresponding value. And complex types like lists and maps? They're in too!\n\n```dart\nbox.put('friends', ['Buzzy', 'Stinger', 'Honey']);\nbox.put('memories', {'firstFlight': 'Sunny Day', 'bestNectar': 'Rose'});\n```\n\nInstead of `.put()` you prefer the syntax of maps? Hive gets you:\n\n```dart\nbox['danceMoves'] = 'Round Dance';\nbox['wingSpeed'] = 220;\n```\n\nGot a bucket of honey facts? Drop them all at once with `box.putAll()`:\n\n```dart\nbox.putAll({'favoriteFlower': 'Lavender', 'wingSpeed': 210});\n```\n\n\u003e Bee fact: A single bee colony can produce anywhere from 30 to 100 pounds of honey in a year, depending on the availability of nectar sources.\n\n### 👀 Extracting Honey... I mean, Data!\n\nNeed a snippet of info from your Hive? No need to don the beekeeper suit; just scoop it out using `box.get()` or `box.getAll()`. If a key doesn't exist, `box.get()` simply return a `null`. But fret not; you can tell it to have a backup plan:\n\n```dart\nfinal box = Hive.box(name: 'beeees');\nfinal fav = box.get('favoriteFlower');\nfinal moves = box.get('danceMoves', defaultValue: 'waggle');\n```\n\nOh, and if you're feeling fancy, use the `[]` operator for a more stylish approach:\n\n```dart\nfinal fav = box['favoriteFlower'];\nfinal moves = box['danceMoves'] ?? 'waggle';\n```\n\n\u003e Bee fact: Worker bees are the only bees most people ever see flying around outside the hive. They're female, and their roles are to forage for food, build and protect the hive, and more.\n\n### 🧹 Deleting Data\n\nTime for some spring cleaning in the hive! To remove a single entry from your box, use `box.delete()`:\n\n```dart\nfinal deleted = box.delete('lavenderHoney');\nprint('Honey eaten: $deleted'); // Honey eaten: true\n```\n\nPerhaps it's time for a complete reset, making space for a fresh batch of honey. If you're looking to remove all key-value pairs from a box, use `box.clear()`:\n\n```dart\nbox.clear();\n```\n\n\u003e Bee fact: Bees have been around for more than 30 million years! Their long history predates the existence of humans and even dinosaurs.\n\n### ✨ Using Boxes like Lists\n\nIn the bee world, honeycombs aren't just random compartments; they're methodically organized. Similarly, while we've been viewing Hive boxes as maps so far, they can be used just like lists:\n\n```dart\nfinal box = Hive.box();\n\nbox.add('Rose');\nbox.add('Tulip');\n\nprint(box.getAt(0)); // Rose\nprint(box.getAt(1)); // Tulip\n```\n\nBut remember, bees can't retrieve honey from a comb that's empty or doesn't exist. Likewise, index-based operations will throw an error if you try an index out of bounds:\n\n```dart\nfinal box = Hive.box();\nbox.add('Daisy');\nprint(box.getAt(1)); // Error! This will make the bees buzz in confusion\n```\n\nEven if we insert a key-value pair we can still access the values by index.\n\n```dart\nfinal box = Hive.box();\n\nbox.add('Lily');\nbox.put('key', 'Orchid');\n\nprint(box.getAt(0)); // Lily\nprint(box.getAt(1)); // Orchid\n```\n\nOf course, we can also use the `[]` operator in combination with indexes :\n\n```dart\nfinal box = Hive.box();\n\nbox.add('Marigold');\nprint(box[0]); // Marigold\n\nbox[0] = 'Daffodil';\nbox[1] = 'Bluebell'; // Error! This will get the bees in a whirl\n```\n\n\u003e Bee fact: To produce one pound of honey, a hive's bees must visit 2 million flowers and fly over 55,000 miles.\n\n### 🛡️ Type safety\n\nSafety is the bee's priority! To keep your data sweet and pure boxes have an optional generic type parameter. It allows you to store only values of a specific type in a box:\n\n```dart\nfinal box = Hive.box\u003cString\u003e(name: 'BeeTreasures');\nbox.put('DaisyDance', 'SweetNectarShake');\nbox.put('RoseRumba', 'GoldenPollenParty');\nbox.put('TulipTango', 777); // Error - You can't fool the bees!\n```\n\nMake sure to use the same type whenever you get the box. Otherwise, you'll get an error:\n\n```dart\nHive.box\u003cint\u003e(name: 'BeeTreasures'); // Error - We already have a String box!\n```\n\n\u003e Bee fact: Bees have two stomachs. One is for eating, and the other is for storing nectar collected from flowers or water so they can carry it back to their hive. Talk about a sweet backpack!\n\n### 🧩 Bee-yond the Basics: Non-primitive Objects\n\nHive goes beyond storing just basic data types! Along with primitives, lists, and maps, Hive can store any Dart object of your liking. The only buzz you need to know? Your object should come equipped with a `.fromJson()` and `.toJson()` method:\n\n```dart\nclass Bee {\n  Bee({required this.name, required this.role});\n\n  factory Bee.fromJson(Map\u003cString, dynamic\u003e json) =\u003e Bee(\n    name: json['name'] as String,\n    role: json['role'] as String,\n  );\n\n  final String name;\n  final String role;\n\n  Map\u003cString, dynamic\u003e toJson() =\u003e {\n    'name': name,\n    'role': role,\n  };\n}\n```\n\nBefore our bee-friends can buzz around in Hive, you need to do the beekeeper's job and register the `Bee` class:\n\n```dart\nHive.registerAdapter('Bee', Bee.fromJson);\n```\n\nNow, you're all set to let your bees fly:\n\n```dart\nfinal box = Hive.box();\n\nfinal bumble = Bee(name: 'Bumble', role: 'Worker');\nbox.put('BumbleID', bumble);\n\nprint(box.get('BumbleID')); // Bumble - Worker\n```\n\n\u003e Bee fact: Bees are responsible for pollinating about one-third of the world's food crops.\n\n### 🪢 Transactions\n\nTransactions are an efficient way to update multiple values at once. They are also useful if you want to make sure that a Box is not changed by other code while you are working with it.\n\n```dart\nfinal box = Hive.box();\n\nbox.write(() {\n  box.store('nectar1', 'GoldenNectar');\n  box.store('nectar2', 'WildflowerBrew');\n  box.store('nectar3', 'CloverDew');\n});\n\nbox.read(() {\n  box.get('nectar1'); // GoldenNectar\n});\n```\n\nChanges made in a transaction are always atomic. Either all changes are applied or none of them. So if an error occurs during a transaction, the box will not be changed.\n\n```dart\nfinal box = Hive.box();\nbox.put('honeyLevel', 5);\n\nbox.write(() {\n  box.put('honeyLevel', 6);\n  throw Exception('Oh no!!!');\n});\n\nprint(box.get('honeyLevel')); // 5\n```\n\n\u003e Bee fact: Bees can recognize human faces, and they can even be trained to associate a picture of a face with sweet treats!\n\n### 💃 The Isolate Dance\n\nJust like a beehive where multiple bees work simultaneously, you can buzz into Hive from various Isolates at the same time. This nifty trick is great when you wish to keep those database activities separate from your UI thread.\n\nHive comes with a sweet `Hive.compute()` method that runs a function in a different isolate. The best part? It also does the honey-making job of setting up and tidying resources for you.\n\n```dart\n// Opening the bee's box\nfinal box = Hive.box();\n\n// Storing some sweet nectar\nbox.put('nectarType', 'wildflower');\n\nawait Hive.compute(() {\n  // Accessing the same box from another worker bee\n  final box = Hive.box();\n  print(box.get('nectarType')); // wildflower\n\n  // Updating the nectar's quality\n  box.put('nectarType', 'lavender');\n});\n\n// Tasting the updated honey flavor\nprint(honeycomb.get('nectarType')); // lavender\n```\n\nJust remember, while the bees dance in harmony, ensure your Isolates do too! 🐝🎶\n\n\u003e Bee fact: Bees have two pairs of wings, and they beat 11,400 times per minute.\n\n### 🍯 Buzzworthy Questions\n\n#### 🐝 To bee or not to bee: Hive or Isar?\n\n\u003e It's not always black and yellow! 🖤💛 Both Hive and Isar have their sweet spots. Hive is a lightweight wrapper around Isar so if you are looking for a simple key-value store, Hive might be enough. Isar is the way to go if you need queries, relations, and more advanced features.\n\n#### 🚀 Will using Hive make my app as fast as a bee?\n\n\u003e While we can't promise your app will gain wings, 🦋 Hive sure will give it the speed it deserves. Hive is very resource efficient and optimized for mobile devices. Flutter like a butterfly, sting like a bee! 🐝\n\n#### 🗂 Where in the beehive does Hive hide my honey... I mean, data?\n\n\u003e Remember the `defaultDirectory` we set at the beginning? 📍 That's where Hive stores your data in a file named `yourBoxName.isar` or `yourBoxName.sqlite`.\n\n#### 📸 I've got some bee-autiful images! Can I store them directly in Hive?\n\n\u003e While you might be tempted to put those pics right into Hive, 🖼️ it's best to store your images and other binary data as files outside Hive. You can then store the file path in Hive. Think of it like leaving honey out in the open; it's better to keep it neatly stored in the appropriate place. 🏺\n\n#### 😲 Yikes! What if my app meets an untimely demise (gets killed)? What becomes of my Hive?\n\n\u003e No need for a bee-mergency! 🚨 If your app buzzes off unexpectedly, Hive ensures that your data remains safe and sound. Transactions are atomic, so either all changes are applied or none of them. If an error occurs during a transaction, the box will not be changed.\n\n#### 🔐 How does Hive keep our data safe from sticky fingers?\n\n\u003e We've got the queen's guard on duty! 🛡️ If you encrypt your box Hive uses 256-bit AES in CBC mode. Every database page is safeguarded separately, ensuring your sweet stuff remains secure and only accessible to those with the right key. Buzz-worthy protection, right? 🗝️\n\n#### 🤝 When should I rally the troops and use transactions?\n\n\u003e Just like a hive making big decisions together, 🌐 you'll want to use transactions when you have several operations that should be executed together. If one fails, they all fail. It ensures your data stays consistent, safe, and buzzing in harmony! 🎶\n\n#### 🤣 What if I'm allergic to bees?\n\n\u003e No worries! Hive is 100% sting-free, 🚫 although we're pretty sure you'll get a buzz out of its performance.\n\n#### ⏳ Hive operations are synchronous. Doesn't that make the bee waltz a bit slow?\n\n\u003e Hive is incredibly fast and efficient. 🚄 It's built on top of Isar, a high-performance database engine. If you want to keep database operations away from your UI isolate, you can use `compute()` or `Isolate.run()` to run them in a separate isolate.\n\n#### 📦 How many boxes should a wise beekeeper have?\n\n\u003e While the sky's the limit in the world of bees, 🌌 in Hive, every box becomes a separate file. So, even if you're buzzing with excitement, it's wise not to overdo it. 📚\n\n### 📜 License\n\n```\nCopyright 2023 Simon Choi\n\nLicensed under the Apache License, Version 2.0 (the \"License\");\nyou may not use this file except in compliance with the License.\nYou may obtain a copy of the License at\n\nhttp://www.apache.org/licenses/LICENSE-2.0\n\nUnless required by applicable law or agreed to in writing, software\ndistributed under the License is distributed on an \"AS IS\" BASIS,\nWITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\nSee the License for the specific language governing permissions and\nlimitations under the License.\n```\n","funding_links":[],"categories":["Databases","Dart","nosql"],"sub_categories":["Key-Value Databases"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fisar%2Fhive","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fisar%2Fhive","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fisar%2Fhive/lists"}