I have problem with delete database to make a storage free. I already tried solution from this How can I delete PouchDB Database indefinitly, to free space? and https://pouchdb.com/guides/compact-and-destroy.html but it not solve my problem. I already used compact() function to clear the previous user data, but when I tried to sync new user data, the old data from other user does not deleted. For example, user A have 3 data and user B have 2 data. First I get the data from user A and I get the data correctly which are 3 data. Then when I want to get data from user B, I get 5 data which mean the data from user A are not deleted/remove. Below is my code :
uuid.ts
retriveTaskRefNo(url, uuid, cb){
//get reference item based on uuid
HTTP.get(url+'/get_item', {uuid: uuid}, {})
.then(data => {
//call the function removeData() in uuid.ts
this.removeData(() => {
//save reference item
this.settingProvider.setInfo(data.data, () => {
cb();
});
})
})
}
//call the removeData() in itemProvider.ts
removeData(cb){
this.itemProvider.resetDB(() => {
});
}
itemProvider.ts
constructor(public http: Http, public settingProvider: SettingProvider) {
this.initializeTaskDB();
}
initializeTaskDB(){
this.db = new PouchDB('item');
console.log('Database created Success!');
}
//function to clear database
resetDB(cb){
if(this.sync){
console.log('Cancelling sync for InspectionTask due to removeData');
this.sync.cancel();
}
this.db.destroy().then(function (response) {
console.log('success delete inspection task');
this.initializeTaskDB();
}).catch(function (err) {
console.log('eror',err);
});
}
Are the code is wrong. Please guide me