how can i retrieve static value as column in sequelize findAll

Viewed 466

In mysql query if I want to retrieve static value as column in select query I would normally use following statement:

SELECT 
  ...,
  "static value" as static_value
FROM table_name;

How can I accomplish such queries in sequelize findAll?

1 Answers

You can use sequelize.literal()

Model.findAll({
  attributes: ['foo', 'bar', [sequelize.literal('static value'), 'static_value']]
});

Which is the equivalent of

SELECT foo, bar, 'static value' AS static_value FROM ...
Related