title: Sequelize, MySQL - Filtering rows in table with JSON column values
body: <p>Need help in figuring out how to filter rows in MySQL table's JSON column with nested values using Sequelize. Documentation doesn't have it (Only given for PostgreSQL &amp; MSSQL - <a href="http://docs.sequelizejs.com/manual/tutorial/querying.html#json" rel="noreferrer">ref</a>)</p>
  
  <p>Table definition -</p>
  
  <pre><code>module.exports = (sequelize, DataTypes) =&gt; {
    const Comment = sequelize.define('Comment', {
      action: DataTypes.STRING,
      type: DataTypes.STRING,
      reason: DataTypes.STRING,
      reference: DataTypes.JSON,
      active: {
        type: DataTypes.INTEGER,
        defaultValue: 1,
      },
    }, {
      classMethods: {
        associate(models) {
          Comment.belongsTo(models.User, {
            foreignKey: 'userId',
          });
        },
      },
    });
    return Comment;
  };
  </code></pre>
  
  <p>Values of reference column in <code>Comments</code> table -</p>
  
  <pre><code>{
    "orderItemId": 2,
    "xkey": 3,
    "ykey": 4
  }
  {
    "orderItemId": 4,
    "xkey": 1,
    "ykey": 1
  }
  {
    "orderItemId": 3,
    "xkey": 1,
    "ykey": 6
  }
  {
    "orderItemId": 2,
    "xkey": 1,
    "ykey": 0
  }
  </code></pre>
  
  <p>How do I filter all the rows where "orderItemId" is 2.</p>
  
  <p>Expected SQL query</p>
  
  <pre><code>select * from Comments where reference-&gt;"$.orderItemId" = 2
  </code></pre>
  
  <p>Figured out a way using <code>sequelize.literal</code>, but is there a way of not using this function.</p>
  
  <pre><code>models.Comment.findAll({
    where: sequelize.literal(`reference-&gt;"$.orderItemId"=2`),
  })
  </code></pre>
  
  <p>How to add multiple conditions in the above case like - </p>
  
  <p><code>reference-&gt;"$.orderItemId" = 2 and action = 'xyz'</code></p>