I have a small javascript project and I use indexedDB to store some values.The problem is that indexedDB is asynchronous and I cant return a value from request.onsuccess.:
function read(email) {
var transaction = db.transaction(["usuario"]);
var objectStore = transaction.objectStore("usuario");
var request = objectStore.get(email);
request.onerror = function (event) {
console.log("No se pudieron sacar los datos de la base de datos!");
};
request.onsuccess = function (event) {
if (request.result) {
console.log(request.result);
}
else {
console.log(email + " no se encontro en la BD!");
return true;
}
};
}
I am trying to return the object stored by the key email.console.log prints out the object in the console but when return request.result is asigned it returns things of no use. I can see that there is a lot of qustions about asynchronous operations already in this site including Deffered function but considering my limited knowlege of javascript I cant seem to get the grasp of it so if anyone could please explain to me how do I return the found value .onsuccess