ObjectBox Flutter: Clear all the tables on logout

Viewed 693

I am using ObjectBox for the database and I have created a couple of tables. Now I need to clear all the tables (like truncate to start primary id from 1 again) like Clean the Database.

I didn't found any method or way to clear the database.

I thought to use removeAll for all the tables, but I think it's not the proper way.

Please do let me know if is there any other way to do it.

Thanks, Pratik.

2 Answers

What you're trying to do seems like you want to start the database from scratch. In that case, you can delete the database directory before initializing Store().

Here is the code that you can copy/paste and change your database name.

  static void removeAllData() async {
    Directory dir = await getApplicationDocumentsDirectory();
    Directory(dir.path + '/your_db').delete().then((FileSystemEntity value) => print("DB Deleted: ${value.existsSync()}"));
  }
Related