hugsql

admay 2018-01-09T15:44:07.000540Z

@achikin did you ever solve that HugSQL issue?

achikin 2018-01-09T15:45:10.000614Z

@admay Sorry for not answering you. I gave up and found the other way.

achikin 2018-01-09T15:45:29.000610Z

Let me give you more details on the issue.

admay 2018-01-09T15:45:59.000299Z

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 2018-01-09T15:49:28.000133Z

@achikin uploaded a file: https://clojurians.slack.com/files/U3A7Z18JZ/F8R7AA2J3/-.sql

achikin 2018-01-09T15:49:59.000121Z

The issue is that :date_start could possibly be nil

achikin 2018-01-09T15:50:12.000328Z

So I tried to wrap it up into when like this

achikin 2018-01-09T15:51:16.000398Z

@achikin uploaded a file: https://clojurians.slack.com/files/U3A7Z18JZ/F8R7BCNNT/-.sql

achikin 2018-01-09T15:51:32.000241Z

And this fails with various errors.

achikin 2018-01-09T15:52:34.000622Z

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.

achikin 2018-01-09T15:53:57.000065Z

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.

admay 2018-01-09T15:56:49.000169Z

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