// Code generated by ent, DO NOT EDIT. package ent import ( "context" "errors" "fmt" "time" "entgo.io/ent/dialect/sql" "entgo.io/ent/dialect/sql/sqlgraph" "entgo.io/ent/schema/field" "github.com/Wei-Shaw/sub2api/ent/channelmonitor" "github.com/Wei-Shaw/sub2api/ent/channelmonitorhistory" "github.com/Wei-Shaw/sub2api/ent/predicate" ) // ChannelMonitorHistoryUpdate is the builder for updating ChannelMonitorHistory entities. type ChannelMonitorHistoryUpdate struct { config hooks []Hook mutation *ChannelMonitorHistoryMutation } // Where appends a list predicates to the ChannelMonitorHistoryUpdate builder. func (_u *ChannelMonitorHistoryUpdate) Where(ps ...predicate.ChannelMonitorHistory) *ChannelMonitorHistoryUpdate { _u.mutation.Where(ps...) return _u } // SetMonitorID sets the "monitor_id" field. func (_u *ChannelMonitorHistoryUpdate) SetMonitorID(v int64) *ChannelMonitorHistoryUpdate { _u.mutation.SetMonitorID(v) return _u } // SetNillableMonitorID sets the "monitor_id" field if the given value is not nil. func (_u *ChannelMonitorHistoryUpdate) SetNillableMonitorID(v *int64) *ChannelMonitorHistoryUpdate { if v != nil { _u.SetMonitorID(*v) } return _u } // SetModel sets the "model" field. func (_u *ChannelMonitorHistoryUpdate) SetModel(v string) *ChannelMonitorHistoryUpdate { _u.mutation.SetModel(v) return _u } // SetNillableModel sets the "model" field if the given value is not nil. func (_u *ChannelMonitorHistoryUpdate) SetNillableModel(v *string) *ChannelMonitorHistoryUpdate { if v != nil { _u.SetModel(*v) } return _u } // SetStatus sets the "status" field. func (_u *ChannelMonitorHistoryUpdate) SetStatus(v channelmonitorhistory.Status) *ChannelMonitorHistoryUpdate { _u.mutation.SetStatus(v) return _u } // SetNillableStatus sets the "status" field if the given value is not nil. func (_u *ChannelMonitorHistoryUpdate) SetNillableStatus(v *channelmonitorhistory.Status) *ChannelMonitorHistoryUpdate { if v != nil { _u.SetStatus(*v) } return _u } // SetLatencyMs sets the "latency_ms" field. func (_u *ChannelMonitorHistoryUpdate) SetLatencyMs(v int) *ChannelMonitorHistoryUpdate { _u.mutation.ResetLatencyMs() _u.mutation.SetLatencyMs(v) return _u } // SetNillableLatencyMs sets the "latency_ms" field if the given value is not nil. func (_u *ChannelMonitorHistoryUpdate) SetNillableLatencyMs(v *int) *ChannelMonitorHistoryUpdate { if v != nil { _u.SetLatencyMs(*v) } return _u } // AddLatencyMs adds value to the "latency_ms" field. func (_u *ChannelMonitorHistoryUpdate) AddLatencyMs(v int) *ChannelMonitorHistoryUpdate { _u.mutation.AddLatencyMs(v) return _u } // ClearLatencyMs clears the value of the "latency_ms" field. func (_u *ChannelMonitorHistoryUpdate) ClearLatencyMs() *ChannelMonitorHistoryUpdate { _u.mutation.ClearLatencyMs() return _u } // SetPingLatencyMs sets the "ping_latency_ms" field. func (_u *ChannelMonitorHistoryUpdate) SetPingLatencyMs(v int) *ChannelMonitorHistoryUpdate { _u.mutation.ResetPingLatencyMs() _u.mutation.SetPingLatencyMs(v) return _u } // SetNillablePingLatencyMs sets the "ping_latency_ms" field if the given value is not nil. func (_u *ChannelMonitorHistoryUpdate) SetNillablePingLatencyMs(v *int) *ChannelMonitorHistoryUpdate { if v != nil { _u.SetPingLatencyMs(*v) } return _u } // AddPingLatencyMs adds value to the "ping_latency_ms" field. func (_u *ChannelMonitorHistoryUpdate) AddPingLatencyMs(v int) *ChannelMonitorHistoryUpdate { _u.mutation.AddPingLatencyMs(v) return _u } // ClearPingLatencyMs clears the value of the "ping_latency_ms" field. func (_u *ChannelMonitorHistoryUpdate) ClearPingLatencyMs() *ChannelMonitorHistoryUpdate { _u.mutation.ClearPingLatencyMs() return _u } // SetMessage sets the "message" field. func (_u *ChannelMonitorHistoryUpdate) SetMessage(v string) *ChannelMonitorHistoryUpdate { _u.mutation.SetMessage(v) return _u } // SetNillableMessage sets the "message" field if the given value is not nil. func (_u *ChannelMonitorHistoryUpdate) SetNillableMessage(v *string) *ChannelMonitorHistoryUpdate { if v != nil { _u.SetMessage(*v) } return _u } // ClearMessage clears the value of the "message" field. func (_u *ChannelMonitorHistoryUpdate) ClearMessage() *ChannelMonitorHistoryUpdate { _u.mutation.ClearMessage() return _u } // SetCheckedAt sets the "checked_at" field. func (_u *ChannelMonitorHistoryUpdate) SetCheckedAt(v time.Time) *ChannelMonitorHistoryUpdate { _u.mutation.SetCheckedAt(v) return _u } // SetNillableCheckedAt sets the "checked_at" field if the given value is not nil. func (_u *ChannelMonitorHistoryUpdate) SetNillableCheckedAt(v *time.Time) *ChannelMonitorHistoryUpdate { if v != nil { _u.SetCheckedAt(*v) } return _u } // SetMonitor sets the "monitor" edge to the ChannelMonitor entity. func (_u *ChannelMonitorHistoryUpdate) SetMonitor(v *ChannelMonitor) *ChannelMonitorHistoryUpdate { return _u.SetMonitorID(v.ID) } // Mutation returns the ChannelMonitorHistoryMutation object of the builder. func (_u *ChannelMonitorHistoryUpdate) Mutation() *ChannelMonitorHistoryMutation { return _u.mutation } // ClearMonitor clears the "monitor" edge to the ChannelMonitor entity. func (_u *ChannelMonitorHistoryUpdate) ClearMonitor() *ChannelMonitorHistoryUpdate { _u.mutation.ClearMonitor() return _u } // Save executes the query and returns the number of nodes affected by the update operation. func (_u *ChannelMonitorHistoryUpdate) 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 *ChannelMonitorHistoryUpdate) SaveX(ctx context.Context) int { affected, err := _u.Save(ctx) if err != nil { panic(err) } return affected } // Exec executes the query. func (_u *ChannelMonitorHistoryUpdate) Exec(ctx context.Context) error { _, err := _u.Save(ctx) return err } // ExecX is like Exec, but panics if an error occurs. func (_u *ChannelMonitorHistoryUpdate) 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 *ChannelMonitorHistoryUpdate) check() error { if v, ok := _u.mutation.Model(); ok { if err := channelmonitorhistory.ModelValidator(v); err != nil { return &ValidationError{Name: "model", err: fmt.Errorf(`ent: validator failed for field "ChannelMonitorHistory.model": %w`, err)} } } if v, ok := _u.mutation.Status(); ok { if err := channelmonitorhistory.StatusValidator(v); err != nil { return &ValidationError{Name: "status", err: fmt.Errorf(`ent: validator failed for field "ChannelMonitorHistory.status": %w`, err)} } } if v, ok := _u.mutation.Message(); ok { if err := channelmonitorhistory.MessageValidator(v); err != nil { return &ValidationError{Name: "message", err: fmt.Errorf(`ent: validator failed for field "ChannelMonitorHistory.message": %w`, err)} } } if _u.mutation.MonitorCleared() && len(_u.mutation.MonitorIDs()) > 0 { return errors.New(`ent: clearing a required unique edge "ChannelMonitorHistory.monitor"`) } return nil } func (_u *ChannelMonitorHistoryUpdate) sqlSave(ctx context.Context) (_node int, err error) { if err := _u.check(); err != nil { return _node, err } _spec := sqlgraph.NewUpdateSpec(channelmonitorhistory.Table, channelmonitorhistory.Columns, sqlgraph.NewFieldSpec(channelmonitorhistory.FieldID, field.TypeInt64)) 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.Model(); ok { _spec.SetField(channelmonitorhistory.FieldModel, field.TypeString, value) } if value, ok := _u.mutation.Status(); ok { _spec.SetField(channelmonitorhistory.FieldStatus, field.TypeEnum, value) } if value, ok := _u.mutation.LatencyMs(); ok { _spec.SetField(channelmonitorhistory.FieldLatencyMs, field.TypeInt, value) } if value, ok := _u.mutation.AddedLatencyMs(); ok { _spec.AddField(channelmonitorhistory.FieldLatencyMs, field.TypeInt, value) } if _u.mutation.LatencyMsCleared() { _spec.ClearField(channelmonitorhistory.FieldLatencyMs, field.TypeInt) } if value, ok := _u.mutation.PingLatencyMs(); ok { _spec.SetField(channelmonitorhistory.FieldPingLatencyMs, field.TypeInt, value) } if value, ok := _u.mutation.AddedPingLatencyMs(); ok { _spec.AddField(channelmonitorhistory.FieldPingLatencyMs, field.TypeInt, value) } if _u.mutation.PingLatencyMsCleared() { _spec.ClearField(channelmonitorhistory.FieldPingLatencyMs, field.TypeInt) } if value, ok := _u.mutation.Message(); ok { _spec.SetField(channelmonitorhistory.FieldMessage, field.TypeString, value) } if _u.mutation.MessageCleared() { _spec.ClearField(channelmonitorhistory.FieldMessage, field.TypeString) } if value, ok := _u.mutation.CheckedAt(); ok { _spec.SetField(channelmonitorhistory.FieldCheckedAt, field.TypeTime, value) } if _u.mutation.MonitorCleared() { edge := &sqlgraph.EdgeSpec{ Rel: sqlgraph.M2O, Inverse: true, Table: channelmonitorhistory.MonitorTable, Columns: []string{channelmonitorhistory.MonitorColumn}, Bidi: false, Target: &sqlgraph.EdgeTarget{ IDSpec: sqlgraph.NewFieldSpec(channelmonitor.FieldID, field.TypeInt64), }, } _spec.Edges.Clear = append(_spec.Edges.Clear, edge) } if nodes := _u.mutation.MonitorIDs(); len(nodes) > 0 { edge := &sqlgraph.EdgeSpec{ Rel: sqlgraph.M2O, Inverse: true, Table: channelmonitorhistory.MonitorTable, Columns: []string{channelmonitorhistory.MonitorColumn}, Bidi: false, Target: &sqlgraph.EdgeTarget{ IDSpec: sqlgraph.NewFieldSpec(channelmonitor.FieldID, field.TypeInt64), }, } for _, k := range nodes { edge.Target.Nodes = append(edge.Target.Nodes, k) } _spec.Edges.Add = append(_spec.Edges.Add, edge) } if _node, err = sqlgraph.UpdateNodes(ctx, _u.driver, _spec); err != nil { if _, ok := err.(*sqlgraph.NotFoundError); ok { err = &NotFoundError{channelmonitorhistory.Label} } else if sqlgraph.IsConstraintError(err) { err = &ConstraintError{msg: err.Error(), wrap: err} } return 0, err } _u.mutation.done = true return _node, nil } // ChannelMonitorHistoryUpdateOne is the builder for updating a single ChannelMonitorHistory entity. type ChannelMonitorHistoryUpdateOne struct { config fields []string hooks []Hook mutation *ChannelMonitorHistoryMutation } // SetMonitorID sets the "monitor_id" field. func (_u *ChannelMonitorHistoryUpdateOne) SetMonitorID(v int64) *ChannelMonitorHistoryUpdateOne { _u.mutation.SetMonitorID(v) return _u } // SetNillableMonitorID sets the "monitor_id" field if the given value is not nil. func (_u *ChannelMonitorHistoryUpdateOne) SetNillableMonitorID(v *int64) *ChannelMonitorHistoryUpdateOne { if v != nil { _u.SetMonitorID(*v) } return _u } // SetModel sets the "model" field. func (_u *ChannelMonitorHistoryUpdateOne) SetModel(v string) *ChannelMonitorHistoryUpdateOne { _u.mutation.SetModel(v) return _u } // SetNillableModel sets the "model" field if the given value is not nil. func (_u *ChannelMonitorHistoryUpdateOne) SetNillableModel(v *string) *ChannelMonitorHistoryUpdateOne { if v != nil { _u.SetModel(*v) } return _u } // SetStatus sets the "status" field. func (_u *ChannelMonitorHistoryUpdateOne) SetStatus(v channelmonitorhistory.Status) *ChannelMonitorHistoryUpdateOne { _u.mutation.SetStatus(v) return _u } // SetNillableStatus sets the "status" field if the given value is not nil. func (_u *ChannelMonitorHistoryUpdateOne) SetNillableStatus(v *channelmonitorhistory.Status) *ChannelMonitorHistoryUpdateOne { if v != nil { _u.SetStatus(*v) } return _u } // SetLatencyMs sets the "latency_ms" field. func (_u *ChannelMonitorHistoryUpdateOne) SetLatencyMs(v int) *ChannelMonitorHistoryUpdateOne { _u.mutation.ResetLatencyMs() _u.mutation.SetLatencyMs(v) return _u } // SetNillableLatencyMs sets the "latency_ms" field if the given value is not nil. func (_u *ChannelMonitorHistoryUpdateOne) SetNillableLatencyMs(v *int) *ChannelMonitorHistoryUpdateOne { if v != nil { _u.SetLatencyMs(*v) } return _u } // AddLatencyMs adds value to the "latency_ms" field. func (_u *ChannelMonitorHistoryUpdateOne) AddLatencyMs(v int) *ChannelMonitorHistoryUpdateOne { _u.mutation.AddLatencyMs(v) return _u } // ClearLatencyMs clears the value of the "latency_ms" field. func (_u *ChannelMonitorHistoryUpdateOne) ClearLatencyMs() *ChannelMonitorHistoryUpdateOne { _u.mutation.ClearLatencyMs() return _u } // SetPingLatencyMs sets the "ping_latency_ms" field. func (_u *ChannelMonitorHistoryUpdateOne) SetPingLatencyMs(v int) *ChannelMonitorHistoryUpdateOne { _u.mutation.ResetPingLatencyMs() _u.mutation.SetPingLatencyMs(v) return _u } // SetNillablePingLatencyMs sets the "ping_latency_ms" field if the given value is not nil. func (_u *ChannelMonitorHistoryUpdateOne) SetNillablePingLatencyMs(v *int) *ChannelMonitorHistoryUpdateOne { if v != nil { _u.SetPingLatencyMs(*v) } return _u } // AddPingLatencyMs adds value to the "ping_latency_ms" field. func (_u *ChannelMonitorHistoryUpdateOne) AddPingLatencyMs(v int) *ChannelMonitorHistoryUpdateOne { _u.mutation.AddPingLatencyMs(v) return _u } // ClearPingLatencyMs clears the value of the "ping_latency_ms" field. func (_u *ChannelMonitorHistoryUpdateOne) ClearPingLatencyMs() *ChannelMonitorHistoryUpdateOne { _u.mutation.ClearPingLatencyMs() return _u } // SetMessage sets the "message" field. func (_u *ChannelMonitorHistoryUpdateOne) SetMessage(v string) *ChannelMonitorHistoryUpdateOne { _u.mutation.SetMessage(v) return _u } // SetNillableMessage sets the "message" field if the given value is not nil. func (_u *ChannelMonitorHistoryUpdateOne) SetNillableMessage(v *string) *ChannelMonitorHistoryUpdateOne { if v != nil { _u.SetMessage(*v) } return _u } // ClearMessage clears the value of the "message" field. func (_u *ChannelMonitorHistoryUpdateOne) ClearMessage() *ChannelMonitorHistoryUpdateOne { _u.mutation.ClearMessage() return _u } // SetCheckedAt sets the "checked_at" field. func (_u *ChannelMonitorHistoryUpdateOne) SetCheckedAt(v time.Time) *ChannelMonitorHistoryUpdateOne { _u.mutation.SetCheckedAt(v) return _u } // SetNillableCheckedAt sets the "checked_at" field if the given value is not nil. func (_u *ChannelMonitorHistoryUpdateOne) SetNillableCheckedAt(v *time.Time) *ChannelMonitorHistoryUpdateOne { if v != nil { _u.SetCheckedAt(*v) } return _u } // SetMonitor sets the "monitor" edge to the ChannelMonitor entity. func (_u *ChannelMonitorHistoryUpdateOne) SetMonitor(v *ChannelMonitor) *ChannelMonitorHistoryUpdateOne { return _u.SetMonitorID(v.ID) } // Mutation returns the ChannelMonitorHistoryMutation object of the builder. func (_u *ChannelMonitorHistoryUpdateOne) Mutation() *ChannelMonitorHistoryMutation { return _u.mutation } // ClearMonitor clears the "monitor" edge to the ChannelMonitor entity. func (_u *ChannelMonitorHistoryUpdateOne) ClearMonitor() *ChannelMonitorHistoryUpdateOne { _u.mutation.ClearMonitor() return _u } // Where appends a list predicates to the ChannelMonitorHistoryUpdate builder. func (_u *ChannelMonitorHistoryUpdateOne) Where(ps ...predicate.ChannelMonitorHistory) *ChannelMonitorHistoryUpdateOne { _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 *ChannelMonitorHistoryUpdateOne) Select(field string, fields ...string) *ChannelMonitorHistoryUpdateOne { _u.fields = append([]string{field}, fields...) return _u } // Save executes the query and returns the updated ChannelMonitorHistory entity. func (_u *ChannelMonitorHistoryUpdateOne) Save(ctx context.Context) (*ChannelMonitorHistory, error) { return withHooks(ctx, _u.sqlSave, _u.mutation, _u.hooks) } // SaveX is like Save, but panics if an error occurs. func (_u *ChannelMonitorHistoryUpdateOne) SaveX(ctx context.Context) *ChannelMonitorHistory { node, err := _u.Save(ctx) if err != nil { panic(err) } return node } // Exec executes the query on the entity. func (_u *ChannelMonitorHistoryUpdateOne) Exec(ctx context.Context) error { _, err := _u.Save(ctx) return err } // ExecX is like Exec, but panics if an error occurs. func (_u *ChannelMonitorHistoryUpdateOne) 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 *ChannelMonitorHistoryUpdateOne) check() error { if v, ok := _u.mutation.Model(); ok { if err := channelmonitorhistory.ModelValidator(v); err != nil { return &ValidationError{Name: "model", err: fmt.Errorf(`ent: validator failed for field "ChannelMonitorHistory.model": %w`, err)} } } if v, ok := _u.mutation.Status(); ok { if err := channelmonitorhistory.StatusValidator(v); err != nil { return &ValidationError{Name: "status", err: fmt.Errorf(`ent: validator failed for field "ChannelMonitorHistory.status": %w`, err)} } } if v, ok := _u.mutation.Message(); ok { if err := channelmonitorhistory.MessageValidator(v); err != nil { return &ValidationError{Name: "message", err: fmt.Errorf(`ent: validator failed for field "ChannelMonitorHistory.message": %w`, err)} } } if _u.mutation.MonitorCleared() && len(_u.mutation.MonitorIDs()) > 0 { return errors.New(`ent: clearing a required unique edge "ChannelMonitorHistory.monitor"`) } return nil } func (_u *ChannelMonitorHistoryUpdateOne) sqlSave(ctx context.Context) (_node *ChannelMonitorHistory, err error) { if err := _u.check(); err != nil { return _node, err } _spec := sqlgraph.NewUpdateSpec(channelmonitorhistory.Table, channelmonitorhistory.Columns, sqlgraph.NewFieldSpec(channelmonitorhistory.FieldID, field.TypeInt64)) id, ok := _u.mutation.ID() if !ok { return nil, &ValidationError{Name: "id", err: errors.New(`ent: missing "ChannelMonitorHistory.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, channelmonitorhistory.FieldID) for _, f := range fields { if !channelmonitorhistory.ValidColumn(f) { return nil, &ValidationError{Name: f, err: fmt.Errorf("ent: invalid field %q for query", f)} } if f != channelmonitorhistory.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.Model(); ok { _spec.SetField(channelmonitorhistory.FieldModel, field.TypeString, value) } if value, ok := _u.mutation.Status(); ok { _spec.SetField(channelmonitorhistory.FieldStatus, field.TypeEnum, value) } if value, ok := _u.mutation.LatencyMs(); ok { _spec.SetField(channelmonitorhistory.FieldLatencyMs, field.TypeInt, value) } if value, ok := _u.mutation.AddedLatencyMs(); ok { _spec.AddField(channelmonitorhistory.FieldLatencyMs, field.TypeInt, value) } if _u.mutation.LatencyMsCleared() { _spec.ClearField(channelmonitorhistory.FieldLatencyMs, field.TypeInt) } if value, ok := _u.mutation.PingLatencyMs(); ok { _spec.SetField(channelmonitorhistory.FieldPingLatencyMs, field.TypeInt, value) } if value, ok := _u.mutation.AddedPingLatencyMs(); ok { _spec.AddField(channelmonitorhistory.FieldPingLatencyMs, field.TypeInt, value) } if _u.mutation.PingLatencyMsCleared() { _spec.ClearField(channelmonitorhistory.FieldPingLatencyMs, field.TypeInt) } if value, ok := _u.mutation.Message(); ok { _spec.SetField(channelmonitorhistory.FieldMessage, field.TypeString, value) } if _u.mutation.MessageCleared() { _spec.ClearField(channelmonitorhistory.FieldMessage, field.TypeString) } if value, ok := _u.mutation.CheckedAt(); ok { _spec.SetField(channelmonitorhistory.FieldCheckedAt, field.TypeTime, value) } if _u.mutation.MonitorCleared() { edge := &sqlgraph.EdgeSpec{ Rel: sqlgraph.M2O, Inverse: true, Table: channelmonitorhistory.MonitorTable, Columns: []string{channelmonitorhistory.MonitorColumn}, Bidi: false, Target: &sqlgraph.EdgeTarget{ IDSpec: sqlgraph.NewFieldSpec(channelmonitor.FieldID, field.TypeInt64), }, } _spec.Edges.Clear = append(_spec.Edges.Clear, edge) } if nodes := _u.mutation.MonitorIDs(); len(nodes) > 0 { edge := &sqlgraph.EdgeSpec{ Rel: sqlgraph.M2O, Inverse: true, Table: channelmonitorhistory.MonitorTable, Columns: []string{channelmonitorhistory.MonitorColumn}, Bidi: false, Target: &sqlgraph.EdgeTarget{ IDSpec: sqlgraph.NewFieldSpec(channelmonitor.FieldID, field.TypeInt64), }, } for _, k := range nodes { edge.Target.Nodes = append(edge.Target.Nodes, k) } _spec.Edges.Add = append(_spec.Edges.Add, edge) } _node = &ChannelMonitorHistory{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{channelmonitorhistory.Label} } else if sqlgraph.IsConstraintError(err) { err = &ConstraintError{msg: err.Error(), wrap: err} } return nil, err } _u.mutation.done = true return _node, nil }