// 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/metrics"
	"github.com/buildbarn/bb-portal/ent/gen/ent/predicate"
	"github.com/buildbarn/bb-portal/ent/gen/ent/timingmetrics"
)

// TimingMetricsUpdate is the builder for updating TimingMetrics entities.
type TimingMetricsUpdate struct {
	config
	hooks    []Hook
	mutation *TimingMetricsMutation
}

// Where appends a list predicates to the TimingMetricsUpdate builder.
func (tmu *TimingMetricsUpdate) Where(ps ...predicate.TimingMetrics) *TimingMetricsUpdate {
	tmu.mutation.Where(ps...)
	return tmu
}

// SetCPUTimeInMs sets the "cpu_time_in_ms" field.
func (tmu *TimingMetricsUpdate) SetCPUTimeInMs(i int64) *TimingMetricsUpdate {
	tmu.mutation.ResetCPUTimeInMs()
	tmu.mutation.SetCPUTimeInMs(i)
	return tmu
}

// SetNillableCPUTimeInMs sets the "cpu_time_in_ms" field if the given value is not nil.
func (tmu *TimingMetricsUpdate) SetNillableCPUTimeInMs(i *int64) *TimingMetricsUpdate {
	if i != nil {
		tmu.SetCPUTimeInMs(*i)
	}
	return tmu
}

// AddCPUTimeInMs adds i to the "cpu_time_in_ms" field.
func (tmu *TimingMetricsUpdate) AddCPUTimeInMs(i int64) *TimingMetricsUpdate {
	tmu.mutation.AddCPUTimeInMs(i)
	return tmu
}

// ClearCPUTimeInMs clears the value of the "cpu_time_in_ms" field.
func (tmu *TimingMetricsUpdate) ClearCPUTimeInMs() *TimingMetricsUpdate {
	tmu.mutation.ClearCPUTimeInMs()
	return tmu
}

// SetWallTimeInMs sets the "wall_time_in_ms" field.
func (tmu *TimingMetricsUpdate) SetWallTimeInMs(i int64) *TimingMetricsUpdate {
	tmu.mutation.ResetWallTimeInMs()
	tmu.mutation.SetWallTimeInMs(i)
	return tmu
}

// SetNillableWallTimeInMs sets the "wall_time_in_ms" field if the given value is not nil.
func (tmu *TimingMetricsUpdate) SetNillableWallTimeInMs(i *int64) *TimingMetricsUpdate {
	if i != nil {
		tmu.SetWallTimeInMs(*i)
	}
	return tmu
}

// AddWallTimeInMs adds i to the "wall_time_in_ms" field.
func (tmu *TimingMetricsUpdate) AddWallTimeInMs(i int64) *TimingMetricsUpdate {
	tmu.mutation.AddWallTimeInMs(i)
	return tmu
}

// ClearWallTimeInMs clears the value of the "wall_time_in_ms" field.
func (tmu *TimingMetricsUpdate) ClearWallTimeInMs() *TimingMetricsUpdate {
	tmu.mutation.ClearWallTimeInMs()
	return tmu
}

// SetAnalysisPhaseTimeInMs sets the "analysis_phase_time_in_ms" field.
func (tmu *TimingMetricsUpdate) SetAnalysisPhaseTimeInMs(i int64) *TimingMetricsUpdate {
	tmu.mutation.ResetAnalysisPhaseTimeInMs()
	tmu.mutation.SetAnalysisPhaseTimeInMs(i)
	return tmu
}

// SetNillableAnalysisPhaseTimeInMs sets the "analysis_phase_time_in_ms" field if the given value is not nil.
func (tmu *TimingMetricsUpdate) SetNillableAnalysisPhaseTimeInMs(i *int64) *TimingMetricsUpdate {
	if i != nil {
		tmu.SetAnalysisPhaseTimeInMs(*i)
	}
	return tmu
}

// AddAnalysisPhaseTimeInMs adds i to the "analysis_phase_time_in_ms" field.
func (tmu *TimingMetricsUpdate) AddAnalysisPhaseTimeInMs(i int64) *TimingMetricsUpdate {
	tmu.mutation.AddAnalysisPhaseTimeInMs(i)
	return tmu
}

// ClearAnalysisPhaseTimeInMs clears the value of the "analysis_phase_time_in_ms" field.
func (tmu *TimingMetricsUpdate) ClearAnalysisPhaseTimeInMs() *TimingMetricsUpdate {
	tmu.mutation.ClearAnalysisPhaseTimeInMs()
	return tmu
}

// SetExecutionPhaseTimeInMs sets the "execution_phase_time_in_ms" field.
func (tmu *TimingMetricsUpdate) SetExecutionPhaseTimeInMs(i int64) *TimingMetricsUpdate {
	tmu.mutation.ResetExecutionPhaseTimeInMs()
	tmu.mutation.SetExecutionPhaseTimeInMs(i)
	return tmu
}

// SetNillableExecutionPhaseTimeInMs sets the "execution_phase_time_in_ms" field if the given value is not nil.
func (tmu *TimingMetricsUpdate) SetNillableExecutionPhaseTimeInMs(i *int64) *TimingMetricsUpdate {
	if i != nil {
		tmu.SetExecutionPhaseTimeInMs(*i)
	}
	return tmu
}

// AddExecutionPhaseTimeInMs adds i to the "execution_phase_time_in_ms" field.
func (tmu *TimingMetricsUpdate) AddExecutionPhaseTimeInMs(i int64) *TimingMetricsUpdate {
	tmu.mutation.AddExecutionPhaseTimeInMs(i)
	return tmu
}

// ClearExecutionPhaseTimeInMs clears the value of the "execution_phase_time_in_ms" field.
func (tmu *TimingMetricsUpdate) ClearExecutionPhaseTimeInMs() *TimingMetricsUpdate {
	tmu.mutation.ClearExecutionPhaseTimeInMs()
	return tmu
}

// SetActionsExecutionStartInMs sets the "actions_execution_start_in_ms" field.
func (tmu *TimingMetricsUpdate) SetActionsExecutionStartInMs(i int64) *TimingMetricsUpdate {
	tmu.mutation.ResetActionsExecutionStartInMs()
	tmu.mutation.SetActionsExecutionStartInMs(i)
	return tmu
}

// SetNillableActionsExecutionStartInMs sets the "actions_execution_start_in_ms" field if the given value is not nil.
func (tmu *TimingMetricsUpdate) SetNillableActionsExecutionStartInMs(i *int64) *TimingMetricsUpdate {
	if i != nil {
		tmu.SetActionsExecutionStartInMs(*i)
	}
	return tmu
}

// AddActionsExecutionStartInMs adds i to the "actions_execution_start_in_ms" field.
func (tmu *TimingMetricsUpdate) AddActionsExecutionStartInMs(i int64) *TimingMetricsUpdate {
	tmu.mutation.AddActionsExecutionStartInMs(i)
	return tmu
}

// ClearActionsExecutionStartInMs clears the value of the "actions_execution_start_in_ms" field.
func (tmu *TimingMetricsUpdate) ClearActionsExecutionStartInMs() *TimingMetricsUpdate {
	tmu.mutation.ClearActionsExecutionStartInMs()
	return tmu
}

// SetMetricsID sets the "metrics" edge to the Metrics entity by ID.
func (tmu *TimingMetricsUpdate) SetMetricsID(id int) *TimingMetricsUpdate {
	tmu.mutation.SetMetricsID(id)
	return tmu
}

// SetNillableMetricsID sets the "metrics" edge to the Metrics entity by ID if the given value is not nil.
func (tmu *TimingMetricsUpdate) SetNillableMetricsID(id *int) *TimingMetricsUpdate {
	if id != nil {
		tmu = tmu.SetMetricsID(*id)
	}
	return tmu
}

// SetMetrics sets the "metrics" edge to the Metrics entity.
func (tmu *TimingMetricsUpdate) SetMetrics(m *Metrics) *TimingMetricsUpdate {
	return tmu.SetMetricsID(m.ID)
}

// Mutation returns the TimingMetricsMutation object of the builder.
func (tmu *TimingMetricsUpdate) Mutation() *TimingMetricsMutation {
	return tmu.mutation
}

// ClearMetrics clears the "metrics" edge to the Metrics entity.
func (tmu *TimingMetricsUpdate) ClearMetrics() *TimingMetricsUpdate {
	tmu.mutation.ClearMetrics()
	return tmu
}

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

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

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

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

func (tmu *TimingMetricsUpdate) sqlSave(ctx context.Context) (n int, err error) {
	_spec := sqlgraph.NewUpdateSpec(timingmetrics.Table, timingmetrics.Columns, sqlgraph.NewFieldSpec(timingmetrics.FieldID, field.TypeInt))
	if ps := tmu.mutation.predicates; len(ps) > 0 {
		_spec.Predicate = func(selector *sql.Selector) {
			for i := range ps {
				ps[i](selector)
			}
		}
	}
	if value, ok := tmu.mutation.CPUTimeInMs(); ok {
		_spec.SetField(timingmetrics.FieldCPUTimeInMs, field.TypeInt64, value)
	}
	if value, ok := tmu.mutation.AddedCPUTimeInMs(); ok {
		_spec.AddField(timingmetrics.FieldCPUTimeInMs, field.TypeInt64, value)
	}
	if tmu.mutation.CPUTimeInMsCleared() {
		_spec.ClearField(timingmetrics.FieldCPUTimeInMs, field.TypeInt64)
	}
	if value, ok := tmu.mutation.WallTimeInMs(); ok {
		_spec.SetField(timingmetrics.FieldWallTimeInMs, field.TypeInt64, value)
	}
	if value, ok := tmu.mutation.AddedWallTimeInMs(); ok {
		_spec.AddField(timingmetrics.FieldWallTimeInMs, field.TypeInt64, value)
	}
	if tmu.mutation.WallTimeInMsCleared() {
		_spec.ClearField(timingmetrics.FieldWallTimeInMs, field.TypeInt64)
	}
	if value, ok := tmu.mutation.AnalysisPhaseTimeInMs(); ok {
		_spec.SetField(timingmetrics.FieldAnalysisPhaseTimeInMs, field.TypeInt64, value)
	}
	if value, ok := tmu.mutation.AddedAnalysisPhaseTimeInMs(); ok {
		_spec.AddField(timingmetrics.FieldAnalysisPhaseTimeInMs, field.TypeInt64, value)
	}
	if tmu.mutation.AnalysisPhaseTimeInMsCleared() {
		_spec.ClearField(timingmetrics.FieldAnalysisPhaseTimeInMs, field.TypeInt64)
	}
	if value, ok := tmu.mutation.ExecutionPhaseTimeInMs(); ok {
		_spec.SetField(timingmetrics.FieldExecutionPhaseTimeInMs, field.TypeInt64, value)
	}
	if value, ok := tmu.mutation.AddedExecutionPhaseTimeInMs(); ok {
		_spec.AddField(timingmetrics.FieldExecutionPhaseTimeInMs, field.TypeInt64, value)
	}
	if tmu.mutation.ExecutionPhaseTimeInMsCleared() {
		_spec.ClearField(timingmetrics.FieldExecutionPhaseTimeInMs, field.TypeInt64)
	}
	if value, ok := tmu.mutation.ActionsExecutionStartInMs(); ok {
		_spec.SetField(timingmetrics.FieldActionsExecutionStartInMs, field.TypeInt64, value)
	}
	if value, ok := tmu.mutation.AddedActionsExecutionStartInMs(); ok {
		_spec.AddField(timingmetrics.FieldActionsExecutionStartInMs, field.TypeInt64, value)
	}
	if tmu.mutation.ActionsExecutionStartInMsCleared() {
		_spec.ClearField(timingmetrics.FieldActionsExecutionStartInMs, field.TypeInt64)
	}
	if tmu.mutation.MetricsCleared() {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.O2O,
			Inverse: true,
			Table:   timingmetrics.MetricsTable,
			Columns: []string{timingmetrics.MetricsColumn},
			Bidi:    false,
			Target: &sqlgraph.EdgeTarget{
				IDSpec: sqlgraph.NewFieldSpec(metrics.FieldID, field.TypeInt),
			},
		}
		_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
	}
	if nodes := tmu.mutation.MetricsIDs(); len(nodes) > 0 {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.O2O,
			Inverse: true,
			Table:   timingmetrics.MetricsTable,
			Columns: []string{timingmetrics.MetricsColumn},
			Bidi:    false,
			Target: &sqlgraph.EdgeTarget{
				IDSpec: sqlgraph.NewFieldSpec(metrics.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, tmu.driver, _spec); err != nil {
		if _, ok := err.(*sqlgraph.NotFoundError); ok {
			err = &NotFoundError{timingmetrics.Label}
		} else if sqlgraph.IsConstraintError(err) {
			err = &ConstraintError{msg: err.Error(), wrap: err}
		}
		return 0, err
	}
	tmu.mutation.done = true
	return n, nil
}

// TimingMetricsUpdateOne is the builder for updating a single TimingMetrics entity.
type TimingMetricsUpdateOne struct {
	config
	fields   []string
	hooks    []Hook
	mutation *TimingMetricsMutation
}

// SetCPUTimeInMs sets the "cpu_time_in_ms" field.
func (tmuo *TimingMetricsUpdateOne) SetCPUTimeInMs(i int64) *TimingMetricsUpdateOne {
	tmuo.mutation.ResetCPUTimeInMs()
	tmuo.mutation.SetCPUTimeInMs(i)
	return tmuo
}

// SetNillableCPUTimeInMs sets the "cpu_time_in_ms" field if the given value is not nil.
func (tmuo *TimingMetricsUpdateOne) SetNillableCPUTimeInMs(i *int64) *TimingMetricsUpdateOne {
	if i != nil {
		tmuo.SetCPUTimeInMs(*i)
	}
	return tmuo
}

// AddCPUTimeInMs adds i to the "cpu_time_in_ms" field.
func (tmuo *TimingMetricsUpdateOne) AddCPUTimeInMs(i int64) *TimingMetricsUpdateOne {
	tmuo.mutation.AddCPUTimeInMs(i)
	return tmuo
}

// ClearCPUTimeInMs clears the value of the "cpu_time_in_ms" field.
func (tmuo *TimingMetricsUpdateOne) ClearCPUTimeInMs() *TimingMetricsUpdateOne {
	tmuo.mutation.ClearCPUTimeInMs()
	return tmuo
}

// SetWallTimeInMs sets the "wall_time_in_ms" field.
func (tmuo *TimingMetricsUpdateOne) SetWallTimeInMs(i int64) *TimingMetricsUpdateOne {
	tmuo.mutation.ResetWallTimeInMs()
	tmuo.mutation.SetWallTimeInMs(i)
	return tmuo
}

// SetNillableWallTimeInMs sets the "wall_time_in_ms" field if the given value is not nil.
func (tmuo *TimingMetricsUpdateOne) SetNillableWallTimeInMs(i *int64) *TimingMetricsUpdateOne {
	if i != nil {
		tmuo.SetWallTimeInMs(*i)
	}
	return tmuo
}

// AddWallTimeInMs adds i to the "wall_time_in_ms" field.
func (tmuo *TimingMetricsUpdateOne) AddWallTimeInMs(i int64) *TimingMetricsUpdateOne {
	tmuo.mutation.AddWallTimeInMs(i)
	return tmuo
}

// ClearWallTimeInMs clears the value of the "wall_time_in_ms" field.
func (tmuo *TimingMetricsUpdateOne) ClearWallTimeInMs() *TimingMetricsUpdateOne {
	tmuo.mutation.ClearWallTimeInMs()
	return tmuo
}

// SetAnalysisPhaseTimeInMs sets the "analysis_phase_time_in_ms" field.
func (tmuo *TimingMetricsUpdateOne) SetAnalysisPhaseTimeInMs(i int64) *TimingMetricsUpdateOne {
	tmuo.mutation.ResetAnalysisPhaseTimeInMs()
	tmuo.mutation.SetAnalysisPhaseTimeInMs(i)
	return tmuo
}

// SetNillableAnalysisPhaseTimeInMs sets the "analysis_phase_time_in_ms" field if the given value is not nil.
func (tmuo *TimingMetricsUpdateOne) SetNillableAnalysisPhaseTimeInMs(i *int64) *TimingMetricsUpdateOne {
	if i != nil {
		tmuo.SetAnalysisPhaseTimeInMs(*i)
	}
	return tmuo
}

// AddAnalysisPhaseTimeInMs adds i to the "analysis_phase_time_in_ms" field.
func (tmuo *TimingMetricsUpdateOne) AddAnalysisPhaseTimeInMs(i int64) *TimingMetricsUpdateOne {
	tmuo.mutation.AddAnalysisPhaseTimeInMs(i)
	return tmuo
}

// ClearAnalysisPhaseTimeInMs clears the value of the "analysis_phase_time_in_ms" field.
func (tmuo *TimingMetricsUpdateOne) ClearAnalysisPhaseTimeInMs() *TimingMetricsUpdateOne {
	tmuo.mutation.ClearAnalysisPhaseTimeInMs()
	return tmuo
}

// SetExecutionPhaseTimeInMs sets the "execution_phase_time_in_ms" field.
func (tmuo *TimingMetricsUpdateOne) SetExecutionPhaseTimeInMs(i int64) *TimingMetricsUpdateOne {
	tmuo.mutation.ResetExecutionPhaseTimeInMs()
	tmuo.mutation.SetExecutionPhaseTimeInMs(i)
	return tmuo
}

// SetNillableExecutionPhaseTimeInMs sets the "execution_phase_time_in_ms" field if the given value is not nil.
func (tmuo *TimingMetricsUpdateOne) SetNillableExecutionPhaseTimeInMs(i *int64) *TimingMetricsUpdateOne {
	if i != nil {
		tmuo.SetExecutionPhaseTimeInMs(*i)
	}
	return tmuo
}

// AddExecutionPhaseTimeInMs adds i to the "execution_phase_time_in_ms" field.
func (tmuo *TimingMetricsUpdateOne) AddExecutionPhaseTimeInMs(i int64) *TimingMetricsUpdateOne {
	tmuo.mutation.AddExecutionPhaseTimeInMs(i)
	return tmuo
}

// ClearExecutionPhaseTimeInMs clears the value of the "execution_phase_time_in_ms" field.
func (tmuo *TimingMetricsUpdateOne) ClearExecutionPhaseTimeInMs() *TimingMetricsUpdateOne {
	tmuo.mutation.ClearExecutionPhaseTimeInMs()
	return tmuo
}

// SetActionsExecutionStartInMs sets the "actions_execution_start_in_ms" field.
func (tmuo *TimingMetricsUpdateOne) SetActionsExecutionStartInMs(i int64) *TimingMetricsUpdateOne {
	tmuo.mutation.ResetActionsExecutionStartInMs()
	tmuo.mutation.SetActionsExecutionStartInMs(i)
	return tmuo
}

// SetNillableActionsExecutionStartInMs sets the "actions_execution_start_in_ms" field if the given value is not nil.
func (tmuo *TimingMetricsUpdateOne) SetNillableActionsExecutionStartInMs(i *int64) *TimingMetricsUpdateOne {
	if i != nil {
		tmuo.SetActionsExecutionStartInMs(*i)
	}
	return tmuo
}

// AddActionsExecutionStartInMs adds i to the "actions_execution_start_in_ms" field.
func (tmuo *TimingMetricsUpdateOne) AddActionsExecutionStartInMs(i int64) *TimingMetricsUpdateOne {
	tmuo.mutation.AddActionsExecutionStartInMs(i)
	return tmuo
}

// ClearActionsExecutionStartInMs clears the value of the "actions_execution_start_in_ms" field.
func (tmuo *TimingMetricsUpdateOne) ClearActionsExecutionStartInMs() *TimingMetricsUpdateOne {
	tmuo.mutation.ClearActionsExecutionStartInMs()
	return tmuo
}

// SetMetricsID sets the "metrics" edge to the Metrics entity by ID.
func (tmuo *TimingMetricsUpdateOne) SetMetricsID(id int) *TimingMetricsUpdateOne {
	tmuo.mutation.SetMetricsID(id)
	return tmuo
}

// SetNillableMetricsID sets the "metrics" edge to the Metrics entity by ID if the given value is not nil.
func (tmuo *TimingMetricsUpdateOne) SetNillableMetricsID(id *int) *TimingMetricsUpdateOne {
	if id != nil {
		tmuo = tmuo.SetMetricsID(*id)
	}
	return tmuo
}

// SetMetrics sets the "metrics" edge to the Metrics entity.
func (tmuo *TimingMetricsUpdateOne) SetMetrics(m *Metrics) *TimingMetricsUpdateOne {
	return tmuo.SetMetricsID(m.ID)
}

// Mutation returns the TimingMetricsMutation object of the builder.
func (tmuo *TimingMetricsUpdateOne) Mutation() *TimingMetricsMutation {
	return tmuo.mutation
}

// ClearMetrics clears the "metrics" edge to the Metrics entity.
func (tmuo *TimingMetricsUpdateOne) ClearMetrics() *TimingMetricsUpdateOne {
	tmuo.mutation.ClearMetrics()
	return tmuo
}

// Where appends a list predicates to the TimingMetricsUpdate builder.
func (tmuo *TimingMetricsUpdateOne) Where(ps ...predicate.TimingMetrics) *TimingMetricsUpdateOne {
	tmuo.mutation.Where(ps...)
	return tmuo
}

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

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

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

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

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

func (tmuo *TimingMetricsUpdateOne) sqlSave(ctx context.Context) (_node *TimingMetrics, err error) {
	_spec := sqlgraph.NewUpdateSpec(timingmetrics.Table, timingmetrics.Columns, sqlgraph.NewFieldSpec(timingmetrics.FieldID, field.TypeInt))
	id, ok := tmuo.mutation.ID()
	if !ok {
		return nil, &ValidationError{Name: "id", err: errors.New(`ent: missing "TimingMetrics.id" for update`)}
	}
	_spec.Node.ID.Value = id
	if fields := tmuo.fields; len(fields) > 0 {
		_spec.Node.Columns = make([]string, 0, len(fields))
		_spec.Node.Columns = append(_spec.Node.Columns, timingmetrics.FieldID)
		for _, f := range fields {
			if !timingmetrics.ValidColumn(f) {
				return nil, &ValidationError{Name: f, err: fmt.Errorf("ent: invalid field %q for query", f)}
			}
			if f != timingmetrics.FieldID {
				_spec.Node.Columns = append(_spec.Node.Columns, f)
			}
		}
	}
	if ps := tmuo.mutation.predicates; len(ps) > 0 {
		_spec.Predicate = func(selector *sql.Selector) {
			for i := range ps {
				ps[i](selector)
			}
		}
	}
	if value, ok := tmuo.mutation.CPUTimeInMs(); ok {
		_spec.SetField(timingmetrics.FieldCPUTimeInMs, field.TypeInt64, value)
	}
	if value, ok := tmuo.mutation.AddedCPUTimeInMs(); ok {
		_spec.AddField(timingmetrics.FieldCPUTimeInMs, field.TypeInt64, value)
	}
	if tmuo.mutation.CPUTimeInMsCleared() {
		_spec.ClearField(timingmetrics.FieldCPUTimeInMs, field.TypeInt64)
	}
	if value, ok := tmuo.mutation.WallTimeInMs(); ok {
		_spec.SetField(timingmetrics.FieldWallTimeInMs, field.TypeInt64, value)
	}
	if value, ok := tmuo.mutation.AddedWallTimeInMs(); ok {
		_spec.AddField(timingmetrics.FieldWallTimeInMs, field.TypeInt64, value)
	}
	if tmuo.mutation.WallTimeInMsCleared() {
		_spec.ClearField(timingmetrics.FieldWallTimeInMs, field.TypeInt64)
	}
	if value, ok := tmuo.mutation.AnalysisPhaseTimeInMs(); ok {
		_spec.SetField(timingmetrics.FieldAnalysisPhaseTimeInMs, field.TypeInt64, value)
	}
	if value, ok := tmuo.mutation.AddedAnalysisPhaseTimeInMs(); ok {
		_spec.AddField(timingmetrics.FieldAnalysisPhaseTimeInMs, field.TypeInt64, value)
	}
	if tmuo.mutation.AnalysisPhaseTimeInMsCleared() {
		_spec.ClearField(timingmetrics.FieldAnalysisPhaseTimeInMs, field.TypeInt64)
	}
	if value, ok := tmuo.mutation.ExecutionPhaseTimeInMs(); ok {
		_spec.SetField(timingmetrics.FieldExecutionPhaseTimeInMs, field.TypeInt64, value)
	}
	if value, ok := tmuo.mutation.AddedExecutionPhaseTimeInMs(); ok {
		_spec.AddField(timingmetrics.FieldExecutionPhaseTimeInMs, field.TypeInt64, value)
	}
	if tmuo.mutation.ExecutionPhaseTimeInMsCleared() {
		_spec.ClearField(timingmetrics.FieldExecutionPhaseTimeInMs, field.TypeInt64)
	}
	if value, ok := tmuo.mutation.ActionsExecutionStartInMs(); ok {
		_spec.SetField(timingmetrics.FieldActionsExecutionStartInMs, field.TypeInt64, value)
	}
	if value, ok := tmuo.mutation.AddedActionsExecutionStartInMs(); ok {
		_spec.AddField(timingmetrics.FieldActionsExecutionStartInMs, field.TypeInt64, value)
	}
	if tmuo.mutation.ActionsExecutionStartInMsCleared() {
		_spec.ClearField(timingmetrics.FieldActionsExecutionStartInMs, field.TypeInt64)
	}
	if tmuo.mutation.MetricsCleared() {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.O2O,
			Inverse: true,
			Table:   timingmetrics.MetricsTable,
			Columns: []string{timingmetrics.MetricsColumn},
			Bidi:    false,
			Target: &sqlgraph.EdgeTarget{
				IDSpec: sqlgraph.NewFieldSpec(metrics.FieldID, field.TypeInt),
			},
		}
		_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
	}
	if nodes := tmuo.mutation.MetricsIDs(); len(nodes) > 0 {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.O2O,
			Inverse: true,
			Table:   timingmetrics.MetricsTable,
			Columns: []string{timingmetrics.MetricsColumn},
			Bidi:    false,
			Target: &sqlgraph.EdgeTarget{
				IDSpec: sqlgraph.NewFieldSpec(metrics.FieldID, field.TypeInt),
			},
		}
		for _, k := range nodes {
			edge.Target.Nodes = append(edge.Target.Nodes, k)
		}
		_spec.Edges.Add = append(_spec.Edges.Add, edge)
	}
	_node = &TimingMetrics{config: tmuo.config}
	_spec.Assign = _node.assignValues
	_spec.ScanValues = _node.scanValues
	if err = sqlgraph.UpdateNode(ctx, tmuo.driver, _spec); err != nil {
		if _, ok := err.(*sqlgraph.NotFoundError); ok {
			err = &NotFoundError{timingmetrics.Label}
		} else if sqlgraph.IsConstraintError(err) {
			err = &ConstraintError{msg: err.Error(), wrap: err}
		}
		return nil, err
	}
	tmuo.mutation.done = true
	return _node, nil
}
