@achikin did you ever solve that HugSQL issue?
@admay Sorry for not answering you. I gave up and found the other way.
Let me give you more details on the issue.
No worries man! That’d be great, I’m putting together a big of an internal HugSQL guide for my team and can always use more material
@achikin uploaded a file: https://clojurians.slack.com/files/U3A7Z18JZ/F8R7AA2J3/-.sql
The issue is that :date_start could possibly be nil
So I tried to wrap it up into when
like this
@achikin uploaded a file: https://clojurians.slack.com/files/U3A7Z18JZ/F8R7BCNNT/-.sql
And this fails with various errors.
My general goal was to reuse that huge select
statement with various conditions, but it appears that snippets are not as straightforward as I expected.
So I ended up passing (java.util.Date. 0)
instead of nil
in request params and that works well, but that's not a general solution for my issue.
select
<lots of joined tables here>
where
some condition
/*~ (if (:ids params) */
and id in (:v*:ids)
/*~*/
and some condition
and some condition
/*~ ) ~*/
--~ (when (:date_start params) "and date >= :date_start")
Give that a go. This allows your if to only have two branches, rather than three as well as conditionally adding your date constraint. I think.
@achikin