1
votes

When I enter a sentence with single quotes in it, I'll get an error because sequelize treat it as closing string. How do I solve this? I've tried using sqlstring module to no avail. (I understand that to escape the single quote I have to double it up. Is there another way to do it with Sequelize?)

sequelize
    .query(
      ` UPDATE dbo.Comments
        SET bio = '${req.body.comment}' where id= '${
        req.session.id
      }';`,
      { model: Comments}
    )
1

1 Answers

1
votes

You just need to escape single quotes with double single quotes.

sequelize
    .query(
      ` UPDATE dbo.Comments
        SET bio = '${req.body.comment.replace("'", "''")}' where id= '${
        req.session.id
      }';`,
      { model: Comments}
    )

Ref. How do I escape a single quote in SQL Server?