{"action":"created","issue":{"url":"https://api.github.com/repos/litehelpers/Cordova-sqlite-storage/issues/281","labels_url":"https://api.github.com/repos/litehelpers/Cordova-sqlite-storage/issues/281/labels{/name}","comments_url":"https://api.github.com/repos/litehelpers/Cordova-sqlite-storage/issues/281/comments","events_url":"https://api.github.com/repos/litehelpers/Cordova-sqlite-storage/issues/281/events","html_url":"https://github.com/litehelpers/Cordova-sqlite-storage/issues/281","id":85752580,"number":281,"title":"Unable to execute two select statements that depend on each other","user":{"login":"dcp3450","id":408527,"avatar_url":"https://avatars.githubusercontent.com/u/408527?v=3","gravatar_id":"","url":"https://api.github.com/users/dcp3450","html_url":"https://github.com/dcp3450","followers_url":"https://api.github.com/users/dcp3450/followers","following_url":"https://api.github.com/users/dcp3450/following{/other_user}","gists_url":"https://api.github.com/users/dcp3450/gists{/gist_id}","starred_url":"https://api.github.com/users/dcp3450/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/dcp3450/subscriptions","organizations_url":"https://api.github.com/users/dcp3450/orgs","repos_url":"https://api.github.com/users/dcp3450/repos","events_url":"https://api.github.com/users/dcp3450/events{/privacy}","received_events_url":"https://api.github.com/users/dcp3450/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/litehelpers/Cordova-sqlite-storage/labels/question","name":"question","color":"cc317c"}],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":1,"created_at":"2015-06-06T13:25:49Z","updated_at":"2015-06-09T14:20:09Z","closed_at":null,"body":"I need to end up with an array that looks something similar to this:\r\n```\r\n[\r\n\t{\r\n\t\tid: \"1\",\r\n\t\tname: \"name1\",\r\n\t\tlocation: \"location1\",\r\n\t\tproducts: [\r\n\t\t\t{\r\n\t\t\t\tname: \"product1\"\r\n\t\t\t},\r\n\t\t\t{\r\n\t\t\t\tname: \"product2\"\r\n\t\t\t},\r\n\t\t\t{\r\n\t\t\t\tname: \"product3\"\r\n\t\t\t}\r\n\t\t]\r\n\t},\r\n\t{\r\n\t\tid: \"2\",\r\n\t\tname: \"name2\",\r\n\t\tlocation: \"location2\",\r\n\t\tproducts: [\r\n\t\t\t{\r\n\t\t\t\tname: \"product4\"\r\n\t\t\t},\r\n\t\t\t{\r\n\t\t\t\tname: \"product5\"\r\n\t\t\t}\r\n\t\t]\r\n\t}\r\n]\r\n```\r\n\r\nWhat I would normally do is run a `select` statement to populate my first level since my second depends on the `id` of the first. Since this is an asynchronous system that doesn't seem to workout. This is my attempt:\r\n```\r\nvar query =\"...\"\r\n$cordovaSQLite.execute(nanoDB, query, []).then(function (res) {\r\n    $scope.installations = [];\r\n    //start loop to get the installations\r\n    for (var x = 0; x < res.rows.length; x++) {\r\n        $scope.installations.push({ id: res.rows.item(x).instID, ... , products: [] });\r\n        var installQuery = \"...\";\r\n        $cordovaSQLite.execute(nanoDB, installQuery, [res.rows.item(x).instID]).then(function (res2) {\r\n            for (var y = 0; y < res2.rows.length; y++) {\r\n                $scope.installations[x].products.push({ name: res2.rows.item(y).prodName })\r\n            }\r\n        });\r\n    }\r\n});\r\n```\r\n\r\nObviously the issue is the first for loop completes before the second (you know asynchronously).  If this ran as a synchronously the second loop would run before moving to the next iteration in the first for loop.\r\n\r\nI can't see anything in the documentation about doing something like this. Can anyone provide some direction?"},"comment":{"url":"https://api.github.com/repos/litehelpers/Cordova-sqlite-storage/issues/comments/110371828","html_url":"https://github.com/litehelpers/Cordova-sqlite-storage/issues/281#issuecomment-110371828","issue_url":"https://api.github.com/repos/litehelpers/Cordova-sqlite-storage/issues/281","id":110371828,"user":{"login":"brodybits","id":1559888,"avatar_url":"https://avatars.githubusercontent.com/u/1559888?v=3","gravatar_id":"","url":"https://api.github.com/users/brodybits","html_url":"https://github.com/brodybits","followers_url":"https://api.github.com/users/brodybits/followers","following_url":"https://api.github.com/users/brodybits/following{/other_user}","gists_url":"https://api.github.com/users/brodybits/gists{/gist_id}","starred_url":"https://api.github.com/users/brodybits/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/brodybits/subscriptions","organizations_url":"https://api.github.com/users/brodybits/orgs","repos_url":"https://api.github.com/users/brodybits/repos","events_url":"https://api.github.com/users/brodybits/events{/privacy}","received_events_url":"https://api.github.com/users/brodybits/received_events","type":"User","site_admin":false},"created_at":"2015-06-09T14:20:09Z","updated_at":"2015-06-09T14:20:09Z","body":"Unfortunately, I do not really follow the code very well. For this kind of question, I suggest you try the same code with a database opened using the normal HTML5/Web SQL API (i.e. `window.openDatabase()`)."}}