2026-09-14 16:31:08 +08:00
|
|
|
// Code generated by ent, DO NOT EDIT.
|
|
|
|
|
|
|
|
|
|
package ent
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"bj_power_mes/ent/alertrule"
|
|
|
|
|
"bj_power_mes/ent/predicate"
|
|
|
|
|
"context"
|
|
|
|
|
"errors"
|
|
|
|
|
"fmt"
|
|
|
|
|
|
|
|
|
|
"entgo.io/ent/dialect/sql"
|
|
|
|
|
"entgo.io/ent/dialect/sql/sqlgraph"
|
|
|
|
|
"entgo.io/ent/schema/field"
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
// AlertRuleUpdate is the builder for updating AlertRule entities.
|
|
|
|
|
type AlertRuleUpdate struct {
|
|
|
|
|
config
|
2026-09-15 16:37:39 +08:00
|
|
|
hooks []Hook
|
|
|
|
|
mutation *AlertRuleMutation
|
|
|
|
|
modifiers []func(*sql.UpdateBuilder)
|
2026-09-14 16:31:08 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Where appends a list predicates to the AlertRuleUpdate builder.
|
|
|
|
|
func (_u *AlertRuleUpdate) Where(ps ...predicate.AlertRule) *AlertRuleUpdate {
|
|
|
|
|
_u.mutation.Where(ps...)
|
|
|
|
|
return _u
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// SetName sets the "name" field.
|
|
|
|
|
func (_u *AlertRuleUpdate) SetName(v string) *AlertRuleUpdate {
|
|
|
|
|
_u.mutation.SetName(v)
|
|
|
|
|
return _u
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// SetNillableName sets the "name" field if the given value is not nil.
|
|
|
|
|
func (_u *AlertRuleUpdate) SetNillableName(v *string) *AlertRuleUpdate {
|
|
|
|
|
if v != nil {
|
|
|
|
|
_u.SetName(*v)
|
|
|
|
|
}
|
|
|
|
|
return _u
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// SetType sets the "type" field.
|
|
|
|
|
func (_u *AlertRuleUpdate) SetType(v string) *AlertRuleUpdate {
|
|
|
|
|
_u.mutation.SetType(v)
|
|
|
|
|
return _u
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// SetNillableType sets the "type" field if the given value is not nil.
|
|
|
|
|
func (_u *AlertRuleUpdate) SetNillableType(v *string) *AlertRuleUpdate {
|
|
|
|
|
if v != nil {
|
|
|
|
|
_u.SetType(*v)
|
|
|
|
|
}
|
|
|
|
|
return _u
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// SetThreshold sets the "threshold" field.
|
|
|
|
|
func (_u *AlertRuleUpdate) SetThreshold(v float64) *AlertRuleUpdate {
|
|
|
|
|
_u.mutation.ResetThreshold()
|
|
|
|
|
_u.mutation.SetThreshold(v)
|
|
|
|
|
return _u
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// SetNillableThreshold sets the "threshold" field if the given value is not nil.
|
|
|
|
|
func (_u *AlertRuleUpdate) SetNillableThreshold(v *float64) *AlertRuleUpdate {
|
|
|
|
|
if v != nil {
|
|
|
|
|
_u.SetThreshold(*v)
|
|
|
|
|
}
|
|
|
|
|
return _u
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// AddThreshold adds value to the "threshold" field.
|
|
|
|
|
func (_u *AlertRuleUpdate) AddThreshold(v float64) *AlertRuleUpdate {
|
|
|
|
|
_u.mutation.AddThreshold(v)
|
|
|
|
|
return _u
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// SetReceiver sets the "receiver" field.
|
|
|
|
|
func (_u *AlertRuleUpdate) SetReceiver(v string) *AlertRuleUpdate {
|
|
|
|
|
_u.mutation.SetReceiver(v)
|
|
|
|
|
return _u
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// SetNillableReceiver sets the "receiver" field if the given value is not nil.
|
|
|
|
|
func (_u *AlertRuleUpdate) SetNillableReceiver(v *string) *AlertRuleUpdate {
|
|
|
|
|
if v != nil {
|
|
|
|
|
_u.SetReceiver(*v)
|
|
|
|
|
}
|
|
|
|
|
return _u
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// SetEnabled sets the "enabled" field.
|
|
|
|
|
func (_u *AlertRuleUpdate) SetEnabled(v bool) *AlertRuleUpdate {
|
|
|
|
|
_u.mutation.SetEnabled(v)
|
|
|
|
|
return _u
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// SetNillableEnabled sets the "enabled" field if the given value is not nil.
|
|
|
|
|
func (_u *AlertRuleUpdate) SetNillableEnabled(v *bool) *AlertRuleUpdate {
|
|
|
|
|
if v != nil {
|
|
|
|
|
_u.SetEnabled(*v)
|
|
|
|
|
}
|
|
|
|
|
return _u
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// SetCreatedBy sets the "createdBy" field.
|
|
|
|
|
func (_u *AlertRuleUpdate) SetCreatedBy(v string) *AlertRuleUpdate {
|
|
|
|
|
_u.mutation.SetCreatedBy(v)
|
|
|
|
|
return _u
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// SetNillableCreatedBy sets the "createdBy" field if the given value is not nil.
|
|
|
|
|
func (_u *AlertRuleUpdate) SetNillableCreatedBy(v *string) *AlertRuleUpdate {
|
|
|
|
|
if v != nil {
|
|
|
|
|
_u.SetCreatedBy(*v)
|
|
|
|
|
}
|
|
|
|
|
return _u
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Mutation returns the AlertRuleMutation object of the builder.
|
|
|
|
|
func (_u *AlertRuleUpdate) Mutation() *AlertRuleMutation {
|
|
|
|
|
return _u.mutation
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Save executes the query and returns the number of nodes affected by the update operation.
|
|
|
|
|
func (_u *AlertRuleUpdate) 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 *AlertRuleUpdate) SaveX(ctx context.Context) int {
|
|
|
|
|
affected, err := _u.Save(ctx)
|
|
|
|
|
if err != nil {
|
|
|
|
|
panic(err)
|
|
|
|
|
}
|
|
|
|
|
return affected
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Exec executes the query.
|
|
|
|
|
func (_u *AlertRuleUpdate) Exec(ctx context.Context) error {
|
|
|
|
|
_, err := _u.Save(ctx)
|
|
|
|
|
return err
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// ExecX is like Exec, but panics if an error occurs.
|
|
|
|
|
func (_u *AlertRuleUpdate) 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 *AlertRuleUpdate) check() error {
|
|
|
|
|
if v, ok := _u.mutation.Name(); ok {
|
|
|
|
|
if err := alertrule.NameValidator(v); err != nil {
|
|
|
|
|
return &ValidationError{Name: "name", err: fmt.Errorf(`ent: validator failed for field "AlertRule.name": %w`, err)}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if v, ok := _u.mutation.GetType(); ok {
|
|
|
|
|
if err := alertrule.TypeValidator(v); err != nil {
|
|
|
|
|
return &ValidationError{Name: "type", err: fmt.Errorf(`ent: validator failed for field "AlertRule.type": %w`, err)}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if v, ok := _u.mutation.Receiver(); ok {
|
|
|
|
|
if err := alertrule.ReceiverValidator(v); err != nil {
|
|
|
|
|
return &ValidationError{Name: "receiver", err: fmt.Errorf(`ent: validator failed for field "AlertRule.receiver": %w`, err)}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if v, ok := _u.mutation.CreatedBy(); ok {
|
|
|
|
|
if err := alertrule.CreatedByValidator(v); err != nil {
|
|
|
|
|
return &ValidationError{Name: "createdBy", err: fmt.Errorf(`ent: validator failed for field "AlertRule.createdBy": %w`, err)}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return nil
|
|
|
|
|
}
|
|
|
|
|
|
2026-09-15 16:37:39 +08:00
|
|
|
// Modify adds a statement modifier for attaching custom logic to the UPDATE statement.
|
|
|
|
|
func (_u *AlertRuleUpdate) Modify(modifiers ...func(u *sql.UpdateBuilder)) *AlertRuleUpdate {
|
|
|
|
|
_u.modifiers = append(_u.modifiers, modifiers...)
|
|
|
|
|
return _u
|
|
|
|
|
}
|
|
|
|
|
|
2026-09-14 16:31:08 +08:00
|
|
|
func (_u *AlertRuleUpdate) sqlSave(ctx context.Context) (_node int, err error) {
|
|
|
|
|
if err := _u.check(); err != nil {
|
|
|
|
|
return _node, err
|
|
|
|
|
}
|
|
|
|
|
_spec := sqlgraph.NewUpdateSpec(alertrule.Table, alertrule.Columns, sqlgraph.NewFieldSpec(alertrule.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.Name(); ok {
|
|
|
|
|
_spec.SetField(alertrule.FieldName, field.TypeString, value)
|
|
|
|
|
}
|
|
|
|
|
if value, ok := _u.mutation.GetType(); ok {
|
|
|
|
|
_spec.SetField(alertrule.FieldType, field.TypeString, value)
|
|
|
|
|
}
|
|
|
|
|
if value, ok := _u.mutation.Threshold(); ok {
|
|
|
|
|
_spec.SetField(alertrule.FieldThreshold, field.TypeFloat64, value)
|
|
|
|
|
}
|
|
|
|
|
if value, ok := _u.mutation.AddedThreshold(); ok {
|
|
|
|
|
_spec.AddField(alertrule.FieldThreshold, field.TypeFloat64, value)
|
|
|
|
|
}
|
|
|
|
|
if value, ok := _u.mutation.Receiver(); ok {
|
|
|
|
|
_spec.SetField(alertrule.FieldReceiver, field.TypeString, value)
|
|
|
|
|
}
|
|
|
|
|
if value, ok := _u.mutation.Enabled(); ok {
|
|
|
|
|
_spec.SetField(alertrule.FieldEnabled, field.TypeBool, value)
|
|
|
|
|
}
|
|
|
|
|
if value, ok := _u.mutation.CreatedBy(); ok {
|
|
|
|
|
_spec.SetField(alertrule.FieldCreatedBy, field.TypeString, value)
|
|
|
|
|
}
|
2026-09-15 16:37:39 +08:00
|
|
|
_spec.AddModifiers(_u.modifiers...)
|
2026-09-14 16:31:08 +08:00
|
|
|
if _node, err = sqlgraph.UpdateNodes(ctx, _u.driver, _spec); err != nil {
|
|
|
|
|
if _, ok := err.(*sqlgraph.NotFoundError); ok {
|
|
|
|
|
err = &NotFoundError{alertrule.Label}
|
|
|
|
|
} else if sqlgraph.IsConstraintError(err) {
|
|
|
|
|
err = &ConstraintError{msg: err.Error(), wrap: err}
|
|
|
|
|
}
|
|
|
|
|
return 0, err
|
|
|
|
|
}
|
|
|
|
|
_u.mutation.done = true
|
|
|
|
|
return _node, nil
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// AlertRuleUpdateOne is the builder for updating a single AlertRule entity.
|
|
|
|
|
type AlertRuleUpdateOne struct {
|
|
|
|
|
config
|
2026-09-15 16:37:39 +08:00
|
|
|
fields []string
|
|
|
|
|
hooks []Hook
|
|
|
|
|
mutation *AlertRuleMutation
|
|
|
|
|
modifiers []func(*sql.UpdateBuilder)
|
2026-09-14 16:31:08 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// SetName sets the "name" field.
|
|
|
|
|
func (_u *AlertRuleUpdateOne) SetName(v string) *AlertRuleUpdateOne {
|
|
|
|
|
_u.mutation.SetName(v)
|
|
|
|
|
return _u
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// SetNillableName sets the "name" field if the given value is not nil.
|
|
|
|
|
func (_u *AlertRuleUpdateOne) SetNillableName(v *string) *AlertRuleUpdateOne {
|
|
|
|
|
if v != nil {
|
|
|
|
|
_u.SetName(*v)
|
|
|
|
|
}
|
|
|
|
|
return _u
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// SetType sets the "type" field.
|
|
|
|
|
func (_u *AlertRuleUpdateOne) SetType(v string) *AlertRuleUpdateOne {
|
|
|
|
|
_u.mutation.SetType(v)
|
|
|
|
|
return _u
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// SetNillableType sets the "type" field if the given value is not nil.
|
|
|
|
|
func (_u *AlertRuleUpdateOne) SetNillableType(v *string) *AlertRuleUpdateOne {
|
|
|
|
|
if v != nil {
|
|
|
|
|
_u.SetType(*v)
|
|
|
|
|
}
|
|
|
|
|
return _u
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// SetThreshold sets the "threshold" field.
|
|
|
|
|
func (_u *AlertRuleUpdateOne) SetThreshold(v float64) *AlertRuleUpdateOne {
|
|
|
|
|
_u.mutation.ResetThreshold()
|
|
|
|
|
_u.mutation.SetThreshold(v)
|
|
|
|
|
return _u
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// SetNillableThreshold sets the "threshold" field if the given value is not nil.
|
|
|
|
|
func (_u *AlertRuleUpdateOne) SetNillableThreshold(v *float64) *AlertRuleUpdateOne {
|
|
|
|
|
if v != nil {
|
|
|
|
|
_u.SetThreshold(*v)
|
|
|
|
|
}
|
|
|
|
|
return _u
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// AddThreshold adds value to the "threshold" field.
|
|
|
|
|
func (_u *AlertRuleUpdateOne) AddThreshold(v float64) *AlertRuleUpdateOne {
|
|
|
|
|
_u.mutation.AddThreshold(v)
|
|
|
|
|
return _u
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// SetReceiver sets the "receiver" field.
|
|
|
|
|
func (_u *AlertRuleUpdateOne) SetReceiver(v string) *AlertRuleUpdateOne {
|
|
|
|
|
_u.mutation.SetReceiver(v)
|
|
|
|
|
return _u
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// SetNillableReceiver sets the "receiver" field if the given value is not nil.
|
|
|
|
|
func (_u *AlertRuleUpdateOne) SetNillableReceiver(v *string) *AlertRuleUpdateOne {
|
|
|
|
|
if v != nil {
|
|
|
|
|
_u.SetReceiver(*v)
|
|
|
|
|
}
|
|
|
|
|
return _u
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// SetEnabled sets the "enabled" field.
|
|
|
|
|
func (_u *AlertRuleUpdateOne) SetEnabled(v bool) *AlertRuleUpdateOne {
|
|
|
|
|
_u.mutation.SetEnabled(v)
|
|
|
|
|
return _u
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// SetNillableEnabled sets the "enabled" field if the given value is not nil.
|
|
|
|
|
func (_u *AlertRuleUpdateOne) SetNillableEnabled(v *bool) *AlertRuleUpdateOne {
|
|
|
|
|
if v != nil {
|
|
|
|
|
_u.SetEnabled(*v)
|
|
|
|
|
}
|
|
|
|
|
return _u
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// SetCreatedBy sets the "createdBy" field.
|
|
|
|
|
func (_u *AlertRuleUpdateOne) SetCreatedBy(v string) *AlertRuleUpdateOne {
|
|
|
|
|
_u.mutation.SetCreatedBy(v)
|
|
|
|
|
return _u
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// SetNillableCreatedBy sets the "createdBy" field if the given value is not nil.
|
|
|
|
|
func (_u *AlertRuleUpdateOne) SetNillableCreatedBy(v *string) *AlertRuleUpdateOne {
|
|
|
|
|
if v != nil {
|
|
|
|
|
_u.SetCreatedBy(*v)
|
|
|
|
|
}
|
|
|
|
|
return _u
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Mutation returns the AlertRuleMutation object of the builder.
|
|
|
|
|
func (_u *AlertRuleUpdateOne) Mutation() *AlertRuleMutation {
|
|
|
|
|
return _u.mutation
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Where appends a list predicates to the AlertRuleUpdate builder.
|
|
|
|
|
func (_u *AlertRuleUpdateOne) Where(ps ...predicate.AlertRule) *AlertRuleUpdateOne {
|
|
|
|
|
_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 *AlertRuleUpdateOne) Select(field string, fields ...string) *AlertRuleUpdateOne {
|
|
|
|
|
_u.fields = append([]string{field}, fields...)
|
|
|
|
|
return _u
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Save executes the query and returns the updated AlertRule entity.
|
|
|
|
|
func (_u *AlertRuleUpdateOne) Save(ctx context.Context) (*AlertRule, error) {
|
|
|
|
|
return withHooks(ctx, _u.sqlSave, _u.mutation, _u.hooks)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// SaveX is like Save, but panics if an error occurs.
|
|
|
|
|
func (_u *AlertRuleUpdateOne) SaveX(ctx context.Context) *AlertRule {
|
|
|
|
|
node, err := _u.Save(ctx)
|
|
|
|
|
if err != nil {
|
|
|
|
|
panic(err)
|
|
|
|
|
}
|
|
|
|
|
return node
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Exec executes the query on the entity.
|
|
|
|
|
func (_u *AlertRuleUpdateOne) Exec(ctx context.Context) error {
|
|
|
|
|
_, err := _u.Save(ctx)
|
|
|
|
|
return err
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// ExecX is like Exec, but panics if an error occurs.
|
|
|
|
|
func (_u *AlertRuleUpdateOne) 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 *AlertRuleUpdateOne) check() error {
|
|
|
|
|
if v, ok := _u.mutation.Name(); ok {
|
|
|
|
|
if err := alertrule.NameValidator(v); err != nil {
|
|
|
|
|
return &ValidationError{Name: "name", err: fmt.Errorf(`ent: validator failed for field "AlertRule.name": %w`, err)}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if v, ok := _u.mutation.GetType(); ok {
|
|
|
|
|
if err := alertrule.TypeValidator(v); err != nil {
|
|
|
|
|
return &ValidationError{Name: "type", err: fmt.Errorf(`ent: validator failed for field "AlertRule.type": %w`, err)}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if v, ok := _u.mutation.Receiver(); ok {
|
|
|
|
|
if err := alertrule.ReceiverValidator(v); err != nil {
|
|
|
|
|
return &ValidationError{Name: "receiver", err: fmt.Errorf(`ent: validator failed for field "AlertRule.receiver": %w`, err)}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if v, ok := _u.mutation.CreatedBy(); ok {
|
|
|
|
|
if err := alertrule.CreatedByValidator(v); err != nil {
|
|
|
|
|
return &ValidationError{Name: "createdBy", err: fmt.Errorf(`ent: validator failed for field "AlertRule.createdBy": %w`, err)}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return nil
|
|
|
|
|
}
|
|
|
|
|
|
2026-09-15 16:37:39 +08:00
|
|
|
// Modify adds a statement modifier for attaching custom logic to the UPDATE statement.
|
|
|
|
|
func (_u *AlertRuleUpdateOne) Modify(modifiers ...func(u *sql.UpdateBuilder)) *AlertRuleUpdateOne {
|
|
|
|
|
_u.modifiers = append(_u.modifiers, modifiers...)
|
|
|
|
|
return _u
|
|
|
|
|
}
|
|
|
|
|
|
2026-09-14 16:31:08 +08:00
|
|
|
func (_u *AlertRuleUpdateOne) sqlSave(ctx context.Context) (_node *AlertRule, err error) {
|
|
|
|
|
if err := _u.check(); err != nil {
|
|
|
|
|
return _node, err
|
|
|
|
|
}
|
|
|
|
|
_spec := sqlgraph.NewUpdateSpec(alertrule.Table, alertrule.Columns, sqlgraph.NewFieldSpec(alertrule.FieldID, field.TypeInt))
|
|
|
|
|
id, ok := _u.mutation.ID()
|
|
|
|
|
if !ok {
|
|
|
|
|
return nil, &ValidationError{Name: "id", err: errors.New(`ent: missing "AlertRule.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, alertrule.FieldID)
|
|
|
|
|
for _, f := range fields {
|
|
|
|
|
if !alertrule.ValidColumn(f) {
|
|
|
|
|
return nil, &ValidationError{Name: f, err: fmt.Errorf("ent: invalid field %q for query", f)}
|
|
|
|
|
}
|
|
|
|
|
if f != alertrule.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.Name(); ok {
|
|
|
|
|
_spec.SetField(alertrule.FieldName, field.TypeString, value)
|
|
|
|
|
}
|
|
|
|
|
if value, ok := _u.mutation.GetType(); ok {
|
|
|
|
|
_spec.SetField(alertrule.FieldType, field.TypeString, value)
|
|
|
|
|
}
|
|
|
|
|
if value, ok := _u.mutation.Threshold(); ok {
|
|
|
|
|
_spec.SetField(alertrule.FieldThreshold, field.TypeFloat64, value)
|
|
|
|
|
}
|
|
|
|
|
if value, ok := _u.mutation.AddedThreshold(); ok {
|
|
|
|
|
_spec.AddField(alertrule.FieldThreshold, field.TypeFloat64, value)
|
|
|
|
|
}
|
|
|
|
|
if value, ok := _u.mutation.Receiver(); ok {
|
|
|
|
|
_spec.SetField(alertrule.FieldReceiver, field.TypeString, value)
|
|
|
|
|
}
|
|
|
|
|
if value, ok := _u.mutation.Enabled(); ok {
|
|
|
|
|
_spec.SetField(alertrule.FieldEnabled, field.TypeBool, value)
|
|
|
|
|
}
|
|
|
|
|
if value, ok := _u.mutation.CreatedBy(); ok {
|
|
|
|
|
_spec.SetField(alertrule.FieldCreatedBy, field.TypeString, value)
|
|
|
|
|
}
|
2026-09-15 16:37:39 +08:00
|
|
|
_spec.AddModifiers(_u.modifiers...)
|
2026-09-14 16:31:08 +08:00
|
|
|
_node = &AlertRule{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{alertrule.Label}
|
|
|
|
|
} else if sqlgraph.IsConstraintError(err) {
|
|
|
|
|
err = &ConstraintError{msg: err.Error(), wrap: err}
|
|
|
|
|
}
|
|
|
|
|
return nil, err
|
|
|
|
|
}
|
|
|
|
|
_u.mutation.done = true
|
|
|
|
|
return _node, nil
|
|
|
|
|
}
|