objectbox-java icon indicating copy to clipboard operation
objectbox-java copied to clipboard

Option to delete the entire DB

Open akul1994 opened this issue 8 years ago • 7 comments

Hey, Is there any way i can delete the entire db. i want to clear the db when a user logs out. any single method to achieve this rather than creating a box for each entity and removing the entities?

akul1994 avatar Dec 20 '17 08:12 akul1994

You can close the BoxStore and then just delete the files. That's the most effcient way to do this.

boxStore.close();
boxStore.deleteAllFiles();

There are also static deleteAllFiles(...) methods if you prefer to delete before you open the store (I think that's not what you want, just for the sake of completeness).

greenrobot avatar Dec 21 '17 11:12 greenrobot

Thanks. This worked for me. I somehow missed this in the docs.

akul1994 avatar Dec 21 '17 14:12 akul1994

This doesn't seem to work for me, Im using the:

boxStore.deleteAllFiles(getContext(), OB_NAME);

OB_NAME being a custom name, and omitting the close as it raises the exception store is closed when user logs back into my app. The data in an entity is still there when logging back in and Im trying to do a simple reset of the database for a user logout and in senario

What am I missing? Cheers

ghost avatar May 22 '18 12:05 ghost

it raises the exception store is closed when user logs back into my app

@dreamcatcha This sounds like your BoxStore instance is not properly cleaned up or the files were not actually deleted. Make sure to close before you delete. -ut

greenrobot-team avatar Jul 03 '18 13:07 greenrobot-team

I'm using dependency injection template and have encountered a problem that I can't use boxStore after boxStore.deleteAllFiles() because it is closed, what solution is there ? how can I delete all data without closing the database? Best regards

EspanaMia avatar Sep 03 '18 11:09 EspanaMia

@EspanaMia Deleting the files is the most efficient way to delete all data. Figure out how to do this in your DI framework or drop DI? ;-)

greenrobot avatar Sep 03 '18 12:09 greenrobot

I'm having a similar issue. I am also using dependency injection which works fine with ObjectBox. At a particular point I need to destroy my DI and re-intialise. I need to destroy my instance of ObjectBox before I call my DI. Using the line:

BoxStore.deleteAllFiles(context, null) won't run as it gives the error

java.lang.IllegalStateException: Cannot delete files: store is still open

BoxStore.close() is not available. I am running ObjectBox 2.3.2 version. Any help would be greatly appreciated :)

ntohill95 avatar Jun 18 '19 13:06 ntohill95