래퍼를 통해 indexedDb를 사용하고 있습니다 Dexie.js. 목표는 항상 api를 호출하는 대신 indexedDb에서 직접 데이터를 가져 오는 것입니다.indexedDb에 여러 테이블로 keyPath를 지정하십시오. 내 프로젝트에서
일부 데이터는 수시로 변경/삭제 될 수 있으므로 버전 번호를 사용하여 사용자 캐시에있는 항목을 추적합니다. 그래서 응용 프로그램이 시작될 때 db의 버전을받습니다. 캐시의 버전과 일치하면 indexedDb를 가져옵니다. 그렇지 않으면 indexedDb를 삭제하고 서버에서 새 데이터를 가져옵니다.
문제는 다른 항목을 추가하지 않고 버전 값을 업데이트하는 방법을 찾을 수 없다는 것입니다. 나는 다음과 같은 오류 얻을
db.version(1).stores({
buildings: "id, name, address, lat, long, purchased, [lat+long]",
versions: "id, version",
});
db.open().then((el) => {
console.log(el);
this.eventBus.$on("refresh-map",() => {
this.fetchHexagons();
});
}).catch(Dexie.MissingAPIError, (e) => {
console.log("Couldn't find indexedDB API");
console.log(e);
rollback = true;
}).catch((error) => {
console.log(`error: ${error}`);
});
db.versions.toArray((res) => {
if (res.length > 0 && res[0].version != version.body.model_version) {
db.buildings.clear().then(() => {
console.log("clearing buildings");
});
}
db.versions.update(1, { version: "2"}).then((update) => {
if (!update) {
db.versions.put({ version: version.body.model_version });
}
});
문제는 다음과 같습니다 :
dexie.es.js?f8d5:1384 Unhandled rejection: Error: Failed to execute 'put' on 'IDBObjectStore': Evaluating the object store's key path did not yield a value.
을 난 그냥 추가/때마다 버전 필드 I을 넣어 있는지 확인하려면 지금이 내가 뭘하는지입니다 그 값을 다른 것을 추가하지 않고서 만 대체 할 수 있습니다. "버전"테이블의 db에는 항상 하나의 요소가 있습니다.
어떻게 해결할 수 있습니까?