Improve on conflict on constraint syntax
This commit is contained in:
parent
155ae25ad0
commit
331597b22b
2 changed files with 8 additions and 2 deletions
|
|
@ -503,6 +503,10 @@
|
||||||
" (" (format-entity (first x)) ") "
|
" (" (format-entity (first x)) ") "
|
||||||
sql)]
|
sql)]
|
||||||
params))
|
params))
|
||||||
|
(and (sequential? x) (= 1 (count x)))
|
||||||
|
(format-on-conflict k (first x))
|
||||||
|
(and (sequential? x) (= 0 (count x)))
|
||||||
|
[(sql-kw k)]
|
||||||
:else
|
:else
|
||||||
(throw (ex-info "unsupported :on-conflict format"
|
(throw (ex-info "unsupported :on-conflict format"
|
||||||
{:clause x}))))
|
{:clause x}))))
|
||||||
|
|
|
||||||
|
|
@ -480,7 +480,7 @@
|
||||||
|
|
||||||
(defn on-conflict
|
(defn on-conflict
|
||||||
[& args]
|
[& args]
|
||||||
(generic-1 :on-conflict args))
|
(generic :on-conflict args))
|
||||||
|
|
||||||
(defn on-constraint
|
(defn on-constraint
|
||||||
"Accepts a single constraint name."
|
"Accepts a single constraint name."
|
||||||
|
|
@ -570,10 +570,12 @@
|
||||||
(do-update-set :x {:where [:<> :x nil]}))"
|
(do-update-set :x {:where [:<> :x nil]}))"
|
||||||
([clause] (upsert {} clause))
|
([clause] (upsert {} clause))
|
||||||
([data 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
|
(cond-> data
|
||||||
on-conflict
|
on-conflict
|
||||||
(assoc :on-conflict on-conflict)
|
(assoc :on-conflict on-conflict)
|
||||||
|
on-constraint
|
||||||
|
(assoc :on-constraint on-constraint)
|
||||||
do-nothing
|
do-nothing
|
||||||
(assoc :do-nothing do-nothing)
|
(assoc :do-nothing do-nothing)
|
||||||
do-update-set
|
do-update-set
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue