0

Below function I copy it from surveyjs-nodejs repository and looking to achieve this similar into mysql.

    function getObjectFromStorage(tableName, callback) {
    db.any("SELECT * FROM " + tableName).then(function(result) {
      var objects = {};
      (result || []).forEach(function(item) {
        objects[item.id] = item;
      });
      callback(objects);
    });
   }

 getObjectFromStorage("surveys", function(objects) {
  if (Object.keys(objects).length > 0) {
    callback(objects);
  } else {
    callback(surveys);
  }
});

how this .any works?

db
  .one("INSERT INTO surveys (name, json) VALUES($1, $2) RETURNING *", [
    name,
    "{}"
  ])
  .then(callback);

and how this RETURNING * use in mysql?

Thanks

Muhammad Saifuddin
  • 1,284
  • 11
  • 29

0 Answers0