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

Add missing path parameter to HiveInterface methods #776

Conversation

wbusey0
Copy link
Contributor

@wbusey0 wbusey0 commented Sep 6, 2021

Adds String? path parameters to HiveInterface methods

@themisir
Copy link
Contributor

themisir commented Sep 6, 2021

Why do you think this is needed? If you want to delete box by name you can use File(path).delete() instead. And same applies for box exists method. HiveInterface doesn't uses path parameter because it tries to be compatible with both io and web platforms. Web platforms doesn't uses filesystem paths so Hive interface doesn't uses it as well.

If there's special need we've missing please let me know..

@wbusey0
Copy link
Contributor Author

wbusey0 commented Sep 7, 2021

Hi @themisir ,

Thanks for the quick response!

We are using Hive in a way where (some) boxes are saved in a different subpath (let's say on a per-user basis). So we heavily use the path parameter with the openBox methods.

I saw the path parameter is already there in the HiveImpl class but we can't use it because not in the interface.
BackendManagerInterface and subclasses already have the path parameter for both methods.
So because of that it seemed weird that only HiveInterface is missing the path parameter which results in HiveImpl always passing homePath instead.

Furthermore openBox & openLazyBox are both in HiveImpl and both have an optional path parameter.

The reason I think it is better to go through the Hive interface instead of using File is to hide implementation details. For example Hive could change so that more than one file is stored and all of them would need to be deleted. That would require us checking the Hive implementation to be sure that our implementations for boxExists and deleteBox are still up to date.

Also I check the implementations and it already seems some more logic is present in these methods:

  • deleteBox deleted hivec & lock files as well
  • boxExists uses toLowerCase() on the name and also checks for the above mentioned files

But I didn't think about the web platform to be fair :-)

(also see issue #742).

@wbusey0
Copy link
Contributor Author

wbusey0 commented Sep 22, 2021

@themisir Could you tell me what you think about our usecases for this?

@themisir
Copy link
Contributor

@themisir Could you tell me what you think about our usecases for this?

Oh thanks for pinging me, I totally forget about that issue. My feelings about the feature is a bit complex cause this is nice to have feature for advanced use cases but might confuse new users (especially the ones that uses Hive for web only).

@themisir
Copy link
Contributor

Sorry for the late response but I don't have enough bandwidth for adding new features to hive. I'm not exactly sure how could new features would affect users or could cause issues + might lead to new feature requests (eg: path will not work on web, so there might be someone requesting that to work). So I'm unsure about merging this feature. What do you think about that?

@wbusey0
Copy link
Contributor Author

wbusey0 commented Oct 12, 2021

My main argument for doing this would be consistency. It's kind of weird that you can open a box with path but not delete it. Having the path parameter there but not in the other methods is in my opinion more confusing.
Of course the inconsistency could also be resolved by removing the path parameter for openBox method, but obviously I'm not vouching for that ;) .

I don't think we can solve our case by calling the Hive.initFlutter() multiple times as we have multiple parts of the app needing boxes in other subdirectories.

Other ways to solve it would indeed be to delete the relevant Hive files manually by checking the deleteBoxFromDisk implementation; which is what we'll be doing. I thought about casting the Hive object to HiveImpl but that's not possible as it is not part of the public API.

@themisir
Copy link
Contributor

My main argument for doing this would be consistency. It's kind of weird that you can open a box with path but not delete it. Having the path parameter there but not in the other methods is in my opinion more confusing.
Of course the inconsistency could also be resolved by removing the path parameter for openBox method, but obviously I'm not vouching for that ;) .

Haven't noticed that openBox supports custom path parameter. So it makes sense to support path parameter for other methods too.

@themisir themisir merged commit da44d6c into isar:master Oct 12, 2021
@wbusey0
Copy link
Contributor Author

wbusey0 commented Oct 14, 2021

Thank you!
I think the the web implementation needs those parameters as well, there were some checks failing on this PR?

@themisir
Copy link
Contributor

I think the the web implementation needs those parameters as well

Hive web uses different implementation (using indexed db) which doesn't relies on file system / so it doesn't uses path parameter.

there were some checks failing on this PR?

I'm currently working on fixing pipeline here #806

mrdavidrees pushed a commit to mrdavidrees/hive that referenced this pull request Jan 16, 2022
Ensure HiveLists are treated as non-nullable in hive_generator (isar#728)

* Replaced ?. operator with . operator

Resolves error "The argument type 'HiveList<T>?' can't be assigned to the parameter type 'HiveList<T>'.

Closes issue isar#664.

* Ensuring nullable HiveLists are properly generated

Co-authored-by: Misir Jafarov <misir.ceferov@gmail.com>

Updated hive_generator dependencies (isar#765)

* Updated dependencies

* Changed version dependencies

Bump up hive_generator to v1.1.1

Get indexDB selectively based on window property (isar#802)

Co-authored-by: Wenhao Wu <wenhao.wu@signanthealth.com>

Add missing path parameter to HiveInterface methods (isar#776)

Fixes broken CI (isar#806)

* Update pubspec.yaml

* Migrated from mockito to mocktail

* Test on dart 2.14

Don't loose track of box objects if init crashes (isar#846)

feat: Add flush method to boxes (isar#852)

bump: Update to v2.0.5

Updated hive_generator analyzer dependency (isar#858)

bump up hive_generator to v1.1.2

Change pedantic to linter and fix warnings (isar#876)
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

Successfully merging this pull request may close these issues.

None yet

2 participants