honeysql

Discussion of https://github.com/seancorfield/honeysql :slightly_smiling_face:
orestis 2020-09-29T04:26:39.096Z

@seancorfield have you thought about using also symbols, lists to help disambiguate stuff?

orestis 2020-09-29T04:27:13.096800Z

Eg a function call could be a list, or the name of the function could be a symbol

seancorfield 2020-09-29T05:12:59.097400Z

@orestis To be honest, that would make a lot of the code more complex, and it would make the documentation more complex.

seancorfield 2020-09-29T05:14:15.098700Z

There are a handful of places where the condition is "`keyword?` or ..." right now but actually in most places (in V2) keywords and symbols are accepted equally and I just have to decide whether that's useful to document or not.

seancorfield 2020-09-29T05:16:38.100500Z

Operators and functions have to be keywords right now in V2. And both :on-conflict and :do-update-set which I implemented today currently expect keywords. But everywhere else symbols would actually be accepted everywhere keywords are. Disambiguating function names via keyword vs symbol doesn't actually help anything.

seancorfield 2020-09-29T05:17:36.101600Z

Well, it would help in that one limited place in a :select where you wanted to tell the difference between a function call and an alias but I've already disambiguated that (by requiring the function call be nested).

seancorfield 2020-09-29T05:17:50.102Z

I don't think that one case is worth the extra confusion/complexity.

seancorfield 2020-09-29T05:19:04.103100Z

As it is, I'll probably allow symbols anywhere a keyword could be used, just because it's pretty trivial to do, although I don't think it makes anything substantially easier to write the DSL.

orestis 2020-09-29T05:36:30.104800Z

The only thing that symbols have over keywords is the datalog-style, quote-the-whole-expression approach.

orestis 2020-09-29T05:37:52.106700Z

Which I think is why I was banging on about named parameters the other day - because quoting the whole expression means you can’t easily pull in values from locals and vars, therefore you need to do the substitution later.

orestis 2020-09-29T05:38:57.108200Z

But, I think that having a specced honeysql data structure means that ergonomic layers such as the one I describe could be done elsewhere.

orestis 2020-09-29T05:40:16.109300Z

So I think your litmus test of “does it make the implementation simple” is the correct one :)

seancorfield 2020-09-29T16:27:05.113Z

@orestis Ah, OK, now I get where you're coming from. Yeah, if I make symbols universally acceptable wherever keywords are accepted, then you could do that (and, to be honest, it doesn't make much difference really on the backend since I'll just add a predicate that tests keyword-or-symbol? (If I make Clojure 1.9 the base version supported, I'll just use ident? 🙂 ). But a lot of people construct queries dynamically so it wouldn't help there. But, yes, named parameters will be coming to 2.x -- I've come up with a clean way to implement that without making the SQL generation engine any more complex.