honeysql

Discussion of https://github.com/seancorfield/honeysql :slightly_smiling_face:
Jakub Zika 2021-05-04T04:58:23.234800Z

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?

seancorfield 2021-05-04T05:23:46.234900Z

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

đź‘Ź 1
Jakub Zika 2021-05-04T09:10:50.239400Z

Thank you, this is exactly what I needed.

Jakub Zika 2021-05-04T09:14:08.243100Z

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?

seancorfield 2021-05-04T16:10:02.245100Z

@zikajk No, V2 does not have that function. Can you explain what you mean by “removing keys with missing values”?

Jakub Zika 2021-05-04T16:20:15.253600Z

@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}

seancorfield 2021-05-04T16:23:44.254200Z

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.

đź’Ż 1