The carping about if statements really gets to me.<p>I mean, I get it, structures like<p><pre><code> if(X) {
if(Y) {} else {
if(Z) {
return;
} else {}
...
</code></pre>
will drive anybody crazy. For a query builder though, you should write something table driven where for instance you have a hash that maps query names to either functions or objects<p><pre><code> variables = { "age": where_age, "username": where_username, ... }
</code></pre>
these could be parameterized functions, e.g.<p><pre><code> where_username = (operator, quantity) => where("username", "text", operator, quantity)
</code></pre>
or you could have some object like<p><pre><code> {field_name: username, field_type: "text"}
</code></pre>
and then, say loop over the get variables so,<p><pre><code> username:gt
</code></pre>
gets broken into "username" and "gt" functions, and the where_username function gets these as arguments in the operator and quantity fields. Easy-peasy, wins at code golf if that's what you're after. Your "field" can be a subselect statement if you want to ask questions like "how pictures are in this photo gallery?"<p>This is the kind of code that Lisp wizards wrote in the 1980s, and there's no reason you can't write it now in the many languages which contain "Lisp, the good parts."