Improve on conflict on constraint syntax

This commit is contained in:
Sean Corfield 2021-02-15 17:56:47 -08:00
parent 155ae25ad0
commit 331597b22b
2 changed files with 8 additions and 2 deletions

View file

@ -503,6 +503,10 @@
" (" (format-entity (first x)) ") "
sql)]
params))
(and (sequential? x) (= 1 (count x)))
(format-on-conflict k (first x))
(and (sequential? x) (= 0 (count x)))
[(sql-kw k)]
:else
(throw (ex-info "unsupported :on-conflict format"
{:clause x}))))

View file

@ -480,7 +480,7 @@
(defn on-conflict
[& args]
(generic-1 :on-conflict args))
(generic :on-conflict args))
(defn on-constraint
"Accepts a single constraint name."
@ -570,10 +570,12 @@
(do-update-set :x {:where [:<> :x nil]}))"
([clause] (upsert {} clause))
([data clause]
(let [{:keys [on-conflict do-nothing do-update-set where]} clause]
(let [{:keys [on-conflict on-constraint do-nothing do-update-set where]} clause]
(cond-> data
on-conflict
(assoc :on-conflict on-conflict)
on-constraint
(assoc :on-constraint on-constraint)
do-nothing
(assoc :do-nothing do-nothing)
do-update-set