Hive: Provide a method of updating the `homePath`

Created on 9 Mar 2021  路  4Comments  路  Source: hivedb/hive

Is your feature request related to a problem? Please describe.
In my app, I initialise Hive when a users logs in passing their user ID as the subDir where all Boxes should be stored. If a user logs out then logs back in (either as themselves or as a different user) I am unable to re-initialise Hive using the new ID as HiveImpl#init performs the following check

if (homePath != null) {
    throw HiveError('Instance has already been initialized.');
}

Describe the solution you'd like
Perhaps a new method like Hive.updateHomePath(String newSubDir)? Or Hive.reinitialize(String subDir)?

Describe alternatives you've considered
For now I will need to manually add the users ID to the begining of every box path.

Version

  • Platform: iOS, Android
  • Flutter version: 2.0.1
  • Hive version:
hive: 2.0.0
hive_flutter: 1.0.0
enhancement

Most helpful comment

On latest version Hive now supports calling .init multiple times to update homePath

All 4 comments

I'd also like the feature to reinitialize Hive with a different path. I use Hive for caching and would like to be able to switch at runtime between a locally running server and a staging server.

Would a PR be accepted?

In Hive 1.* I could call Hive.init() multiple times and it worked:
See: #595

Hey @leisim , can you look at the issue? I think we have to allow changing homePath's value multiple times to not break exists use cases.

On latest version Hive now supports calling .init multiple times to update homePath

Was this page helpful?
0 / 5 - 0 ratings

Related issues

azilvl picture azilvl  路  3Comments

jamesdixon picture jamesdixon  路  3Comments

yaymalaga picture yaymalaga  路  4Comments

abacaj picture abacaj  路  3Comments

Ferdzzzzzzzz picture Ferdzzzzzzzz  路  3Comments