Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Isar vs Hive (what should we be using now?) #1292

Open
vanlooverenkoen opened this issue May 31, 2024 · 3 comments
Open

Isar vs Hive (what should we be using now?) #1292

vanlooverenkoen opened this issue May 31, 2024 · 3 comments

Comments

@vanlooverenkoen
Copy link

vanlooverenkoen commented May 31, 2024

I am confused on what to use. On Isar faq page I find this.

Isar vs Hive
The answer is easy: Isar was started as a replacement for Hive and is now at a state where I recommend always using Isar over Hive.

On the hive quick start page I find this:

Before you start: Consider using [Isar](https://isar.dev/) a Flutter database by the author of Hive that is superior in every way!

And in the github page of hive I find this:

🐝 To bee or not to bee: Hive or Isar?
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.

I am building a shopping list/ todo list. Super simple. What should I be using? I would think hive because it is just a key value store. But after reading the other pages I am not sure anymore. Can we have clarification on this?

@CardosoShlomo
Copy link

Hive, in my opinion is better for clean architecture because you don't have to use the generator and all the annotations in your core model classes.

consider this product model using dart_mappable package to generate toMap and fromMap

@MappableClass(discriminatorKey: 'type')
sealed class Product with ProductMappable {
  const Product(this.id, {required this.isAvailable});

  final int id;
  final bool isAvailable;
}

@MappableClass()
class AvailableProduct extends Product with AvailableProductMappable {
  const AvailableProduct(super.id) : super(isAvailable: true);
}

@MappableClass()
class UnAvailableProduct extends Product with UnAvailableProductMappable {
  const UnAvailableProduct(super.id) : super(isAvailable: false);
}

using this code at your core folder of your app is a good practice because it depends only on dart_mappable and not on your services (Hive, Isar, Sqflite) or logic (Bloc, Riverpod) ....

then you add the following code to make it compatible with Hive

class ProductAdapter extends TypeAdapter<Product> {

  @override
  Product read(BinaryReader reader) {
    final map = reader.readMap().map((key, value) => MapEntry(key.toString(), value));
    return ProductMapper.fromMap(map);
  }

  @override
  int get typeId => 10;

  @override
  void write(BinaryWriter writer, Product obj) {
    writer.writeMap(obj.toMap());
  }

}

If you want now to change, lets say to Sqflite, you don't need to change your core prodcut models.

@OnClickListener2048
Copy link

To bee or not to bee:

@978bobs
Copy link

978bobs commented Jun 17, 2024

I suggest you find the most recent version of either hive or isar that works for your requirement. Do not bank on any future functionality being delivered to bail you out. Now if you're able to fork and self maintain go crazy. I use hive for exactly the reasons @CardosoShlomo cites. But don't have much faith in future support.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants