Dexie.js indexedDB 找不到指定的对象
Dexie.js indexedDB can't find specified object
我正在我的 Vue + Laravel 应用程序中添加一个 indexedDB,这是我当前使用的代码:
export default {
mixins: [VueGoogleMap.MapElementMixin],
created() {
this.eventBus.$on("refresh-map", () => {
this.fetchHexagons();
});
const getAllBuildings = () => Vue.http.get("/sandbox/buildings");
getAllBuildings().then((result) => {
const async = Dexie.async;
const spawn = Dexie.spawn;
const db = new Dexie("buildings");
db.version(1).stores({
buildings: `++dexie_id, id, name, address, city, nr_units, lat, long, purchased`,
});
db.transaction("rw", db.buildings, function* () {
result.body.forEach(function*(el) {
const a = yield db.buildings.add({
id: el.id,
name: el.name,
address: el.address,
city: el.city,
nr_units: el.nr_units,
lat: el.lat,
long: el.long,
purchased: el.purchased,
});
});
console.log("done");
}).catch(function(err) {
// Catch any error event or exception and log it:
console.error(err.stack || err);
});
如您所见,我查询数据库是为了传输 indexedDB 中的所有建筑物,以便更快地解析它们(我需要将它们显示在地图中..)。问题是,当我 运行 此代码时,出现以下错误:
CanvasOverlay.vue?e208:68 Error: Failed to execute 'transaction' on 'IDBDatabase': One of the specified object stores was not found.
at Transaction.create (dexie.es.js?f8d5:2900)
at eval (dexie.es.js?f8d5:2222)
at eval (dexie.es.js?f8d5:1343)
at callListener (dexie.es.js?f8d5:1026)
at endMicroTickScope (dexie.es.js?f8d5:1113)
at IDBOpenDBRequest.eval (dexie.es.js?f8d5:1180)
我安装的唯一软件包是 Dexie:
npm install --save dexie
我需要安装更多东西还是 Webpack 的问题?
尝试删除数据库并重新运行代码。这个问题很常见,当更新相同版本 (1) 而没有根据 these docs.
增加版本号时会发生此问题
此外,我还看到另一个错误 - 您不能使用 forEach() 调用中的函数*。而是使用:
for (let el of result.body) {
...
}
甚至更好:
const itemsToAdd = result.body.map(el => ({
id: el.id,
name: el.name,
address: el.address,
city: el.city,
nr_units: el.nr_units,
lat: el.lat,
long: el.long,
purchased: el.purchased,
}));
return db.buildings.bulkAdd(itemsToAdd);
我正在我的 Vue + Laravel 应用程序中添加一个 indexedDB,这是我当前使用的代码:
export default {
mixins: [VueGoogleMap.MapElementMixin],
created() {
this.eventBus.$on("refresh-map", () => {
this.fetchHexagons();
});
const getAllBuildings = () => Vue.http.get("/sandbox/buildings");
getAllBuildings().then((result) => {
const async = Dexie.async;
const spawn = Dexie.spawn;
const db = new Dexie("buildings");
db.version(1).stores({
buildings: `++dexie_id, id, name, address, city, nr_units, lat, long, purchased`,
});
db.transaction("rw", db.buildings, function* () {
result.body.forEach(function*(el) {
const a = yield db.buildings.add({
id: el.id,
name: el.name,
address: el.address,
city: el.city,
nr_units: el.nr_units,
lat: el.lat,
long: el.long,
purchased: el.purchased,
});
});
console.log("done");
}).catch(function(err) {
// Catch any error event or exception and log it:
console.error(err.stack || err);
});
如您所见,我查询数据库是为了传输 indexedDB 中的所有建筑物,以便更快地解析它们(我需要将它们显示在地图中..)。问题是,当我 运行 此代码时,出现以下错误:
CanvasOverlay.vue?e208:68 Error: Failed to execute 'transaction' on 'IDBDatabase': One of the specified object stores was not found.
at Transaction.create (dexie.es.js?f8d5:2900)
at eval (dexie.es.js?f8d5:2222)
at eval (dexie.es.js?f8d5:1343)
at callListener (dexie.es.js?f8d5:1026)
at endMicroTickScope (dexie.es.js?f8d5:1113)
at IDBOpenDBRequest.eval (dexie.es.js?f8d5:1180)
我安装的唯一软件包是 Dexie:
npm install --save dexie
我需要安装更多东西还是 Webpack 的问题?
尝试删除数据库并重新运行代码。这个问题很常见,当更新相同版本 (1) 而没有根据 these docs.
增加版本号时会发生此问题此外,我还看到另一个错误 - 您不能使用 forEach() 调用中的函数*。而是使用:
for (let el of result.body) {
...
}
甚至更好:
const itemsToAdd = result.body.map(el => ({
id: el.id,
name: el.name,
address: el.address,
city: el.city,
nr_units: el.nr_units,
lat: el.lat,
long: el.long,
purchased: el.purchased,
}));
return db.buildings.bulkAdd(itemsToAdd);