Closed skhizerabass closed 5 years ago
You can clear the whole database using database.unsafeClearDatabase()
. There's no feature for cleaing the whole table. You can delete contents of an empty query collection.query().markAllAsDeleted()
(or destroyAllPermanently()
), but it's not very efficient (yet). You could also use a raw query β see https://github.com/Nozbe/WatermelonDB/issues/103 for discussion
Thank you very much . This is the exact thing i wanted . I wanted to clear my db and it worked like a charm
I see that the method has changed to database.unsafeResetDatabase()
.
Could It be documented?
@radex
it should! I remember there was an issue where this was explained more clearly βcan you find it @cesargdm ?
If I use the unsafeResetDatabase does my sync timestamp resets to null too?
change version of appSchema and reload the app .. this way will clear all database :) π
const schemas = appSchema({ version: 1, //make it version: 2 })
@luk3skyw4lker did you ever find out the answer to that?
@KrisLau I think that yes, the sync timestamp was also set to null. It's been a long time since my last contact with the library, but I'm almost sure that the timestamp was set to null too.
This works fine for me;
async function resetDatabase() {
try {
await database.action(async () => {
await database.unsafeResetDatabase();
});
} catch (error: any) {
console.log('Error clearing local database', error);
}
}
@ushicode do you use that for migrations? I'm trying to reset my database and then sync again immediately but I'm having trouble figuring out how to do so: https://github.com/Nozbe/WatermelonDB/issues/1609
I want to clear all the records from different tables. Is there anyway to do that ?