Using built-in SQL functions with SequelizeJS

Can I force Sequelize JS to include the combo box in the result set to get the results as for the following query?

SELECT id, NOW()-timestamp as recordAge FROM myTable

      

I would not use a raw query for this task, I prefer to resolve it using the model paradigm.

+3


source to share


1 answer


Since there was no answer, but someone took my question down, I am posting the answer I found myself:

The solution is to use the Sequelize.literal () function . For example, in the question, the answer is:



options = {};
options.attributes = ['id', sequelize.literal('(NOW() - timestamp) as recordAge')];
MyTable.find(options).success(success);

      

+2


source







All Articles