Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add-column / drop-column for multiple fields #415

Closed
kwrooijen opened this issue Jul 21, 2022 · 4 comments
Closed

add-column / drop-column for multiple fields #415

kwrooijen opened this issue Jul 21, 2022 · 4 comments
Assignees
Labels
documentation I need to write something up!

Comments

@kwrooijen
Copy link

(postgres specific?)

It's currently not possible to add / drop multiple columns using honeysql

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

;; => ["ALTER TABLE account DROP COLUMN name, email"]

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

;; => ["ALTER TABLE account DROP COLUMN email"]

Expected

["ALTER TABLE account DROP COLUMN name, DROP COLUMN email"]

HoneySQL Version 1

(defmethod format-clause :drop-column* [[_ fields] _]
  (->> fields
       (map #(str "DROP COLUMN " (honeysql.format/to-sql %)))
       (string/join ",\n")))
@seancorfield
Copy link
Owner

I checked on some other databases -- including my "home" MySQL -- and, yeah, HoneySQL's behavior here is just wrong.

@seancorfield seancorfield self-assigned this Jul 29, 2022
@seancorfield seancorfield added the bug It's broken, I'll fix it! label Jul 29, 2022
@seancorfield
Copy link
Owner

This looks reasonably straightforward for drop but hard for add -- I'll have to give this some thought...

@seancorfield
Copy link
Owner

It's not even straightforward for drop since you can optionally have :if-exists as a guard -- and there's currently no way to provide that "per item" without making the drop formatting substantially more complex and hard to document. Not discounting it -- just need to think harder about it.

@seancorfield
Copy link
Owner

Multiple columns are now supported in :drop-column. I'm still thinking about how to support this for alter/modify/add column without breaking anything...

@seancorfield seancorfield added documentation I need to write something up! and removed bug It's broken, I'll fix it! labels Sep 13, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation I need to write something up!
Projects
None yet
Development

No branches or pull requests

2 participants