Question

I am working under mobile backend using pg with connection pooling, now I meet the problem

Error text

Error: connection pointer is NULL

As I understand from this issue, https://github.com/brianc/node-postgres/issues/182.

My question how done() works in pg, and where should I call it?

If I have for example multiple queries should be called one by one

pg.connect("constr", function(err,client,done) {
  if (err) callback(err);
  else {
    client.query("some query", function(err, result) {
       if (err) callback(err);
       else {
          client.query("one more", function(err, result) {
             if (err) callback(err);
             else {
                callback(null, result);
             }
          });
       }
    });
  }
});

Please explain me done() on this example.

Was it helpful?

Solution

You will call done after you are done with the client -

 client.query("some query", function(err, result) {
       if (err) {
           done();
           callback(err);
       } else {
          client.query("one more", function(err, result) {
             done();
             if (err) callback(err);
             else {
                callback(null, result);
             }
          });
       }
    });
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top