Fork me on GitHub
#honeysql
<
2021-10-18
>
mauricio.szabo14:10:39

Hi there! Is it possible to somehow keep the aliases on HoneySQL as qualified keywords? I'm querying a SQL database and I want to make aliases like SUM("person.age") as "people/age". Is it possible for HoneySQL to keep aliases as qualified keywords? Something like {:select [[[:sum :person.age] :people/age]]}, but keeping the alias as-is (currently it is converting to "people"."age")

seancorfield17:10:06

@mauricio.szabo Which version of HoneySQL? I think this differs between 1.x and 2.x?

mauricio.szabo17:10:05

I'm using the latest version (2.1.818). I remember that I was able to make it work with 1.x a long time ago, but it was even a different Clojure version so I'm not sure what changed (or even if something changed). I somehow was able to fix by monkey-patching honey/format-entity, but I don't think that's a great solution 😄

seancorfield17:10:01

Could you create an issue on GH with a small repro case of what you need? There may be a way to make it work but I'll need to spend some time experimenting.

seancorfield17:10:13

dev=> (sql/format {:select [[[:sum :person.age] "people/age"]]})
["SELECT SUM(person.age) AS \"people/age\""]
In general, using strings for aliases leaves them as-is. Not sure if that helps you?

🤯 1
mauricio.szabo20:10:27

Oh, and it already quotes! Ok, that works for me 🙂

seancorfield20:10:02

It is mentioned in the docs but it's probably not very obvious, since it's in a big paragraph about naming and quoting strategies...