Created
September 13, 2016 10:49
IndexedDB upgrade code to add index to an existing object store
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
request.onupgradeneeded = function(event) { | |
var db = event.target.result; | |
var upgradeTransaction = event.target.transaction; | |
var objectStore; | |
if (!db.objectStoreNames.contains("my-store")) { | |
objectStore = db.createObjectStore("my-store"); | |
} else { | |
objectStore = upgradeTransaction.objectStore('my-store'); | |
} | |
if (!objectStore.indexNames.contains("my-index")) { | |
objectStore.createIndex("my-index", "status", { unique: false }); | |
} | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment