title: sqlalchemy - elegant way to deal with several optional filters?
body: <p>Suppose I have a query method with serveral <strong>optional</strong> filters. What I want to achieve is, If I pass some not None value to filter parameters then do a filter, if filter value is None, then just ignore it.</p>
  
  <pre><code>def get_query_results(filter1=None, filter2=None, ...):
      res = models.Item.query
      if filter1 is not None:
          res = res.filter(filter1=filter1)
      if filter2 is not None:
          res = res.filter(filter2=filter2)
      ....
      return res.all()
  </code></pre>
  
  <p>What I want to avoid is the pattern</p>
  
  <pre><code>if XXX:
      res.filter(XXX=XXX)
  </code></pre>
  
  <p>I wonder if there is any more elegant way to achieve this?</p>
  
  <p>For example, pass various filters as parameters?</p>
  
  <p>Or maybe, we can do some magic to omit the filter when the filter value is None?</p>