Look at line:
if (doc.rows.length > 0) return doc.rows;
You expect that to return the contents of doc.rows
so that your console.log(projects);
will display that to you, right? Well, that's not what will happen. The return
statement will return from the callback function (function(error, doc) {
), not the load_all
function. If you want to get at the doc.rows
, you need to do it inside the callback function. Like this:
if (doc.rows.length > 0) console.log(doc.rows);
The reason this is necessary is because IndexedDB is asynchronous. To really understand what that implies and why the code, as you wrote it, cannot work, I recommend you Google for some tutorials about IndexedDB or about asynchronous JavaScript in general (sorry, I don't have any good recommendations off the top of my head).