592 lines
17 KiB
Go
592 lines
17 KiB
Go
// Code generated by ent, DO NOT EDIT.
|
|||
|
|
|
||
|
|
package ent
|
||
|
|
|
||
|
|
import (
|
||
|
|
"bj_power_mes/ent/predicate"
|
||
|
|
"bj_power_mes/ent/stepcriterion"
|
||
|
|
"context"
|
||
|
|
"errors"
|
||
|
|
"fmt"
|
||
|
|
|
||
|
|
"entgo.io/ent/dialect/sql"
|
||
|
|
"entgo.io/ent/dialect/sql/sqlgraph"
|
||
|
|
"entgo.io/ent/schema/field"
|
||
|
|
)
|
||
|
|
|
||
|
|
// StepCriterionUpdate is the builder for updating StepCriterion entities.
|
||
|
|
type StepCriterionUpdate struct {
|
||
|
|
config
|
||
|
|
hooks []Hook
|
||
|
|
mutation *StepCriterionMutation
|
||
|
|
modifiers []func(*sql.UpdateBuilder)
|
||
|
|
}
|
||
|
|
|
||
|
|
// Where appends a list predicates to the StepCriterionUpdate builder.
|
||
|
|
func (_u *StepCriterionUpdate) Where(ps ...predicate.StepCriterion) *StepCriterionUpdate {
|
||
|
|
_u.mutation.Where(ps...)
|
||
|
|
return _u
|
||
|
|
}
|
||
|
|
|
||
|
|
// SetStepId sets the "stepId" field.
|
||
|
|
func (_u *StepCriterionUpdate) SetStepId(v int) *StepCriterionUpdate {
|
||
|
|
_u.mutation.ResetStepId()
|
||
|
|
_u.mutation.SetStepId(v)
|
||
|
|
return _u
|
||
|
|
}
|
||
|
|
|
||
|
|
// SetNillableStepId sets the "stepId" field if the given value is not nil.
|
||
|
|
func (_u *StepCriterionUpdate) SetNillableStepId(v *int) *StepCriterionUpdate {
|
||
|
|
if v != nil {
|
||
|
|
_u.SetStepId(*v)
|
||
|
|
}
|
||
|
|
return _u
|
||
|
|
}
|
||
|
|
|
||
|
|
// AddStepId adds value to the "stepId" field.
|
||
|
|
func (_u *StepCriterionUpdate) AddStepId(v int) *StepCriterionUpdate {
|
||
|
|
_u.mutation.AddStepId(v)
|
||
|
|
return _u
|
||
|
|
}
|
||
|
|
|
||
|
|
// SetName sets the "name" field.
|
||
|
|
func (_u *StepCriterionUpdate) SetName(v string) *StepCriterionUpdate {
|
||
|
|
_u.mutation.SetName(v)
|
||
|
|
return _u
|
||
|
|
}
|
||
|
|
|
||
|
|
// SetNillableName sets the "name" field if the given value is not nil.
|
||
|
|
func (_u *StepCriterionUpdate) SetNillableName(v *string) *StepCriterionUpdate {
|
||
|
|
if v != nil {
|
||
|
|
_u.SetName(*v)
|
||
|
|
}
|
||
|
|
return _u
|
||
|
|
}
|
||
|
|
|
||
|
|
// SetUnit sets the "unit" field.
|
||
|
|
func (_u *StepCriterionUpdate) SetUnit(v string) *StepCriterionUpdate {
|
||
|
|
_u.mutation.SetUnit(v)
|
||
|
|
return _u
|
||
|
|
}
|
||
|
|
|
||
|
|
// SetNillableUnit sets the "unit" field if the given value is not nil.
|
||
|
|
func (_u *StepCriterionUpdate) SetNillableUnit(v *string) *StepCriterionUpdate {
|
||
|
|
if v != nil {
|
||
|
|
_u.SetUnit(*v)
|
||
|
|
}
|
||
|
|
return _u
|
||
|
|
}
|
||
|
|
|
||
|
|
// SetLogic sets the "logic" field.
|
||
|
|
func (_u *StepCriterionUpdate) SetLogic(v string) *StepCriterionUpdate {
|
||
|
|
_u.mutation.SetLogic(v)
|
||
|
|
return _u
|
||
|
|
}
|
||
|
|
|
||
|
|
// SetNillableLogic sets the "logic" field if the given value is not nil.
|
||
|
|
func (_u *StepCriterionUpdate) SetNillableLogic(v *string) *StepCriterionUpdate {
|
||
|
|
if v != nil {
|
||
|
|
_u.SetLogic(*v)
|
||
|
|
}
|
||
|
|
return _u
|
||
|
|
}
|
||
|
|
|
||
|
|
// SetTarget sets the "target" field.
|
||
|
|
func (_u *StepCriterionUpdate) SetTarget(v float64) *StepCriterionUpdate {
|
||
|
|
_u.mutation.ResetTarget()
|
||
|
|
_u.mutation.SetTarget(v)
|
||
|
|
return _u
|
||
|
|
}
|
||
|
|
|
||
|
|
// SetNillableTarget sets the "target" field if the given value is not nil.
|
||
|
|
func (_u *StepCriterionUpdate) SetNillableTarget(v *float64) *StepCriterionUpdate {
|
||
|
|
if v != nil {
|
||
|
|
_u.SetTarget(*v)
|
||
|
|
}
|
||
|
|
return _u
|
||
|
|
}
|
||
|
|
|
||
|
|
// AddTarget adds value to the "target" field.
|
||
|
|
func (_u *StepCriterionUpdate) AddTarget(v float64) *StepCriterionUpdate {
|
||
|
|
_u.mutation.AddTarget(v)
|
||
|
|
return _u
|
||
|
|
}
|
||
|
|
|
||
|
|
// SetMin sets the "min" field.
|
||
|
|
func (_u *StepCriterionUpdate) SetMin(v float64) *StepCriterionUpdate {
|
||
|
|
_u.mutation.ResetMin()
|
||
|
|
_u.mutation.SetMin(v)
|
||
|
|
return _u
|
||
|
|
}
|
||
|
|
|
||
|
|
// SetNillableMin sets the "min" field if the given value is not nil.
|
||
|
|
func (_u *StepCriterionUpdate) SetNillableMin(v *float64) *StepCriterionUpdate {
|
||
|
|
if v != nil {
|
||
|
|
_u.SetMin(*v)
|
||
|
|
}
|
||
|
|
return _u
|
||
|
|
}
|
||
|
|
|
||
|
|
// AddMin adds value to the "min" field.
|
||
|
|
func (_u *StepCriterionUpdate) AddMin(v float64) *StepCriterionUpdate {
|
||
|
|
_u.mutation.AddMin(v)
|
||
|
|
return _u
|
||
|
|
}
|
||
|
|
|
||
|
|
// ClearMin clears the value of the "min" field.
|
||
|
|
func (_u *StepCriterionUpdate) ClearMin() *StepCriterionUpdate {
|
||
|
|
_u.mutation.ClearMin()
|
||
|
|
return _u
|
||
|
|
}
|
||
|
|
|
||
|
|
// SetMax sets the "max" field.
|
||
|
|
func (_u *StepCriterionUpdate) SetMax(v float64) *StepCriterionUpdate {
|
||
|
|
_u.mutation.ResetMax()
|
||
|
|
_u.mutation.SetMax(v)
|
||
|
|
return _u
|
||
|
|
}
|
||
|
|
|
||
|
|
// SetNillableMax sets the "max" field if the given value is not nil.
|
||
|
|
func (_u *StepCriterionUpdate) SetNillableMax(v *float64) *StepCriterionUpdate {
|
||
|
|
if v != nil {
|
||
|
|
_u.SetMax(*v)
|
||
|
|
}
|
||
|
|
return _u
|
||
|
|
}
|
||
|
|
|
||
|
|
// AddMax adds value to the "max" field.
|
||
|
|
func (_u *StepCriterionUpdate) AddMax(v float64) *StepCriterionUpdate {
|
||
|
|
_u.mutation.AddMax(v)
|
||
|
|
return _u
|
||
|
|
}
|
||
|
|
|
||
|
|
// ClearMax clears the value of the "max" field.
|
||
|
|
func (_u *StepCriterionUpdate) ClearMax() *StepCriterionUpdate {
|
||
|
|
_u.mutation.ClearMax()
|
||
|
|
return _u
|
||
|
|
}
|
||
|
|
|
||
|
|
// Mutation returns the StepCriterionMutation object of the builder.
|
||
|
|
func (_u *StepCriterionUpdate) Mutation() *StepCriterionMutation {
|
||
|
|
return _u.mutation
|
||
|
|
}
|
||
|
|
|
||
|
|
// Save executes the query and returns the number of nodes affected by the update operation.
|
||
|
|
func (_u *StepCriterionUpdate) 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 *StepCriterionUpdate) SaveX(ctx context.Context) int {
|
||
|
|
affected, err := _u.Save(ctx)
|
||
|
|
if err != nil {
|
||
|
|
panic(err)
|
||
|
|
}
|
||
|
|
return affected
|
||
|
|
}
|
||
|
|
|
||
|
|
// Exec executes the query.
|
||
|
|
func (_u *StepCriterionUpdate) Exec(ctx context.Context) error {
|
||
|
|
_, err := _u.Save(ctx)
|
||
|
|
return err
|
||
|
|
}
|
||
|
|
|
||
|
|
// ExecX is like Exec, but panics if an error occurs.
|
||
|
|
func (_u *StepCriterionUpdate) 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 *StepCriterionUpdate) check() error {
|
||
|
|
if v, ok := _u.mutation.Name(); ok {
|
||
|
|
if err := stepcriterion.NameValidator(v); err != nil {
|
||
|
|
return &ValidationError{Name: "name", err: fmt.Errorf(`ent: validator failed for field "StepCriterion.name": %w`, err)}
|
||
|
|
}
|
||
|
|
}
|
||
|
|
if v, ok := _u.mutation.Unit(); ok {
|
||
|
|
if err := stepcriterion.UnitValidator(v); err != nil {
|
||
|
|
return &ValidationError{Name: "unit", err: fmt.Errorf(`ent: validator failed for field "StepCriterion.unit": %w`, err)}
|
||
|
|
}
|
||
|
|
}
|
||
|
|
if v, ok := _u.mutation.Logic(); ok {
|
||
|
|
if err := stepcriterion.LogicValidator(v); err != nil {
|
||
|
|
return &ValidationError{Name: "logic", err: fmt.Errorf(`ent: validator failed for field "StepCriterion.logic": %w`, err)}
|
||
|
|
}
|
||
|
|
}
|
||
|
|
return nil
|
||
|
|
}
|
||
|
|
|
||
|
|
// Modify adds a statement modifier for attaching custom logic to the UPDATE statement.
|
||
|
|
func (_u *StepCriterionUpdate) Modify(modifiers ...func(u *sql.UpdateBuilder)) *StepCriterionUpdate {
|
||
|
|
_u.modifiers = append(_u.modifiers, modifiers...)
|
||
|
|
return _u
|
||
|
|
}
|
||
|
|
|
||
|
|
func (_u *StepCriterionUpdate) sqlSave(ctx context.Context) (_node int, err error) {
|
||
|
|
if err := _u.check(); err != nil {
|
||
|
|
return _node, err
|
||
|
|
}
|
||
|
|
_spec := sqlgraph.NewUpdateSpec(stepcriterion.Table, stepcriterion.Columns, sqlgraph.NewFieldSpec(stepcriterion.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.StepId(); ok {
|
||
|
|
_spec.SetField(stepcriterion.FieldStepId, field.TypeInt, value)
|
||
|
|
}
|
||
|
|
if value, ok := _u.mutation.AddedStepId(); ok {
|
||
|
|
_spec.AddField(stepcriterion.FieldStepId, field.TypeInt, value)
|
||
|
|
}
|
||
|
|
if value, ok := _u.mutation.Name(); ok {
|
||
|
|
_spec.SetField(stepcriterion.FieldName, field.TypeString, value)
|
||
|
|
}
|
||
|
|
if value, ok := _u.mutation.Unit(); ok {
|
||
|
|
_spec.SetField(stepcriterion.FieldUnit, field.TypeString, value)
|
||
|
|
}
|
||
|
|
if value, ok := _u.mutation.Logic(); ok {
|
||
|
|
_spec.SetField(stepcriterion.FieldLogic, field.TypeString, value)
|
||
|
|
}
|
||
|
|
if value, ok := _u.mutation.Target(); ok {
|
||
|
|
_spec.SetField(stepcriterion.FieldTarget, field.TypeFloat64, value)
|
||
|
|
}
|
||
|
|
if value, ok := _u.mutation.AddedTarget(); ok {
|
||
|
|
_spec.AddField(stepcriterion.FieldTarget, field.TypeFloat64, value)
|
||
|
|
}
|
||
|
|
if value, ok := _u.mutation.Min(); ok {
|
||
|
|
_spec.SetField(stepcriterion.FieldMin, field.TypeFloat64, value)
|
||
|
|
}
|
||
|
|
if value, ok := _u.mutation.AddedMin(); ok {
|
||
|
|
_spec.AddField(stepcriterion.FieldMin, field.TypeFloat64, value)
|
||
|
|
}
|
||
|
|
if _u.mutation.MinCleared() {
|
||
|
|
_spec.ClearField(stepcriterion.FieldMin, field.TypeFloat64)
|
||
|
|
}
|
||
|
|
if value, ok := _u.mutation.Max(); ok {
|
||
|
|
_spec.SetField(stepcriterion.FieldMax, field.TypeFloat64, value)
|
||
|
|
}
|
||
|
|
if value, ok := _u.mutation.AddedMax(); ok {
|
||
|
|
_spec.AddField(stepcriterion.FieldMax, field.TypeFloat64, value)
|
||
|
|
}
|
||
|
|
if _u.mutation.MaxCleared() {
|
||
|
|
_spec.ClearField(stepcriterion.FieldMax, field.TypeFloat64)
|
||
|
|
}
|
||
|
|
_spec.AddModifiers(_u.modifiers...)
|
||
|
|
if _node, err = sqlgraph.UpdateNodes(ctx, _u.driver, _spec); err != nil {
|
||
|
|
if _, ok := err.(*sqlgraph.NotFoundError); ok {
|
||
|
|
err = &NotFoundError{stepcriterion.Label}
|
||
|
|
} else if sqlgraph.IsConstraintError(err) {
|
||
|
|
err = &ConstraintError{msg: err.Error(), wrap: err}
|
||
|
|
}
|
||
|
|
return 0, err
|
||
|
|
}
|
||
|
|
_u.mutation.done = true
|
||
|
|
return _node, nil
|
||
|
|
}
|
||
|
|
|
||
|
|
// StepCriterionUpdateOne is the builder for updating a single StepCriterion entity.
|
||
|
|
type StepCriterionUpdateOne struct {
|
||
|
|
config
|
||
|
|
fields []string
|
||
|
|
hooks []Hook
|
||
|
|
mutation *StepCriterionMutation
|
||
|
|
modifiers []func(*sql.UpdateBuilder)
|
||
|
|
}
|
||
|
|
|
||
|
|
// SetStepId sets the "stepId" field.
|
||
|
|
func (_u *StepCriterionUpdateOne) SetStepId(v int) *StepCriterionUpdateOne {
|
||
|
|
_u.mutation.ResetStepId()
|
||
|
|
_u.mutation.SetStepId(v)
|
||
|
|
return _u
|
||
|
|
}
|
||
|
|
|
||
|
|
// SetNillableStepId sets the "stepId" field if the given value is not nil.
|
||
|
|
func (_u *StepCriterionUpdateOne) SetNillableStepId(v *int) *StepCriterionUpdateOne {
|
||
|
|
if v != nil {
|
||
|
|
_u.SetStepId(*v)
|
||
|
|
}
|
||
|
|
return _u
|
||
|
|
}
|
||
|
|
|
||
|
|
// AddStepId adds value to the "stepId" field.
|
||
|
|
func (_u *StepCriterionUpdateOne) AddStepId(v int) *StepCriterionUpdateOne {
|
||
|
|
_u.mutation.AddStepId(v)
|
||
|
|
return _u
|
||
|
|
}
|
||
|
|
|
||
|
|
// SetName sets the "name" field.
|
||
|
|
func (_u *StepCriterionUpdateOne) SetName(v string) *StepCriterionUpdateOne {
|
||
|
|
_u.mutation.SetName(v)
|
||
|
|
return _u
|
||
|
|
}
|
||
|
|
|
||
|
|
// SetNillableName sets the "name" field if the given value is not nil.
|
||
|
|
func (_u *StepCriterionUpdateOne) SetNillableName(v *string) *StepCriterionUpdateOne {
|
||
|
|
if v != nil {
|
||
|
|
_u.SetName(*v)
|
||
|
|
}
|
||
|
|
return _u
|
||
|
|
}
|
||
|
|
|
||
|
|
// SetUnit sets the "unit" field.
|
||
|
|
func (_u *StepCriterionUpdateOne) SetUnit(v string) *StepCriterionUpdateOne {
|
||
|
|
_u.mutation.SetUnit(v)
|
||
|
|
return _u
|
||
|
|
}
|
||
|
|
|
||
|
|
// SetNillableUnit sets the "unit" field if the given value is not nil.
|
||
|
|
func (_u *StepCriterionUpdateOne) SetNillableUnit(v *string) *StepCriterionUpdateOne {
|
||
|
|
if v != nil {
|
||
|
|
_u.SetUnit(*v)
|
||
|
|
}
|
||
|
|
return _u
|
||
|
|
}
|
||
|
|
|
||
|
|
// SetLogic sets the "logic" field.
|
||
|
|
func (_u *StepCriterionUpdateOne) SetLogic(v string) *StepCriterionUpdateOne {
|
||
|
|
_u.mutation.SetLogic(v)
|
||
|
|
return _u
|
||
|
|
}
|
||
|
|
|
||
|
|
// SetNillableLogic sets the "logic" field if the given value is not nil.
|
||
|
|
func (_u *StepCriterionUpdateOne) SetNillableLogic(v *string) *StepCriterionUpdateOne {
|
||
|
|
if v != nil {
|
||
|
|
_u.SetLogic(*v)
|
||
|
|
}
|
||
|
|
return _u
|
||
|
|
}
|
||
|
|
|
||
|
|
// SetTarget sets the "target" field.
|
||
|
|
func (_u *StepCriterionUpdateOne) SetTarget(v float64) *StepCriterionUpdateOne {
|
||
|
|
_u.mutation.ResetTarget()
|
||
|
|
_u.mutation.SetTarget(v)
|
||
|
|
return _u
|
||
|
|
}
|
||
|
|
|
||
|
|
// SetNillableTarget sets the "target" field if the given value is not nil.
|
||
|
|
func (_u *StepCriterionUpdateOne) SetNillableTarget(v *float64) *StepCriterionUpdateOne {
|
||
|
|
if v != nil {
|
||
|
|
_u.SetTarget(*v)
|
||
|
|
}
|
||
|
|
return _u
|
||
|
|
}
|
||
|
|
|
||
|
|
// AddTarget adds value to the "target" field.
|
||
|
|
func (_u *StepCriterionUpdateOne) AddTarget(v float64) *StepCriterionUpdateOne {
|
||
|
|
_u.mutation.AddTarget(v)
|
||
|
|
return _u
|
||
|
|
}
|
||
|
|
|
||
|
|
// SetMin sets the "min" field.
|
||
|
|
func (_u *StepCriterionUpdateOne) SetMin(v float64) *StepCriterionUpdateOne {
|
||
|
|
_u.mutation.ResetMin()
|
||
|
|
_u.mutation.SetMin(v)
|
||
|
|
return _u
|
||
|
|
}
|
||
|
|
|
||
|
|
// SetNillableMin sets the "min" field if the given value is not nil.
|
||
|
|
func (_u *StepCriterionUpdateOne) SetNillableMin(v *float64) *StepCriterionUpdateOne {
|
||
|
|
if v != nil {
|
||
|
|
_u.SetMin(*v)
|
||
|
|
}
|
||
|
|
return _u
|
||
|
|
}
|
||
|
|
|
||
|
|
// AddMin adds value to the "min" field.
|
||
|
|
func (_u *StepCriterionUpdateOne) AddMin(v float64) *StepCriterionUpdateOne {
|
||
|
|
_u.mutation.AddMin(v)
|
||
|
|
return _u
|
||
|
|
}
|
||
|
|
|
||
|
|
// ClearMin clears the value of the "min" field.
|
||
|
|
func (_u *StepCriterionUpdateOne) ClearMin() *StepCriterionUpdateOne {
|
||
|
|
_u.mutation.ClearMin()
|
||
|
|
return _u
|
||
|
|
}
|
||
|
|
|
||
|
|
// SetMax sets the "max" field.
|
||
|
|
func (_u *StepCriterionUpdateOne) SetMax(v float64) *StepCriterionUpdateOne {
|
||
|
|
_u.mutation.ResetMax()
|
||
|
|
_u.mutation.SetMax(v)
|
||
|
|
return _u
|
||
|
|
}
|
||
|
|
|
||
|
|
// SetNillableMax sets the "max" field if the given value is not nil.
|
||
|
|
func (_u *StepCriterionUpdateOne) SetNillableMax(v *float64) *StepCriterionUpdateOne {
|
||
|
|
if v != nil {
|
||
|
|
_u.SetMax(*v)
|
||
|
|
}
|
||
|
|
return _u
|
||
|
|
}
|
||
|
|
|
||
|
|
// AddMax adds value to the "max" field.
|
||
|
|
func (_u *StepCriterionUpdateOne) AddMax(v float64) *StepCriterionUpdateOne {
|
||
|
|
_u.mutation.AddMax(v)
|
||
|
|
return _u
|
||
|
|
}
|
||
|
|
|
||
|
|
// ClearMax clears the value of the "max" field.
|
||
|
|
func (_u *StepCriterionUpdateOne) ClearMax() *StepCriterionUpdateOne {
|
||
|
|
_u.mutation.ClearMax()
|
||
|
|
return _u
|
||
|
|
}
|
||
|
|
|
||
|
|
// Mutation returns the StepCriterionMutation object of the builder.
|
||
|
|
func (_u *StepCriterionUpdateOne) Mutation() *StepCriterionMutation {
|
||
|
|
return _u.mutation
|
||
|
|
}
|
||
|
|
|
||
|
|
// Where appends a list predicates to the StepCriterionUpdate builder.
|
||
|
|
func (_u *StepCriterionUpdateOne) Where(ps ...predicate.StepCriterion) *StepCriterionUpdateOne {
|
||
|
|
_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 *StepCriterionUpdateOne) Select(field string, fields ...string) *StepCriterionUpdateOne {
|
||
|
|
_u.fields = append([]string{field}, fields...)
|
||
|
|
return _u
|
||
|
|
}
|
||
|
|
|
||
|
|
// Save executes the query and returns the updated StepCriterion entity.
|
||
|
|
func (_u *StepCriterionUpdateOne) Save(ctx context.Context) (*StepCriterion, error) {
|
||
|
|
return withHooks(ctx, _u.sqlSave, _u.mutation, _u.hooks)
|
||
|
|
}
|
||
|
|
|
||
|
|
// SaveX is like Save, but panics if an error occurs.
|
||
|
|
func (_u *StepCriterionUpdateOne) SaveX(ctx context.Context) *StepCriterion {
|
||
|
|
node, err := _u.Save(ctx)
|
||
|
|
if err != nil {
|
||
|
|
panic(err)
|
||
|
|
}
|
||
|
|
return node
|
||
|
|
}
|
||
|
|
|
||
|
|
// Exec executes the query on the entity.
|
||
|
|
func (_u *StepCriterionUpdateOne) Exec(ctx context.Context) error {
|
||
|
|
_, err := _u.Save(ctx)
|
||
|
|
return err
|
||
|
|
}
|
||
|
|
|
||
|
|
// ExecX is like Exec, but panics if an error occurs.
|
||
|
|
func (_u *StepCriterionUpdateOne) 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 *StepCriterionUpdateOne) check() error {
|
||
|
|
if v, ok := _u.mutation.Name(); ok {
|
||
|
|
if err := stepcriterion.NameValidator(v); err != nil {
|
||
|
|
return &ValidationError{Name: "name", err: fmt.Errorf(`ent: validator failed for field "StepCriterion.name": %w`, err)}
|
||
|
|
}
|
||
|
|
}
|
||
|
|
if v, ok := _u.mutation.Unit(); ok {
|
||
|
|
if err := stepcriterion.UnitValidator(v); err != nil {
|
||
|
|
return &ValidationError{Name: "unit", err: fmt.Errorf(`ent: validator failed for field "StepCriterion.unit": %w`, err)}
|
||
|
|
}
|
||
|
|
}
|
||
|
|
if v, ok := _u.mutation.Logic(); ok {
|
||
|
|
if err := stepcriterion.LogicValidator(v); err != nil {
|
||
|
|
return &ValidationError{Name: "logic", err: fmt.Errorf(`ent: validator failed for field "StepCriterion.logic": %w`, err)}
|
||
|
|
}
|
||
|
|
}
|
||
|
|
return nil
|
||
|
|
}
|
||
|
|
|
||
|
|
// Modify adds a statement modifier for attaching custom logic to the UPDATE statement.
|
||
|
|
func (_u *StepCriterionUpdateOne) Modify(modifiers ...func(u *sql.UpdateBuilder)) *StepCriterionUpdateOne {
|
||
|
|
_u.modifiers = append(_u.modifiers, modifiers...)
|
||
|
|
return _u
|
||
|
|
}
|
||
|
|
|
||
|
|
func (_u *StepCriterionUpdateOne) sqlSave(ctx context.Context) (_node *StepCriterion, err error) {
|
||
|
|
if err := _u.check(); err != nil {
|
||
|
|
return _node, err
|
||
|
|
}
|
||
|
|
_spec := sqlgraph.NewUpdateSpec(stepcriterion.Table, stepcriterion.Columns, sqlgraph.NewFieldSpec(stepcriterion.FieldID, field.TypeInt))
|
||
|
|
id, ok := _u.mutation.ID()
|
||
|
|
if !ok {
|
||
|
|
return nil, &ValidationError{Name: "id", err: errors.New(`ent: missing "StepCriterion.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, stepcriterion.FieldID)
|
||
|
|
for _, f := range fields {
|
||
|
|
if !stepcriterion.ValidColumn(f) {
|
||
|
|
return nil, &ValidationError{Name: f, err: fmt.Errorf("ent: invalid field %q for query", f)}
|
||
|
|
}
|
||
|
|
if f != stepcriterion.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.StepId(); ok {
|
||
|
|
_spec.SetField(stepcriterion.FieldStepId, field.TypeInt, value)
|
||
|
|
}
|
||
|
|
if value, ok := _u.mutation.AddedStepId(); ok {
|
||
|
|
_spec.AddField(stepcriterion.FieldStepId, field.TypeInt, value)
|
||
|
|
}
|
||
|
|
if value, ok := _u.mutation.Name(); ok {
|
||
|
|
_spec.SetField(stepcriterion.FieldName, field.TypeString, value)
|
||
|
|
}
|
||
|
|
if value, ok := _u.mutation.Unit(); ok {
|
||
|
|
_spec.SetField(stepcriterion.FieldUnit, field.TypeString, value)
|
||
|
|
}
|
||
|
|
if value, ok := _u.mutation.Logic(); ok {
|
||
|
|
_spec.SetField(stepcriterion.FieldLogic, field.TypeString, value)
|
||
|
|
}
|
||
|
|
if value, ok := _u.mutation.Target(); ok {
|
||
|
|
_spec.SetField(stepcriterion.FieldTarget, field.TypeFloat64, value)
|
||
|
|
}
|
||
|
|
if value, ok := _u.mutation.AddedTarget(); ok {
|
||
|
|
_spec.AddField(stepcriterion.FieldTarget, field.TypeFloat64, value)
|
||
|
|
}
|
||
|
|
if value, ok := _u.mutation.Min(); ok {
|
||
|
|
_spec.SetField(stepcriterion.FieldMin, field.TypeFloat64, value)
|
||
|
|
}
|
||
|
|
if value, ok := _u.mutation.AddedMin(); ok {
|
||
|
|
_spec.AddField(stepcriterion.FieldMin, field.TypeFloat64, value)
|
||
|
|
}
|
||
|
|
if _u.mutation.MinCleared() {
|
||
|
|
_spec.ClearField(stepcriterion.FieldMin, field.TypeFloat64)
|
||
|
|
}
|
||
|
|
if value, ok := _u.mutation.Max(); ok {
|
||
|
|
_spec.SetField(stepcriterion.FieldMax, field.TypeFloat64, value)
|
||
|
|
}
|
||
|
|
if value, ok := _u.mutation.AddedMax(); ok {
|
||
|
|
_spec.AddField(stepcriterion.FieldMax, field.TypeFloat64, value)
|
||
|
|
}
|
||
|
|
if _u.mutation.MaxCleared() {
|
||
|
|
_spec.ClearField(stepcriterion.FieldMax, field.TypeFloat64)
|
||
|
|
}
|
||
|
|
_spec.AddModifiers(_u.modifiers...)
|
||
|
|
_node = &StepCriterion{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{stepcriterion.Label}
|
||
|
|
} else if sqlgraph.IsConstraintError(err) {
|
||
|
|
err = &ConstraintError{msg: err.Error(), wrap: err}
|
||
|
|
}
|
||
|
|
return nil, err
|
||
|
|
}
|
||
|
|
_u.mutation.done = true
|
||
|
|
return _node, nil
|
||
|
|
}
|