hugsql

lukasz 2023-01-29T18:33:43.562369Z

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._.b 2023-01-29T18:51:45.011309Z

i've had the opposite experience

d._.b 2023-01-29T18:52:17.647179Z

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

d._.b 2023-01-29T18:54:05.065579Z

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

lukasz 2023-01-29T18:54:39.732539Z

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._.b 2023-01-29T18:56:29.067019Z

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

lukasz 2023-01-29T18:56:45.614689Z

yep

d._.b 2023-01-29T18:58:13.044139Z

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._.b 2023-01-29T18:58:31.005569Z

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

d._.b 2023-01-29T18:59:06.068649Z

but as you said, no silver bullet

lukasz 2023-01-29T18:59:23.770399Z

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

d._.b 2023-01-29T18:59:42.581789Z

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

d._.b 2023-01-29T19:00:10.936009Z

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

lukasz 2023-01-29T19:01:22.572599Z

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