It works but its still calllback hell :-( The db connection gets reused
tho.
getApp: function(appid) {
this.useConnection( function(db, client) {
this.useCollection(db, 'authors', function(collection) {
this.useQuery(collection, {'apps.id':appid},
function(data) {
console.log(data);
}.bind(this));
}.bind(this));
}.bind(this));
}
On 4/8/2012 10:45 PM, Bryan Donovan wrote:
The EasyMySQL npm eliminates these callbacks and uses a connection
pool, so it only opens a new connection when needed.
Sent from an iPhone.
On Apr 8, 2012, at 6:17 PM, Matthew Hazlett <[email protected]
<mailto:[email protected]>> wrote:
Thats how I originally did it, but when you need to do multiple
queries to the database you shoud open the connection once and reuse
it instead of opening it multiple times a session.
On 4/8/2012 9:14 PM, Matt Patenaude wrote:
I agree, it seems entirely manageable.
One low-overhead option would be just to split that out into a
function, if it's used frequently:
function dbQuery(query, callback){
db.open(... fn() {
db.collection(.... fn() {
db.query(query, callback);
});
});
}
dbQuery("SELET * FROM blah", fn() {
// stuff you would have done in the inner-most part here
});
-Matt
On Apr 8, 2012, at 9:06 PM, Mark Hahn wrote:
> But as you can see this creates callback hell.
It doesn't look that bad to me.
--
Job Board: http://jobs.nodejs.org/
Posting guidelines:
https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines
You received this message because you are subscribed to the Google
Groups "nodejs" group.
To post to this group, send email to [email protected]
<mailto:[email protected]>
To unsubscribe from this group, send email to
[email protected]
<mailto:[email protected]>
For more options, visit this group at
http://groups.google.com/group/nodejs?hl=en?hl=en
--
Job Board: http://jobs.nodejs.org/
Posting guidelines:
https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines
You received this message because you are subscribed to the Google
Groups "nodejs" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/nodejs?hl=en?hl=en
--
Job Board: http://jobs.nodejs.org/
Posting guidelines:
https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines
You received this message because you are subscribed to the Google
Groups "nodejs" group.
To post to this group, send email to [email protected]
<mailto:[email protected]>
To unsubscribe from this group, send email to
[email protected]
<mailto:[email protected]>
For more options, visit this group at
http://groups.google.com/group/nodejs?hl=en?hl=en
--
Job Board: http://jobs.nodejs.org/
Posting guidelines:
https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines
You received this message because you are subscribed to the Google
Groups "nodejs" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/nodejs?hl=en?hl=en
--
Job Board: http://jobs.nodejs.org/
Posting guidelines:
https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines
You received this message because you are subscribed to the Google
Groups "nodejs" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/nodejs?hl=en?hl=en