gorm/clause/set.go

38 lines
717 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('=')
builder.Write(builder.AddVar(assignment.Value))
}
} 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
}