Send multiples params securely to IN clause with Sequelize for raw query

Viewed 529

Using Sequelize I can perform raw queries and send params securely (thanks to database bound params via parameters:

const baz = 1;

sequelize.query(
  'select * from foo where bar=:baz',
  { replacements: { baz } },
);

Is there a similar way to address the IN (with multiple values)?

const baz = [1, 2, 3];

sequelize.query(
  'select * from foo where bar IN (:baz)',
  { replacements: { baz } },
);
1 Answers

According to the documentation:

Array replacements will automatically be handled, the following query searches for projects where the status matches an array of values

So this should actually work:

const baz = [1, 2, 3];

sequelize.query(
  'select * from foo where bar IN (:baz)',
  { replacements: { baz } },
);
Related