title: Rust diesel conditionally filter a query
body: <p>I am trying to use diesel for a project and I would like to have a &quot;filterable&quot; type. The idea is that you can go to <code>/api/foo?id=10&amp;bar=11</code> and it would return a struct <code>Foo</code>:</p>
  <pre><code>struct Foo {
      id: Option&lt;i64&gt;,
      bar: Option&lt;i64&gt;,
      name: Option&lt;String&gt;,
  }
  </code></pre>
  <p>Such as:</p>
  <pre><code>Foo {
     id: Some(10),
     bar: Some(11),
     name: None,
  }
  </code></pre>
  <p>I've been scouring the internet for a way to filter by the fields that exist, but I am unable to find a solution that works. I was initially using the <a href="https://crates.io/crates/mysql" rel="noreferrer">mysql driver</a> and constructing sql queries with proc macros, but diesel is a lot nicer to work with and I was wondering if there was a way to get the same behaviour I had with the mysql driver with diesel.</p>