Something data-oriented like {:select [:x :y] :where [{:x := 1}]}, which allows us to target clauses by type when compiling the query. This might be redundant and unnecessary given representation number 2.
Also data-oriented, but as a collection, like [{:t :select :v :x} {:t :select :v :y} {:t :where :k :x :op := :v 1}]. This allows the user to easily compose/modify queries, since a query is a (recursive, with subqueries) collection of clauses.
A convenience layer, e.g. (q (select x y z) (where= x 1)). The q function should compile directly to the collection representation above, flattening values returned from query building functions/macros into a single list. This should recur into subqueries as well.
A compile function should take any of the three representations above and turn it into a string, escaping literals and identifiers as necessary. If the input is a string already, it should just return it.
Execution functions shouldn't know about this layer, but should expose a configuration option for preparing queries, which can be configured by setting it to compile.
Three layers:
{:select [:x :y] :where [{:x := 1}]}
, which allows us to target clauses by type when compiling the query. This might be redundant and unnecessary given representation number 2.[{:t :select :v :x} {:t :select :v :y} {:t :where :k :x :op := :v 1}]
. This allows the user to easily compose/modify queries, since a query is a (recursive, with subqueries) collection of clauses.(q (select x y z) (where= x 1))
. Theq
function should compile directly to the collection representation above, flattening values returned from query building functions/macros into a single list. This should recur into subqueries as well.A
compile
function should take any of the three representations above and turn it into a string, escaping literals and identifiers as necessary. If the input is a string already, it should just return it.Execution functions shouldn't know about this layer, but should expose a configuration option for preparing queries, which can be configured by setting it to
compile
.