Definitely not an easy task but the degree of difficulty depends on the language.<p>Both Haskell and Scala, for example, have sufficiently powerful type systems to allow for building up a typed query expression of arbitrary complexity, which can then be deconstructed via pattern matching to assemble the sql statement. Easy? Not at all, but very much doable, and incredibly elegant...until you need to support various database engines and their limitations&#x2F;extended features; then the implementation hacks begin :\<p>Personally I think the work of Stephan Zeiger on the Slick library in Scala is ground breaking. Also, Wadler et al&#x27;s recent-ish paper on a composable query DSL in F# is worth checking out[1]<p>[1] <a href="http:&#x2F;&#x2F;homepages.inf.ed.ac.uk&#x2F;wadler&#x2F;papers&#x2F;yow&#x2F;dsl-long.pdf" rel="nofollow">http:&#x2F;&#x2F;homepages.inf.ed.ac.uk&#x2F;wadler&#x2F;papers&#x2F;yow&#x2F;dsl-long.pdf</a>