Skip to content

Misunderstanding something #40

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
ghost opened this issue Jul 27, 2011 · 1 comment
Closed

Misunderstanding something #40

ghost opened this issue Jul 27, 2011 · 1 comment

Comments

@ghost
Copy link

ghost commented Jul 27, 2011

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 [] }

@ghost
Copy link
Author

ghost commented Jul 27, 2011

ah, stupid mistake. sorry mates. of course it's an async issue. db not returning result before the second log is written.

@ghost ghost closed this as completed Jul 27, 2011
brianc added a commit that referenced this issue Dec 18, 2019
This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

0 participants