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.


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')];




All Articles