如何删除数据库以释放 Pouchdb 中的存储空间?
How to delete database to free storage in Pouchdb?
我在删除数据库以释放存储空间时遇到问题。我已经尝试过这个 and https://pouchdb.com/guides/compact-and-destroy.html 的解决方案,但它没有解决我的问题。我已经使用 compact() 函数来清除以前的用户数据,但是当我尝试同步新用户数据时,其他用户的旧数据并没有被删除。例如,用户 A 有 3 个数据,用户 B 有 2 个数据。首先,我从用户 A 获取数据,然后正确获取数据,即 3 个数据。然后当我想从用户 B 获取数据时,我得到 5 个数据,这意味着来自用户 A 的数据不是 deleted/remove。下面是我的代码:
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);
});
}
是不是代码有误。请指导我
压缩
CouchDB 基于 B 树。每次更新文档时,它都会创建一个新的修订版。压缩会删除所有旧修订以清理 space 但不会清理 _deleted 文档。
清除
Purge 是 CouchDB 的一项功能,可以完全删除文档。不可逆,PouchDB暂不支持。
解决方案
在 PouchDB 中清除数据库的唯一方法是使用 destroy。
我在删除数据库以释放存储空间时遇到问题。我已经尝试过这个
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);
});
}
是不是代码有误。请指导我
压缩
CouchDB 基于 B 树。每次更新文档时,它都会创建一个新的修订版。压缩会删除所有旧修订以清理 space 但不会清理 _deleted 文档。
清除
Purge 是 CouchDB 的一项功能,可以完全删除文档。不可逆,PouchDB暂不支持。
解决方案
在 PouchDB 中清除数据库的唯一方法是使用 destroy。