honeysql

Discussion of https://github.com/seancorfield/honeysql :slightly_smiling_face:
exit2 2020-02-04T00:10:59.020700Z

@seancorfield Is there a way to write this using the honeysql helpers?

exit2 2020-02-04T00:11:01.021Z

(defn bulk-update! [table data]
  (let [query (into [(str "UPDATE " table " SET record = ?, import_timestamp = ? WHERE id = ?")] data)]
    query
    (sql/db-do-prepared
     *conn*
     query
     {:multi? true})))

exit2 2020-02-04T00:11:48.021700Z

I’d like to not use a prepared statement if possible, otherwise I have to convert my data into a vector of values where as now its all a clojure map/json

seancorfield 2020-02-04T00:12:56.022200Z

HoneySQL does not understand the concept of multiple parameter groups.

exit2 2020-02-04T00:14:28.022900Z

gotcha

seancorfield 2020-02-04T00:16:48.025200Z

@njj Consider that HoneySQL takes "expressions" that already contain values and turns them into a SQL string and those values in a vector. So it could convert (-> (update table) (sset :record some-val) (sset :import_timestamp other-val) (where [:= :id some-id])) into the SQL you have above with some-val other-val some-id as the following three values in that vector.

seancorfield 2020-02-04T00:17:33.025800Z

Given what you already have, I think trying to do it via HoneySQL would be worse.

exit2 2020-02-04T00:18:14.026400Z

Haha okay, maybe I can use HoneySQL for individual updates and iterate over the vector