Вопрос

I have an objectStore created with:

    db.createObjectStore('mystore', {autoIncrement: true})
      .createIndex('myindex', 'myindex', {unique: true});

I need to amend the schema to use inline keys, like:

    db.createObjectStore('mystore', {autoIncrement: true, keyPath: 'seq'})
      .createIndex('myindex', 'myindex', {unique: true});

I dont see any way to modify the object store like that inside a migration

Это было полезно?

Решение

Unfortunately the primary key for an object store cannot be changed after that object store's creation.

To migrate, you'll have to create a new store with your inline key and then copy over the data.

I'm guessing this is related to your other question. Note that you don't need inline keys to use puts. The IDBIndex exposes a put() method as well. You can likely achieve what you're looking for by adding a new index and using it to put() your records.

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top