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
i've had the opposite experience
i'm trying hugsql because i found honeysql to occasionally feel really convoluted when i knew the plain SQL i wanted
though to be honest, that example i gave above of on conflict do update set isn't much better 😄
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
oh neat, so that could be something like -- :snip on-conflict-do-update-set and then just use it where you need it?
yep
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
so i do genuinely like the idea of just forcing them to live outside of the clojure codebase
but as you said, no silver bullet
we've run into an opposite problem: way too many similar queries, that cannot be easily parametrized without making a clojure+sql mess
im considering this an experiment for the moment 🙂 we don't have too many queries yet
so if i wind up forced to rewrite all of this in honeysql, that will be fine 🙂
if you will have to, you can compare them directly - since you can get sql vecs from both, definitely makes it easier