gorm/clause/set.go

38 lines
711 B
Go
Raw Normal View History

2020-02-07 18:45:35 +03:00
package clause
type Set []Assignment
type Assignment struct {
Column Column
Value interface{}
}
func (set Set) Name() string {
return "SET"
}
func (set Set) Build(builder Builder) {
if len(set) > 0 {
for idx, assignment := range set {
if idx > 0 {
builder.WriteByte(',')
}
builder.WriteQuoted(assignment.Column)
builder.WriteByte('=')
2020-03-09 12:07:00 +03:00
builder.AddVar(builder, assignment.Value)
2020-02-07 18:45:35 +03:00
}
} else {
builder.WriteQuoted(PrimaryColumn)
builder.WriteByte('=')
builder.WriteQuoted(PrimaryColumn)
}
}
// MergeClause merge assignments clauses
func (set Set) MergeClause(clause *Clause) {
if v, ok := clause.Expression.(Set); ok {
set = append(v, set...)
}
clause.Expression = set
}