Fork me on GitHub
#honeysql
<
2022-06-16
>
pinkfrog09:06:47

Hi. Sounds like honeysql can be used in clojurescript. Anyone has used honeysql with an in-browser database like sql.js, how do you feel?

wombawomba17:06:11

I'd like to extend HoneySQL (1) to support H2's MERGE INTO syntax (`MERGE INTO mytable (x, y, x) KEY(x) VALUES('foo', 'bar', 'baz')`). How would I go about this?

wombawomba17:06:24

Nevermind! Turns out it was way easier than I'd thought it'd be:

(defmethod honeysql.format/format-clause :merge-into [[_ table] _]
  (str "MERGE INTO " (honeysql.format/to-sql table)))

(defmethod honeysql.format/format-clause :key [[_ ks] _]
  (str "KEY (" (clojure.string/join ", " (map name ks)) \)))

(honeysql.format/register-clause! :merge-into 61)
(honeysql.format/register-clause! :key 91)
(hh/format {:merge-into :foo, :key [:foo :bar], :columns [:foo :bar :baz], :values [[1 2 3]]})
; => ["MERGE INTO foo (foo, bar, baz) KEY (foo, bar) VALUES (?, ?, ?)" 1 2 3]