Fork me on GitHub
#honeysql
<
2022-07-21
>
kwrooijen19:07:27

Is there a way to drop multiple columns with honeysql? Currently:

(-> (honey.sql.helpers/alter-table :account)
    (honey.sql.helpers/drop-column [:name :email])
    (honey.sql/format))

;; => ["ALTER TABLE account DROP COLUMN name, email"]
Which isn't correct. It should be:
["ALTER TABLE account DROP COLUMN name, DROP COLUMN email"]

seancorfield19:07:55

I'll have to check how it works on other DBs but please create a GH issue so I'll remember to look at it.

👍 1
seancorfield19:07:06

DDL support is fraught with edge cases, unfortunately.

kwrooijen19:07:10

Will do. Apparently I wrote my own format-clause for honeysql/v1 in the past

(defmethod format-clause :drop-column* [[_ fields] _]
  (->> fields
       (map #(str "DROP COLUMN " (sqlf/to-sql %)))
       (string/join ",\n")))