I love your solution it is similar to what I came up with when talking to
elastic search.
On Sunday, April 8, 2012 at 6:24:09 PM UTC-7, Matt wrote:
>
> In that case, you might consider doing something like this:
>
> function obtainConnection(callback){
> var c = null;
> if (c == null){
> var conn = db.open(... fn() {
> c = conn;
> callback(c);
>
> // set some close timeout here
> });
> }
> else
> callback(c);
> }
>
> function dbQuery(query, callback){
> obtainConnection(fn() {
> db.collection(... fn() {
> db.query(query, callback);
> });
> });
> }
>
> Voila! Connection reuse. :)
>
> -Matt
>
> On Apr 8, 2012, at 9:17 PM, Matthew Hazlett 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] <javascript:>
> To unsubscribe from this group, send email to
> [email protected] <javascript:>
> 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] <javascript:>
> To unsubscribe from this group, send email to
> [email protected] <javascript:>
> 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] <javascript:>
> To unsubscribe from this group, send email to
> [email protected] <javascript:>
> For more options, visit this group at
> http://groups.google.com/group/nodejs?hl=en?hl=en
>
>
>
--
Job board: http://jobs.nodejs.org/
New group rules:
https://gist.github.com/othiym23/9886289#file-moderation-policy-md
Old group rules:
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 unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/nodejs/99fcb529-0669-47b6-8080-ce8baf88af4b%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.