Hive: How to remove all data from the box?

Created on 7 Feb 2020  路  4Comments  路  Source: hivedb/hive

How to remove all data from the box?

question

Most helpful comment

@erabti @leisim I really think clear should clear the in-memory data immediately, then resolve the Future once the data has been removed from disk (similar to how put works).

Is there a reason this can't or shouldn't be done?

All 4 comments

Either using box.clear() to clear the box or box.deleteFromDisk() to also delete the file containing the box (or the indexeddb database in the browser).

It looks like box.clear operation is not immediately applied:

box.add(0);
print(box.length); // 1
box.clear();
print(box.length); // 1

But box.deleteAll works as expected:

box.add(0);
print(box.length); // 1
box.deleteAll(box.keys);
print(box.length); // 0

@leisim: Is that the correct behavior? It doesn't seem right...

@jimmy-robert the clear method is async, you have to await for it:

await box.clear();

@erabti @leisim I really think clear should clear the in-memory data immediately, then resolve the Future once the data has been removed from disk (similar to how put works).

Is there a reason this can't or shouldn't be done?

Was this page helpful?
0 / 5 - 0 ratings

Related issues

ninest picture ninest  路  3Comments

kthecoder picture kthecoder  路  3Comments

Ferdzzzzzzzz picture Ferdzzzzzzzz  路  3Comments

aminjoharinia picture aminjoharinia  路  3Comments

kaboc picture kaboc  路  3Comments