// Code generated by ent, DO NOT EDIT. package ent import ( "bj_power_mes/ent/predicate" "bj_power_mes/ent/stationshift" "context" "errors" "fmt" "entgo.io/ent/dialect/sql" "entgo.io/ent/dialect/sql/sqlgraph" "entgo.io/ent/schema/field" ) // StationShiftUpdate is the builder for updating StationShift entities. type StationShiftUpdate struct { config hooks []Hook mutation *StationShiftMutation modifiers []func(*sql.UpdateBuilder) } // Where appends a list predicates to the StationShiftUpdate builder. func (_u *StationShiftUpdate) Where(ps ...predicate.StationShift) *StationShiftUpdate { _u.mutation.Where(ps...) return _u } // SetStationNo sets the "stationNo" field. func (_u *StationShiftUpdate) SetStationNo(v int) *StationShiftUpdate { _u.mutation.ResetStationNo() _u.mutation.SetStationNo(v) return _u } // SetNillableStationNo sets the "stationNo" field if the given value is not nil. func (_u *StationShiftUpdate) SetNillableStationNo(v *int) *StationShiftUpdate { if v != nil { _u.SetStationNo(*v) } return _u } // AddStationNo adds value to the "stationNo" field. func (_u *StationShiftUpdate) AddStationNo(v int) *StationShiftUpdate { _u.mutation.AddStationNo(v) return _u } // SetOperator sets the "operator" field. func (_u *StationShiftUpdate) SetOperator(v string) *StationShiftUpdate { _u.mutation.SetOperator(v) return _u } // SetNillableOperator sets the "operator" field if the given value is not nil. func (_u *StationShiftUpdate) SetNillableOperator(v *string) *StationShiftUpdate { if v != nil { _u.SetOperator(*v) } return _u } // SetStatus sets the "status" field. func (_u *StationShiftUpdate) SetStatus(v string) *StationShiftUpdate { _u.mutation.SetStatus(v) return _u } // SetNillableStatus sets the "status" field if the given value is not nil. func (_u *StationShiftUpdate) SetNillableStatus(v *string) *StationShiftUpdate { if v != nil { _u.SetStatus(*v) } return _u } // SetStartAt sets the "startAt" field. func (_u *StationShiftUpdate) SetStartAt(v int64) *StationShiftUpdate { _u.mutation.ResetStartAt() _u.mutation.SetStartAt(v) return _u } // SetNillableStartAt sets the "startAt" field if the given value is not nil. func (_u *StationShiftUpdate) SetNillableStartAt(v *int64) *StationShiftUpdate { if v != nil { _u.SetStartAt(*v) } return _u } // AddStartAt adds value to the "startAt" field. func (_u *StationShiftUpdate) AddStartAt(v int64) *StationShiftUpdate { _u.mutation.AddStartAt(v) return _u } // SetEndApplyAt sets the "endApplyAt" field. func (_u *StationShiftUpdate) SetEndApplyAt(v int64) *StationShiftUpdate { _u.mutation.ResetEndApplyAt() _u.mutation.SetEndApplyAt(v) return _u } // SetNillableEndApplyAt sets the "endApplyAt" field if the given value is not nil. func (_u *StationShiftUpdate) SetNillableEndApplyAt(v *int64) *StationShiftUpdate { if v != nil { _u.SetEndApplyAt(*v) } return _u } // AddEndApplyAt adds value to the "endApplyAt" field. func (_u *StationShiftUpdate) AddEndApplyAt(v int64) *StationShiftUpdate { _u.mutation.AddEndApplyAt(v) return _u } // SetClosedAt sets the "closedAt" field. func (_u *StationShiftUpdate) SetClosedAt(v int64) *StationShiftUpdate { _u.mutation.ResetClosedAt() _u.mutation.SetClosedAt(v) return _u } // SetNillableClosedAt sets the "closedAt" field if the given value is not nil. func (_u *StationShiftUpdate) SetNillableClosedAt(v *int64) *StationShiftUpdate { if v != nil { _u.SetClosedAt(*v) } return _u } // AddClosedAt adds value to the "closedAt" field. func (_u *StationShiftUpdate) AddClosedAt(v int64) *StationShiftUpdate { _u.mutation.AddClosedAt(v) return _u } // SetRemark sets the "remark" field. func (_u *StationShiftUpdate) SetRemark(v string) *StationShiftUpdate { _u.mutation.SetRemark(v) return _u } // SetNillableRemark sets the "remark" field if the given value is not nil. func (_u *StationShiftUpdate) SetNillableRemark(v *string) *StationShiftUpdate { if v != nil { _u.SetRemark(*v) } return _u } // ClearRemark clears the value of the "remark" field. func (_u *StationShiftUpdate) ClearRemark() *StationShiftUpdate { _u.mutation.ClearRemark() return _u } // Mutation returns the StationShiftMutation object of the builder. func (_u *StationShiftUpdate) Mutation() *StationShiftMutation { return _u.mutation } // Save executes the query and returns the number of nodes affected by the update operation. func (_u *StationShiftUpdate) 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 *StationShiftUpdate) SaveX(ctx context.Context) int { affected, err := _u.Save(ctx) if err != nil { panic(err) } return affected } // Exec executes the query. func (_u *StationShiftUpdate) Exec(ctx context.Context) error { _, err := _u.Save(ctx) return err } // ExecX is like Exec, but panics if an error occurs. func (_u *StationShiftUpdate) 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 *StationShiftUpdate) check() error { if v, ok := _u.mutation.Operator(); ok { if err := stationshift.OperatorValidator(v); err != nil { return &ValidationError{Name: "operator", err: fmt.Errorf(`ent: validator failed for field "StationShift.operator": %w`, err)} } } if v, ok := _u.mutation.Status(); ok { if err := stationshift.StatusValidator(v); err != nil { return &ValidationError{Name: "status", err: fmt.Errorf(`ent: validator failed for field "StationShift.status": %w`, err)} } } if v, ok := _u.mutation.Remark(); ok { if err := stationshift.RemarkValidator(v); err != nil { return &ValidationError{Name: "remark", err: fmt.Errorf(`ent: validator failed for field "StationShift.remark": %w`, err)} } } return nil } // Modify adds a statement modifier for attaching custom logic to the UPDATE statement. func (_u *StationShiftUpdate) Modify(modifiers ...func(u *sql.UpdateBuilder)) *StationShiftUpdate { _u.modifiers = append(_u.modifiers, modifiers...) return _u } func (_u *StationShiftUpdate) sqlSave(ctx context.Context) (_node int, err error) { if err := _u.check(); err != nil { return _node, err } _spec := sqlgraph.NewUpdateSpec(stationshift.Table, stationshift.Columns, sqlgraph.NewFieldSpec(stationshift.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.StationNo(); ok { _spec.SetField(stationshift.FieldStationNo, field.TypeInt, value) } if value, ok := _u.mutation.AddedStationNo(); ok { _spec.AddField(stationshift.FieldStationNo, field.TypeInt, value) } if value, ok := _u.mutation.Operator(); ok { _spec.SetField(stationshift.FieldOperator, field.TypeString, value) } if value, ok := _u.mutation.Status(); ok { _spec.SetField(stationshift.FieldStatus, field.TypeString, value) } if value, ok := _u.mutation.StartAt(); ok { _spec.SetField(stationshift.FieldStartAt, field.TypeInt64, value) } if value, ok := _u.mutation.AddedStartAt(); ok { _spec.AddField(stationshift.FieldStartAt, field.TypeInt64, value) } if value, ok := _u.mutation.EndApplyAt(); ok { _spec.SetField(stationshift.FieldEndApplyAt, field.TypeInt64, value) } if value, ok := _u.mutation.AddedEndApplyAt(); ok { _spec.AddField(stationshift.FieldEndApplyAt, field.TypeInt64, value) } if value, ok := _u.mutation.ClosedAt(); ok { _spec.SetField(stationshift.FieldClosedAt, field.TypeInt64, value) } if value, ok := _u.mutation.AddedClosedAt(); ok { _spec.AddField(stationshift.FieldClosedAt, field.TypeInt64, value) } if value, ok := _u.mutation.Remark(); ok { _spec.SetField(stationshift.FieldRemark, field.TypeString, value) } if _u.mutation.RemarkCleared() { _spec.ClearField(stationshift.FieldRemark, field.TypeString) } _spec.AddModifiers(_u.modifiers...) if _node, err = sqlgraph.UpdateNodes(ctx, _u.driver, _spec); err != nil { if _, ok := err.(*sqlgraph.NotFoundError); ok { err = &NotFoundError{stationshift.Label} } else if sqlgraph.IsConstraintError(err) { err = &ConstraintError{msg: err.Error(), wrap: err} } return 0, err } _u.mutation.done = true return _node, nil } // StationShiftUpdateOne is the builder for updating a single StationShift entity. type StationShiftUpdateOne struct { config fields []string hooks []Hook mutation *StationShiftMutation modifiers []func(*sql.UpdateBuilder) } // SetStationNo sets the "stationNo" field. func (_u *StationShiftUpdateOne) SetStationNo(v int) *StationShiftUpdateOne { _u.mutation.ResetStationNo() _u.mutation.SetStationNo(v) return _u } // SetNillableStationNo sets the "stationNo" field if the given value is not nil. func (_u *StationShiftUpdateOne) SetNillableStationNo(v *int) *StationShiftUpdateOne { if v != nil { _u.SetStationNo(*v) } return _u } // AddStationNo adds value to the "stationNo" field. func (_u *StationShiftUpdateOne) AddStationNo(v int) *StationShiftUpdateOne { _u.mutation.AddStationNo(v) return _u } // SetOperator sets the "operator" field. func (_u *StationShiftUpdateOne) SetOperator(v string) *StationShiftUpdateOne { _u.mutation.SetOperator(v) return _u } // SetNillableOperator sets the "operator" field if the given value is not nil. func (_u *StationShiftUpdateOne) SetNillableOperator(v *string) *StationShiftUpdateOne { if v != nil { _u.SetOperator(*v) } return _u } // SetStatus sets the "status" field. func (_u *StationShiftUpdateOne) SetStatus(v string) *StationShiftUpdateOne { _u.mutation.SetStatus(v) return _u } // SetNillableStatus sets the "status" field if the given value is not nil. func (_u *StationShiftUpdateOne) SetNillableStatus(v *string) *StationShiftUpdateOne { if v != nil { _u.SetStatus(*v) } return _u } // SetStartAt sets the "startAt" field. func (_u *StationShiftUpdateOne) SetStartAt(v int64) *StationShiftUpdateOne { _u.mutation.ResetStartAt() _u.mutation.SetStartAt(v) return _u } // SetNillableStartAt sets the "startAt" field if the given value is not nil. func (_u *StationShiftUpdateOne) SetNillableStartAt(v *int64) *StationShiftUpdateOne { if v != nil { _u.SetStartAt(*v) } return _u } // AddStartAt adds value to the "startAt" field. func (_u *StationShiftUpdateOne) AddStartAt(v int64) *StationShiftUpdateOne { _u.mutation.AddStartAt(v) return _u } // SetEndApplyAt sets the "endApplyAt" field. func (_u *StationShiftUpdateOne) SetEndApplyAt(v int64) *StationShiftUpdateOne { _u.mutation.ResetEndApplyAt() _u.mutation.SetEndApplyAt(v) return _u } // SetNillableEndApplyAt sets the "endApplyAt" field if the given value is not nil. func (_u *StationShiftUpdateOne) SetNillableEndApplyAt(v *int64) *StationShiftUpdateOne { if v != nil { _u.SetEndApplyAt(*v) } return _u } // AddEndApplyAt adds value to the "endApplyAt" field. func (_u *StationShiftUpdateOne) AddEndApplyAt(v int64) *StationShiftUpdateOne { _u.mutation.AddEndApplyAt(v) return _u } // SetClosedAt sets the "closedAt" field. func (_u *StationShiftUpdateOne) SetClosedAt(v int64) *StationShiftUpdateOne { _u.mutation.ResetClosedAt() _u.mutation.SetClosedAt(v) return _u } // SetNillableClosedAt sets the "closedAt" field if the given value is not nil. func (_u *StationShiftUpdateOne) SetNillableClosedAt(v *int64) *StationShiftUpdateOne { if v != nil { _u.SetClosedAt(*v) } return _u } // AddClosedAt adds value to the "closedAt" field. func (_u *StationShiftUpdateOne) AddClosedAt(v int64) *StationShiftUpdateOne { _u.mutation.AddClosedAt(v) return _u } // SetRemark sets the "remark" field. func (_u *StationShiftUpdateOne) SetRemark(v string) *StationShiftUpdateOne { _u.mutation.SetRemark(v) return _u } // SetNillableRemark sets the "remark" field if the given value is not nil. func (_u *StationShiftUpdateOne) SetNillableRemark(v *string) *StationShiftUpdateOne { if v != nil { _u.SetRemark(*v) } return _u } // ClearRemark clears the value of the "remark" field. func (_u *StationShiftUpdateOne) ClearRemark() *StationShiftUpdateOne { _u.mutation.ClearRemark() return _u } // Mutation returns the StationShiftMutation object of the builder. func (_u *StationShiftUpdateOne) Mutation() *StationShiftMutation { return _u.mutation } // Where appends a list predicates to the StationShiftUpdate builder. func (_u *StationShiftUpdateOne) Where(ps ...predicate.StationShift) *StationShiftUpdateOne { _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 *StationShiftUpdateOne) Select(field string, fields ...string) *StationShiftUpdateOne { _u.fields = append([]string{field}, fields...) return _u } // Save executes the query and returns the updated StationShift entity. func (_u *StationShiftUpdateOne) Save(ctx context.Context) (*StationShift, error) { return withHooks(ctx, _u.sqlSave, _u.mutation, _u.hooks) } // SaveX is like Save, but panics if an error occurs. func (_u *StationShiftUpdateOne) SaveX(ctx context.Context) *StationShift { node, err := _u.Save(ctx) if err != nil { panic(err) } return node } // Exec executes the query on the entity. func (_u *StationShiftUpdateOne) Exec(ctx context.Context) error { _, err := _u.Save(ctx) return err } // ExecX is like Exec, but panics if an error occurs. func (_u *StationShiftUpdateOne) 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 *StationShiftUpdateOne) check() error { if v, ok := _u.mutation.Operator(); ok { if err := stationshift.OperatorValidator(v); err != nil { return &ValidationError{Name: "operator", err: fmt.Errorf(`ent: validator failed for field "StationShift.operator": %w`, err)} } } if v, ok := _u.mutation.Status(); ok { if err := stationshift.StatusValidator(v); err != nil { return &ValidationError{Name: "status", err: fmt.Errorf(`ent: validator failed for field "StationShift.status": %w`, err)} } } if v, ok := _u.mutation.Remark(); ok { if err := stationshift.RemarkValidator(v); err != nil { return &ValidationError{Name: "remark", err: fmt.Errorf(`ent: validator failed for field "StationShift.remark": %w`, err)} } } return nil } // Modify adds a statement modifier for attaching custom logic to the UPDATE statement. func (_u *StationShiftUpdateOne) Modify(modifiers ...func(u *sql.UpdateBuilder)) *StationShiftUpdateOne { _u.modifiers = append(_u.modifiers, modifiers...) return _u } func (_u *StationShiftUpdateOne) sqlSave(ctx context.Context) (_node *StationShift, err error) { if err := _u.check(); err != nil { return _node, err } _spec := sqlgraph.NewUpdateSpec(stationshift.Table, stationshift.Columns, sqlgraph.NewFieldSpec(stationshift.FieldID, field.TypeInt)) id, ok := _u.mutation.ID() if !ok { return nil, &ValidationError{Name: "id", err: errors.New(`ent: missing "StationShift.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, stationshift.FieldID) for _, f := range fields { if !stationshift.ValidColumn(f) { return nil, &ValidationError{Name: f, err: fmt.Errorf("ent: invalid field %q for query", f)} } if f != stationshift.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.StationNo(); ok { _spec.SetField(stationshift.FieldStationNo, field.TypeInt, value) } if value, ok := _u.mutation.AddedStationNo(); ok { _spec.AddField(stationshift.FieldStationNo, field.TypeInt, value) } if value, ok := _u.mutation.Operator(); ok { _spec.SetField(stationshift.FieldOperator, field.TypeString, value) } if value, ok := _u.mutation.Status(); ok { _spec.SetField(stationshift.FieldStatus, field.TypeString, value) } if value, ok := _u.mutation.StartAt(); ok { _spec.SetField(stationshift.FieldStartAt, field.TypeInt64, value) } if value, ok := _u.mutation.AddedStartAt(); ok { _spec.AddField(stationshift.FieldStartAt, field.TypeInt64, value) } if value, ok := _u.mutation.EndApplyAt(); ok { _spec.SetField(stationshift.FieldEndApplyAt, field.TypeInt64, value) } if value, ok := _u.mutation.AddedEndApplyAt(); ok { _spec.AddField(stationshift.FieldEndApplyAt, field.TypeInt64, value) } if value, ok := _u.mutation.ClosedAt(); ok { _spec.SetField(stationshift.FieldClosedAt, field.TypeInt64, value) } if value, ok := _u.mutation.AddedClosedAt(); ok { _spec.AddField(stationshift.FieldClosedAt, field.TypeInt64, value) } if value, ok := _u.mutation.Remark(); ok { _spec.SetField(stationshift.FieldRemark, field.TypeString, value) } if _u.mutation.RemarkCleared() { _spec.ClearField(stationshift.FieldRemark, field.TypeString) } _spec.AddModifiers(_u.modifiers...) _node = &StationShift{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{stationshift.Label} } else if sqlgraph.IsConstraintError(err) { err = &ConstraintError{msg: err.Error(), wrap: err} } return nil, err } _u.mutation.done = true return _node, nil }