Created
October 18, 2020 10:51
-
-
Save tofusoup429/84abe7c99902641d4fe77e6f07d059bd to your computer and use it in GitHub Desktop.
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
let DB_NAME = 'testIDB' // Name of database => one origin can have as many databases as it wants. | |
let OBJECT_STORE_NAME = 'testObjectStore' // Name of object store. => one database can have as many object store as it wants. | |
let request = indexedDB.open(DB_NAME, 1) // fire to open DB named 'testIDB' version 1. | |
request.onupgradeneeded = (e) => { | |
let db = request.result; | |
let objectStore = db.createObjectStore(OBJECT_STORE_NAME,{keyPath:"id"}); | |
console.info('database and object store created'); | |
}; | |
request.onerror = (e) => { | |
console.log(e); | |
//when something went wrong and failed to open the database. | |
//Most likely, this happens when user did not allow the application to access indexeddb. | |
} | |
request.onsuccess = (e) => { | |
//when request was made successfully | |
console.log(e) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment