// Code generated by ent, DO NOT EDIT. package ent import ( "bj_power_mes/ent/flowmaterial" "bj_power_mes/ent/predicate" "context" "errors" "fmt" "entgo.io/ent/dialect/sql" "entgo.io/ent/dialect/sql/sqlgraph" "entgo.io/ent/schema/field" ) // FlowMaterialUpdate is the builder for updating FlowMaterial entities. type FlowMaterialUpdate struct { config hooks []Hook mutation *FlowMaterialMutation modifiers []func(*sql.UpdateBuilder) } // Where appends a list predicates to the FlowMaterialUpdate builder. func (_u *FlowMaterialUpdate) Where(ps ...predicate.FlowMaterial) *FlowMaterialUpdate { _u.mutation.Where(ps...) return _u } // SetFlowId sets the "flowId" field. func (_u *FlowMaterialUpdate) SetFlowId(v int) *FlowMaterialUpdate { _u.mutation.ResetFlowId() _u.mutation.SetFlowId(v) return _u } // SetNillableFlowId sets the "flowId" field if the given value is not nil. func (_u *FlowMaterialUpdate) SetNillableFlowId(v *int) *FlowMaterialUpdate { if v != nil { _u.SetFlowId(*v) } return _u } // AddFlowId adds value to the "flowId" field. func (_u *FlowMaterialUpdate) AddFlowId(v int) *FlowMaterialUpdate { _u.mutation.AddFlowId(v) return _u } // SetMaterialCode sets the "materialCode" field. func (_u *FlowMaterialUpdate) SetMaterialCode(v string) *FlowMaterialUpdate { _u.mutation.SetMaterialCode(v) return _u } // SetNillableMaterialCode sets the "materialCode" field if the given value is not nil. func (_u *FlowMaterialUpdate) SetNillableMaterialCode(v *string) *FlowMaterialUpdate { if v != nil { _u.SetMaterialCode(*v) } return _u } // SetMaterialName sets the "materialName" field. func (_u *FlowMaterialUpdate) SetMaterialName(v string) *FlowMaterialUpdate { _u.mutation.SetMaterialName(v) return _u } // SetNillableMaterialName sets the "materialName" field if the given value is not nil. func (_u *FlowMaterialUpdate) SetNillableMaterialName(v *string) *FlowMaterialUpdate { if v != nil { _u.SetMaterialName(*v) } return _u } // SetSpec sets the "spec" field. func (_u *FlowMaterialUpdate) SetSpec(v string) *FlowMaterialUpdate { _u.mutation.SetSpec(v) return _u } // SetNillableSpec sets the "spec" field if the given value is not nil. func (_u *FlowMaterialUpdate) SetNillableSpec(v *string) *FlowMaterialUpdate { if v != nil { _u.SetSpec(*v) } return _u } // SetUnit sets the "unit" field. func (_u *FlowMaterialUpdate) SetUnit(v string) *FlowMaterialUpdate { _u.mutation.SetUnit(v) return _u } // SetNillableUnit sets the "unit" field if the given value is not nil. func (_u *FlowMaterialUpdate) SetNillableUnit(v *string) *FlowMaterialUpdate { if v != nil { _u.SetUnit(*v) } return _u } // SetManageMode sets the "manageMode" field. func (_u *FlowMaterialUpdate) SetManageMode(v string) *FlowMaterialUpdate { _u.mutation.SetManageMode(v) return _u } // SetNillableManageMode sets the "manageMode" field if the given value is not nil. func (_u *FlowMaterialUpdate) SetNillableManageMode(v *string) *FlowMaterialUpdate { if v != nil { _u.SetManageMode(*v) } return _u } // SetUnitQty sets the "unitQty" field. func (_u *FlowMaterialUpdate) SetUnitQty(v float64) *FlowMaterialUpdate { _u.mutation.ResetUnitQty() _u.mutation.SetUnitQty(v) return _u } // SetNillableUnitQty sets the "unitQty" field if the given value is not nil. func (_u *FlowMaterialUpdate) SetNillableUnitQty(v *float64) *FlowMaterialUpdate { if v != nil { _u.SetUnitQty(*v) } return _u } // AddUnitQty adds value to the "unitQty" field. func (_u *FlowMaterialUpdate) AddUnitQty(v float64) *FlowMaterialUpdate { _u.mutation.AddUnitQty(v) return _u } // SetLossRate sets the "lossRate" field. func (_u *FlowMaterialUpdate) SetLossRate(v float64) *FlowMaterialUpdate { _u.mutation.ResetLossRate() _u.mutation.SetLossRate(v) return _u } // SetNillableLossRate sets the "lossRate" field if the given value is not nil. func (_u *FlowMaterialUpdate) SetNillableLossRate(v *float64) *FlowMaterialUpdate { if v != nil { _u.SetLossRate(*v) } return _u } // AddLossRate adds value to the "lossRate" field. func (_u *FlowMaterialUpdate) AddLossRate(v float64) *FlowMaterialUpdate { _u.mutation.AddLossRate(v) return _u } // Mutation returns the FlowMaterialMutation object of the builder. func (_u *FlowMaterialUpdate) Mutation() *FlowMaterialMutation { return _u.mutation } // Save executes the query and returns the number of nodes affected by the update operation. func (_u *FlowMaterialUpdate) 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 *FlowMaterialUpdate) SaveX(ctx context.Context) int { affected, err := _u.Save(ctx) if err != nil { panic(err) } return affected } // Exec executes the query. func (_u *FlowMaterialUpdate) Exec(ctx context.Context) error { _, err := _u.Save(ctx) return err } // ExecX is like Exec, but panics if an error occurs. func (_u *FlowMaterialUpdate) 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 *FlowMaterialUpdate) check() error { if v, ok := _u.mutation.MaterialCode(); ok { if err := flowmaterial.MaterialCodeValidator(v); err != nil { return &ValidationError{Name: "materialCode", err: fmt.Errorf(`ent: validator failed for field "FlowMaterial.materialCode": %w`, err)} } } if v, ok := _u.mutation.MaterialName(); ok { if err := flowmaterial.MaterialNameValidator(v); err != nil { return &ValidationError{Name: "materialName", err: fmt.Errorf(`ent: validator failed for field "FlowMaterial.materialName": %w`, err)} } } if v, ok := _u.mutation.Spec(); ok { if err := flowmaterial.SpecValidator(v); err != nil { return &ValidationError{Name: "spec", err: fmt.Errorf(`ent: validator failed for field "FlowMaterial.spec": %w`, err)} } } if v, ok := _u.mutation.Unit(); ok { if err := flowmaterial.UnitValidator(v); err != nil { return &ValidationError{Name: "unit", err: fmt.Errorf(`ent: validator failed for field "FlowMaterial.unit": %w`, err)} } } if v, ok := _u.mutation.ManageMode(); ok { if err := flowmaterial.ManageModeValidator(v); err != nil { return &ValidationError{Name: "manageMode", err: fmt.Errorf(`ent: validator failed for field "FlowMaterial.manageMode": %w`, err)} } } return nil } // Modify adds a statement modifier for attaching custom logic to the UPDATE statement. func (_u *FlowMaterialUpdate) Modify(modifiers ...func(u *sql.UpdateBuilder)) *FlowMaterialUpdate { _u.modifiers = append(_u.modifiers, modifiers...) return _u } func (_u *FlowMaterialUpdate) sqlSave(ctx context.Context) (_node int, err error) { if err := _u.check(); err != nil { return _node, err } _spec := sqlgraph.NewUpdateSpec(flowmaterial.Table, flowmaterial.Columns, sqlgraph.NewFieldSpec(flowmaterial.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.FlowId(); ok { _spec.SetField(flowmaterial.FieldFlowId, field.TypeInt, value) } if value, ok := _u.mutation.AddedFlowId(); ok { _spec.AddField(flowmaterial.FieldFlowId, field.TypeInt, value) } if value, ok := _u.mutation.MaterialCode(); ok { _spec.SetField(flowmaterial.FieldMaterialCode, field.TypeString, value) } if value, ok := _u.mutation.MaterialName(); ok { _spec.SetField(flowmaterial.FieldMaterialName, field.TypeString, value) } if value, ok := _u.mutation.Spec(); ok { _spec.SetField(flowmaterial.FieldSpec, field.TypeString, value) } if value, ok := _u.mutation.Unit(); ok { _spec.SetField(flowmaterial.FieldUnit, field.TypeString, value) } if value, ok := _u.mutation.ManageMode(); ok { _spec.SetField(flowmaterial.FieldManageMode, field.TypeString, value) } if value, ok := _u.mutation.UnitQty(); ok { _spec.SetField(flowmaterial.FieldUnitQty, field.TypeFloat64, value) } if value, ok := _u.mutation.AddedUnitQty(); ok { _spec.AddField(flowmaterial.FieldUnitQty, field.TypeFloat64, value) } if value, ok := _u.mutation.LossRate(); ok { _spec.SetField(flowmaterial.FieldLossRate, field.TypeFloat64, value) } if value, ok := _u.mutation.AddedLossRate(); ok { _spec.AddField(flowmaterial.FieldLossRate, field.TypeFloat64, value) } _spec.AddModifiers(_u.modifiers...) if _node, err = sqlgraph.UpdateNodes(ctx, _u.driver, _spec); err != nil { if _, ok := err.(*sqlgraph.NotFoundError); ok { err = &NotFoundError{flowmaterial.Label} } else if sqlgraph.IsConstraintError(err) { err = &ConstraintError{msg: err.Error(), wrap: err} } return 0, err } _u.mutation.done = true return _node, nil } // FlowMaterialUpdateOne is the builder for updating a single FlowMaterial entity. type FlowMaterialUpdateOne struct { config fields []string hooks []Hook mutation *FlowMaterialMutation modifiers []func(*sql.UpdateBuilder) } // SetFlowId sets the "flowId" field. func (_u *FlowMaterialUpdateOne) SetFlowId(v int) *FlowMaterialUpdateOne { _u.mutation.ResetFlowId() _u.mutation.SetFlowId(v) return _u } // SetNillableFlowId sets the "flowId" field if the given value is not nil. func (_u *FlowMaterialUpdateOne) SetNillableFlowId(v *int) *FlowMaterialUpdateOne { if v != nil { _u.SetFlowId(*v) } return _u } // AddFlowId adds value to the "flowId" field. func (_u *FlowMaterialUpdateOne) AddFlowId(v int) *FlowMaterialUpdateOne { _u.mutation.AddFlowId(v) return _u } // SetMaterialCode sets the "materialCode" field. func (_u *FlowMaterialUpdateOne) SetMaterialCode(v string) *FlowMaterialUpdateOne { _u.mutation.SetMaterialCode(v) return _u } // SetNillableMaterialCode sets the "materialCode" field if the given value is not nil. func (_u *FlowMaterialUpdateOne) SetNillableMaterialCode(v *string) *FlowMaterialUpdateOne { if v != nil { _u.SetMaterialCode(*v) } return _u } // SetMaterialName sets the "materialName" field. func (_u *FlowMaterialUpdateOne) SetMaterialName(v string) *FlowMaterialUpdateOne { _u.mutation.SetMaterialName(v) return _u } // SetNillableMaterialName sets the "materialName" field if the given value is not nil. func (_u *FlowMaterialUpdateOne) SetNillableMaterialName(v *string) *FlowMaterialUpdateOne { if v != nil { _u.SetMaterialName(*v) } return _u } // SetSpec sets the "spec" field. func (_u *FlowMaterialUpdateOne) SetSpec(v string) *FlowMaterialUpdateOne { _u.mutation.SetSpec(v) return _u } // SetNillableSpec sets the "spec" field if the given value is not nil. func (_u *FlowMaterialUpdateOne) SetNillableSpec(v *string) *FlowMaterialUpdateOne { if v != nil { _u.SetSpec(*v) } return _u } // SetUnit sets the "unit" field. func (_u *FlowMaterialUpdateOne) SetUnit(v string) *FlowMaterialUpdateOne { _u.mutation.SetUnit(v) return _u } // SetNillableUnit sets the "unit" field if the given value is not nil. func (_u *FlowMaterialUpdateOne) SetNillableUnit(v *string) *FlowMaterialUpdateOne { if v != nil { _u.SetUnit(*v) } return _u } // SetManageMode sets the "manageMode" field. func (_u *FlowMaterialUpdateOne) SetManageMode(v string) *FlowMaterialUpdateOne { _u.mutation.SetManageMode(v) return _u } // SetNillableManageMode sets the "manageMode" field if the given value is not nil. func (_u *FlowMaterialUpdateOne) SetNillableManageMode(v *string) *FlowMaterialUpdateOne { if v != nil { _u.SetManageMode(*v) } return _u } // SetUnitQty sets the "unitQty" field. func (_u *FlowMaterialUpdateOne) SetUnitQty(v float64) *FlowMaterialUpdateOne { _u.mutation.ResetUnitQty() _u.mutation.SetUnitQty(v) return _u } // SetNillableUnitQty sets the "unitQty" field if the given value is not nil. func (_u *FlowMaterialUpdateOne) SetNillableUnitQty(v *float64) *FlowMaterialUpdateOne { if v != nil { _u.SetUnitQty(*v) } return _u } // AddUnitQty adds value to the "unitQty" field. func (_u *FlowMaterialUpdateOne) AddUnitQty(v float64) *FlowMaterialUpdateOne { _u.mutation.AddUnitQty(v) return _u } // SetLossRate sets the "lossRate" field. func (_u *FlowMaterialUpdateOne) SetLossRate(v float64) *FlowMaterialUpdateOne { _u.mutation.ResetLossRate() _u.mutation.SetLossRate(v) return _u } // SetNillableLossRate sets the "lossRate" field if the given value is not nil. func (_u *FlowMaterialUpdateOne) SetNillableLossRate(v *float64) *FlowMaterialUpdateOne { if v != nil { _u.SetLossRate(*v) } return _u } // AddLossRate adds value to the "lossRate" field. func (_u *FlowMaterialUpdateOne) AddLossRate(v float64) *FlowMaterialUpdateOne { _u.mutation.AddLossRate(v) return _u } // Mutation returns the FlowMaterialMutation object of the builder. func (_u *FlowMaterialUpdateOne) Mutation() *FlowMaterialMutation { return _u.mutation } // Where appends a list predicates to the FlowMaterialUpdate builder. func (_u *FlowMaterialUpdateOne) Where(ps ...predicate.FlowMaterial) *FlowMaterialUpdateOne { _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 *FlowMaterialUpdateOne) Select(field string, fields ...string) *FlowMaterialUpdateOne { _u.fields = append([]string{field}, fields...) return _u } // Save executes the query and returns the updated FlowMaterial entity. func (_u *FlowMaterialUpdateOne) Save(ctx context.Context) (*FlowMaterial, error) { return withHooks(ctx, _u.sqlSave, _u.mutation, _u.hooks) } // SaveX is like Save, but panics if an error occurs. func (_u *FlowMaterialUpdateOne) SaveX(ctx context.Context) *FlowMaterial { node, err := _u.Save(ctx) if err != nil { panic(err) } return node } // Exec executes the query on the entity. func (_u *FlowMaterialUpdateOne) Exec(ctx context.Context) error { _, err := _u.Save(ctx) return err } // ExecX is like Exec, but panics if an error occurs. func (_u *FlowMaterialUpdateOne) 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 *FlowMaterialUpdateOne) check() error { if v, ok := _u.mutation.MaterialCode(); ok { if err := flowmaterial.MaterialCodeValidator(v); err != nil { return &ValidationError{Name: "materialCode", err: fmt.Errorf(`ent: validator failed for field "FlowMaterial.materialCode": %w`, err)} } } if v, ok := _u.mutation.MaterialName(); ok { if err := flowmaterial.MaterialNameValidator(v); err != nil { return &ValidationError{Name: "materialName", err: fmt.Errorf(`ent: validator failed for field "FlowMaterial.materialName": %w`, err)} } } if v, ok := _u.mutation.Spec(); ok { if err := flowmaterial.SpecValidator(v); err != nil { return &ValidationError{Name: "spec", err: fmt.Errorf(`ent: validator failed for field "FlowMaterial.spec": %w`, err)} } } if v, ok := _u.mutation.Unit(); ok { if err := flowmaterial.UnitValidator(v); err != nil { return &ValidationError{Name: "unit", err: fmt.Errorf(`ent: validator failed for field "FlowMaterial.unit": %w`, err)} } } if v, ok := _u.mutation.ManageMode(); ok { if err := flowmaterial.ManageModeValidator(v); err != nil { return &ValidationError{Name: "manageMode", err: fmt.Errorf(`ent: validator failed for field "FlowMaterial.manageMode": %w`, err)} } } return nil } // Modify adds a statement modifier for attaching custom logic to the UPDATE statement. func (_u *FlowMaterialUpdateOne) Modify(modifiers ...func(u *sql.UpdateBuilder)) *FlowMaterialUpdateOne { _u.modifiers = append(_u.modifiers, modifiers...) return _u } func (_u *FlowMaterialUpdateOne) sqlSave(ctx context.Context) (_node *FlowMaterial, err error) { if err := _u.check(); err != nil { return _node, err } _spec := sqlgraph.NewUpdateSpec(flowmaterial.Table, flowmaterial.Columns, sqlgraph.NewFieldSpec(flowmaterial.FieldID, field.TypeInt)) id, ok := _u.mutation.ID() if !ok { return nil, &ValidationError{Name: "id", err: errors.New(`ent: missing "FlowMaterial.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, flowmaterial.FieldID) for _, f := range fields { if !flowmaterial.ValidColumn(f) { return nil, &ValidationError{Name: f, err: fmt.Errorf("ent: invalid field %q for query", f)} } if f != flowmaterial.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.FlowId(); ok { _spec.SetField(flowmaterial.FieldFlowId, field.TypeInt, value) } if value, ok := _u.mutation.AddedFlowId(); ok { _spec.AddField(flowmaterial.FieldFlowId, field.TypeInt, value) } if value, ok := _u.mutation.MaterialCode(); ok { _spec.SetField(flowmaterial.FieldMaterialCode, field.TypeString, value) } if value, ok := _u.mutation.MaterialName(); ok { _spec.SetField(flowmaterial.FieldMaterialName, field.TypeString, value) } if value, ok := _u.mutation.Spec(); ok { _spec.SetField(flowmaterial.FieldSpec, field.TypeString, value) } if value, ok := _u.mutation.Unit(); ok { _spec.SetField(flowmaterial.FieldUnit, field.TypeString, value) } if value, ok := _u.mutation.ManageMode(); ok { _spec.SetField(flowmaterial.FieldManageMode, field.TypeString, value) } if value, ok := _u.mutation.UnitQty(); ok { _spec.SetField(flowmaterial.FieldUnitQty, field.TypeFloat64, value) } if value, ok := _u.mutation.AddedUnitQty(); ok { _spec.AddField(flowmaterial.FieldUnitQty, field.TypeFloat64, value) } if value, ok := _u.mutation.LossRate(); ok { _spec.SetField(flowmaterial.FieldLossRate, field.TypeFloat64, value) } if value, ok := _u.mutation.AddedLossRate(); ok { _spec.AddField(flowmaterial.FieldLossRate, field.TypeFloat64, value) } _spec.AddModifiers(_u.modifiers...) _node = &FlowMaterial{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{flowmaterial.Label} } else if sqlgraph.IsConstraintError(err) { err = &ConstraintError{msg: err.Error(), wrap: err} } return nil, err } _u.mutation.done = true return _node, nil }