Add ON DUPLICATE KEY UPDATE support (MySQL).

This commit is contained in:
go-jet 2020-05-03 20:46:21 +02:00
parent 30284af33e
commit 980b9b6aac
18 changed files with 388 additions and 109 deletions

View file

@ -4,16 +4,15 @@ import "github.com/go-jet/jet/internal/jet"
type conflictAction interface {
jet.Serializer
SET(column jet.ColumnSerializer, expression interface{}) conflictAction
WHERE(condition BoolExpression) conflictAction
}
// SET creates conflict action for ON_CONFLICT clause
func SET(column jet.ColumnSerializer, expression interface{}) conflictAction {
func SET(assigments ...ColumnAssigment) conflictAction {
conflictAction := updateConflictActionImpl{}
conflictAction.doUpdate = jet.KeywordClause{Keyword: "DO UPDATE"}
conflictAction.Serializer = jet.NewSerializerClauseImpl(&conflictAction.doUpdate, &conflictAction.set, &conflictAction.where)
conflictAction.SET(column, expression)
conflictAction.set = assigments
return &conflictAction
}
@ -25,11 +24,6 @@ type updateConflictActionImpl struct {
where jet.ClauseWhere
}
func (u *updateConflictActionImpl) SET(column jet.ColumnSerializer, expression interface{}) conflictAction {
u.set = append(u.set, jet.SetPair{Column: column, Value: jet.ToSerializerValue(expression)})
return u
}
func (u *updateConflictActionImpl) WHERE(condition BoolExpression) conflictAction {
u.where.Condition = condition
return u