// Code generated by ent, DO NOT EDIT. package ent import ( "bj_power_mes/ent/agvpoint" "bj_power_mes/ent/predicate" "context" "errors" "fmt" "entgo.io/ent/dialect/sql" "entgo.io/ent/dialect/sql/sqlgraph" "entgo.io/ent/schema/field" ) // AgvPointUpdate is the builder for updating AgvPoint entities. type AgvPointUpdate struct { config hooks []Hook mutation *AgvPointMutation modifiers []func(*sql.UpdateBuilder) } // Where appends a list predicates to the AgvPointUpdate builder. func (_u *AgvPointUpdate) Where(ps ...predicate.AgvPoint) *AgvPointUpdate { _u.mutation.Where(ps...) return _u } // SetPositionCode sets the "position_code" field. func (_u *AgvPointUpdate) SetPositionCode(v string) *AgvPointUpdate { _u.mutation.SetPositionCode(v) return _u } // SetNillablePositionCode sets the "position_code" field if the given value is not nil. func (_u *AgvPointUpdate) SetNillablePositionCode(v *string) *AgvPointUpdate { if v != nil { _u.SetPositionCode(*v) } return _u } // SetName sets the "name" field. func (_u *AgvPointUpdate) SetName(v string) *AgvPointUpdate { _u.mutation.SetName(v) return _u } // SetNillableName sets the "name" field if the given value is not nil. func (_u *AgvPointUpdate) SetNillableName(v *string) *AgvPointUpdate { if v != nil { _u.SetName(*v) } return _u } // SetIsDock sets the "is_dock" field. func (_u *AgvPointUpdate) SetIsDock(v bool) *AgvPointUpdate { _u.mutation.SetIsDock(v) return _u } // SetNillableIsDock sets the "is_dock" field if the given value is not nil. func (_u *AgvPointUpdate) SetNillableIsDock(v *bool) *AgvPointUpdate { if v != nil { _u.SetIsDock(*v) } return _u } // SetDockID sets the "dock_id" field. func (_u *AgvPointUpdate) SetDockID(v int) *AgvPointUpdate { _u.mutation.ResetDockID() _u.mutation.SetDockID(v) return _u } // SetNillableDockID sets the "dock_id" field if the given value is not nil. func (_u *AgvPointUpdate) SetNillableDockID(v *int) *AgvPointUpdate { if v != nil { _u.SetDockID(*v) } return _u } // AddDockID adds value to the "dock_id" field. func (_u *AgvPointUpdate) AddDockID(v int) *AgvPointUpdate { _u.mutation.AddDockID(v) return _u } // ClearDockID clears the value of the "dock_id" field. func (_u *AgvPointUpdate) ClearDockID() *AgvPointUpdate { _u.mutation.ClearDockID() return _u } // SetEnabled sets the "enabled" field. func (_u *AgvPointUpdate) SetEnabled(v bool) *AgvPointUpdate { _u.mutation.SetEnabled(v) return _u } // SetNillableEnabled sets the "enabled" field if the given value is not nil. func (_u *AgvPointUpdate) SetNillableEnabled(v *bool) *AgvPointUpdate { if v != nil { _u.SetEnabled(*v) } return _u } // Mutation returns the AgvPointMutation object of the builder. func (_u *AgvPointUpdate) Mutation() *AgvPointMutation { return _u.mutation } // Save executes the query and returns the number of nodes affected by the update operation. func (_u *AgvPointUpdate) 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 *AgvPointUpdate) SaveX(ctx context.Context) int { affected, err := _u.Save(ctx) if err != nil { panic(err) } return affected } // Exec executes the query. func (_u *AgvPointUpdate) Exec(ctx context.Context) error { _, err := _u.Save(ctx) return err } // ExecX is like Exec, but panics if an error occurs. func (_u *AgvPointUpdate) 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 *AgvPointUpdate) check() error { if v, ok := _u.mutation.PositionCode(); ok { if err := agvpoint.PositionCodeValidator(v); err != nil { return &ValidationError{Name: "position_code", err: fmt.Errorf(`ent: validator failed for field "AgvPoint.position_code": %w`, err)} } } if v, ok := _u.mutation.Name(); ok { if err := agvpoint.NameValidator(v); err != nil { return &ValidationError{Name: "name", err: fmt.Errorf(`ent: validator failed for field "AgvPoint.name": %w`, err)} } } return nil } // Modify adds a statement modifier for attaching custom logic to the UPDATE statement. func (_u *AgvPointUpdate) Modify(modifiers ...func(u *sql.UpdateBuilder)) *AgvPointUpdate { _u.modifiers = append(_u.modifiers, modifiers...) return _u } func (_u *AgvPointUpdate) sqlSave(ctx context.Context) (_node int, err error) { if err := _u.check(); err != nil { return _node, err } _spec := sqlgraph.NewUpdateSpec(agvpoint.Table, agvpoint.Columns, sqlgraph.NewFieldSpec(agvpoint.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.PositionCode(); ok { _spec.SetField(agvpoint.FieldPositionCode, field.TypeString, value) } if value, ok := _u.mutation.Name(); ok { _spec.SetField(agvpoint.FieldName, field.TypeString, value) } if value, ok := _u.mutation.IsDock(); ok { _spec.SetField(agvpoint.FieldIsDock, field.TypeBool, value) } if value, ok := _u.mutation.DockID(); ok { _spec.SetField(agvpoint.FieldDockID, field.TypeInt, value) } if value, ok := _u.mutation.AddedDockID(); ok { _spec.AddField(agvpoint.FieldDockID, field.TypeInt, value) } if _u.mutation.DockIDCleared() { _spec.ClearField(agvpoint.FieldDockID, field.TypeInt) } if value, ok := _u.mutation.Enabled(); ok { _spec.SetField(agvpoint.FieldEnabled, field.TypeBool, value) } _spec.AddModifiers(_u.modifiers...) if _node, err = sqlgraph.UpdateNodes(ctx, _u.driver, _spec); err != nil { if _, ok := err.(*sqlgraph.NotFoundError); ok { err = &NotFoundError{agvpoint.Label} } else if sqlgraph.IsConstraintError(err) { err = &ConstraintError{msg: err.Error(), wrap: err} } return 0, err } _u.mutation.done = true return _node, nil } // AgvPointUpdateOne is the builder for updating a single AgvPoint entity. type AgvPointUpdateOne struct { config fields []string hooks []Hook mutation *AgvPointMutation modifiers []func(*sql.UpdateBuilder) } // SetPositionCode sets the "position_code" field. func (_u *AgvPointUpdateOne) SetPositionCode(v string) *AgvPointUpdateOne { _u.mutation.SetPositionCode(v) return _u } // SetNillablePositionCode sets the "position_code" field if the given value is not nil. func (_u *AgvPointUpdateOne) SetNillablePositionCode(v *string) *AgvPointUpdateOne { if v != nil { _u.SetPositionCode(*v) } return _u } // SetName sets the "name" field. func (_u *AgvPointUpdateOne) SetName(v string) *AgvPointUpdateOne { _u.mutation.SetName(v) return _u } // SetNillableName sets the "name" field if the given value is not nil. func (_u *AgvPointUpdateOne) SetNillableName(v *string) *AgvPointUpdateOne { if v != nil { _u.SetName(*v) } return _u } // SetIsDock sets the "is_dock" field. func (_u *AgvPointUpdateOne) SetIsDock(v bool) *AgvPointUpdateOne { _u.mutation.SetIsDock(v) return _u } // SetNillableIsDock sets the "is_dock" field if the given value is not nil. func (_u *AgvPointUpdateOne) SetNillableIsDock(v *bool) *AgvPointUpdateOne { if v != nil { _u.SetIsDock(*v) } return _u } // SetDockID sets the "dock_id" field. func (_u *AgvPointUpdateOne) SetDockID(v int) *AgvPointUpdateOne { _u.mutation.ResetDockID() _u.mutation.SetDockID(v) return _u } // SetNillableDockID sets the "dock_id" field if the given value is not nil. func (_u *AgvPointUpdateOne) SetNillableDockID(v *int) *AgvPointUpdateOne { if v != nil { _u.SetDockID(*v) } return _u } // AddDockID adds value to the "dock_id" field. func (_u *AgvPointUpdateOne) AddDockID(v int) *AgvPointUpdateOne { _u.mutation.AddDockID(v) return _u } // ClearDockID clears the value of the "dock_id" field. func (_u *AgvPointUpdateOne) ClearDockID() *AgvPointUpdateOne { _u.mutation.ClearDockID() return _u } // SetEnabled sets the "enabled" field. func (_u *AgvPointUpdateOne) SetEnabled(v bool) *AgvPointUpdateOne { _u.mutation.SetEnabled(v) return _u } // SetNillableEnabled sets the "enabled" field if the given value is not nil. func (_u *AgvPointUpdateOne) SetNillableEnabled(v *bool) *AgvPointUpdateOne { if v != nil { _u.SetEnabled(*v) } return _u } // Mutation returns the AgvPointMutation object of the builder. func (_u *AgvPointUpdateOne) Mutation() *AgvPointMutation { return _u.mutation } // Where appends a list predicates to the AgvPointUpdate builder. func (_u *AgvPointUpdateOne) Where(ps ...predicate.AgvPoint) *AgvPointUpdateOne { _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 *AgvPointUpdateOne) Select(field string, fields ...string) *AgvPointUpdateOne { _u.fields = append([]string{field}, fields...) return _u } // Save executes the query and returns the updated AgvPoint entity. func (_u *AgvPointUpdateOne) Save(ctx context.Context) (*AgvPoint, error) { return withHooks(ctx, _u.sqlSave, _u.mutation, _u.hooks) } // SaveX is like Save, but panics if an error occurs. func (_u *AgvPointUpdateOne) SaveX(ctx context.Context) *AgvPoint { node, err := _u.Save(ctx) if err != nil { panic(err) } return node } // Exec executes the query on the entity. func (_u *AgvPointUpdateOne) Exec(ctx context.Context) error { _, err := _u.Save(ctx) return err } // ExecX is like Exec, but panics if an error occurs. func (_u *AgvPointUpdateOne) 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 *AgvPointUpdateOne) check() error { if v, ok := _u.mutation.PositionCode(); ok { if err := agvpoint.PositionCodeValidator(v); err != nil { return &ValidationError{Name: "position_code", err: fmt.Errorf(`ent: validator failed for field "AgvPoint.position_code": %w`, err)} } } if v, ok := _u.mutation.Name(); ok { if err := agvpoint.NameValidator(v); err != nil { return &ValidationError{Name: "name", err: fmt.Errorf(`ent: validator failed for field "AgvPoint.name": %w`, err)} } } return nil } // Modify adds a statement modifier for attaching custom logic to the UPDATE statement. func (_u *AgvPointUpdateOne) Modify(modifiers ...func(u *sql.UpdateBuilder)) *AgvPointUpdateOne { _u.modifiers = append(_u.modifiers, modifiers...) return _u } func (_u *AgvPointUpdateOne) sqlSave(ctx context.Context) (_node *AgvPoint, err error) { if err := _u.check(); err != nil { return _node, err } _spec := sqlgraph.NewUpdateSpec(agvpoint.Table, agvpoint.Columns, sqlgraph.NewFieldSpec(agvpoint.FieldID, field.TypeInt)) id, ok := _u.mutation.ID() if !ok { return nil, &ValidationError{Name: "id", err: errors.New(`ent: missing "AgvPoint.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, agvpoint.FieldID) for _, f := range fields { if !agvpoint.ValidColumn(f) { return nil, &ValidationError{Name: f, err: fmt.Errorf("ent: invalid field %q for query", f)} } if f != agvpoint.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.PositionCode(); ok { _spec.SetField(agvpoint.FieldPositionCode, field.TypeString, value) } if value, ok := _u.mutation.Name(); ok { _spec.SetField(agvpoint.FieldName, field.TypeString, value) } if value, ok := _u.mutation.IsDock(); ok { _spec.SetField(agvpoint.FieldIsDock, field.TypeBool, value) } if value, ok := _u.mutation.DockID(); ok { _spec.SetField(agvpoint.FieldDockID, field.TypeInt, value) } if value, ok := _u.mutation.AddedDockID(); ok { _spec.AddField(agvpoint.FieldDockID, field.TypeInt, value) } if _u.mutation.DockIDCleared() { _spec.ClearField(agvpoint.FieldDockID, field.TypeInt) } if value, ok := _u.mutation.Enabled(); ok { _spec.SetField(agvpoint.FieldEnabled, field.TypeBool, value) } _spec.AddModifiers(_u.modifiers...) _node = &AgvPoint{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{agvpoint.Label} } else if sqlgraph.IsConstraintError(err) { err = &ConstraintError{msg: err.Error(), wrap: err} } return nil, err } _u.mutation.done = true return _node, nil }