title: Passing empty params as filter condition in flask sqlalchemy get request
body: <h3>Scenario</h3>
  <p>I am building a <code>GET</code> API which is supposed to take params, apply the filters and return the result.</p>
  <p><strong>Tech-stack:</strong> <em>flask-restful(framework), flask-sqlalchemy(orm), MySQL(database)</em></p>
  <p>Suppose I have four params in my <code>GET</code> request namely, <code>p1, p2, p3, p4</code> and corresponding values be <code>v1, v2, v3, v4</code>. Any or all of the params CAN HAVE A NULL VALUE.</p>
  <p><em><strong>Example:</strong></em> This <code>http://myhost.com/apply-filter?p1=v1&amp;p3=v4</code> is a valid request for our case.</p>
  <p>Assume that same fields(columns) are present in the database table as well.<br />
  The model name is <code>Model</code></p>
  <h3>What's not the problem</h3>
  <p>The API ought to apply <code>and</code> condition for all these params and return all the rows which satisfy these params. I know a bit of flask and sqlalchemy so, at first, I did something like this:</p>
  <pre><code>db.session.query(Model).filter(Model.p1 == v1, Model.p2 == v2, Model.p3 == v3, Model.p4 == v4).all()
  </code></pre>
  <p>Works fine...</p>
  <h3>Problem</h3>
  <p>Now the problem is, I can't figure out what to do if the user-request does not have values for one or more parameters, <em><strong>i.e.</strong> what if she/he wants to filter according to only p1 and p3</em>?</p>
  <p>I know I can solve this problem using <code>if...else</code>, but <strong>is there a better way</strong>?</p>
  <p><strong>Something like:</strong></p>
  <pre><code>db.session.query(Model).filter(Model.p1 == v1 or all, Model.p2 == v2 or all, Model.p3 == v3 or all, Model.p4 == v4 or all)
  </code></pre>
  <blockquote>
  <p>Request method: GET<br />
  Assume only one table.<br />
  Fetching the params using <code>request.args.get('param')</code></p>
  </blockquote>
  <p>Namaste</p>