For example, I want to write simple SQL queries this way:
(-> "table" (cols col1 col2 col3) (where (= col1 10)) (order-by col3 :desc))For example, I want to write simple SQL queries this way:
(-> "table" (cols col1 col2 col3) (where (= col1 10)) (order-by col3 :desc))https://engineering.fb.com/2016/03/18/data-infrastructure/dr...
There is an example under "Functional programming primitives".
It was a C++ implementation that fell victim to Greenspun's 10th rule. So I wrote a specification for it, first in Clojure and then in python.
The C++ execution engine is open source:
https://github.com/facebookarchive/iterlib/
Main problems writing such code:
* The output of SQL is generally flat. GraphQL makes it nested, but doesn't support all the operators SQL does natively. * Anyone trying to implement such an engine needs to ensure a fundamental property - the shape of the output can be inferred from the shape of the query. * Writing async code in C++ with futures and promises is like pulling teeth. At some point the complexity explodes and the code becomes unmaintainable.
My most recent attempt is here:
https://adsharma.github.io/fquery/
It shouldn't be hard to put a wrapper around fquery that looks like the query string you present above. In fact, there is a s-expression parser in iterlib/python above that could be tweaked to do this.
I'm hoping that we can build a community around such languages and once the specification is agreed on, a more performant implementation can be written in a systems programming language.
This allows "normal" C++ code, which by the compiler is converted into the query string, allowing code like
for (const auto& row : db(select(all_of(foo)).from(foo).where(foo.hasFun or foo.name == "joker")))
{
int64_t id = row.id; // numeric fields are implicitly convertible to numeric c++ types
}
(Random pick from the README)Why not test it at the Clojure REPL?