// Code generated by ent, DO NOT EDIT. package ent import ( "bj_power_mes/ent/predicate" "bj_power_mes/ent/semiflow" "context" "errors" "fmt" "entgo.io/ent/dialect/sql" "entgo.io/ent/dialect/sql/sqlgraph" "entgo.io/ent/dialect/sql/sqljson" "entgo.io/ent/schema/field" ) // SemiFlowUpdate is the builder for updating SemiFlow entities. type SemiFlowUpdate struct { config hooks []Hook mutation *SemiFlowMutation modifiers []func(*sql.UpdateBuilder) } // Where appends a list predicates to the SemiFlowUpdate builder. func (_u *SemiFlowUpdate) Where(ps ...predicate.SemiFlow) *SemiFlowUpdate { _u.mutation.Where(ps...) return _u } // SetSn sets the "sn" field. func (_u *SemiFlowUpdate) SetSn(v string) *SemiFlowUpdate { _u.mutation.SetSn(v) return _u } // SetNillableSn sets the "sn" field if the given value is not nil. func (_u *SemiFlowUpdate) SetNillableSn(v *string) *SemiFlowUpdate { if v != nil { _u.SetSn(*v) } return _u } // SetOrderNo sets the "orderNo" field. func (_u *SemiFlowUpdate) SetOrderNo(v string) *SemiFlowUpdate { _u.mutation.SetOrderNo(v) return _u } // SetNillableOrderNo sets the "orderNo" field if the given value is not nil. func (_u *SemiFlowUpdate) SetNillableOrderNo(v *string) *SemiFlowUpdate { if v != nil { _u.SetOrderNo(*v) } return _u } // SetDoneProcessCodes sets the "doneProcessCodes" field. func (_u *SemiFlowUpdate) SetDoneProcessCodes(v []int) *SemiFlowUpdate { _u.mutation.SetDoneProcessCodes(v) return _u } // AppendDoneProcessCodes appends value to the "doneProcessCodes" field. func (_u *SemiFlowUpdate) AppendDoneProcessCodes(v []int) *SemiFlowUpdate { _u.mutation.AppendDoneProcessCodes(v) return _u } // ClearDoneProcessCodes clears the value of the "doneProcessCodes" field. func (_u *SemiFlowUpdate) ClearDoneProcessCodes() *SemiFlowUpdate { _u.mutation.ClearDoneProcessCodes() return _u } // SetAction sets the "action" field. func (_u *SemiFlowUpdate) SetAction(v string) *SemiFlowUpdate { _u.mutation.SetAction(v) return _u } // SetNillableAction sets the "action" field if the given value is not nil. func (_u *SemiFlowUpdate) SetNillableAction(v *string) *SemiFlowUpdate { if v != nil { _u.SetAction(*v) } return _u } // SetTargetDock sets the "targetDock" field. func (_u *SemiFlowUpdate) SetTargetDock(v string) *SemiFlowUpdate { _u.mutation.SetTargetDock(v) return _u } // SetNillableTargetDock sets the "targetDock" field if the given value is not nil. func (_u *SemiFlowUpdate) SetNillableTargetDock(v *string) *SemiFlowUpdate { if v != nil { _u.SetTargetDock(*v) } return _u } // SetOperator sets the "operator" field. func (_u *SemiFlowUpdate) SetOperator(v string) *SemiFlowUpdate { _u.mutation.SetOperator(v) return _u } // SetNillableOperator sets the "operator" field if the given value is not nil. func (_u *SemiFlowUpdate) SetNillableOperator(v *string) *SemiFlowUpdate { if v != nil { _u.SetOperator(*v) } return _u } // Mutation returns the SemiFlowMutation object of the builder. func (_u *SemiFlowUpdate) Mutation() *SemiFlowMutation { return _u.mutation } // Save executes the query and returns the number of nodes affected by the update operation. func (_u *SemiFlowUpdate) Save(ctx context.Context) (int, error) { return withHooks(ctx, _u.sqlSave, _u.mutation, _u.hooks) } // SaveX is like Save, but panics if an error occurs. func (_u *SemiFlowUpdate) SaveX(ctx context.Context) int { affected, err := _u.Save(ctx) if err != nil { panic(err) } return affected } // Exec executes the query. func (_u *SemiFlowUpdate) Exec(ctx context.Context) error { _, err := _u.Save(ctx) return err } // ExecX is like Exec, but panics if an error occurs. func (_u *SemiFlowUpdate) ExecX(ctx context.Context) { if err := _u.Exec(ctx); err != nil { panic(err) } } // check runs all checks and user-defined validators on the builder. func (_u *SemiFlowUpdate) check() error { if v, ok := _u.mutation.Sn(); ok { if err := semiflow.SnValidator(v); err != nil { return &ValidationError{Name: "sn", err: fmt.Errorf(`ent: validator failed for field "SemiFlow.sn": %w`, err)} } } if v, ok := _u.mutation.OrderNo(); ok { if err := semiflow.OrderNoValidator(v); err != nil { return &ValidationError{Name: "orderNo", err: fmt.Errorf(`ent: validator failed for field "SemiFlow.orderNo": %w`, err)} } } if v, ok := _u.mutation.Action(); ok { if err := semiflow.ActionValidator(v); err != nil { return &ValidationError{Name: "action", err: fmt.Errorf(`ent: validator failed for field "SemiFlow.action": %w`, err)} } } if v, ok := _u.mutation.TargetDock(); ok { if err := semiflow.TargetDockValidator(v); err != nil { return &ValidationError{Name: "targetDock", err: fmt.Errorf(`ent: validator failed for field "SemiFlow.targetDock": %w`, err)} } } if v, ok := _u.mutation.Operator(); ok { if err := semiflow.OperatorValidator(v); err != nil { return &ValidationError{Name: "operator", err: fmt.Errorf(`ent: validator failed for field "SemiFlow.operator": %w`, err)} } } return nil } // Modify adds a statement modifier for attaching custom logic to the UPDATE statement. func (_u *SemiFlowUpdate) Modify(modifiers ...func(u *sql.UpdateBuilder)) *SemiFlowUpdate { _u.modifiers = append(_u.modifiers, modifiers...) return _u } func (_u *SemiFlowUpdate) sqlSave(ctx context.Context) (_node int, err error) { if err := _u.check(); err != nil { return _node, err } _spec := sqlgraph.NewUpdateSpec(semiflow.Table, semiflow.Columns, sqlgraph.NewFieldSpec(semiflow.FieldID, field.TypeInt)) if ps := _u.mutation.predicates; len(ps) > 0 { _spec.Predicate = func(selector *sql.Selector) { for i := range ps { ps[i](selector) } } } if value, ok := _u.mutation.Sn(); ok { _spec.SetField(semiflow.FieldSn, field.TypeString, value) } if value, ok := _u.mutation.OrderNo(); ok { _spec.SetField(semiflow.FieldOrderNo, field.TypeString, value) } if value, ok := _u.mutation.DoneProcessCodes(); ok { _spec.SetField(semiflow.FieldDoneProcessCodes, field.TypeJSON, value) } if value, ok := _u.mutation.AppendedDoneProcessCodes(); ok { _spec.AddModifier(func(u *sql.UpdateBuilder) { sqljson.Append(u, semiflow.FieldDoneProcessCodes, value) }) } if _u.mutation.DoneProcessCodesCleared() { _spec.ClearField(semiflow.FieldDoneProcessCodes, field.TypeJSON) } if value, ok := _u.mutation.Action(); ok { _spec.SetField(semiflow.FieldAction, field.TypeString, value) } if value, ok := _u.mutation.TargetDock(); ok { _spec.SetField(semiflow.FieldTargetDock, field.TypeString, value) } if value, ok := _u.mutation.Operator(); ok { _spec.SetField(semiflow.FieldOperator, field.TypeString, value) } _spec.AddModifiers(_u.modifiers...) if _node, err = sqlgraph.UpdateNodes(ctx, _u.driver, _spec); err != nil { if _, ok := err.(*sqlgraph.NotFoundError); ok { err = &NotFoundError{semiflow.Label} } else if sqlgraph.IsConstraintError(err) { err = &ConstraintError{msg: err.Error(), wrap: err} } return 0, err } _u.mutation.done = true return _node, nil } // SemiFlowUpdateOne is the builder for updating a single SemiFlow entity. type SemiFlowUpdateOne struct { config fields []string hooks []Hook mutation *SemiFlowMutation modifiers []func(*sql.UpdateBuilder) } // SetSn sets the "sn" field. func (_u *SemiFlowUpdateOne) SetSn(v string) *SemiFlowUpdateOne { _u.mutation.SetSn(v) return _u } // SetNillableSn sets the "sn" field if the given value is not nil. func (_u *SemiFlowUpdateOne) SetNillableSn(v *string) *SemiFlowUpdateOne { if v != nil { _u.SetSn(*v) } return _u } // SetOrderNo sets the "orderNo" field. func (_u *SemiFlowUpdateOne) SetOrderNo(v string) *SemiFlowUpdateOne { _u.mutation.SetOrderNo(v) return _u } // SetNillableOrderNo sets the "orderNo" field if the given value is not nil. func (_u *SemiFlowUpdateOne) SetNillableOrderNo(v *string) *SemiFlowUpdateOne { if v != nil { _u.SetOrderNo(*v) } return _u } // SetDoneProcessCodes sets the "doneProcessCodes" field. func (_u *SemiFlowUpdateOne) SetDoneProcessCodes(v []int) *SemiFlowUpdateOne { _u.mutation.SetDoneProcessCodes(v) return _u } // AppendDoneProcessCodes appends value to the "doneProcessCodes" field. func (_u *SemiFlowUpdateOne) AppendDoneProcessCodes(v []int) *SemiFlowUpdateOne { _u.mutation.AppendDoneProcessCodes(v) return _u } // ClearDoneProcessCodes clears the value of the "doneProcessCodes" field. func (_u *SemiFlowUpdateOne) ClearDoneProcessCodes() *SemiFlowUpdateOne { _u.mutation.ClearDoneProcessCodes() return _u } // SetAction sets the "action" field. func (_u *SemiFlowUpdateOne) SetAction(v string) *SemiFlowUpdateOne { _u.mutation.SetAction(v) return _u } // SetNillableAction sets the "action" field if the given value is not nil. func (_u *SemiFlowUpdateOne) SetNillableAction(v *string) *SemiFlowUpdateOne { if v != nil { _u.SetAction(*v) } return _u } // SetTargetDock sets the "targetDock" field. func (_u *SemiFlowUpdateOne) SetTargetDock(v string) *SemiFlowUpdateOne { _u.mutation.SetTargetDock(v) return _u } // SetNillableTargetDock sets the "targetDock" field if the given value is not nil. func (_u *SemiFlowUpdateOne) SetNillableTargetDock(v *string) *SemiFlowUpdateOne { if v != nil { _u.SetTargetDock(*v) } return _u } // SetOperator sets the "operator" field. func (_u *SemiFlowUpdateOne) SetOperator(v string) *SemiFlowUpdateOne { _u.mutation.SetOperator(v) return _u } // SetNillableOperator sets the "operator" field if the given value is not nil. func (_u *SemiFlowUpdateOne) SetNillableOperator(v *string) *SemiFlowUpdateOne { if v != nil { _u.SetOperator(*v) } return _u } // Mutation returns the SemiFlowMutation object of the builder. func (_u *SemiFlowUpdateOne) Mutation() *SemiFlowMutation { return _u.mutation } // Where appends a list predicates to the SemiFlowUpdate builder. func (_u *SemiFlowUpdateOne) Where(ps ...predicate.SemiFlow) *SemiFlowUpdateOne { _u.mutation.Where(ps...) return _u } // Select allows selecting one or more fields (columns) of the returned entity. // The default is selecting all fields defined in the entity schema. func (_u *SemiFlowUpdateOne) Select(field string, fields ...string) *SemiFlowUpdateOne { _u.fields = append([]string{field}, fields...) return _u } // Save executes the query and returns the updated SemiFlow entity. func (_u *SemiFlowUpdateOne) Save(ctx context.Context) (*SemiFlow, error) { return withHooks(ctx, _u.sqlSave, _u.mutation, _u.hooks) } // SaveX is like Save, but panics if an error occurs. func (_u *SemiFlowUpdateOne) SaveX(ctx context.Context) *SemiFlow { node, err := _u.Save(ctx) if err != nil { panic(err) } return node } // Exec executes the query on the entity. func (_u *SemiFlowUpdateOne) Exec(ctx context.Context) error { _, err := _u.Save(ctx) return err } // ExecX is like Exec, but panics if an error occurs. func (_u *SemiFlowUpdateOne) ExecX(ctx context.Context) { if err := _u.Exec(ctx); err != nil { panic(err) } } // check runs all checks and user-defined validators on the builder. func (_u *SemiFlowUpdateOne) check() error { if v, ok := _u.mutation.Sn(); ok { if err := semiflow.SnValidator(v); err != nil { return &ValidationError{Name: "sn", err: fmt.Errorf(`ent: validator failed for field "SemiFlow.sn": %w`, err)} } } if v, ok := _u.mutation.OrderNo(); ok { if err := semiflow.OrderNoValidator(v); err != nil { return &ValidationError{Name: "orderNo", err: fmt.Errorf(`ent: validator failed for field "SemiFlow.orderNo": %w`, err)} } } if v, ok := _u.mutation.Action(); ok { if err := semiflow.ActionValidator(v); err != nil { return &ValidationError{Name: "action", err: fmt.Errorf(`ent: validator failed for field "SemiFlow.action": %w`, err)} } } if v, ok := _u.mutation.TargetDock(); ok { if err := semiflow.TargetDockValidator(v); err != nil { return &ValidationError{Name: "targetDock", err: fmt.Errorf(`ent: validator failed for field "SemiFlow.targetDock": %w`, err)} } } if v, ok := _u.mutation.Operator(); ok { if err := semiflow.OperatorValidator(v); err != nil { return &ValidationError{Name: "operator", err: fmt.Errorf(`ent: validator failed for field "SemiFlow.operator": %w`, err)} } } return nil } // Modify adds a statement modifier for attaching custom logic to the UPDATE statement. func (_u *SemiFlowUpdateOne) Modify(modifiers ...func(u *sql.UpdateBuilder)) *SemiFlowUpdateOne { _u.modifiers = append(_u.modifiers, modifiers...) return _u } func (_u *SemiFlowUpdateOne) sqlSave(ctx context.Context) (_node *SemiFlow, err error) { if err := _u.check(); err != nil { return _node, err } _spec := sqlgraph.NewUpdateSpec(semiflow.Table, semiflow.Columns, sqlgraph.NewFieldSpec(semiflow.FieldID, field.TypeInt)) id, ok := _u.mutation.ID() if !ok { return nil, &ValidationError{Name: "id", err: errors.New(`ent: missing "SemiFlow.id" for update`)} } _spec.Node.ID.Value = id if fields := _u.fields; len(fields) > 0 { _spec.Node.Columns = make([]string, 0, len(fields)) _spec.Node.Columns = append(_spec.Node.Columns, semiflow.FieldID) for _, f := range fields { if !semiflow.ValidColumn(f) { return nil, &ValidationError{Name: f, err: fmt.Errorf("ent: invalid field %q for query", f)} } if f != semiflow.FieldID { _spec.Node.Columns = append(_spec.Node.Columns, f) } } } if ps := _u.mutation.predicates; len(ps) > 0 { _spec.Predicate = func(selector *sql.Selector) { for i := range ps { ps[i](selector) } } } if value, ok := _u.mutation.Sn(); ok { _spec.SetField(semiflow.FieldSn, field.TypeString, value) } if value, ok := _u.mutation.OrderNo(); ok { _spec.SetField(semiflow.FieldOrderNo, field.TypeString, value) } if value, ok := _u.mutation.DoneProcessCodes(); ok { _spec.SetField(semiflow.FieldDoneProcessCodes, field.TypeJSON, value) } if value, ok := _u.mutation.AppendedDoneProcessCodes(); ok { _spec.AddModifier(func(u *sql.UpdateBuilder) { sqljson.Append(u, semiflow.FieldDoneProcessCodes, value) }) } if _u.mutation.DoneProcessCodesCleared() { _spec.ClearField(semiflow.FieldDoneProcessCodes, field.TypeJSON) } if value, ok := _u.mutation.Action(); ok { _spec.SetField(semiflow.FieldAction, field.TypeString, value) } if value, ok := _u.mutation.TargetDock(); ok { _spec.SetField(semiflow.FieldTargetDock, field.TypeString, value) } if value, ok := _u.mutation.Operator(); ok { _spec.SetField(semiflow.FieldOperator, field.TypeString, value) } _spec.AddModifiers(_u.modifiers...) _node = &SemiFlow{config: _u.config} _spec.Assign = _node.assignValues _spec.ScanValues = _node.scanValues if err = sqlgraph.UpdateNode(ctx, _u.driver, _spec); err != nil { if _, ok := err.(*sqlgraph.NotFoundError); ok { err = &NotFoundError{semiflow.Label} } else if sqlgraph.IsConstraintError(err) { err = &ConstraintError{msg: err.Error(), wrap: err} } return nil, err } _u.mutation.done = true return _node, nil }