glao 0 Newbie Poster

Hello ,I want to ask how can I succeed an analogous from mongodb to postgresql.

app.post('/myjob', function(req, res) {
     var collection = db.collection('theDB');

     collection.insert({
      "my_id" : myID,
      ....

        }, function (err, mes) {
      if (err) {
          res.send("There was an error");
      }
      else {
          console.log("Ok with ID "+myID);
          res.send({ "Done!", ID is: myID });

      }
  });
});

});

I tried :

app.post('/myjob', isLoggedIn, function(req, res) {

   var conString = "pg://postgres:postgres@127.0.0.1:5432/theDB"; 

  pg.connect(conString, function(err, client, done) {

    if (err) return console.error('error ', err);

          function(makeQuery) {
           client.query(theFields, myData, function(err, result) {

              if (err)  return makeQuery(err); 
              makeQuery();
           });
  }
 async.series([ ...., makeQuery ],  function(err) {

                 if (err) return err;
                 console.log("Ok with ID "+myID);
                res.send({ "Done!", ID is: myID });

                 done();
            }); // ending async

            });
            });

I can't see in the terminal the output

console.log("Ok with ID "+myID);
res.send({ "Done!", ID is: myID });

even though the myID is correctly returned.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.