fix #478 by removing duplication in one branch
This commit is contained in:
parent
3f31e5a61f
commit
e8753efa3e
2 changed files with 9 additions and 9 deletions
|
|
@ -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) " "
|
||||||
(map (fn [e]
|
(str/join ", "
|
||||||
(let [e (format-entity e {:drop-ns true})]
|
(map (fn [e]
|
||||||
(str e " = EXCLUDED." e)))
|
(let [e (format-entity e {:drop-ns true})]
|
||||||
fields))])
|
(str e " = EXCLUDED." e)))
|
||||||
|
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))
|
||||||
|
|
|
||||||
|
|
@ -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)
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue