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

// MemoryMetricsUpdate is the builder for updating MemoryMetrics entities.
type MemoryMetricsUpdate struct {
	config
	hooks    []Hook
	mutation *MemoryMetricsMutation
}

// Where appends a list predicates to the MemoryMetricsUpdate builder.
func (mmu *MemoryMetricsUpdate) Where(ps ...predicate.MemoryMetrics) *MemoryMetricsUpdate {
	mmu.mutation.Where(ps...)
	return mmu
}

// SetPeakPostGcHeapSize sets the "peak_post_gc_heap_size" field.
func (mmu *MemoryMetricsUpdate) SetPeakPostGcHeapSize(i int64) *MemoryMetricsUpdate {
	mmu.mutation.ResetPeakPostGcHeapSize()
	mmu.mutation.SetPeakPostGcHeapSize(i)
	return mmu
}

// SetNillablePeakPostGcHeapSize sets the "peak_post_gc_heap_size" field if the given value is not nil.
func (mmu *MemoryMetricsUpdate) SetNillablePeakPostGcHeapSize(i *int64) *MemoryMetricsUpdate {
	if i != nil {
		mmu.SetPeakPostGcHeapSize(*i)
	}
	return mmu
}

// AddPeakPostGcHeapSize adds i to the "peak_post_gc_heap_size" field.
func (mmu *MemoryMetricsUpdate) AddPeakPostGcHeapSize(i int64) *MemoryMetricsUpdate {
	mmu.mutation.AddPeakPostGcHeapSize(i)
	return mmu
}

// ClearPeakPostGcHeapSize clears the value of the "peak_post_gc_heap_size" field.
func (mmu *MemoryMetricsUpdate) ClearPeakPostGcHeapSize() *MemoryMetricsUpdate {
	mmu.mutation.ClearPeakPostGcHeapSize()
	return mmu
}

// SetUsedHeapSizePostBuild sets the "used_heap_size_post_build" field.
func (mmu *MemoryMetricsUpdate) SetUsedHeapSizePostBuild(i int64) *MemoryMetricsUpdate {
	mmu.mutation.ResetUsedHeapSizePostBuild()
	mmu.mutation.SetUsedHeapSizePostBuild(i)
	return mmu
}

// SetNillableUsedHeapSizePostBuild sets the "used_heap_size_post_build" field if the given value is not nil.
func (mmu *MemoryMetricsUpdate) SetNillableUsedHeapSizePostBuild(i *int64) *MemoryMetricsUpdate {
	if i != nil {
		mmu.SetUsedHeapSizePostBuild(*i)
	}
	return mmu
}

// AddUsedHeapSizePostBuild adds i to the "used_heap_size_post_build" field.
func (mmu *MemoryMetricsUpdate) AddUsedHeapSizePostBuild(i int64) *MemoryMetricsUpdate {
	mmu.mutation.AddUsedHeapSizePostBuild(i)
	return mmu
}

// ClearUsedHeapSizePostBuild clears the value of the "used_heap_size_post_build" field.
func (mmu *MemoryMetricsUpdate) ClearUsedHeapSizePostBuild() *MemoryMetricsUpdate {
	mmu.mutation.ClearUsedHeapSizePostBuild()
	return mmu
}

// SetPeakPostGcTenuredSpaceHeapSize sets the "peak_post_gc_tenured_space_heap_size" field.
func (mmu *MemoryMetricsUpdate) SetPeakPostGcTenuredSpaceHeapSize(i int64) *MemoryMetricsUpdate {
	mmu.mutation.ResetPeakPostGcTenuredSpaceHeapSize()
	mmu.mutation.SetPeakPostGcTenuredSpaceHeapSize(i)
	return mmu
}

// SetNillablePeakPostGcTenuredSpaceHeapSize sets the "peak_post_gc_tenured_space_heap_size" field if the given value is not nil.
func (mmu *MemoryMetricsUpdate) SetNillablePeakPostGcTenuredSpaceHeapSize(i *int64) *MemoryMetricsUpdate {
	if i != nil {
		mmu.SetPeakPostGcTenuredSpaceHeapSize(*i)
	}
	return mmu
}

// AddPeakPostGcTenuredSpaceHeapSize adds i to the "peak_post_gc_tenured_space_heap_size" field.
func (mmu *MemoryMetricsUpdate) AddPeakPostGcTenuredSpaceHeapSize(i int64) *MemoryMetricsUpdate {
	mmu.mutation.AddPeakPostGcTenuredSpaceHeapSize(i)
	return mmu
}

// ClearPeakPostGcTenuredSpaceHeapSize clears the value of the "peak_post_gc_tenured_space_heap_size" field.
func (mmu *MemoryMetricsUpdate) ClearPeakPostGcTenuredSpaceHeapSize() *MemoryMetricsUpdate {
	mmu.mutation.ClearPeakPostGcTenuredSpaceHeapSize()
	return mmu
}

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

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

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

// AddGarbageMetricIDs adds the "garbage_metrics" edge to the GarbageMetrics entity by IDs.
func (mmu *MemoryMetricsUpdate) AddGarbageMetricIDs(ids ...int) *MemoryMetricsUpdate {
	mmu.mutation.AddGarbageMetricIDs(ids...)
	return mmu
}

// AddGarbageMetrics adds the "garbage_metrics" edges to the GarbageMetrics entity.
func (mmu *MemoryMetricsUpdate) AddGarbageMetrics(g ...*GarbageMetrics) *MemoryMetricsUpdate {
	ids := make([]int, len(g))
	for i := range g {
		ids[i] = g[i].ID
	}
	return mmu.AddGarbageMetricIDs(ids...)
}

// Mutation returns the MemoryMetricsMutation object of the builder.
func (mmu *MemoryMetricsUpdate) Mutation() *MemoryMetricsMutation {
	return mmu.mutation
}

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

// ClearGarbageMetrics clears all "garbage_metrics" edges to the GarbageMetrics entity.
func (mmu *MemoryMetricsUpdate) ClearGarbageMetrics() *MemoryMetricsUpdate {
	mmu.mutation.ClearGarbageMetrics()
	return mmu
}

// RemoveGarbageMetricIDs removes the "garbage_metrics" edge to GarbageMetrics entities by IDs.
func (mmu *MemoryMetricsUpdate) RemoveGarbageMetricIDs(ids ...int) *MemoryMetricsUpdate {
	mmu.mutation.RemoveGarbageMetricIDs(ids...)
	return mmu
}

// RemoveGarbageMetrics removes "garbage_metrics" edges to GarbageMetrics entities.
func (mmu *MemoryMetricsUpdate) RemoveGarbageMetrics(g ...*GarbageMetrics) *MemoryMetricsUpdate {
	ids := make([]int, len(g))
	for i := range g {
		ids[i] = g[i].ID
	}
	return mmu.RemoveGarbageMetricIDs(ids...)
}

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

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

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

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

func (mmu *MemoryMetricsUpdate) sqlSave(ctx context.Context) (n int, err error) {
	_spec := sqlgraph.NewUpdateSpec(memorymetrics.Table, memorymetrics.Columns, sqlgraph.NewFieldSpec(memorymetrics.FieldID, field.TypeInt))
	if ps := mmu.mutation.predicates; len(ps) > 0 {
		_spec.Predicate = func(selector *sql.Selector) {
			for i := range ps {
				ps[i](selector)
			}
		}
	}
	if value, ok := mmu.mutation.PeakPostGcHeapSize(); ok {
		_spec.SetField(memorymetrics.FieldPeakPostGcHeapSize, field.TypeInt64, value)
	}
	if value, ok := mmu.mutation.AddedPeakPostGcHeapSize(); ok {
		_spec.AddField(memorymetrics.FieldPeakPostGcHeapSize, field.TypeInt64, value)
	}
	if mmu.mutation.PeakPostGcHeapSizeCleared() {
		_spec.ClearField(memorymetrics.FieldPeakPostGcHeapSize, field.TypeInt64)
	}
	if value, ok := mmu.mutation.UsedHeapSizePostBuild(); ok {
		_spec.SetField(memorymetrics.FieldUsedHeapSizePostBuild, field.TypeInt64, value)
	}
	if value, ok := mmu.mutation.AddedUsedHeapSizePostBuild(); ok {
		_spec.AddField(memorymetrics.FieldUsedHeapSizePostBuild, field.TypeInt64, value)
	}
	if mmu.mutation.UsedHeapSizePostBuildCleared() {
		_spec.ClearField(memorymetrics.FieldUsedHeapSizePostBuild, field.TypeInt64)
	}
	if value, ok := mmu.mutation.PeakPostGcTenuredSpaceHeapSize(); ok {
		_spec.SetField(memorymetrics.FieldPeakPostGcTenuredSpaceHeapSize, field.TypeInt64, value)
	}
	if value, ok := mmu.mutation.AddedPeakPostGcTenuredSpaceHeapSize(); ok {
		_spec.AddField(memorymetrics.FieldPeakPostGcTenuredSpaceHeapSize, field.TypeInt64, value)
	}
	if mmu.mutation.PeakPostGcTenuredSpaceHeapSizeCleared() {
		_spec.ClearField(memorymetrics.FieldPeakPostGcTenuredSpaceHeapSize, field.TypeInt64)
	}
	if mmu.mutation.MetricsCleared() {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.O2O,
			Inverse: true,
			Table:   memorymetrics.MetricsTable,
			Columns: []string{memorymetrics.MetricsColumn},
			Bidi:    false,
			Target: &sqlgraph.EdgeTarget{
				IDSpec: sqlgraph.NewFieldSpec(metrics.FieldID, field.TypeInt),
			},
		}
		_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
	}
	if nodes := mmu.mutation.MetricsIDs(); len(nodes) > 0 {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.O2O,
			Inverse: true,
			Table:   memorymetrics.MetricsTable,
			Columns: []string{memorymetrics.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 mmu.mutation.GarbageMetricsCleared() {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.O2M,
			Inverse: false,
			Table:   memorymetrics.GarbageMetricsTable,
			Columns: []string{memorymetrics.GarbageMetricsColumn},
			Bidi:    false,
			Target: &sqlgraph.EdgeTarget{
				IDSpec: sqlgraph.NewFieldSpec(garbagemetrics.FieldID, field.TypeInt),
			},
		}
		_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
	}
	if nodes := mmu.mutation.RemovedGarbageMetricsIDs(); len(nodes) > 0 && !mmu.mutation.GarbageMetricsCleared() {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.O2M,
			Inverse: false,
			Table:   memorymetrics.GarbageMetricsTable,
			Columns: []string{memorymetrics.GarbageMetricsColumn},
			Bidi:    false,
			Target: &sqlgraph.EdgeTarget{
				IDSpec: sqlgraph.NewFieldSpec(garbagemetrics.FieldID, field.TypeInt),
			},
		}
		for _, k := range nodes {
			edge.Target.Nodes = append(edge.Target.Nodes, k)
		}
		_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
	}
	if nodes := mmu.mutation.GarbageMetricsIDs(); len(nodes) > 0 {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.O2M,
			Inverse: false,
			Table:   memorymetrics.GarbageMetricsTable,
			Columns: []string{memorymetrics.GarbageMetricsColumn},
			Bidi:    false,
			Target: &sqlgraph.EdgeTarget{
				IDSpec: sqlgraph.NewFieldSpec(garbagemetrics.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, mmu.driver, _spec); err != nil {
		if _, ok := err.(*sqlgraph.NotFoundError); ok {
			err = &NotFoundError{memorymetrics.Label}
		} else if sqlgraph.IsConstraintError(err) {
			err = &ConstraintError{msg: err.Error(), wrap: err}
		}
		return 0, err
	}
	mmu.mutation.done = true
	return n, nil
}

// MemoryMetricsUpdateOne is the builder for updating a single MemoryMetrics entity.
type MemoryMetricsUpdateOne struct {
	config
	fields   []string
	hooks    []Hook
	mutation *MemoryMetricsMutation
}

// SetPeakPostGcHeapSize sets the "peak_post_gc_heap_size" field.
func (mmuo *MemoryMetricsUpdateOne) SetPeakPostGcHeapSize(i int64) *MemoryMetricsUpdateOne {
	mmuo.mutation.ResetPeakPostGcHeapSize()
	mmuo.mutation.SetPeakPostGcHeapSize(i)
	return mmuo
}

// SetNillablePeakPostGcHeapSize sets the "peak_post_gc_heap_size" field if the given value is not nil.
func (mmuo *MemoryMetricsUpdateOne) SetNillablePeakPostGcHeapSize(i *int64) *MemoryMetricsUpdateOne {
	if i != nil {
		mmuo.SetPeakPostGcHeapSize(*i)
	}
	return mmuo
}

// AddPeakPostGcHeapSize adds i to the "peak_post_gc_heap_size" field.
func (mmuo *MemoryMetricsUpdateOne) AddPeakPostGcHeapSize(i int64) *MemoryMetricsUpdateOne {
	mmuo.mutation.AddPeakPostGcHeapSize(i)
	return mmuo
}

// ClearPeakPostGcHeapSize clears the value of the "peak_post_gc_heap_size" field.
func (mmuo *MemoryMetricsUpdateOne) ClearPeakPostGcHeapSize() *MemoryMetricsUpdateOne {
	mmuo.mutation.ClearPeakPostGcHeapSize()
	return mmuo
}

// SetUsedHeapSizePostBuild sets the "used_heap_size_post_build" field.
func (mmuo *MemoryMetricsUpdateOne) SetUsedHeapSizePostBuild(i int64) *MemoryMetricsUpdateOne {
	mmuo.mutation.ResetUsedHeapSizePostBuild()
	mmuo.mutation.SetUsedHeapSizePostBuild(i)
	return mmuo
}

// SetNillableUsedHeapSizePostBuild sets the "used_heap_size_post_build" field if the given value is not nil.
func (mmuo *MemoryMetricsUpdateOne) SetNillableUsedHeapSizePostBuild(i *int64) *MemoryMetricsUpdateOne {
	if i != nil {
		mmuo.SetUsedHeapSizePostBuild(*i)
	}
	return mmuo
}

// AddUsedHeapSizePostBuild adds i to the "used_heap_size_post_build" field.
func (mmuo *MemoryMetricsUpdateOne) AddUsedHeapSizePostBuild(i int64) *MemoryMetricsUpdateOne {
	mmuo.mutation.AddUsedHeapSizePostBuild(i)
	return mmuo
}

// ClearUsedHeapSizePostBuild clears the value of the "used_heap_size_post_build" field.
func (mmuo *MemoryMetricsUpdateOne) ClearUsedHeapSizePostBuild() *MemoryMetricsUpdateOne {
	mmuo.mutation.ClearUsedHeapSizePostBuild()
	return mmuo
}

// SetPeakPostGcTenuredSpaceHeapSize sets the "peak_post_gc_tenured_space_heap_size" field.
func (mmuo *MemoryMetricsUpdateOne) SetPeakPostGcTenuredSpaceHeapSize(i int64) *MemoryMetricsUpdateOne {
	mmuo.mutation.ResetPeakPostGcTenuredSpaceHeapSize()
	mmuo.mutation.SetPeakPostGcTenuredSpaceHeapSize(i)
	return mmuo
}

// SetNillablePeakPostGcTenuredSpaceHeapSize sets the "peak_post_gc_tenured_space_heap_size" field if the given value is not nil.
func (mmuo *MemoryMetricsUpdateOne) SetNillablePeakPostGcTenuredSpaceHeapSize(i *int64) *MemoryMetricsUpdateOne {
	if i != nil {
		mmuo.SetPeakPostGcTenuredSpaceHeapSize(*i)
	}
	return mmuo
}

// AddPeakPostGcTenuredSpaceHeapSize adds i to the "peak_post_gc_tenured_space_heap_size" field.
func (mmuo *MemoryMetricsUpdateOne) AddPeakPostGcTenuredSpaceHeapSize(i int64) *MemoryMetricsUpdateOne {
	mmuo.mutation.AddPeakPostGcTenuredSpaceHeapSize(i)
	return mmuo
}

// ClearPeakPostGcTenuredSpaceHeapSize clears the value of the "peak_post_gc_tenured_space_heap_size" field.
func (mmuo *MemoryMetricsUpdateOne) ClearPeakPostGcTenuredSpaceHeapSize() *MemoryMetricsUpdateOne {
	mmuo.mutation.ClearPeakPostGcTenuredSpaceHeapSize()
	return mmuo
}

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

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

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

// AddGarbageMetricIDs adds the "garbage_metrics" edge to the GarbageMetrics entity by IDs.
func (mmuo *MemoryMetricsUpdateOne) AddGarbageMetricIDs(ids ...int) *MemoryMetricsUpdateOne {
	mmuo.mutation.AddGarbageMetricIDs(ids...)
	return mmuo
}

// AddGarbageMetrics adds the "garbage_metrics" edges to the GarbageMetrics entity.
func (mmuo *MemoryMetricsUpdateOne) AddGarbageMetrics(g ...*GarbageMetrics) *MemoryMetricsUpdateOne {
	ids := make([]int, len(g))
	for i := range g {
		ids[i] = g[i].ID
	}
	return mmuo.AddGarbageMetricIDs(ids...)
}

// Mutation returns the MemoryMetricsMutation object of the builder.
func (mmuo *MemoryMetricsUpdateOne) Mutation() *MemoryMetricsMutation {
	return mmuo.mutation
}

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

// ClearGarbageMetrics clears all "garbage_metrics" edges to the GarbageMetrics entity.
func (mmuo *MemoryMetricsUpdateOne) ClearGarbageMetrics() *MemoryMetricsUpdateOne {
	mmuo.mutation.ClearGarbageMetrics()
	return mmuo
}

// RemoveGarbageMetricIDs removes the "garbage_metrics" edge to GarbageMetrics entities by IDs.
func (mmuo *MemoryMetricsUpdateOne) RemoveGarbageMetricIDs(ids ...int) *MemoryMetricsUpdateOne {
	mmuo.mutation.RemoveGarbageMetricIDs(ids...)
	return mmuo
}

// RemoveGarbageMetrics removes "garbage_metrics" edges to GarbageMetrics entities.
func (mmuo *MemoryMetricsUpdateOne) RemoveGarbageMetrics(g ...*GarbageMetrics) *MemoryMetricsUpdateOne {
	ids := make([]int, len(g))
	for i := range g {
		ids[i] = g[i].ID
	}
	return mmuo.RemoveGarbageMetricIDs(ids...)
}

// Where appends a list predicates to the MemoryMetricsUpdate builder.
func (mmuo *MemoryMetricsUpdateOne) Where(ps ...predicate.MemoryMetrics) *MemoryMetricsUpdateOne {
	mmuo.mutation.Where(ps...)
	return mmuo
}

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

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

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

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

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

func (mmuo *MemoryMetricsUpdateOne) sqlSave(ctx context.Context) (_node *MemoryMetrics, err error) {
	_spec := sqlgraph.NewUpdateSpec(memorymetrics.Table, memorymetrics.Columns, sqlgraph.NewFieldSpec(memorymetrics.FieldID, field.TypeInt))
	id, ok := mmuo.mutation.ID()
	if !ok {
		return nil, &ValidationError{Name: "id", err: errors.New(`ent: missing "MemoryMetrics.id" for update`)}
	}
	_spec.Node.ID.Value = id
	if fields := mmuo.fields; len(fields) > 0 {
		_spec.Node.Columns = make([]string, 0, len(fields))
		_spec.Node.Columns = append(_spec.Node.Columns, memorymetrics.FieldID)
		for _, f := range fields {
			if !memorymetrics.ValidColumn(f) {
				return nil, &ValidationError{Name: f, err: fmt.Errorf("ent: invalid field %q for query", f)}
			}
			if f != memorymetrics.FieldID {
				_spec.Node.Columns = append(_spec.Node.Columns, f)
			}
		}
	}
	if ps := mmuo.mutation.predicates; len(ps) > 0 {
		_spec.Predicate = func(selector *sql.Selector) {
			for i := range ps {
				ps[i](selector)
			}
		}
	}
	if value, ok := mmuo.mutation.PeakPostGcHeapSize(); ok {
		_spec.SetField(memorymetrics.FieldPeakPostGcHeapSize, field.TypeInt64, value)
	}
	if value, ok := mmuo.mutation.AddedPeakPostGcHeapSize(); ok {
		_spec.AddField(memorymetrics.FieldPeakPostGcHeapSize, field.TypeInt64, value)
	}
	if mmuo.mutation.PeakPostGcHeapSizeCleared() {
		_spec.ClearField(memorymetrics.FieldPeakPostGcHeapSize, field.TypeInt64)
	}
	if value, ok := mmuo.mutation.UsedHeapSizePostBuild(); ok {
		_spec.SetField(memorymetrics.FieldUsedHeapSizePostBuild, field.TypeInt64, value)
	}
	if value, ok := mmuo.mutation.AddedUsedHeapSizePostBuild(); ok {
		_spec.AddField(memorymetrics.FieldUsedHeapSizePostBuild, field.TypeInt64, value)
	}
	if mmuo.mutation.UsedHeapSizePostBuildCleared() {
		_spec.ClearField(memorymetrics.FieldUsedHeapSizePostBuild, field.TypeInt64)
	}
	if value, ok := mmuo.mutation.PeakPostGcTenuredSpaceHeapSize(); ok {
		_spec.SetField(memorymetrics.FieldPeakPostGcTenuredSpaceHeapSize, field.TypeInt64, value)
	}
	if value, ok := mmuo.mutation.AddedPeakPostGcTenuredSpaceHeapSize(); ok {
		_spec.AddField(memorymetrics.FieldPeakPostGcTenuredSpaceHeapSize, field.TypeInt64, value)
	}
	if mmuo.mutation.PeakPostGcTenuredSpaceHeapSizeCleared() {
		_spec.ClearField(memorymetrics.FieldPeakPostGcTenuredSpaceHeapSize, field.TypeInt64)
	}
	if mmuo.mutation.MetricsCleared() {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.O2O,
			Inverse: true,
			Table:   memorymetrics.MetricsTable,
			Columns: []string{memorymetrics.MetricsColumn},
			Bidi:    false,
			Target: &sqlgraph.EdgeTarget{
				IDSpec: sqlgraph.NewFieldSpec(metrics.FieldID, field.TypeInt),
			},
		}
		_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
	}
	if nodes := mmuo.mutation.MetricsIDs(); len(nodes) > 0 {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.O2O,
			Inverse: true,
			Table:   memorymetrics.MetricsTable,
			Columns: []string{memorymetrics.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 mmuo.mutation.GarbageMetricsCleared() {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.O2M,
			Inverse: false,
			Table:   memorymetrics.GarbageMetricsTable,
			Columns: []string{memorymetrics.GarbageMetricsColumn},
			Bidi:    false,
			Target: &sqlgraph.EdgeTarget{
				IDSpec: sqlgraph.NewFieldSpec(garbagemetrics.FieldID, field.TypeInt),
			},
		}
		_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
	}
	if nodes := mmuo.mutation.RemovedGarbageMetricsIDs(); len(nodes) > 0 && !mmuo.mutation.GarbageMetricsCleared() {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.O2M,
			Inverse: false,
			Table:   memorymetrics.GarbageMetricsTable,
			Columns: []string{memorymetrics.GarbageMetricsColumn},
			Bidi:    false,
			Target: &sqlgraph.EdgeTarget{
				IDSpec: sqlgraph.NewFieldSpec(garbagemetrics.FieldID, field.TypeInt),
			},
		}
		for _, k := range nodes {
			edge.Target.Nodes = append(edge.Target.Nodes, k)
		}
		_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
	}
	if nodes := mmuo.mutation.GarbageMetricsIDs(); len(nodes) > 0 {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.O2M,
			Inverse: false,
			Table:   memorymetrics.GarbageMetricsTable,
			Columns: []string{memorymetrics.GarbageMetricsColumn},
			Bidi:    false,
			Target: &sqlgraph.EdgeTarget{
				IDSpec: sqlgraph.NewFieldSpec(garbagemetrics.FieldID, field.TypeInt),
			},
		}
		for _, k := range nodes {
			edge.Target.Nodes = append(edge.Target.Nodes, k)
		}
		_spec.Edges.Add = append(_spec.Edges.Add, edge)
	}
	_node = &MemoryMetrics{config: mmuo.config}
	_spec.Assign = _node.assignValues
	_spec.ScanValues = _node.scanValues
	if err = sqlgraph.UpdateNode(ctx, mmuo.driver, _spec); err != nil {
		if _, ok := err.(*sqlgraph.NotFoundError); ok {
			err = &NotFoundError{memorymetrics.Label}
		} else if sqlgraph.IsConstraintError(err) {
			err = &ConstraintError{msg: err.Error(), wrap: err}
		}
		return nil, err
	}
	mmuo.mutation.done = true
	return _node, nil
}
