I want to do a raw query using Sequelize and use replacements to avoid sql injection:
var sequelize = require('sequelize');
sequelize.query("SELECT * FROM table where name =:name ORDER BY :age:direction",
{replacements:{name:"test", age:"age", direction:"desc"}, type: sequelize.QueryTypes.SELECT })
This will be converted to following query
SELECT *
FROM table
WHERE name = 'test'
ORDER BY 'age' 'desc'
Since the order by column is having single quotes and direction also with single quotes, postgres throws error
Can anyone suggest how do I solve this problem with replacements in place?