3

Can I make Sequelize JS to include combined field to the result set, to get results like for following query?

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

I wouldn't use raw query for this task, prefer to resolve it with model paradigm.

1 Answer 1

4

As there was no answer but someone has starred my question I'm posting the answer I've found myself:

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

options = {};
options.attributes = ['id', sequelize.literal('(NOW() - timestamp) as recordAge')];
MyTable.find(options).success(success);
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.