Skip to content

Instantly share code, notes, and snippets.

@kevinmungai
Forked from TalAter/idb.js
Created June 3, 2021 10:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kevinmungai/7315f6eb2205571c86db558d524b6bae to your computer and use it in GitHub Desktop.
Save kevinmungai/7315f6eb2205571c86db558d524b6bae to your computer and use it in GitHub Desktop.
IndexedDB upgrade code to add index to an existing object store
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