You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'm sure I'm just misunderstanding something, but should this not work? Variables defined outside the pg.connect scope are not visible within it? I feel like I must be missing something obvious. Any little advice would be great. Thanks. function(){ var myResultStore = []; pg.connect(conString, function(err, client) { if(err) throw new Error('Could not connect to the database'); client.query("SELECT name FROM people LIMIT 2", function(err, result) { if(err) throw new Error('Query Failure'); result.rows.forEach(function(row){ myResultStore.push(row.name)}); console.log(myResultStore.toString()); // ** correctly returns [Bob, John] }); } console.log(myResultStore); // ** returns [] }
The text was updated successfully, but these errors were encountered:
I'm sure I'm just misunderstanding something, but should this not work? Variables defined outside the pg.connect scope are not visible within it? I feel like I must be missing something obvious. Any little advice would be great. Thanks.
function(){ var myResultStore = []; pg.connect(conString, function(err, client) { if(err) throw new Error('Could not connect to the database'); client.query("SELECT name FROM people LIMIT 2", function(err, result) { if(err) throw new Error('Query Failure'); result.rows.forEach(function(row){ myResultStore.push(row.name)}); console.log(myResultStore.toString()); // ** correctly returns [Bob, John] }); } console.log(myResultStore); // ** returns [] }
The text was updated successfully, but these errors were encountered: