fix #478 by removing duplication in one branch

This commit is contained in:
Sean Corfield 2023-03-13 14:24:11 -07:00
parent 3f31e5a61f
commit e8753efa3e
2 changed files with 9 additions and 9 deletions

View file

@ -902,15 +902,15 @@
[sets & set-params] [sets & set-params]
(if (map? fields) (if (map? fields)
(format-set-exprs k fields) (format-set-exprs k fields)
[(str/join ", " [(str (sql-kw k) " "
(str/join ", "
(map (fn [e] (map (fn [e]
(let [e (format-entity e {:drop-ns true})] (let [e (format-entity e {:drop-ns true})]
(str e " = EXCLUDED." e))) (str e " = EXCLUDED." e)))
fields))]) fields)))])
where (or (:where x) ('where x)) where (or (:where x) ('where x))
[sql & params] (when where (format-dsl {:where where}))] [sql & params] (when where (format-dsl {:where where}))]
(-> [(str (sql-kw k) " " sets (-> [(str sets (when sql (str " " sql)))]
(when sql (str " " sql)))]
(into set-params) (into set-params)
(into params))) (into params)))
(format-set-exprs k x)) (format-set-exprs k x))

View file

@ -93,14 +93,14 @@
(upsert (-> (on-conflict (on-constraint :distributors_pkey)) (upsert (-> (on-conflict (on-constraint :distributors_pkey))
do-nothing)) do-nothing))
sql/format))) sql/format)))
(is (= ["INSERT INTO foo (id, data) VALUES (?, ?) ON CONFLICT (id) DO UPDATE SET DO UPDATE SET into = ((STATE(?), MODIFIED(NOW()))) WHERE state = ?" 1 42 "enabled" "disabled"] (is (= ["INSERT INTO foo (id, data) VALUES (?, ?) ON CONFLICT (id) DO UPDATE SET into = ((STATE(?), MODIFIED(NOW()))) WHERE state = ?" 1 42 "enabled" "disabled"]
(sql/format (-> (insert-into :foo) (sql/format (-> (insert-into :foo)
(values [{:id 1 :data 42}]) (values [{:id 1 :data 42}])
(upsert (-> (on-conflict :id) (upsert (-> (on-conflict :id)
(do-update-set [:state "enabled"] (do-update-set [:state "enabled"]
[:modified [:now]]) [:modified [:now]])
(where [:= :state "disabled"]))))))) (where [:= :state "disabled"])))))))
(is (= ["INSERT INTO foo (id, data) VALUES (?, ?) ON CONFLICT (id) DO UPDATE SET DO UPDATE SET state = ?, modified = NOW() WHERE state = ?" 1 42 "enabled" "disabled"] (is (= ["INSERT INTO foo (id, data) VALUES (?, ?) ON CONFLICT (id) DO UPDATE SET state = ?, modified = NOW() WHERE state = ?" 1 42 "enabled" "disabled"]
(sql/format (-> (insert-into :foo) (sql/format (-> (insert-into :foo)
(values [{:id 1 :data 42}]) (values [{:id 1 :data 42}])
(upsert (-> (on-conflict :id) (upsert (-> (on-conflict :id)