2020-04-12 18:53:57 +02:00
|
|
|
package postgres
|
|
|
|
|
|
|
|
|
|
import "github.com/go-jet/jet/internal/jet"
|
|
|
|
|
|
|
|
|
|
type conflictAction interface {
|
|
|
|
|
jet.Serializer
|
|
|
|
|
WHERE(condition BoolExpression) conflictAction
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// SET creates conflict action for ON_CONFLICT clause
|
2020-05-03 20:46:21 +02:00
|
|
|
func SET(assigments ...ColumnAssigment) conflictAction {
|
2020-04-12 18:53:57 +02:00
|
|
|
conflictAction := updateConflictActionImpl{}
|
|
|
|
|
conflictAction.doUpdate = jet.KeywordClause{Keyword: "DO UPDATE"}
|
|
|
|
|
conflictAction.Serializer = jet.NewSerializerClauseImpl(&conflictAction.doUpdate, &conflictAction.set, &conflictAction.where)
|
2020-05-03 20:46:21 +02:00
|
|
|
conflictAction.set = assigments
|
2020-04-12 18:53:57 +02:00
|
|
|
return &conflictAction
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
type updateConflictActionImpl struct {
|
|
|
|
|
jet.Serializer
|
|
|
|
|
|
|
|
|
|
doUpdate jet.KeywordClause
|
2020-05-09 10:49:09 +02:00
|
|
|
set jet.SetClauseNew
|
2020-04-12 18:53:57 +02:00
|
|
|
where jet.ClauseWhere
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (u *updateConflictActionImpl) WHERE(condition BoolExpression) conflictAction {
|
|
|
|
|
u.where.Condition = condition
|
|
|
|
|
return u
|
|
|
|
|
}
|