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

View file

@ -93,14 +93,14 @@
(upsert (-> (on-conflict (on-constraint :distributors_pkey))
do-nothing))
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)
(values [{:id 1 :data 42}])
(upsert (-> (on-conflict :id)
(do-update-set [:state "enabled"]
[:modified [:now]])
(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)
(values [{:id 1 :data 42}])
(upsert (-> (on-conflict :id)