I am working on a web app that uses Indexed DB to work. I want to check if an object with that ID exists in my Database. This is my actual code:
function checkKeyExists(id){
request = window.indexedDB.open("ManagementDB", 1);
let exists = false;
request.onerror = function (event) {
window.alert("Error using indexedDB");
return false
}
request.onsuccess = function (event) {
let getRequest = request.result.transaction("KeyStorage", "readonly").objectStore("KeyStorage").get(id)
getRequest.onerror = function(event){
console.log("Info: checkKey: error reading key "+ id+ " : " + event);
}
getRequest.onsuccess = function(event){
if (typeof(getRequest.result) === 'object'){
keyStatus = true;
}
}
}
// Need to wait for everything to finish before doing the return
return keyStatus
}
I do not know how to wait for all of the code to finish before executing the return. I am still a starter in javascript, it might be an easy question, but I did not get any response to this looking at other questions. Other questions uses await, but that would not resolve anything for me.