From 435bf7086589a69361f5063348ec38768149d071 Mon Sep 17 00:00:00 2001 From: Jinzhu Date: Tue, 5 Jan 2021 21:31:51 +0800 Subject: [PATCH] Add OnConflict OnConstraint support, close #3882 --- clause/on_conflict.go | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/clause/on_conflict.go b/clause/on_conflict.go index 47fe169c..5ecd8e93 100644 --- a/clause/on_conflict.go +++ b/clause/on_conflict.go @@ -1,11 +1,12 @@ package clause type OnConflict struct { - Columns []Column - Where Where - DoNothing bool - DoUpdates Set - UpdateAll bool + Columns []Column + Where Where + OnConstraint string + DoNothing bool + DoUpdates Set + UpdateAll bool } func (OnConflict) Name() string { @@ -31,6 +32,12 @@ func (onConflict OnConflict) Build(builder Builder) { builder.WriteByte(' ') } + if onConflict.OnConstraint != "" { + builder.WriteString("ON CONSTRAINT ") + builder.WriteString(onConflict.OnConstraint) + builder.WriteByte(' ') + } + if onConflict.DoNothing { builder.WriteString("DO NOTHING") } else {