Hi! I am using honeysql together with Babashka and I would like to produce a raw sql queries compatible with psql. Is this possible right now?
If you're using V2, there is an inline option that tries to put the values inline in the string instead of using ? And putting the parameters in a vector
Thank you, this is exactly what I needed.
Hi, version 1 has build fn, i use it for removing keys with missing values to build a valid sql map. Is there something simiÄşlar in v2?
@zikajk No, V2 does not have that function. Can you explain what you mean by “removing keys with missing values”?
@seancorfield
In HoneySQL v1 I had got a function like this:
(defn build-select [table-name where limit]
(hsql/format
(hsql/build :select :*
:from table-name
:where where
:limit limit)))
All this was valid thanks to the build fn:
(build-select :public.table)
(build-select :public.table [:= :table.field "string"])
(build-select :public.table [:= :table.field "string"] 10)
Now I changed the logic in HoneySQL v2 to this - so I can supply map with/out :where or :limit as before.
(defn build-select [table-opts]
(hsql/format (merge {:select [:*] :from [(:table-name table-opts)]}
(select-keys table-opts [:where :limit]))))
The input got a little different of course:
(build-select {:table-name :public.table})
(I am building custom sql queries from EDN files. I used to read list of [table-name where limit] now it is (:table-name string :where vector :limit int}
Well, it’s “just data” so you can use cond->
and assoc
to conditionally add things, or use the helper functions to make sure you get the right structure.