title: How to perform a search with conditional where parameters using Sequelize
body: <p>Usually whenever I write a search query for SQL, I do something similar to this:</p>
  
  <pre><code>SELECT * FROM users u
  WHERE (@username IS NULL OR u.username like '%' + @username + '%')
  AND (@id IS NULL OR u.id = @id)
  </code></pre>
  
  <p>Basically this simulates a conditional WHERE clause. We only want to compare @searchParam to the column if @searchParam was provided.</p>
  
  <p>Is there a way to replicate this using Sequelize?</p>
  
  <p><strong>EDIT:</strong> Here is my best attempt which fails:</p>
  
  <pre><code>models.user.findAll({
    where: {
      username: searchParams.username || models.sequelize.col('user.username'),
      id: searchParams.id || models.sequelize.col('user.id')
    }
  })
  </code></pre>
  
  <p><strong>UPDATE:</strong> I found a way to do it, but it feels like a workaround. I'm certain there has to be a more elegant way. This works, but is ugly:</p>
  
  <pre><code>models.user.findAll({
    where: [
      '(? IS NULL OR "user"."username" LIKE ?) AND (? IS NULL OR "user"."id" = ?)',
      searchParams.username,
      `%${searchParams.username}%`,
      searchParams.id,
      searchParams.id
    ]
  })
  </code></pre>