dialect/sql/sqlgraph: add update spec builder (#3301)

This commit is contained in:
Ariel Mashraki
2023-02-06 07:13:06 +02:00
committed by GitHub
parent ca7408e81c
commit 0e6ef32505
125 changed files with 268 additions and 2529 deletions

View File

@@ -443,6 +443,20 @@ type (
}
)
// NewUpdateSpec creates a new node update spec.
func NewUpdateSpec(table string, columns []string, id ...*FieldSpec) *UpdateSpec {
spec := &UpdateSpec{
Node: &NodeSpec{Table: table, Columns: columns},
}
switch {
case len(id) == 1:
spec.Node.ID = id[0]
case len(id) > 1:
spec.Node.CompositeID = id
}
return spec
}
// AddModifier adds a new statement modifier to the spec.
func (u *UpdateSpec) AddModifier(m func(*sql.UpdateBuilder)) {
u.Modifiers = append(u.Modifiers, m)