1

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.

Pratik Butani
  • 60,504
  • 58
  • 273
  • 437

2 Answers2

3

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().

vaind
  • 1,642
  • 10
  • 19
0

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()}"));
  }
Pratik Butani
  • 60,504
  • 58
  • 273
  • 437