hugsql

igrishaev 2023-03-22T16:46:40.151759Z

Hi! In HugSQL, how do you deal with arbitrary maps when inserting or updating a row? In my case, it leads to manual joining keys and values which looks unreadable. For example:

-- :name hsql-bulk-update-from-table!
/* :require [clojure.string :as string] */
update :i:dest dest
set /*~ (string/join ",\n" (map #(str % " = src." %) (:updates params))) ~*/
from :i:src src
where /*~ (string/join "\nand " (map #(str "dest." % " = src." %) (:keys params))) ~*/
      /*~ (when (:where-activep params) (str "\nand dest.sys_activep")) ~*/
returning /*~ (str "(" (string/join ", " (map #(str "dest." %) (:ret params))) ")" ) ~*/;
I'd like to avoid this somehow

seancorfield 2023-03-22T17:53:17.774369Z

Programmatic construction of queries is probably better handled by something like HoneySQL?

igrishaev 2023-03-22T18:04:10.728869Z

Well, I use both hug and honey depending on a project. Honey is really powerful but sometimes I spend hours in psql writing and testing my queries. Porting them to maps and vectors takes extra time.