Skip to content

Instantly share code, notes, and snippets.

@tofusoup429
Created October 18, 2020 10:51
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 tofusoup429/84abe7c99902641d4fe77e6f07d059bd to your computer and use it in GitHub Desktop.
Save tofusoup429/84abe7c99902641d4fe77e6f07d059bd to your computer and use it in GitHub Desktop.
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