Skip to content
This repository has been archived by the owner on Feb 21, 2020. It is now read-only.

Add query dsl #6

Open
staab opened this issue Dec 11, 2019 · 1 comment
Open

Add query dsl #6

staab opened this issue Dec 11, 2019 · 1 comment

Comments

@staab
Copy link
Owner

staab commented Dec 11, 2019

Three layers:

  1. 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.
  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.
  3. 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.

@staab
Copy link
Owner Author

staab commented Dec 24, 2019

It might be worth replacing unpack with something in this layer for creating aliases. This would:

  • Solve the same problem as unpack, but would be faster since postgres would be doing the work.
  • Unpacked/calculated columns could be used in non-select clauses

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant