honeysql

Discussion of https://github.com/seancorfield/honeysql :slightly_smiling_face:
seancorfield 2021-02-22T19:22:09.001600Z

In case anyone missed this in #announcements

πŸ‘ 3
devn 2021-02-22T22:48:32.006600Z

I am using honeysql to generate a suffix which I then pass into sql.builder/for-insert-multi as an option. The trouble is that the suffix has a param named group , which needs to be quoted, otherwise PG is unhappy. Roughly it goes something like this:

(let [suffix (first (hsql/format {:upsert {:on-conflict [:id] :do-update-set [:a :group :b]}}))
      insert-multi (sql.builder/for-insert-multi table cols rows {:suffix suffix :column-fn (fn [col] (format "\"%s\"" col))})]
  (jdbc/execute! ...))

devn 2021-02-22T22:49:09.007300Z

i may just rename the column, but im curious if anyone has any bright ideas

seancorfield 2021-02-22T23:08:07.008500Z

HoneySQL can do quoting for different databases: it's an option to hsql/format

seancorfield 2021-02-22T23:09:15.009600Z

If you're still using HoneySQL 1.0 or earlier: (hsql/format .. :quoting :ansi) If you're already using HoneySQL 2.0: (hsql/format .. {:quoted true}) (the ANSI dialect is the default).

seancorfield 2021-02-22T23:09:28.010Z

^ @devn does that solve your problem?

devn 2021-02-22T23:21:08.010500Z

unfortunately, no. I tried that.

devn 2021-02-22T23:21:27.010900Z

it’s alright, I went ahead and renamed the column

seancorfield 2021-02-22T23:21:48.011300Z

Which version of HoneySQL are you using?

devn 2021-02-22T23:22:24.012Z

actually, you know what, let me try one more time because i see you have :quoting :ansi bare there (with no wrapping {})

devn 2021-02-22T23:23:53.012800Z

ah yes, that’ll do it β€” however it still is a bit of a mess to also add in the column-fn transformation. if we run into another instance of this i’ll consider switching it up

seancorfield 2021-02-22T23:24:39.013500Z

I realized you must be using 1.0 and the honeysql-postgres extension lib -- :upsert πŸ™‚

seancorfield 2021-02-22T23:25:07.013900Z

In 2.0, you don't need the extension lib and it's just

user=> (sql/format 
  #_=>  {:on-conflict [:id] :do-update-set [:a :group :b]} {:quoted true})
["ON CONFLICT (\"id\") DO UPDATE SET \"a\" = EXCLUDED.\"a\", \"group\" = EXCLUDED.\"group\", \"b\" = EXCLUDED.\"b\""]
user=> 

devn 2021-02-22T23:25:29.014300Z

[honeysql "1.0.444"]
                 [nilenso/honeysql-postgres "0.2.6"]

devn 2021-02-22T23:25:38.014600Z

ah, nice!

devn 2021-02-22T23:25:56.015200Z

then /that/ is what i’ll do to finish out my day πŸ™‚

devn 2021-02-22T23:25:57.015500Z

thanks

seancorfield 2021-02-22T23:25:59.015700Z

Also, since you're on 1.0, make sure you update to 1.0.461 for the important bug fix.

devn 2021-02-22T23:26:09.015900Z

yep, saw that

seancorfield 2021-02-22T23:27:01.016600Z

You can use 1.0 and 2.0 side-by-side and migrate piecemeal: different maven coords and different namespaces πŸ™‚

devn 2021-02-22T23:28:15.017Z

:male-cook: πŸ’‹ 🀌

πŸ‘ 1