title: Conditional filter using Knex.js and SQL with multiple search criteria
body: <p>I have a database of items that my user needs to be able to search. They can apply different filters such as <code>category</code>, <code>searchTerm</code>, <code>itemType</code>. </p>
  
  <p>I know how to apply each of these filters in a knex query, but am not sure how to combine them conditionally. E.g. in one case, the user inputs only searchTerm. So I do not want to filter by category or item type, but only searchTerm. However, I want to have only one knex function which conditionally adds extra clauses to the query.</p>
  
  <p>Something like: </p>
  
  <pre><code>const getFilteredItems = (searchCriteria) =&gt; knex('items')
     // IF (searchCriteria.searchTerm)
    .where('items.itemName', 'like', `%${searchCriteria.searchTerm}%`)
    // IF (searchCriteria.itemType)
    .where('items.itemType', '=', searchCriteria.itemType)
    // IF (searchCriteria.category)
    .where('items.category', '=', searchCriteria.category)
  </code></pre>
  
  <p>But I am not sure how to conditionally append the extra <code>where</code> clauses to the knex query. Is there an elegant way to do this without writing raw SQL?</p>