Hi, i am having a weird problem using (sql/call)
or probably i am missing something
i have this query:
(-> (h/select (hql/call :coalesce :settlement-days 1))
(h/from :trd_fund))
if i format the query on the same namespace it works just fine, this is the output: [SELECT coalesce("settlement_days", ?) FROM "trd_fund" 1]
but if i pass this query to be formatted another ns then the query doesntβ generate the sql for the function: [SELECT ( ) FROM "trd_fund"]
same thing happens if i use sql/raw
. also tried with a simlpe function like :%now
and same thing. in all cases the function is not present when formatted on a different ns
@jmayaalv Sounds like your other namespace isn't causing honeysql.types
to be required. I would have expected that to required by honeysql.core
...
...which it definitely does. Odd. Can you put together a simple repro of this on GitHub somewhere that I can take a look? And then create an issue on the HoneySQL repo linking to your repro on GitHub. Thanks.
I have never seen that behavior.
Thank you @seancorfield, will do
oddly enough i canβt reproduce it on a clean project π
Well... it is certainly unexpected behavior so I would imagine it's something fairly unusual about your current project (or maybe just bad REPL state?).
for sure not the repl. will dig deeper on the dependencies, hopefully will find something and let you know π thanks for the help
@seancorfield managed to reproduce it, what happened is that we were passing the query to a map, then the map was walked with a postwalk to remove nils
(defn remove-nils
[m]
(let [f (fn [[k v]] (when (not (nil? v)) [k v]))]
(walk/postwalk (wfn [x]
(if (map? x)
(into {} (map f x))
x))
m)))
(not (nil? v))
can be (some? v)
(into {} (map f x))
should be (into {} (keep f x))
@jmayaalv otherwise your map will contain the association [nil nil]
thanks, at the end we dont need to do a postwalk, so code is now much simpler, but thank you for the suggestion
in fact, it could also be just (into {} (filter (comp some? second)) x)
or (into {} (remove (comp nil? second)) x)
before the postwalk: {:select (#sql/call [:coalesce :f.bla 1]), :from ([:foo :f])}
after the postwalk: {:select ({:name :coalesce, :args (:f.bla 1)}), :from ([:foo :f])}
π
Ouch! Yup, that would break the structure.
So the problem is that records satisfy map?
but then you are turning them into plain ol' hash maps and losing the record type.
You could check for (and (map? x) (not (instance? clojure.lang.IRecord x)))
instead of just (map? x)
and it should work @jmayaalv
yeah, thanks a lot π you are awesome!