// Code generated by ent, DO NOT EDIT.

package ent

import (
	"context"
	"errors"
	"fmt"

	"entgo.io/ent/dialect/sql"
	"entgo.io/ent/dialect/sql/sqlgraph"
	"entgo.io/ent/schema/field"
	"github.com/buildbarn/bb-portal/ent/gen/ent/packageloadmetrics"
	"github.com/buildbarn/bb-portal/ent/gen/ent/packagemetrics"
	"github.com/buildbarn/bb-portal/ent/gen/ent/predicate"
)

// PackageLoadMetricsUpdate is the builder for updating PackageLoadMetrics entities.
type PackageLoadMetricsUpdate struct {
	config
	hooks    []Hook
	mutation *PackageLoadMetricsMutation
}

// Where appends a list predicates to the PackageLoadMetricsUpdate builder.
func (plmu *PackageLoadMetricsUpdate) Where(ps ...predicate.PackageLoadMetrics) *PackageLoadMetricsUpdate {
	plmu.mutation.Where(ps...)
	return plmu
}

// SetName sets the "name" field.
func (plmu *PackageLoadMetricsUpdate) SetName(s string) *PackageLoadMetricsUpdate {
	plmu.mutation.SetName(s)
	return plmu
}

// SetNillableName sets the "name" field if the given value is not nil.
func (plmu *PackageLoadMetricsUpdate) SetNillableName(s *string) *PackageLoadMetricsUpdate {
	if s != nil {
		plmu.SetName(*s)
	}
	return plmu
}

// ClearName clears the value of the "name" field.
func (plmu *PackageLoadMetricsUpdate) ClearName() *PackageLoadMetricsUpdate {
	plmu.mutation.ClearName()
	return plmu
}

// SetLoadDuration sets the "load_duration" field.
func (plmu *PackageLoadMetricsUpdate) SetLoadDuration(i int64) *PackageLoadMetricsUpdate {
	plmu.mutation.ResetLoadDuration()
	plmu.mutation.SetLoadDuration(i)
	return plmu
}

// SetNillableLoadDuration sets the "load_duration" field if the given value is not nil.
func (plmu *PackageLoadMetricsUpdate) SetNillableLoadDuration(i *int64) *PackageLoadMetricsUpdate {
	if i != nil {
		plmu.SetLoadDuration(*i)
	}
	return plmu
}

// AddLoadDuration adds i to the "load_duration" field.
func (plmu *PackageLoadMetricsUpdate) AddLoadDuration(i int64) *PackageLoadMetricsUpdate {
	plmu.mutation.AddLoadDuration(i)
	return plmu
}

// ClearLoadDuration clears the value of the "load_duration" field.
func (plmu *PackageLoadMetricsUpdate) ClearLoadDuration() *PackageLoadMetricsUpdate {
	plmu.mutation.ClearLoadDuration()
	return plmu
}

// SetNumTargets sets the "num_targets" field.
func (plmu *PackageLoadMetricsUpdate) SetNumTargets(u uint64) *PackageLoadMetricsUpdate {
	plmu.mutation.ResetNumTargets()
	plmu.mutation.SetNumTargets(u)
	return plmu
}

// SetNillableNumTargets sets the "num_targets" field if the given value is not nil.
func (plmu *PackageLoadMetricsUpdate) SetNillableNumTargets(u *uint64) *PackageLoadMetricsUpdate {
	if u != nil {
		plmu.SetNumTargets(*u)
	}
	return plmu
}

// AddNumTargets adds u to the "num_targets" field.
func (plmu *PackageLoadMetricsUpdate) AddNumTargets(u int64) *PackageLoadMetricsUpdate {
	plmu.mutation.AddNumTargets(u)
	return plmu
}

// ClearNumTargets clears the value of the "num_targets" field.
func (plmu *PackageLoadMetricsUpdate) ClearNumTargets() *PackageLoadMetricsUpdate {
	plmu.mutation.ClearNumTargets()
	return plmu
}

// SetComputationSteps sets the "computation_steps" field.
func (plmu *PackageLoadMetricsUpdate) SetComputationSteps(u uint64) *PackageLoadMetricsUpdate {
	plmu.mutation.ResetComputationSteps()
	plmu.mutation.SetComputationSteps(u)
	return plmu
}

// SetNillableComputationSteps sets the "computation_steps" field if the given value is not nil.
func (plmu *PackageLoadMetricsUpdate) SetNillableComputationSteps(u *uint64) *PackageLoadMetricsUpdate {
	if u != nil {
		plmu.SetComputationSteps(*u)
	}
	return plmu
}

// AddComputationSteps adds u to the "computation_steps" field.
func (plmu *PackageLoadMetricsUpdate) AddComputationSteps(u int64) *PackageLoadMetricsUpdate {
	plmu.mutation.AddComputationSteps(u)
	return plmu
}

// ClearComputationSteps clears the value of the "computation_steps" field.
func (plmu *PackageLoadMetricsUpdate) ClearComputationSteps() *PackageLoadMetricsUpdate {
	plmu.mutation.ClearComputationSteps()
	return plmu
}

// SetNumTransitiveLoads sets the "num_transitive_loads" field.
func (plmu *PackageLoadMetricsUpdate) SetNumTransitiveLoads(u uint64) *PackageLoadMetricsUpdate {
	plmu.mutation.ResetNumTransitiveLoads()
	plmu.mutation.SetNumTransitiveLoads(u)
	return plmu
}

// SetNillableNumTransitiveLoads sets the "num_transitive_loads" field if the given value is not nil.
func (plmu *PackageLoadMetricsUpdate) SetNillableNumTransitiveLoads(u *uint64) *PackageLoadMetricsUpdate {
	if u != nil {
		plmu.SetNumTransitiveLoads(*u)
	}
	return plmu
}

// AddNumTransitiveLoads adds u to the "num_transitive_loads" field.
func (plmu *PackageLoadMetricsUpdate) AddNumTransitiveLoads(u int64) *PackageLoadMetricsUpdate {
	plmu.mutation.AddNumTransitiveLoads(u)
	return plmu
}

// ClearNumTransitiveLoads clears the value of the "num_transitive_loads" field.
func (plmu *PackageLoadMetricsUpdate) ClearNumTransitiveLoads() *PackageLoadMetricsUpdate {
	plmu.mutation.ClearNumTransitiveLoads()
	return plmu
}

// SetPackageOverhead sets the "package_overhead" field.
func (plmu *PackageLoadMetricsUpdate) SetPackageOverhead(u uint64) *PackageLoadMetricsUpdate {
	plmu.mutation.ResetPackageOverhead()
	plmu.mutation.SetPackageOverhead(u)
	return plmu
}

// SetNillablePackageOverhead sets the "package_overhead" field if the given value is not nil.
func (plmu *PackageLoadMetricsUpdate) SetNillablePackageOverhead(u *uint64) *PackageLoadMetricsUpdate {
	if u != nil {
		plmu.SetPackageOverhead(*u)
	}
	return plmu
}

// AddPackageOverhead adds u to the "package_overhead" field.
func (plmu *PackageLoadMetricsUpdate) AddPackageOverhead(u int64) *PackageLoadMetricsUpdate {
	plmu.mutation.AddPackageOverhead(u)
	return plmu
}

// ClearPackageOverhead clears the value of the "package_overhead" field.
func (plmu *PackageLoadMetricsUpdate) ClearPackageOverhead() *PackageLoadMetricsUpdate {
	plmu.mutation.ClearPackageOverhead()
	return plmu
}

// SetPackageMetricsID sets the "package_metrics" edge to the PackageMetrics entity by ID.
func (plmu *PackageLoadMetricsUpdate) SetPackageMetricsID(id int) *PackageLoadMetricsUpdate {
	plmu.mutation.SetPackageMetricsID(id)
	return plmu
}

// SetNillablePackageMetricsID sets the "package_metrics" edge to the PackageMetrics entity by ID if the given value is not nil.
func (plmu *PackageLoadMetricsUpdate) SetNillablePackageMetricsID(id *int) *PackageLoadMetricsUpdate {
	if id != nil {
		plmu = plmu.SetPackageMetricsID(*id)
	}
	return plmu
}

// SetPackageMetrics sets the "package_metrics" edge to the PackageMetrics entity.
func (plmu *PackageLoadMetricsUpdate) SetPackageMetrics(p *PackageMetrics) *PackageLoadMetricsUpdate {
	return plmu.SetPackageMetricsID(p.ID)
}

// Mutation returns the PackageLoadMetricsMutation object of the builder.
func (plmu *PackageLoadMetricsUpdate) Mutation() *PackageLoadMetricsMutation {
	return plmu.mutation
}

// ClearPackageMetrics clears the "package_metrics" edge to the PackageMetrics entity.
func (plmu *PackageLoadMetricsUpdate) ClearPackageMetrics() *PackageLoadMetricsUpdate {
	plmu.mutation.ClearPackageMetrics()
	return plmu
}

// Save executes the query and returns the number of nodes affected by the update operation.
func (plmu *PackageLoadMetricsUpdate) Save(ctx context.Context) (int, error) {
	return withHooks(ctx, plmu.sqlSave, plmu.mutation, plmu.hooks)
}

// SaveX is like Save, but panics if an error occurs.
func (plmu *PackageLoadMetricsUpdate) SaveX(ctx context.Context) int {
	affected, err := plmu.Save(ctx)
	if err != nil {
		panic(err)
	}
	return affected
}

// Exec executes the query.
func (plmu *PackageLoadMetricsUpdate) Exec(ctx context.Context) error {
	_, err := plmu.Save(ctx)
	return err
}

// ExecX is like Exec, but panics if an error occurs.
func (plmu *PackageLoadMetricsUpdate) ExecX(ctx context.Context) {
	if err := plmu.Exec(ctx); err != nil {
		panic(err)
	}
}

func (plmu *PackageLoadMetricsUpdate) sqlSave(ctx context.Context) (n int, err error) {
	_spec := sqlgraph.NewUpdateSpec(packageloadmetrics.Table, packageloadmetrics.Columns, sqlgraph.NewFieldSpec(packageloadmetrics.FieldID, field.TypeInt))
	if ps := plmu.mutation.predicates; len(ps) > 0 {
		_spec.Predicate = func(selector *sql.Selector) {
			for i := range ps {
				ps[i](selector)
			}
		}
	}
	if value, ok := plmu.mutation.Name(); ok {
		_spec.SetField(packageloadmetrics.FieldName, field.TypeString, value)
	}
	if plmu.mutation.NameCleared() {
		_spec.ClearField(packageloadmetrics.FieldName, field.TypeString)
	}
	if value, ok := plmu.mutation.LoadDuration(); ok {
		_spec.SetField(packageloadmetrics.FieldLoadDuration, field.TypeInt64, value)
	}
	if value, ok := plmu.mutation.AddedLoadDuration(); ok {
		_spec.AddField(packageloadmetrics.FieldLoadDuration, field.TypeInt64, value)
	}
	if plmu.mutation.LoadDurationCleared() {
		_spec.ClearField(packageloadmetrics.FieldLoadDuration, field.TypeInt64)
	}
	if value, ok := plmu.mutation.NumTargets(); ok {
		_spec.SetField(packageloadmetrics.FieldNumTargets, field.TypeUint64, value)
	}
	if value, ok := plmu.mutation.AddedNumTargets(); ok {
		_spec.AddField(packageloadmetrics.FieldNumTargets, field.TypeUint64, value)
	}
	if plmu.mutation.NumTargetsCleared() {
		_spec.ClearField(packageloadmetrics.FieldNumTargets, field.TypeUint64)
	}
	if value, ok := plmu.mutation.ComputationSteps(); ok {
		_spec.SetField(packageloadmetrics.FieldComputationSteps, field.TypeUint64, value)
	}
	if value, ok := plmu.mutation.AddedComputationSteps(); ok {
		_spec.AddField(packageloadmetrics.FieldComputationSteps, field.TypeUint64, value)
	}
	if plmu.mutation.ComputationStepsCleared() {
		_spec.ClearField(packageloadmetrics.FieldComputationSteps, field.TypeUint64)
	}
	if value, ok := plmu.mutation.NumTransitiveLoads(); ok {
		_spec.SetField(packageloadmetrics.FieldNumTransitiveLoads, field.TypeUint64, value)
	}
	if value, ok := plmu.mutation.AddedNumTransitiveLoads(); ok {
		_spec.AddField(packageloadmetrics.FieldNumTransitiveLoads, field.TypeUint64, value)
	}
	if plmu.mutation.NumTransitiveLoadsCleared() {
		_spec.ClearField(packageloadmetrics.FieldNumTransitiveLoads, field.TypeUint64)
	}
	if value, ok := plmu.mutation.PackageOverhead(); ok {
		_spec.SetField(packageloadmetrics.FieldPackageOverhead, field.TypeUint64, value)
	}
	if value, ok := plmu.mutation.AddedPackageOverhead(); ok {
		_spec.AddField(packageloadmetrics.FieldPackageOverhead, field.TypeUint64, value)
	}
	if plmu.mutation.PackageOverheadCleared() {
		_spec.ClearField(packageloadmetrics.FieldPackageOverhead, field.TypeUint64)
	}
	if plmu.mutation.PackageMetricsCleared() {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.M2O,
			Inverse: true,
			Table:   packageloadmetrics.PackageMetricsTable,
			Columns: []string{packageloadmetrics.PackageMetricsColumn},
			Bidi:    false,
			Target: &sqlgraph.EdgeTarget{
				IDSpec: sqlgraph.NewFieldSpec(packagemetrics.FieldID, field.TypeInt),
			},
		}
		_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
	}
	if nodes := plmu.mutation.PackageMetricsIDs(); len(nodes) > 0 {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.M2O,
			Inverse: true,
			Table:   packageloadmetrics.PackageMetricsTable,
			Columns: []string{packageloadmetrics.PackageMetricsColumn},
			Bidi:    false,
			Target: &sqlgraph.EdgeTarget{
				IDSpec: sqlgraph.NewFieldSpec(packagemetrics.FieldID, field.TypeInt),
			},
		}
		for _, k := range nodes {
			edge.Target.Nodes = append(edge.Target.Nodes, k)
		}
		_spec.Edges.Add = append(_spec.Edges.Add, edge)
	}
	if n, err = sqlgraph.UpdateNodes(ctx, plmu.driver, _spec); err != nil {
		if _, ok := err.(*sqlgraph.NotFoundError); ok {
			err = &NotFoundError{packageloadmetrics.Label}
		} else if sqlgraph.IsConstraintError(err) {
			err = &ConstraintError{msg: err.Error(), wrap: err}
		}
		return 0, err
	}
	plmu.mutation.done = true
	return n, nil
}

// PackageLoadMetricsUpdateOne is the builder for updating a single PackageLoadMetrics entity.
type PackageLoadMetricsUpdateOne struct {
	config
	fields   []string
	hooks    []Hook
	mutation *PackageLoadMetricsMutation
}

// SetName sets the "name" field.
func (plmuo *PackageLoadMetricsUpdateOne) SetName(s string) *PackageLoadMetricsUpdateOne {
	plmuo.mutation.SetName(s)
	return plmuo
}

// SetNillableName sets the "name" field if the given value is not nil.
func (plmuo *PackageLoadMetricsUpdateOne) SetNillableName(s *string) *PackageLoadMetricsUpdateOne {
	if s != nil {
		plmuo.SetName(*s)
	}
	return plmuo
}

// ClearName clears the value of the "name" field.
func (plmuo *PackageLoadMetricsUpdateOne) ClearName() *PackageLoadMetricsUpdateOne {
	plmuo.mutation.ClearName()
	return plmuo
}

// SetLoadDuration sets the "load_duration" field.
func (plmuo *PackageLoadMetricsUpdateOne) SetLoadDuration(i int64) *PackageLoadMetricsUpdateOne {
	plmuo.mutation.ResetLoadDuration()
	plmuo.mutation.SetLoadDuration(i)
	return plmuo
}

// SetNillableLoadDuration sets the "load_duration" field if the given value is not nil.
func (plmuo *PackageLoadMetricsUpdateOne) SetNillableLoadDuration(i *int64) *PackageLoadMetricsUpdateOne {
	if i != nil {
		plmuo.SetLoadDuration(*i)
	}
	return plmuo
}

// AddLoadDuration adds i to the "load_duration" field.
func (plmuo *PackageLoadMetricsUpdateOne) AddLoadDuration(i int64) *PackageLoadMetricsUpdateOne {
	plmuo.mutation.AddLoadDuration(i)
	return plmuo
}

// ClearLoadDuration clears the value of the "load_duration" field.
func (plmuo *PackageLoadMetricsUpdateOne) ClearLoadDuration() *PackageLoadMetricsUpdateOne {
	plmuo.mutation.ClearLoadDuration()
	return plmuo
}

// SetNumTargets sets the "num_targets" field.
func (plmuo *PackageLoadMetricsUpdateOne) SetNumTargets(u uint64) *PackageLoadMetricsUpdateOne {
	plmuo.mutation.ResetNumTargets()
	plmuo.mutation.SetNumTargets(u)
	return plmuo
}

// SetNillableNumTargets sets the "num_targets" field if the given value is not nil.
func (plmuo *PackageLoadMetricsUpdateOne) SetNillableNumTargets(u *uint64) *PackageLoadMetricsUpdateOne {
	if u != nil {
		plmuo.SetNumTargets(*u)
	}
	return plmuo
}

// AddNumTargets adds u to the "num_targets" field.
func (plmuo *PackageLoadMetricsUpdateOne) AddNumTargets(u int64) *PackageLoadMetricsUpdateOne {
	plmuo.mutation.AddNumTargets(u)
	return plmuo
}

// ClearNumTargets clears the value of the "num_targets" field.
func (plmuo *PackageLoadMetricsUpdateOne) ClearNumTargets() *PackageLoadMetricsUpdateOne {
	plmuo.mutation.ClearNumTargets()
	return plmuo
}

// SetComputationSteps sets the "computation_steps" field.
func (plmuo *PackageLoadMetricsUpdateOne) SetComputationSteps(u uint64) *PackageLoadMetricsUpdateOne {
	plmuo.mutation.ResetComputationSteps()
	plmuo.mutation.SetComputationSteps(u)
	return plmuo
}

// SetNillableComputationSteps sets the "computation_steps" field if the given value is not nil.
func (plmuo *PackageLoadMetricsUpdateOne) SetNillableComputationSteps(u *uint64) *PackageLoadMetricsUpdateOne {
	if u != nil {
		plmuo.SetComputationSteps(*u)
	}
	return plmuo
}

// AddComputationSteps adds u to the "computation_steps" field.
func (plmuo *PackageLoadMetricsUpdateOne) AddComputationSteps(u int64) *PackageLoadMetricsUpdateOne {
	plmuo.mutation.AddComputationSteps(u)
	return plmuo
}

// ClearComputationSteps clears the value of the "computation_steps" field.
func (plmuo *PackageLoadMetricsUpdateOne) ClearComputationSteps() *PackageLoadMetricsUpdateOne {
	plmuo.mutation.ClearComputationSteps()
	return plmuo
}

// SetNumTransitiveLoads sets the "num_transitive_loads" field.
func (plmuo *PackageLoadMetricsUpdateOne) SetNumTransitiveLoads(u uint64) *PackageLoadMetricsUpdateOne {
	plmuo.mutation.ResetNumTransitiveLoads()
	plmuo.mutation.SetNumTransitiveLoads(u)
	return plmuo
}

// SetNillableNumTransitiveLoads sets the "num_transitive_loads" field if the given value is not nil.
func (plmuo *PackageLoadMetricsUpdateOne) SetNillableNumTransitiveLoads(u *uint64) *PackageLoadMetricsUpdateOne {
	if u != nil {
		plmuo.SetNumTransitiveLoads(*u)
	}
	return plmuo
}

// AddNumTransitiveLoads adds u to the "num_transitive_loads" field.
func (plmuo *PackageLoadMetricsUpdateOne) AddNumTransitiveLoads(u int64) *PackageLoadMetricsUpdateOne {
	plmuo.mutation.AddNumTransitiveLoads(u)
	return plmuo
}

// ClearNumTransitiveLoads clears the value of the "num_transitive_loads" field.
func (plmuo *PackageLoadMetricsUpdateOne) ClearNumTransitiveLoads() *PackageLoadMetricsUpdateOne {
	plmuo.mutation.ClearNumTransitiveLoads()
	return plmuo
}

// SetPackageOverhead sets the "package_overhead" field.
func (plmuo *PackageLoadMetricsUpdateOne) SetPackageOverhead(u uint64) *PackageLoadMetricsUpdateOne {
	plmuo.mutation.ResetPackageOverhead()
	plmuo.mutation.SetPackageOverhead(u)
	return plmuo
}

// SetNillablePackageOverhead sets the "package_overhead" field if the given value is not nil.
func (plmuo *PackageLoadMetricsUpdateOne) SetNillablePackageOverhead(u *uint64) *PackageLoadMetricsUpdateOne {
	if u != nil {
		plmuo.SetPackageOverhead(*u)
	}
	return plmuo
}

// AddPackageOverhead adds u to the "package_overhead" field.
func (plmuo *PackageLoadMetricsUpdateOne) AddPackageOverhead(u int64) *PackageLoadMetricsUpdateOne {
	plmuo.mutation.AddPackageOverhead(u)
	return plmuo
}

// ClearPackageOverhead clears the value of the "package_overhead" field.
func (plmuo *PackageLoadMetricsUpdateOne) ClearPackageOverhead() *PackageLoadMetricsUpdateOne {
	plmuo.mutation.ClearPackageOverhead()
	return plmuo
}

// SetPackageMetricsID sets the "package_metrics" edge to the PackageMetrics entity by ID.
func (plmuo *PackageLoadMetricsUpdateOne) SetPackageMetricsID(id int) *PackageLoadMetricsUpdateOne {
	plmuo.mutation.SetPackageMetricsID(id)
	return plmuo
}

// SetNillablePackageMetricsID sets the "package_metrics" edge to the PackageMetrics entity by ID if the given value is not nil.
func (plmuo *PackageLoadMetricsUpdateOne) SetNillablePackageMetricsID(id *int) *PackageLoadMetricsUpdateOne {
	if id != nil {
		plmuo = plmuo.SetPackageMetricsID(*id)
	}
	return plmuo
}

// SetPackageMetrics sets the "package_metrics" edge to the PackageMetrics entity.
func (plmuo *PackageLoadMetricsUpdateOne) SetPackageMetrics(p *PackageMetrics) *PackageLoadMetricsUpdateOne {
	return plmuo.SetPackageMetricsID(p.ID)
}

// Mutation returns the PackageLoadMetricsMutation object of the builder.
func (plmuo *PackageLoadMetricsUpdateOne) Mutation() *PackageLoadMetricsMutation {
	return plmuo.mutation
}

// ClearPackageMetrics clears the "package_metrics" edge to the PackageMetrics entity.
func (plmuo *PackageLoadMetricsUpdateOne) ClearPackageMetrics() *PackageLoadMetricsUpdateOne {
	plmuo.mutation.ClearPackageMetrics()
	return plmuo
}

// Where appends a list predicates to the PackageLoadMetricsUpdate builder.
func (plmuo *PackageLoadMetricsUpdateOne) Where(ps ...predicate.PackageLoadMetrics) *PackageLoadMetricsUpdateOne {
	plmuo.mutation.Where(ps...)
	return plmuo
}

// Select allows selecting one or more fields (columns) of the returned entity.
// The default is selecting all fields defined in the entity schema.
func (plmuo *PackageLoadMetricsUpdateOne) Select(field string, fields ...string) *PackageLoadMetricsUpdateOne {
	plmuo.fields = append([]string{field}, fields...)
	return plmuo
}

// Save executes the query and returns the updated PackageLoadMetrics entity.
func (plmuo *PackageLoadMetricsUpdateOne) Save(ctx context.Context) (*PackageLoadMetrics, error) {
	return withHooks(ctx, plmuo.sqlSave, plmuo.mutation, plmuo.hooks)
}

// SaveX is like Save, but panics if an error occurs.
func (plmuo *PackageLoadMetricsUpdateOne) SaveX(ctx context.Context) *PackageLoadMetrics {
	node, err := plmuo.Save(ctx)
	if err != nil {
		panic(err)
	}
	return node
}

// Exec executes the query on the entity.
func (plmuo *PackageLoadMetricsUpdateOne) Exec(ctx context.Context) error {
	_, err := plmuo.Save(ctx)
	return err
}

// ExecX is like Exec, but panics if an error occurs.
func (plmuo *PackageLoadMetricsUpdateOne) ExecX(ctx context.Context) {
	if err := plmuo.Exec(ctx); err != nil {
		panic(err)
	}
}

func (plmuo *PackageLoadMetricsUpdateOne) sqlSave(ctx context.Context) (_node *PackageLoadMetrics, err error) {
	_spec := sqlgraph.NewUpdateSpec(packageloadmetrics.Table, packageloadmetrics.Columns, sqlgraph.NewFieldSpec(packageloadmetrics.FieldID, field.TypeInt))
	id, ok := plmuo.mutation.ID()
	if !ok {
		return nil, &ValidationError{Name: "id", err: errors.New(`ent: missing "PackageLoadMetrics.id" for update`)}
	}
	_spec.Node.ID.Value = id
	if fields := plmuo.fields; len(fields) > 0 {
		_spec.Node.Columns = make([]string, 0, len(fields))
		_spec.Node.Columns = append(_spec.Node.Columns, packageloadmetrics.FieldID)
		for _, f := range fields {
			if !packageloadmetrics.ValidColumn(f) {
				return nil, &ValidationError{Name: f, err: fmt.Errorf("ent: invalid field %q for query", f)}
			}
			if f != packageloadmetrics.FieldID {
				_spec.Node.Columns = append(_spec.Node.Columns, f)
			}
		}
	}
	if ps := plmuo.mutation.predicates; len(ps) > 0 {
		_spec.Predicate = func(selector *sql.Selector) {
			for i := range ps {
				ps[i](selector)
			}
		}
	}
	if value, ok := plmuo.mutation.Name(); ok {
		_spec.SetField(packageloadmetrics.FieldName, field.TypeString, value)
	}
	if plmuo.mutation.NameCleared() {
		_spec.ClearField(packageloadmetrics.FieldName, field.TypeString)
	}
	if value, ok := plmuo.mutation.LoadDuration(); ok {
		_spec.SetField(packageloadmetrics.FieldLoadDuration, field.TypeInt64, value)
	}
	if value, ok := plmuo.mutation.AddedLoadDuration(); ok {
		_spec.AddField(packageloadmetrics.FieldLoadDuration, field.TypeInt64, value)
	}
	if plmuo.mutation.LoadDurationCleared() {
		_spec.ClearField(packageloadmetrics.FieldLoadDuration, field.TypeInt64)
	}
	if value, ok := plmuo.mutation.NumTargets(); ok {
		_spec.SetField(packageloadmetrics.FieldNumTargets, field.TypeUint64, value)
	}
	if value, ok := plmuo.mutation.AddedNumTargets(); ok {
		_spec.AddField(packageloadmetrics.FieldNumTargets, field.TypeUint64, value)
	}
	if plmuo.mutation.NumTargetsCleared() {
		_spec.ClearField(packageloadmetrics.FieldNumTargets, field.TypeUint64)
	}
	if value, ok := plmuo.mutation.ComputationSteps(); ok {
		_spec.SetField(packageloadmetrics.FieldComputationSteps, field.TypeUint64, value)
	}
	if value, ok := plmuo.mutation.AddedComputationSteps(); ok {
		_spec.AddField(packageloadmetrics.FieldComputationSteps, field.TypeUint64, value)
	}
	if plmuo.mutation.ComputationStepsCleared() {
		_spec.ClearField(packageloadmetrics.FieldComputationSteps, field.TypeUint64)
	}
	if value, ok := plmuo.mutation.NumTransitiveLoads(); ok {
		_spec.SetField(packageloadmetrics.FieldNumTransitiveLoads, field.TypeUint64, value)
	}
	if value, ok := plmuo.mutation.AddedNumTransitiveLoads(); ok {
		_spec.AddField(packageloadmetrics.FieldNumTransitiveLoads, field.TypeUint64, value)
	}
	if plmuo.mutation.NumTransitiveLoadsCleared() {
		_spec.ClearField(packageloadmetrics.FieldNumTransitiveLoads, field.TypeUint64)
	}
	if value, ok := plmuo.mutation.PackageOverhead(); ok {
		_spec.SetField(packageloadmetrics.FieldPackageOverhead, field.TypeUint64, value)
	}
	if value, ok := plmuo.mutation.AddedPackageOverhead(); ok {
		_spec.AddField(packageloadmetrics.FieldPackageOverhead, field.TypeUint64, value)
	}
	if plmuo.mutation.PackageOverheadCleared() {
		_spec.ClearField(packageloadmetrics.FieldPackageOverhead, field.TypeUint64)
	}
	if plmuo.mutation.PackageMetricsCleared() {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.M2O,
			Inverse: true,
			Table:   packageloadmetrics.PackageMetricsTable,
			Columns: []string{packageloadmetrics.PackageMetricsColumn},
			Bidi:    false,
			Target: &sqlgraph.EdgeTarget{
				IDSpec: sqlgraph.NewFieldSpec(packagemetrics.FieldID, field.TypeInt),
			},
		}
		_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
	}
	if nodes := plmuo.mutation.PackageMetricsIDs(); len(nodes) > 0 {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.M2O,
			Inverse: true,
			Table:   packageloadmetrics.PackageMetricsTable,
			Columns: []string{packageloadmetrics.PackageMetricsColumn},
			Bidi:    false,
			Target: &sqlgraph.EdgeTarget{
				IDSpec: sqlgraph.NewFieldSpec(packagemetrics.FieldID, field.TypeInt),
			},
		}
		for _, k := range nodes {
			edge.Target.Nodes = append(edge.Target.Nodes, k)
		}
		_spec.Edges.Add = append(_spec.Edges.Add, edge)
	}
	_node = &PackageLoadMetrics{config: plmuo.config}
	_spec.Assign = _node.assignValues
	_spec.ScanValues = _node.scanValues
	if err = sqlgraph.UpdateNode(ctx, plmuo.driver, _spec); err != nil {
		if _, ok := err.(*sqlgraph.NotFoundError); ok {
			err = &NotFoundError{packageloadmetrics.Label}
		} else if sqlgraph.IsConstraintError(err) {
			err = &ConstraintError{msg: err.Error(), wrap: err}
		}
		return nil, err
	}
	plmuo.mutation.done = true
	return _node, nil
}
