Comment by delegate
1 year ago
There's honeysql library in Clojure, where you define queries as maps, which are then rendered to SQL strings:
{:select [:name :age]
:from {:people :p}
:where [:> :age 10]}
Since maps are unordered, this is equivalent to
{:from {:people :p}
:select [:name :age]
:where [:> :age 10]}
and also
{:where [:> :age 10]
:select [:name :age]
:from {:people :p}}
These can all be rendered to 'SELECT... FROM' or 'FROM .. SELECT'.
Queries as data structures are very versatile, since you can use the language constructs to compose them.
Queries as strings (FROM-first or not) are still strings which are hard to compose without breaking the syntax.
No comments yet
Contribute on Hacker News ↗