title: Sequelize sending multiple queries data to page
body: <p>I am trying to display results from multiple Sequelize queries to one page using express. However, I am having trouble returning data from one in-model functions. I'm pretty sure this has to do with me not having a proper understanding of promises in javascript and also a misunderstanding of async programming.</p>
  
  <p>In my report_ty model I have this function:</p>
  
  <pre><code>report_ty.getTopFreedomIndex = function(){
    report_ty.findAll({
        raw: true,
        limit: 10,
        attributes: ['Country','Freedom'],
        order: [['Freedom', 'DESC']]
      }).then(topfreedomindex =&gt; {
        console.log(topfreedomindex);
        return topfreedomindex;
      })
    };
  </code></pre>
  
  <p>In my controller, I am trying to take the data from that query and send it to the page in a JSON format.</p>
  
  <pre><code>var db = require('../models/index.js');
  
  module.exports.index_get = (req, res, next) =&gt; {
  
    var topFreedomIndexPromise = new Promise ((resolve, reject) =&gt; {
      db.report_ty.getTopFreedomIndex(err, topfreedomindex) =&gt; {
        if(err){
          return reject(err);
        } else {
          return resolve(topfreedomindex);
        }
      }
    })
  
    Promise.all([topFreedomIndexPromise]).then((results)=&gt;{
      return res.render('index', {topfreedomindex:topfreedomindex});
    }).catch((err) =&gt; {
      return next(err);
    })
  }
  </code></pre>
  
  <p>I would like to create multiple promises and cash them out to variables that I can render to the page.</p>
  
  <p>However, the code in the controller is not working because the console says there is a syntax error: unexpected '.' after db. I'm sort of lost at the current moment on how to go about doing this. I modeled this code on a previous project's code that used mongoose with mongoDB.</p>
  
  <p>I can make it work if I move the findAll code to the controller but I was only able to run one query in that case. I would like to run many and leave the logic in the models.</p>
  
  <p>Any help/suggestions/criticisms are much appreciated. Thanks!</p>