I have create stores dynamically in the database.
try {
if (!(await existingCollection).includes(tableName)) {
const dbVersion = this.collectionsDb.verno + 1;
await this.collectionsDb.close();
await this.collectionsDb.version(dbVersion).stores({
[tableName]: '++_id,' + replaceAll(element.headerNames.join(',').toLowerCase(), '[^a-zA-Z,]', ''),
});
localStorage.setItem('collectionDbVersion', dbVersion.toString());
await this.collectionsDb.open();
await this.collectionsDb[tableName].bulkAdd(csvDataArray);
} else {
await this.collectionsDb[tableName].clear();
await this.collectionsDb[tableName].bulkAdd(csvDataArray);
}
existingStoresData.push({
collectionId: tableName
});
} catch (e) {
console.error('Unable to create collection:\n' + JSON.stringify(e, null, 2));
}
I am able to perform search when database gets created for first time.
But when I refresh the page (this time neither any new table created nor update the DB version) and trying to perform search, I am getting InvalidTableError - table does not exist even though I can see the table in database.
Please refer the error description below
DexieError {_e: Error at getErrorWithStack (http://localhost:4200/vendor.js:56951:12) at new DexieError (ht…, name: "InvalidTableError", message: "Table collection_6135f2c6166805000120ab45 does not exist", inner: null, _promise: DexiePromise, …} inner: null message: "Table collection_6135f2c6166805000120ab45 does not exist" name: "InvalidTableError" _e: Error at getErrorWithStack (http://localhost:4200/vendor.js:56951:12) at new DexieError (http://localhost:4200/vendor.js:57048:19) at CollectionsDatabase.push.Texg.Dexie.table (http://localhost:4200/vendor.js:60875:19) at http://localhost:4200/main.js:11795:48 at http://localhost:4200/vendor.js:57836:23 at callListener (http://localhost:4200/vendor.js:57559:19) at endMicroTickScope (http://localhost:4200/vendor.js:57631:25) at physicalTick (http://localhost:4200/vendor.js:57614:30) at ZoneDelegate.invoke (http://localhost:4200/polyfills.js:9743:30) at Object.onInvoke (http://localhost:4200/vendor.js:108914:33) stack: "Error\n at getErrorWithStack (http://localhost:4200/vendor.js:56951:12)\n at new DexieError (http://localhost:4200/vendor.js:57048:19)\n at CollectionsDatabase.push.Texg.Dexie.table (http://localhost:4200/vendor.js:60875:19)\n at http://localhost:4200/main.js:11795:48\n at http://localhost:4200/vendor.js:57836:23\n at callListener (http://localhost:4200/vendor.js:57559:19)\n at endMicroTickScope (http://localhost:4200/vendor.js:57631:25)\n at physicalTick (http://localhost:4200/vendor.js:57614:30)\n at ZoneDelegate.invoke (http://localhost:4200/polyfills.js:9743:30)\n at Object.onInvoke (http://localhost:4200/vendor.js:108914:33)" [[Prototype]]: Object _promise: DexiePromise onuncatched: ƒ nop() _PSD: {id: "global", global: true, ref: 19, unhandleds: Array(0), onunhandled: ƒ, …} _lib: false _listeners: [] _numPrev: 2 _prev: DexiePromise {_listeners: Array(0), _lib: false, _PSD: {…}, _stackHolder: Error at getErrorWithStack (http://localhost:4200/vendor.js:56951:12) at new DexiePromise (…, onuncatched: ƒ, …} _stackHolder: Error at getErrorWithStack (http://localhost:4200/vendor.js:56951:12) at new DexiePromise (http://localhost:4200/vendor.js:57271:29) at DexiePromise.then (http://localhost:4200/vendor.js:57297:22) at CollectionsService.isColumnExists (http://localhost:4200/main.js:11794:35) at CollectionsService. (http://localhost:4200/main.js:11686:42) at Generator.next () at http://localhost:4200/vendor.js:135975:71 at new ZoneAwarePromise (http://localhost:4200/polyfills.js:10339:33) at __awaiter (http://localhost:4200/vendor.js:135971:12) at http://localhost:4200/main.js:11683:148 _state: false _value: DexieError inner: null message: "Table collection_6135f2c6166805000120ab45 does not exist" name: "InvalidTableError" _e: Error at getErrorWithStack (http://localhost:4200/vendor.js:56951:12) at new DexieError (http://localhost:4200/vendor.js:57048:19) at CollectionsDatabase.push.Texg.Dexie.table (http://localhost:4200/vendor.js:60875:19) at http://localhost:4200/main.js:11795:48 at http://localhost:4200/vendor.js:57836:23 at callListener (http://localhost:4200/vendor.js:57559:19) at endMicroTickScope (http://localhost:4200/vendor.js:57631:25) at physicalTick (http://localhost:4200/vendor.js:57614:30) at ZoneDelegate.invoke (http://localhost:4200/polyfills.js:9743:30) at Object.onInvoke (http://localhost:4200/vendor.js:108914:33) stack: "Error\n at getErrorWithStack (http://localhost:4200/vendor.js:56951:12)\n at new DexieError (http://localhost:4200/vendor.js:57048:19)\n at CollectionsDatabase.push.Texg.Dexie.table (http://localhost:4200/vendor.js:60875:19)\n at http://localhost:4200/main.js:11795:48\n at http://localhost:4200/vendor.js:57836:23\n at callListener (http://localhost:4200/vendor.js:57559:19)\n at endMicroTickScope (http://localhost:4200/vendor.js:57631:25)\n at physicalTick (http://localhost:4200/vendor.js:57614:30)\n at ZoneDelegate.invoke (http://localhost:4200/polyfills.js:9743:30)\n at Object.onInvoke (http://localhost:4200/vendor.js:108914:33)" [[Prototype]]: Object _promise: DexiePromise {_listeners: Array(0), _lib: false, _PSD: {…}, _stackHolder: Error at getErrorWithStack (http://localhost:4200/vendor.js:56951:12) at new DexiePromise (…, onuncatched: ƒ, …} stack: (...) get stack: ƒ () [[Prototype]]: DexieError stack: (...) then: (...) [[Prototype]]: Dexie.Promise stack: (...) get stack: ƒ ()