createObjectStore bumps db version
See original GitHub issueEverytime createObjectStore is called, the database version is incremented. Just trying to figure out if this is intended behaviour or am I doing something wrong?
I have the following config in my app.module, which is passed to the ngx-indexed-db module forRoot method:
const dbConfig: DBConfig = { name: 'appDb', version: 1, objectStoresMeta: [ ] };
Which creates a new database (version 1) with no stores, which is fine.
Then, in the user authentication service, I’m creating new object stores when a user logs in:
private createDataStores(): void {
const offlineCacheSchema: ObjectStoreMeta = {
store: 'offlineCache-' + this.user.id,
storeConfig: { keyPath: 'id', autoIncrement: true },
storeSchema: [
{ name: 'endpoint', keypath: 'endpoint', options: { unique: false } },
{ name: 'ulid', keypath: 'ulid', options: { unique: true } },
{ name: 'data', keypath: 'data', options: { unique: false } }
]
}
const apiCacheSchema: ObjectStoreMeta = {
store: 'apiCache-' + this.user.id,
storeConfig: { keyPath: 'id', autoIncrement: true },
storeSchema: [
{ name: 'endpoint', keypath: 'endpoint', options: { unique: true } },
{ name: 'timestamp', keypath: 'timestamp', options: { unique: false } },
{ name: 'data', keypath: 'data', options: { unique: false } }
]
};
this.dbService.createObjectStore(offlineCacheSchema);
this.dbService.createObjectStore(apiCacheSchema);
}
The stores are created fine, but the database version bumps to 3. Reloading the app gives the following error:
Since version is a required property, and the module requires DbConfig. I’m not sure how to use createObjectStore to create dynamic stores if the version increments every time.
Issue Analytics
- State:
- Created 2 years ago
- Comments:8 (5 by maintainers)
Top GitHub Comments
Yup, here ya go. https://codesandbox.io/s/trusting-glade-7dwm3
That is a good catch for the lib to handler in the future, for now I would say the consumer will have to handle the dbVersion control. Here is a example of workaround https://codesandbox.io/s/floral-thunder-thbnf?file=/src/app/app.component.ts