// Code generated by ent, DO NOT EDIT. package ent import ( "bj_power_mes/ent/plcmovecmd" "bj_power_mes/ent/predicate" "context" "errors" "fmt" "time" "entgo.io/ent/dialect/sql" "entgo.io/ent/dialect/sql/sqlgraph" "entgo.io/ent/schema/field" ) // PlcMoveCmdUpdate is the builder for updating PlcMoveCmd entities. type PlcMoveCmdUpdate struct { config hooks []Hook mutation *PlcMoveCmdMutation } // Where appends a list predicates to the PlcMoveCmdUpdate builder. func (_u *PlcMoveCmdUpdate) Where(ps ...predicate.PlcMoveCmd) *PlcMoveCmdUpdate { _u.mutation.Where(ps...) return _u } // SetCmdNo sets the "cmdNo" field. func (_u *PlcMoveCmdUpdate) SetCmdNo(v string) *PlcMoveCmdUpdate { _u.mutation.SetCmdNo(v) return _u } // SetNillableCmdNo sets the "cmdNo" field if the given value is not nil. func (_u *PlcMoveCmdUpdate) SetNillableCmdNo(v *string) *PlcMoveCmdUpdate { if v != nil { _u.SetCmdNo(*v) } return _u } // SetSn sets the "sn" field. func (_u *PlcMoveCmdUpdate) SetSn(v string) *PlcMoveCmdUpdate { _u.mutation.SetSn(v) return _u } // SetNillableSn sets the "sn" field if the given value is not nil. func (_u *PlcMoveCmdUpdate) SetNillableSn(v *string) *PlcMoveCmdUpdate { if v != nil { _u.SetSn(*v) } return _u } // SetOrderNo sets the "orderNo" field. func (_u *PlcMoveCmdUpdate) SetOrderNo(v string) *PlcMoveCmdUpdate { _u.mutation.SetOrderNo(v) return _u } // SetNillableOrderNo sets the "orderNo" field if the given value is not nil. func (_u *PlcMoveCmdUpdate) SetNillableOrderNo(v *string) *PlcMoveCmdUpdate { if v != nil { _u.SetOrderNo(*v) } return _u } // SetFromPoint sets the "fromPoint" field. func (_u *PlcMoveCmdUpdate) SetFromPoint(v string) *PlcMoveCmdUpdate { _u.mutation.SetFromPoint(v) return _u } // SetNillableFromPoint sets the "fromPoint" field if the given value is not nil. func (_u *PlcMoveCmdUpdate) SetNillableFromPoint(v *string) *PlcMoveCmdUpdate { if v != nil { _u.SetFromPoint(*v) } return _u } // SetToPoint sets the "toPoint" field. func (_u *PlcMoveCmdUpdate) SetToPoint(v string) *PlcMoveCmdUpdate { _u.mutation.SetToPoint(v) return _u } // SetNillableToPoint sets the "toPoint" field if the given value is not nil. func (_u *PlcMoveCmdUpdate) SetNillableToPoint(v *string) *PlcMoveCmdUpdate { if v != nil { _u.SetToPoint(*v) } return _u } // SetStatus sets the "status" field. func (_u *PlcMoveCmdUpdate) SetStatus(v string) *PlcMoveCmdUpdate { _u.mutation.SetStatus(v) return _u } // SetNillableStatus sets the "status" field if the given value is not nil. func (_u *PlcMoveCmdUpdate) SetNillableStatus(v *string) *PlcMoveCmdUpdate { if v != nil { _u.SetStatus(*v) } return _u } // SetOperator sets the "operator" field. func (_u *PlcMoveCmdUpdate) SetOperator(v string) *PlcMoveCmdUpdate { _u.mutation.SetOperator(v) return _u } // SetNillableOperator sets the "operator" field if the given value is not nil. func (_u *PlcMoveCmdUpdate) SetNillableOperator(v *string) *PlcMoveCmdUpdate { if v != nil { _u.SetOperator(*v) } return _u } // SetMessage sets the "message" field. func (_u *PlcMoveCmdUpdate) SetMessage(v string) *PlcMoveCmdUpdate { _u.mutation.SetMessage(v) return _u } // SetNillableMessage sets the "message" field if the given value is not nil. func (_u *PlcMoveCmdUpdate) SetNillableMessage(v *string) *PlcMoveCmdUpdate { if v != nil { _u.SetMessage(*v) } return _u } // SetUpdatedAt sets the "updatedAt" field. func (_u *PlcMoveCmdUpdate) SetUpdatedAt(v time.Time) *PlcMoveCmdUpdate { _u.mutation.SetUpdatedAt(v) return _u } // Mutation returns the PlcMoveCmdMutation object of the builder. func (_u *PlcMoveCmdUpdate) Mutation() *PlcMoveCmdMutation { return _u.mutation } // Save executes the query and returns the number of nodes affected by the update operation. func (_u *PlcMoveCmdUpdate) Save(ctx context.Context) (int, error) { _u.defaults() return withHooks(ctx, _u.sqlSave, _u.mutation, _u.hooks) } // SaveX is like Save, but panics if an error occurs. func (_u *PlcMoveCmdUpdate) SaveX(ctx context.Context) int { affected, err := _u.Save(ctx) if err != nil { panic(err) } return affected } // Exec executes the query. func (_u *PlcMoveCmdUpdate) Exec(ctx context.Context) error { _, err := _u.Save(ctx) return err } // ExecX is like Exec, but panics if an error occurs. func (_u *PlcMoveCmdUpdate) ExecX(ctx context.Context) { if err := _u.Exec(ctx); err != nil { panic(err) } } // defaults sets the default values of the builder before save. func (_u *PlcMoveCmdUpdate) defaults() { if _, ok := _u.mutation.UpdatedAt(); !ok { v := plcmovecmd.UpdateDefaultUpdatedAt() _u.mutation.SetUpdatedAt(v) } } // check runs all checks and user-defined validators on the builder. func (_u *PlcMoveCmdUpdate) check() error { if v, ok := _u.mutation.CmdNo(); ok { if err := plcmovecmd.CmdNoValidator(v); err != nil { return &ValidationError{Name: "cmdNo", err: fmt.Errorf(`ent: validator failed for field "PlcMoveCmd.cmdNo": %w`, err)} } } if v, ok := _u.mutation.Sn(); ok { if err := plcmovecmd.SnValidator(v); err != nil { return &ValidationError{Name: "sn", err: fmt.Errorf(`ent: validator failed for field "PlcMoveCmd.sn": %w`, err)} } } if v, ok := _u.mutation.OrderNo(); ok { if err := plcmovecmd.OrderNoValidator(v); err != nil { return &ValidationError{Name: "orderNo", err: fmt.Errorf(`ent: validator failed for field "PlcMoveCmd.orderNo": %w`, err)} } } if v, ok := _u.mutation.FromPoint(); ok { if err := plcmovecmd.FromPointValidator(v); err != nil { return &ValidationError{Name: "fromPoint", err: fmt.Errorf(`ent: validator failed for field "PlcMoveCmd.fromPoint": %w`, err)} } } if v, ok := _u.mutation.ToPoint(); ok { if err := plcmovecmd.ToPointValidator(v); err != nil { return &ValidationError{Name: "toPoint", err: fmt.Errorf(`ent: validator failed for field "PlcMoveCmd.toPoint": %w`, err)} } } if v, ok := _u.mutation.Status(); ok { if err := plcmovecmd.StatusValidator(v); err != nil { return &ValidationError{Name: "status", err: fmt.Errorf(`ent: validator failed for field "PlcMoveCmd.status": %w`, err)} } } if v, ok := _u.mutation.Operator(); ok { if err := plcmovecmd.OperatorValidator(v); err != nil { return &ValidationError{Name: "operator", err: fmt.Errorf(`ent: validator failed for field "PlcMoveCmd.operator": %w`, err)} } } if v, ok := _u.mutation.Message(); ok { if err := plcmovecmd.MessageValidator(v); err != nil { return &ValidationError{Name: "message", err: fmt.Errorf(`ent: validator failed for field "PlcMoveCmd.message": %w`, err)} } } return nil } func (_u *PlcMoveCmdUpdate) sqlSave(ctx context.Context) (_node int, err error) { if err := _u.check(); err != nil { return _node, err } _spec := sqlgraph.NewUpdateSpec(plcmovecmd.Table, plcmovecmd.Columns, sqlgraph.NewFieldSpec(plcmovecmd.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.CmdNo(); ok { _spec.SetField(plcmovecmd.FieldCmdNo, field.TypeString, value) } if value, ok := _u.mutation.Sn(); ok { _spec.SetField(plcmovecmd.FieldSn, field.TypeString, value) } if value, ok := _u.mutation.OrderNo(); ok { _spec.SetField(plcmovecmd.FieldOrderNo, field.TypeString, value) } if value, ok := _u.mutation.FromPoint(); ok { _spec.SetField(plcmovecmd.FieldFromPoint, field.TypeString, value) } if value, ok := _u.mutation.ToPoint(); ok { _spec.SetField(plcmovecmd.FieldToPoint, field.TypeString, value) } if value, ok := _u.mutation.Status(); ok { _spec.SetField(plcmovecmd.FieldStatus, field.TypeString, value) } if value, ok := _u.mutation.Operator(); ok { _spec.SetField(plcmovecmd.FieldOperator, field.TypeString, value) } if value, ok := _u.mutation.Message(); ok { _spec.SetField(plcmovecmd.FieldMessage, field.TypeString, value) } if value, ok := _u.mutation.UpdatedAt(); ok { _spec.SetField(plcmovecmd.FieldUpdatedAt, field.TypeTime, value) } if _node, err = sqlgraph.UpdateNodes(ctx, _u.driver, _spec); err != nil { if _, ok := err.(*sqlgraph.NotFoundError); ok { err = &NotFoundError{plcmovecmd.Label} } else if sqlgraph.IsConstraintError(err) { err = &ConstraintError{msg: err.Error(), wrap: err} } return 0, err } _u.mutation.done = true return _node, nil } // PlcMoveCmdUpdateOne is the builder for updating a single PlcMoveCmd entity. type PlcMoveCmdUpdateOne struct { config fields []string hooks []Hook mutation *PlcMoveCmdMutation } // SetCmdNo sets the "cmdNo" field. func (_u *PlcMoveCmdUpdateOne) SetCmdNo(v string) *PlcMoveCmdUpdateOne { _u.mutation.SetCmdNo(v) return _u } // SetNillableCmdNo sets the "cmdNo" field if the given value is not nil. func (_u *PlcMoveCmdUpdateOne) SetNillableCmdNo(v *string) *PlcMoveCmdUpdateOne { if v != nil { _u.SetCmdNo(*v) } return _u } // SetSn sets the "sn" field. func (_u *PlcMoveCmdUpdateOne) SetSn(v string) *PlcMoveCmdUpdateOne { _u.mutation.SetSn(v) return _u } // SetNillableSn sets the "sn" field if the given value is not nil. func (_u *PlcMoveCmdUpdateOne) SetNillableSn(v *string) *PlcMoveCmdUpdateOne { if v != nil { _u.SetSn(*v) } return _u } // SetOrderNo sets the "orderNo" field. func (_u *PlcMoveCmdUpdateOne) SetOrderNo(v string) *PlcMoveCmdUpdateOne { _u.mutation.SetOrderNo(v) return _u } // SetNillableOrderNo sets the "orderNo" field if the given value is not nil. func (_u *PlcMoveCmdUpdateOne) SetNillableOrderNo(v *string) *PlcMoveCmdUpdateOne { if v != nil { _u.SetOrderNo(*v) } return _u } // SetFromPoint sets the "fromPoint" field. func (_u *PlcMoveCmdUpdateOne) SetFromPoint(v string) *PlcMoveCmdUpdateOne { _u.mutation.SetFromPoint(v) return _u } // SetNillableFromPoint sets the "fromPoint" field if the given value is not nil. func (_u *PlcMoveCmdUpdateOne) SetNillableFromPoint(v *string) *PlcMoveCmdUpdateOne { if v != nil { _u.SetFromPoint(*v) } return _u } // SetToPoint sets the "toPoint" field. func (_u *PlcMoveCmdUpdateOne) SetToPoint(v string) *PlcMoveCmdUpdateOne { _u.mutation.SetToPoint(v) return _u } // SetNillableToPoint sets the "toPoint" field if the given value is not nil. func (_u *PlcMoveCmdUpdateOne) SetNillableToPoint(v *string) *PlcMoveCmdUpdateOne { if v != nil { _u.SetToPoint(*v) } return _u } // SetStatus sets the "status" field. func (_u *PlcMoveCmdUpdateOne) SetStatus(v string) *PlcMoveCmdUpdateOne { _u.mutation.SetStatus(v) return _u } // SetNillableStatus sets the "status" field if the given value is not nil. func (_u *PlcMoveCmdUpdateOne) SetNillableStatus(v *string) *PlcMoveCmdUpdateOne { if v != nil { _u.SetStatus(*v) } return _u } // SetOperator sets the "operator" field. func (_u *PlcMoveCmdUpdateOne) SetOperator(v string) *PlcMoveCmdUpdateOne { _u.mutation.SetOperator(v) return _u } // SetNillableOperator sets the "operator" field if the given value is not nil. func (_u *PlcMoveCmdUpdateOne) SetNillableOperator(v *string) *PlcMoveCmdUpdateOne { if v != nil { _u.SetOperator(*v) } return _u } // SetMessage sets the "message" field. func (_u *PlcMoveCmdUpdateOne) SetMessage(v string) *PlcMoveCmdUpdateOne { _u.mutation.SetMessage(v) return _u } // SetNillableMessage sets the "message" field if the given value is not nil. func (_u *PlcMoveCmdUpdateOne) SetNillableMessage(v *string) *PlcMoveCmdUpdateOne { if v != nil { _u.SetMessage(*v) } return _u } // SetUpdatedAt sets the "updatedAt" field. func (_u *PlcMoveCmdUpdateOne) SetUpdatedAt(v time.Time) *PlcMoveCmdUpdateOne { _u.mutation.SetUpdatedAt(v) return _u } // Mutation returns the PlcMoveCmdMutation object of the builder. func (_u *PlcMoveCmdUpdateOne) Mutation() *PlcMoveCmdMutation { return _u.mutation } // Where appends a list predicates to the PlcMoveCmdUpdate builder. func (_u *PlcMoveCmdUpdateOne) Where(ps ...predicate.PlcMoveCmd) *PlcMoveCmdUpdateOne { _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 *PlcMoveCmdUpdateOne) Select(field string, fields ...string) *PlcMoveCmdUpdateOne { _u.fields = append([]string{field}, fields...) return _u } // Save executes the query and returns the updated PlcMoveCmd entity. func (_u *PlcMoveCmdUpdateOne) Save(ctx context.Context) (*PlcMoveCmd, error) { _u.defaults() return withHooks(ctx, _u.sqlSave, _u.mutation, _u.hooks) } // SaveX is like Save, but panics if an error occurs. func (_u *PlcMoveCmdUpdateOne) SaveX(ctx context.Context) *PlcMoveCmd { node, err := _u.Save(ctx) if err != nil { panic(err) } return node } // Exec executes the query on the entity. func (_u *PlcMoveCmdUpdateOne) Exec(ctx context.Context) error { _, err := _u.Save(ctx) return err } // ExecX is like Exec, but panics if an error occurs. func (_u *PlcMoveCmdUpdateOne) ExecX(ctx context.Context) { if err := _u.Exec(ctx); err != nil { panic(err) } } // defaults sets the default values of the builder before save. func (_u *PlcMoveCmdUpdateOne) defaults() { if _, ok := _u.mutation.UpdatedAt(); !ok { v := plcmovecmd.UpdateDefaultUpdatedAt() _u.mutation.SetUpdatedAt(v) } } // check runs all checks and user-defined validators on the builder. func (_u *PlcMoveCmdUpdateOne) check() error { if v, ok := _u.mutation.CmdNo(); ok { if err := plcmovecmd.CmdNoValidator(v); err != nil { return &ValidationError{Name: "cmdNo", err: fmt.Errorf(`ent: validator failed for field "PlcMoveCmd.cmdNo": %w`, err)} } } if v, ok := _u.mutation.Sn(); ok { if err := plcmovecmd.SnValidator(v); err != nil { return &ValidationError{Name: "sn", err: fmt.Errorf(`ent: validator failed for field "PlcMoveCmd.sn": %w`, err)} } } if v, ok := _u.mutation.OrderNo(); ok { if err := plcmovecmd.OrderNoValidator(v); err != nil { return &ValidationError{Name: "orderNo", err: fmt.Errorf(`ent: validator failed for field "PlcMoveCmd.orderNo": %w`, err)} } } if v, ok := _u.mutation.FromPoint(); ok { if err := plcmovecmd.FromPointValidator(v); err != nil { return &ValidationError{Name: "fromPoint", err: fmt.Errorf(`ent: validator failed for field "PlcMoveCmd.fromPoint": %w`, err)} } } if v, ok := _u.mutation.ToPoint(); ok { if err := plcmovecmd.ToPointValidator(v); err != nil { return &ValidationError{Name: "toPoint", err: fmt.Errorf(`ent: validator failed for field "PlcMoveCmd.toPoint": %w`, err)} } } if v, ok := _u.mutation.Status(); ok { if err := plcmovecmd.StatusValidator(v); err != nil { return &ValidationError{Name: "status", err: fmt.Errorf(`ent: validator failed for field "PlcMoveCmd.status": %w`, err)} } } if v, ok := _u.mutation.Operator(); ok { if err := plcmovecmd.OperatorValidator(v); err != nil { return &ValidationError{Name: "operator", err: fmt.Errorf(`ent: validator failed for field "PlcMoveCmd.operator": %w`, err)} } } if v, ok := _u.mutation.Message(); ok { if err := plcmovecmd.MessageValidator(v); err != nil { return &ValidationError{Name: "message", err: fmt.Errorf(`ent: validator failed for field "PlcMoveCmd.message": %w`, err)} } } return nil } func (_u *PlcMoveCmdUpdateOne) sqlSave(ctx context.Context) (_node *PlcMoveCmd, err error) { if err := _u.check(); err != nil { return _node, err } _spec := sqlgraph.NewUpdateSpec(plcmovecmd.Table, plcmovecmd.Columns, sqlgraph.NewFieldSpec(plcmovecmd.FieldID, field.TypeInt)) id, ok := _u.mutation.ID() if !ok { return nil, &ValidationError{Name: "id", err: errors.New(`ent: missing "PlcMoveCmd.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, plcmovecmd.FieldID) for _, f := range fields { if !plcmovecmd.ValidColumn(f) { return nil, &ValidationError{Name: f, err: fmt.Errorf("ent: invalid field %q for query", f)} } if f != plcmovecmd.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.CmdNo(); ok { _spec.SetField(plcmovecmd.FieldCmdNo, field.TypeString, value) } if value, ok := _u.mutation.Sn(); ok { _spec.SetField(plcmovecmd.FieldSn, field.TypeString, value) } if value, ok := _u.mutation.OrderNo(); ok { _spec.SetField(plcmovecmd.FieldOrderNo, field.TypeString, value) } if value, ok := _u.mutation.FromPoint(); ok { _spec.SetField(plcmovecmd.FieldFromPoint, field.TypeString, value) } if value, ok := _u.mutation.ToPoint(); ok { _spec.SetField(plcmovecmd.FieldToPoint, field.TypeString, value) } if value, ok := _u.mutation.Status(); ok { _spec.SetField(plcmovecmd.FieldStatus, field.TypeString, value) } if value, ok := _u.mutation.Operator(); ok { _spec.SetField(plcmovecmd.FieldOperator, field.TypeString, value) } if value, ok := _u.mutation.Message(); ok { _spec.SetField(plcmovecmd.FieldMessage, field.TypeString, value) } if value, ok := _u.mutation.UpdatedAt(); ok { _spec.SetField(plcmovecmd.FieldUpdatedAt, field.TypeTime, value) } _node = &PlcMoveCmd{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{plcmovecmd.Label} } else if sqlgraph.IsConstraintError(err) { err = &ConstraintError{msg: err.Error(), wrap: err} } return nil, err } _u.mutation.done = true return _node, nil }