Skip to content

Instantly share code, notes, and snippets.

@ashwinkumar2438
Last active January 8, 2021 18:09
Show Gist options
  • Save ashwinkumar2438/0f15a161d4fcb7c71665050f8344ad42 to your computer and use it in GitHub Desktop.
Save ashwinkumar2438/0f15a161d4fcb7c71665050f8344ad42 to your computer and use it in GitHub Desktop.
let openRequest = indexedDB.open("mystore", 3);
openRequest.onupgradeneeded = function(event) {
let db = openRequest.result;
switch(event.oldVersion) { // existing db version
case 1:
// do changes for update from version 1 to 3...
db.createObjectStore("books",{autoIncrement:true});
case 2:
// do changes for update from version 2 to 3...
let booksStore=openRequest.transaction.objectStore("books");
books.createIndex("name","book_name",{unique:false});
db.createObjectStore("users",{autoIncrement:true});
}
};
openRequest.onerror = function() {
console.error("Error", openRequest.error);
};
openRequest.onsuccess = function() {
let db = openRequest.result;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment