hive
hive copied to clipboard
Hive box(xyz).delete(keyhere) not working
I am using hive for data persistence and now I want to delete data at a particular key of a box. But delete
method is not working, My code is :
final box = Hive.box("boxName"); box.delete(keyName);
but its not working.
delete()
is an async function. Did you try awaiting it?
Was it resolved? Facing same issue even with await https://github.com/hivedb/hive/issues/1197
@friedScotch @LiveRock delete() is not async but I also tried. It not worked.
Then I tried another way that may be not professional but it works.
I am storing a list of strings and to delete any particular key I am saving an empty list against the key.
box.put("keyName", <String>[]);
we can also use it as:
box.put("keyName", null);
It all depends upon the scenario.
box.put will replace the previous data with a new one.
Will Hive store/save with duplicate keys? Like will it create multiple records or just overwrite the record of the same key?
It will replace/ Overwrite the previous record with the new one.
The official doc does not use async, however if you look inside box_base.dart, delete() is an async function
@LiveRock @UmairSaqibBhutta No, it does not overwrite the value, it only appends. See this link