Fork me on GitHub
#hugsql
<
2023-03-22
>
igrishaev16:03:40

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

seancorfield17:03:17

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

igrishaev18:03:10

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.