I have to return query result from indexedDB, but the result is only available in onsuccess event handler.
1 function listPeople(){
...
4 var open = indexedDB.open("AccordionDatabase",1),
5 res;
6
7 open.onsuccess = function(){
8 var db = open.result;
9 var transaction = db.transaction("PeopleStore", "readwrite");
10 var store = transaction.objectStore("PeopleStore");
11 var request = store.getAll();
12 request.onsuccess = function(event){
13 res = event.target.result;
14 console.log(res);
15 };
16
17 // Close the db when the transaction is done
18 transaction.oncomplete = function() {
19 db.close();
20 };
21
22 };
23 return res;
24 }
The output of the function call shows undefined, though console prints the result array. Please guide me how to use the variable as output.