hive icon indicating copy to clipboard operation
hive copied to clipboard

Hive box(xyz).delete(keyhere) not working

Open UmairSaqibBhutta opened this issue 1 year ago • 7 comments

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.

UmairSaqibBhutta avatar Mar 15 '23 13:03 UmairSaqibBhutta

delete() is an async function. Did you try awaiting it?

friedScotch avatar Apr 06 '23 06:04 friedScotch

Was it resolved? Facing same issue even with await https://github.com/hivedb/hive/issues/1197

LiveRock avatar Apr 19 '23 08:04 LiveRock

@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.

UmairSaqibBhutta avatar Apr 19 '23 14:04 UmairSaqibBhutta

Will Hive store/save with duplicate keys? Like will it create multiple records or just overwrite the record of the same key?

LiveRock avatar Apr 21 '23 04:04 LiveRock

It will replace/ Overwrite the previous record with the new one.

UmairSaqibBhutta avatar Apr 21 '23 06:04 UmairSaqibBhutta

The official doc does not use async, however if you look inside box_base.dart, delete() is an async function

grafik

friedScotch avatar Apr 21 '23 07:04 friedScotch

@LiveRock @UmairSaqibBhutta No, it does not overwrite the value, it only appends. See this link

darielkurt avatar Jan 23 '24 10:01 darielkurt