Fork me on GitHub
#hugsql
<
2023-01-29
>
lukasz18:01:43

While it's totally doable with HugSQL and probably can be done a bit cleaner with snippets - I'd suggest looking at HoneySQL at this point, as you're heading towards that direction. I've used HugSQL for... 6 or 7 years at this point and started moving to HoneySQL because Postgres support improved so much in v2, that most if not all queries that I have can be rewritten 1-1. Once your queries are expressed as just data (it's Clojure after all) everything becomes so much composable and easier to reason about than multiple snippets, inline code in queries ( --~ etc). It's not perfect, but what you're trying to do - HoneySQL might work much better. Just my 2c

d._.b18:01:45

i've had the opposite experience

d._.b18:01:17

i'm trying hugsql because i found honeysql to occasionally feel really convoluted when i knew the plain SQL i wanted

d._.b18:01:05

though to be honest, that example i gave above of on conflict do update set isn't much better 😄

lukasz18:01:39

Yeah, there's no silver bullet, that's for sure. So to answer your question - snippets makes this more manageable - because you can lift the logic that you have within /**~ ... ~**/ block to your Clojure layer, and it all becomes somewhat more manageable

d._.b18:01:29

oh neat, so that could be something like -- :snip on-conflict-do-update-set and then just use it where you need it?

d._.b18:01:13

to be more specific, i don't think it was just the composability thing, it was that queries got littered around a bit over time

d._.b18:01:31

so i do genuinely like the idea of just forcing them to live outside of the clojure codebase

d._.b18:01:06

but as you said, no silver bullet

lukasz18:01:23

we've run into an opposite problem: way too many similar queries, that cannot be easily parametrized without making a clojure+sql mess

d._.b18:01:42

im considering this an experiment for the moment 🙂 we don't have too many queries yet

d._.b19:01:10

so if i wind up forced to rewrite all of this in honeysql, that will be fine 🙂

lukasz19:01:22

if you will have to, you can compare them directly - since you can get sql vecs from both, definitely makes it easier