4 ms·
I like SQL. The problem with SQL is that it is a string and simple errors, like an extra comma, are not caught by the compiler/interpreter. Are there good well-
by asimjalis 6y ago
I like SQL. The problem with SQL is that it is a string and simple errors, like an extra comma, are not caught by the compiler/interpreter. Are there good well-thought out libraries that are isomorphic to SQL but can be used with a language like Python or Clojure?
For example, I want to write simple SQL queries this way:
(-> "table" (cols col1 col2 col3) (where (= col1 10)) (order-by col3 :desc))
- johannes1234321 6y agoIf you love C++ Template magic look at https://github.com/rbock/sqlpp11 https://github.com/rbock/sqlpp11 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)
- adamkl 6y agoI believe Honey SQL might be just what you are looking for: https://github.com/seancorfield/honeysql https://github.com/seancorfield/honeysql
- adsharma 6y agoI wrote such a C++ implementation during my days at Facebook around 8 years ago: https://engineering.fb.com/2016/03/18/data-infrastructure/dragon-a-distributed-graph-query-engine/ 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/ 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/ 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.
- Scarbutt 6y agoThe problem with SQL is that it is a string and simple errors, like an extra comma, are not caught by the compiler/interpreter. Why not test it at the Clojure REPL?