Add ON DUPLICATE KEY UPDATE support (MySQL).
This commit is contained in:
parent
30284af33e
commit
980b9b6aac
18 changed files with 388 additions and 109 deletions
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue