isar / hive

Lightweight and blazing fast key-value database written in pure Dart.
Apache License 2.0
4.02k stars 400 forks source link

A new chapter: Hive v4 #1225

Open simc opened 1 year ago

simc commented 1 year ago

Dear Hive Community,

I'd like to apologize for my lack of support and updates for Hive over the past year. Despite this, your commitment to the community has ensured that the package is still in a remarkably good state, and for that, I'm incredibly grateful.

As many of you know, I have spent a lot of time optimizing Isar to be as fast, reliable, and fun to use as possible. However, I recognize that a lot of you truly appreciate the simplicity of Hive. The thought of discontinuing Hive did cross my mind, but I now see a much more constructive way forward:

Over the next several weeks and months, I plan to invest my energy into the development of Hive v4. The primary focus will be to maintain the user-friendly interface and feature set that you've come to love. However, instead of continuing with the custom storage engine that has been causing several issues, we will transition Hive's data storage to Isar.

This significant change comes with several exciting advantages, including support for multiple isolates, significantly improving resource efficiency and reducing startup time, among others. Moreover, this will simplify the maintenance of Hive, ensuring its longevity through sustained support.

I cannot thank you enough for your continued support and use of Hive. Together, let's continue to make it a tool we all love and rely on. 💜

Simon

Zchandev commented 1 year ago

Great news!

I love Isar, but I also still use Hive in the same project, because it's just a simple key-value storage.

I use it to store cache, counters, json responses, lists and maps. I don't need complex stuff like indexes and queries, because I already have that data in isar.

themisir commented 1 year ago

Hey Simon, thanks for an update! I am wondering what's your plans regarding storage migration. How do you think to handle the transition to make sure existing applications won't lose any data.

Also considering both hive and isar has (or had) their own way of encoding data types, not sure about isar, but hive also have support for writing custom encoders/serializers. What's the plan for migrating them?

simc commented 1 year ago

I am wondering what's your plans regarding storage migration.

That's indeed the biggest problem to solve. I think the best approach for now is to let the hive generator generate migration code.

For custom encoders & decoders I didn't find a solution yet. Maybe we can just deprecate them and ask users who rely on them to stay on Hive v2

themisir commented 1 year ago

Are you planning to support database queries like Isar does? If so, then it's tough, I don't have an idea to create smooth migration plan.

If not (only key to value lookups), maybe we can continue using the existing hive generated (and custom) encoders to encode structs into byte stream and store it within isar with its respective key.

jamesdixon commented 1 year ago

This is really exciting news!

Are you planning to support database queries like Isar does? If so, then it's tough, I don't have an idea to create smooth migration plan.

In my opinion, a migration to Isar as the data store should focus solely on that and leave out advanced functionality that Isar could provide. That simplifies the migration and maintains the simplicity of Hive. If you need more advanced functionality, using Isar directly is likely a better fit.

simc commented 1 year ago

Are you planning to support database queries

In my opinion, a migration to Isar as the data store should focus solely on that

Yeah agreed! I think Hive has a good feature set and if someone is looking for queries, Isar should be used directly. The only feature I think would be valuable for Hive is (optional) atomic transactions.

simc commented 1 year ago

I merged my work in the main branch. Check it out and provide feedback please 💜

t-kozak commented 1 year ago

Hey @simc , that plan sounds great!

I wanted to use Isar but decided to stick with Hive, as Hive supports Flutter on the web. With the migration to Isar as the engine for Hive, will it still work over IndexedDB?

holocronweaver commented 1 year ago

This is promising, but I have a few questions.

Is there a list of things that Hive v4 will lack vs. v2?

Will there be a v2 support branch if v4 will not have feature parity?

Also what of Hive v3, is it being abandoned?

BTW, thanks for all this work! Glad to hear Hive will live on in one form or another.

simc commented 1 year ago

With the migration to Isar as the engine for Hive, will it still work over IndexedDB?

No. Isar web uses SQLite compiled to WASM and so will Hive.

Is there a list of things that Hive v4 will lack

I don't think there is anything Hive v4 will lack. The API is almost identical with a few minor differences.

Edit: HiveObject and HiveList will be removed.

Also what of Hive v3, is it being abandoned?

To my knowledge Hive v3 was never released as a stable version and I don't have time to maintain it unfortunately.

simc commented 1 year ago

I published the first version of Hive v4 and I'd love to hear your feedback

978bobs commented 1 year ago

Does "No more code generation" mean that we don't need to reference a generated file like part 'main.g.dart';?

If so sounds pretty good. As a follow-on, does this also hold for Isar 4.0?

t-kozak commented 1 year ago

@simc, thanks for reply. Can you confirm that given this issue: https://github.com/isar/isar/issues/1362 (Isar on the web supports only in-memory sqlite), in practice, Hive v4 cannot be used as a persistency service on the web?

simc commented 1 year ago

Not right now that's correct @t-kozak. I hope to implement that before a stable release

pishguy commented 1 year ago

Because MY_APP depends on hive ^4.0.0 which doesn't match any versions, version solving failed.

You can try the following suggestion to make the pubspec resolve:

sprimm98 commented 1 year ago

@pishguy You can use hive: ^4.0.0-dev.2 to get access to the pre-release :)

jamesdixon commented 1 year ago

@simc we're working on testing this and noticed that it's leveraging Isar 4 Alpha. Any timeline on Isar 4 getting to stable? Also, any chance that Hive 4 could leverage Isar 3?

Yetispapa commented 12 months ago

Hi @simc,

First of all, I want to express my sincere appreciation for all your hard work on Hive and the dedication you've shown to the community. Hive has been an invaluable tool for me, and I'm excited to see its future unfold with Hive v4.

I'm sure many of us are eager to get our hands on the new Hive v4. Do you have a rough estimate of when we can expect a release candidate or a beta version?

Lastly, cheers from Munich! 🍻

Looking forward to Hive's continued evolution and success.

rivella50 commented 11 months ago

@simc Do you have any rough time schedule when a stable release for Hive v4 will be available?

sonysm commented 7 months ago

Please make it happen i can't wait to see Hive V4.0.0 official release

Macacoazul01 commented 7 months ago

@simc Do you have any rough time schedule when a stable release for Hive v4 will be available?

At the same week US starts using metric system 👀.

giridat commented 6 months ago

LGTM!

stavgafny commented 6 months ago

Hi @simc, I tried the v4 pre release version(^4.0.0-dev.2) and its absolutely awesome, registering the type with its .fromJson method is such an elegant way. I really want to use it on my app and just wondering when will there be stable release. If its still got time can you maybe specify how unstable it is? I would love to switch to that for an Android app I'm working on.

Anyway thanks for making this amazing package.

Rexios80 commented 3 months ago

I have a PR built on Hive v2 that supports Flutter web WASM if anyone wants to try it: https://github.com/isar/hive/pull/1291

I know it's not really relevant to this discussion, but I figured people with notifications turned on for this issue might be interested.

xxxIxxxx commented 2 months ago

flutter: 3.19.6 hive: ^4.0.0-dev.2 isar_flutter_libs: ^4.0.0-dev.14 path_provider: ^2.1.0

static Box  settingBox = Hive.box(name: "setting", maxSizeMiB: 128);

When I call settingBox.clear();, the data is indeed cleared, and after restarting the app, there is no data. However, in the sandbox, the .isar size is 20MB, and I noticed that almost all .isar files are 20MB in size, but I'm sure the data they store is less than 1MB. Why is this happening?

some error

"DbError (12): Cannot allocate memory"

I am sure that the phone has enough RAM and enough disk storage space.

carsh in:

case ERROR_DB_FULL:
        throw DatabaseFullError();
      default:
        final length = IsarCore.b.isar_get_error(IsarCore.stringPtrPtr);
        final ptr = IsarCore.stringPtr;
        if (length != 0 && !ptr.isNull) {
          final error = utf8.decode(ptr.asU8List(length));
          throw DatabaseError(error);
Fethi-Hamdani commented 1 month ago

Any updates V4 stable release?

Rexios80 commented 1 month ago

For anyone still on v2, I released hive_ce that supports WASM compilation and Sets. Also the hive_ce_generator generates a HiveRegistrar extension so you can register all your adapters in one call (and not forget to register new ones like I used to every single time):

import 'package:your_package/hive_registrar.g.dart';

void main() {
  final path = Directory.current.path;
  Hive
    ..init(path)
    ..registerAdapters();
}
mrasityilmaz commented 1 month ago
image image

Issue: Box Name Causing Non-Responsiveness

Description

When using Hive.box(name: boxName) in Hive 4.x.x, the application stops responding after the Isar.open function call if the boxName is set to "test5". However, if the boxName is set to "1" (still a String), everything works as expected.

Steps to Reproduce

~Initialize Hive. ~Use Hive.box(name: "test5"). ~Call Isar.open. ~The application becomes non-responsive.

Expected Behavior

The application should not become non-responsive regardless of the box name provided.

Actual Behavior

When the boxName is set to "test5", the application stops responding after Isar.open. Changing the boxName to "1" or anything resolves the issue.

Additional Details

When using 'test5' as the boxName, Isar.fastHash(typeName) returns a typeId such as -90198......, as shown in the instanceId in the second screenshot.

The application does not proceed beyond the point shown in the second screenshot.

Anything other than 'test5' for the boxName works fine, but 'test5' does not.

The issue might be unique to my setup, but I spent several hours trying to identify this problem.

environment:
  sdk: '>=3.4.4 <4.0.0'
  flutter: ">=1.17.0"

dependencies:
  flutter:
    sdk: flutter
  hive: ^4.0.0-dev.2
  isar_flutter_libs: ^4.0.0-dev.13
  logger: ^2.4.0
  path_provider: ^2.1.0

dev_dependencies:
  flutter_lints: ^4.0.0
  flutter_test:
    sdk: flutter
  very_good_analysis: ^6.0.0

[✓] Flutter (Channel stable, 3.22.3, on macOS 14.5 23F79 darwin-arm64, locale tr-TR)
[!] Android toolchain - develop for Android devices (Android SDK version 35.0.0-rc4)
    ✗ Android license status unknown.
      Run `flutter doctor --android-licenses` to accept the SDK licenses.
      See https://flutter.dev/docs/get-started/install/macos#android-setup for more details.
[✓] Xcode - develop for iOS and macOS (Xcode 15.4)
[✓] Chrome - develop for the web
[✓] Android Studio (version 2022.1)
[✓] VS Code (version 1.92.0)
[✓] Connected device (4 available)
[✓] Network resources```
appconsultio commented 1 month ago

hive_flutter: ^1.1.0 hive: ^2.2.3

Hive is not persisting data after flutter mobile app gets terminated.. Is there any solution for this ?? @simc

azmasamy commented 1 month ago

hive_flutter: ^1.1.0 hive: ^2.2.3

Hive is not persisting data after flutter mobile app gets terminated.. Is there any solution for this ?? @simc

Flutter secured storage

rivella50 commented 1 month ago

I switched to objectbox recently.

Rexios80 commented 1 month ago

I just use hive_ce since that was easier than migrating to an entirely different storage solution

mrasityilmaz commented 1 month ago

I just use hive_ce since that was easier than migrating to an entirely different storage solution

Actually, it's not different, it's just a package with a different name that contains traces of each version of Hive. I recommend the Hive 4.x.x and my Hive extension https://pub.dev/packages/bee_hive

Also Hive 4.x.x doesn't need any generator.

Rexios80 commented 1 month ago

I'm the maintainer of hive_ce so I know what it is. I have many apps that are using Hive v2 in production, and I see no easy way to migrate to v4. Even if there was a way to migrate from v2 to v4, I have little to no faith in the future support of Hive. Please do not recommend using Hive v4 in production applications. I wouldn't even recommend using hive_ce for new projects unless you intend to contribute.

I am aware of Hive v4 not requiring code generation, but you lose the efficient binary storage of Hive v2 which was like... the entire point of choosing Hive over other options...

mrasityilmaz commented 1 month ago

I'm the maintainer of hive_ce so I know what it is. I have many apps that are using Hive v2 in production, and I see no easy way to migrate to v4. Even if there was a way to migrate from v2 to v4, I have little to no faith in the future support of Hive. Please do not recommend using Hive v4 in production applications. I wouldn't even recommend using hive_ce for new projects unless you intend to contribute.

I am aware of Hive v4 not requiring code generation, but you lose the efficient binary storage of Hive v2 which was like... the entire point of choosing Hive over other options...

Actually, I'm not fully aware of the advantages of binary storage. But based on my research, I believe the new Hive may be faster than the old one.

Rexios80 commented 1 month ago

Actually, I'm not fully aware of the advantages of binary storage. But based on my research, I believe the new Hive may be faster than the old one.

Well it doesn't really matter if it's a dead package

mrasityilmaz commented 1 month ago

Actually, I'm not fully aware of the advantages of binary storage. But based on my research, I believe the new Hive may be faster than the old one.

Well it doesn't really matter if it's a dead package

Okay, I respect your decisions. Good luck

appconsultio commented 1 month ago

I switched to objectbox recently.

do you face any issue while application move to terminate state?? on restart does it restore previous save data ??

appconsultio commented 1 month ago

I just use hive_ce since that was easier than migrating to an entirely different storage solution

does it keep you data saved when mobile app gets terminated or crash ??

rivella50 commented 1 month ago

do you face any issue while application move to terminate state?? on restart does it restore previous save data ??

@appconsultio Sure it does, and tbh i would be suprised if hive wouldn't do that too. Are you sure you're doing everything correctly on app startup?

oscarshaitan commented 1 month ago

I'm still using Hive and is working fine after phone restart or crash, the only place I have issues is on web. @Rexios80 at this point I'm considering moving away from hive. do hive_ce has any improvement for web? I love the binary storage, but if the phone is a budget phone and you have stored a massive Box the app could suffer opening if you open that box in launch.

Rexios80 commented 1 month ago

@oscarshaitan hive_ce supports Flutter web WASM compilation which drastically improves performance.

If you're having issues opening boxes on startup, does making them lazy help?

appconsultio commented 1 month ago

hive_flutter: ^1.1.0 hive: ^2.2.3

Hive is not persisting data after flutter mobile app gets terminated.. Is there any solution for this ?? @simc

@simc plz reply how to solve this issue ??

oscarshaitan commented 1 month ago

@oscarshaitan hive_ce supports Flutter web WASM compilation which drastically improves performance.

If you're having issues opening boxes on startup, does making them lazy help?

Yes Im thinking on moving some to lazy.

I'm going to join to your discord so I can make more questions there

tomvanoost commented 1 month ago

@simc Thank you for all the great work. Any idea when we can expect a release version of Hive v4 based on Isar? Would it be possible to execute queries on a Hive box using Isar?

vishnuagbly commented 1 week ago

I believe @simc has stopped supporting this package. The sad truth of the Open-Source Community is that we do not get paid, and hence the wobbly support for packages.