Last active
February 15, 2024 13:02
-
-
Save bstavroulakis/a962b30bb2de84cd3eb0e2856bff86ca to your computer and use it in GitHub Desktop.
This file contains hidden or 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
<!DOCTYPE html> | |
<html> | |
<body> | |
<div id="data"></div> | |
<script> | |
const request = window.indexedDB.open("testDB", 1); | |
request.onupdatedneeded = function(){ | |
const objectStore = request.result.createObjectStore("users", {keyPath:"id"}); | |
objectStore.add({ | |
id: 1, | |
name: "Eva Smith", | |
hobbies: ["travelling"] | |
}); | |
objectStore.add({ | |
id: 2, | |
name: "Bill Smith", | |
hobbies: ["tennis"] | |
}); | |
objectStore.createIndex("by-name", "name") | |
} | |
request.onsuccess = function(){ | |
const transaction = request.result.transaction(['users'], 'readonly'); | |
const objectStore = transaction.objectStore("users"); | |
objectStore.get(1).onsuccess = function(){ | |
document.getElementById("data").innerHTML = this.result.name; | |
} | |
} | |
request.onerror = function(){} | |
request.onblocked = function(){} | |
</script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
"onupdatedneeded" doesn't exist, I think you mean "onupgradeneeded"