node.js - Querying MySql table using Sails.js -


i new sails.js. followed of documentation, not able retrieve simple data mysql database. when run route in browser - http://localhost:1337/getallchoices, browser seems hang. don't see errors in browser console either.

in models folder, have multiplechoice.js

module.exports = {     attributes: {         multiplechoiceid: { type: 'integer'},         description: { type: 'string'}     },      getallchoices: function(){         return this.description ;     } } 

my route.js contains this: 'get /allchoices': 'homecontroller.getallchoices'

my homecontroller contains this: getallchoices: function(req, res){ return multiplechoice.getallchoices(); }

am missing something?

thank you.

it looks you're trying retrieve description each multiple choice. you'd need following code:

getallchoices: function(req, res){    var descriptions = [];    multiplechoice.find({}).exec(function findcb(err, choices)   {     for(var in choices)     {       descriptions.push(choices[i].description);     }      res.json(200, descriptions);   });  } 

getallchoices() not retrieve data each record in multiplechoice model. reason server hangs because it's waiting specify response send client (return "somevalue"; not accomplish this). since don't provide 1 waits forever. try commenting out res.json(200, descriptions); , server hang forever.


Comments

Popular posts from this blog

java - Spring Data JPA: Why findOne(id) executing delete query internally? -

python - Mongodb How to add addtional information when aggregating? -

java - Incorrect order of records in M-M relationship in hibernate -