492 lines
14 KiB
Go
492 lines
14 KiB
Go
// Code generated by ent, DO NOT EDIT.
|
|
|
|
package ent
|
|
|
|
import (
|
|
"bj_power_wms/ent/alertrule"
|
|
"bj_power_wms/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
|
|
hooks []Hook
|
|
mutation *AlertRuleMutation
|
|
}
|
|
|
|
// Where appends a list predicates to the AlertRuleUpdate builder.
|
|
func (_u *AlertRuleUpdate) Where(ps ...predicate.AlertRule) *AlertRuleUpdate {
|
|
_u.mutation.Where(ps...)
|
|
return _u
|
|
}
|
|
|
|
// SetCode sets the "code" field.
|
|
func (_u *AlertRuleUpdate) SetCode(v string) *AlertRuleUpdate {
|
|
_u.mutation.SetCode(v)
|
|
return _u
|
|
}
|
|
|
|
// SetNillableCode sets the "code" field if the given value is not nil.
|
|
func (_u *AlertRuleUpdate) SetNillableCode(v *string) *AlertRuleUpdate {
|
|
if v != nil {
|
|
_u.SetCode(*v)
|
|
}
|
|
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
|
|
}
|
|
|
|
// 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
|
|
}
|
|
|
|
// SetThreshold sets the "threshold" field.
|
|
func (_u *AlertRuleUpdate) SetThreshold(v int) *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 *int) *AlertRuleUpdate {
|
|
if v != nil {
|
|
_u.SetThreshold(*v)
|
|
}
|
|
return _u
|
|
}
|
|
|
|
// AddThreshold adds value to the "threshold" field.
|
|
func (_u *AlertRuleUpdate) AddThreshold(v int) *AlertRuleUpdate {
|
|
_u.mutation.AddThreshold(v)
|
|
return _u
|
|
}
|
|
|
|
// SetRemark sets the "remark" field.
|
|
func (_u *AlertRuleUpdate) SetRemark(v string) *AlertRuleUpdate {
|
|
_u.mutation.SetRemark(v)
|
|
return _u
|
|
}
|
|
|
|
// SetNillableRemark sets the "remark" field if the given value is not nil.
|
|
func (_u *AlertRuleUpdate) SetNillableRemark(v *string) *AlertRuleUpdate {
|
|
if v != nil {
|
|
_u.SetRemark(*v)
|
|
}
|
|
return _u
|
|
}
|
|
|
|
// ClearRemark clears the value of the "remark" field.
|
|
func (_u *AlertRuleUpdate) ClearRemark() *AlertRuleUpdate {
|
|
_u.mutation.ClearRemark()
|
|
return _u
|
|
}
|
|
|
|
// SetCreatedAt sets the "created_at" field.
|
|
func (_u *AlertRuleUpdate) SetCreatedAt(v int64) *AlertRuleUpdate {
|
|
_u.mutation.ResetCreatedAt()
|
|
_u.mutation.SetCreatedAt(v)
|
|
return _u
|
|
}
|
|
|
|
// SetNillableCreatedAt sets the "created_at" field if the given value is not nil.
|
|
func (_u *AlertRuleUpdate) SetNillableCreatedAt(v *int64) *AlertRuleUpdate {
|
|
if v != nil {
|
|
_u.SetCreatedAt(*v)
|
|
}
|
|
return _u
|
|
}
|
|
|
|
// AddCreatedAt adds value to the "created_at" field.
|
|
func (_u *AlertRuleUpdate) AddCreatedAt(v int64) *AlertRuleUpdate {
|
|
_u.mutation.AddCreatedAt(v)
|
|
return _u
|
|
}
|
|
|
|
// SetUpdatedAt sets the "updated_at" field.
|
|
func (_u *AlertRuleUpdate) SetUpdatedAt(v int64) *AlertRuleUpdate {
|
|
_u.mutation.ResetUpdatedAt()
|
|
_u.mutation.SetUpdatedAt(v)
|
|
return _u
|
|
}
|
|
|
|
// SetNillableUpdatedAt sets the "updated_at" field if the given value is not nil.
|
|
func (_u *AlertRuleUpdate) SetNillableUpdatedAt(v *int64) *AlertRuleUpdate {
|
|
if v != nil {
|
|
_u.SetUpdatedAt(*v)
|
|
}
|
|
return _u
|
|
}
|
|
|
|
// AddUpdatedAt adds value to the "updated_at" field.
|
|
func (_u *AlertRuleUpdate) AddUpdatedAt(v int64) *AlertRuleUpdate {
|
|
_u.mutation.AddUpdatedAt(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)
|
|
}
|
|
}
|
|
|
|
func (_u *AlertRuleUpdate) sqlSave(ctx context.Context) (_node int, err error) {
|
|
_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.Code(); ok {
|
|
_spec.SetField(alertrule.FieldCode, field.TypeString, value)
|
|
}
|
|
if value, ok := _u.mutation.Name(); ok {
|
|
_spec.SetField(alertrule.FieldName, field.TypeString, value)
|
|
}
|
|
if value, ok := _u.mutation.Enabled(); ok {
|
|
_spec.SetField(alertrule.FieldEnabled, field.TypeBool, value)
|
|
}
|
|
if value, ok := _u.mutation.Threshold(); ok {
|
|
_spec.SetField(alertrule.FieldThreshold, field.TypeInt, value)
|
|
}
|
|
if value, ok := _u.mutation.AddedThreshold(); ok {
|
|
_spec.AddField(alertrule.FieldThreshold, field.TypeInt, value)
|
|
}
|
|
if value, ok := _u.mutation.Remark(); ok {
|
|
_spec.SetField(alertrule.FieldRemark, field.TypeString, value)
|
|
}
|
|
if _u.mutation.RemarkCleared() {
|
|
_spec.ClearField(alertrule.FieldRemark, field.TypeString)
|
|
}
|
|
if value, ok := _u.mutation.CreatedAt(); ok {
|
|
_spec.SetField(alertrule.FieldCreatedAt, field.TypeInt64, value)
|
|
}
|
|
if value, ok := _u.mutation.AddedCreatedAt(); ok {
|
|
_spec.AddField(alertrule.FieldCreatedAt, field.TypeInt64, value)
|
|
}
|
|
if value, ok := _u.mutation.UpdatedAt(); ok {
|
|
_spec.SetField(alertrule.FieldUpdatedAt, field.TypeInt64, value)
|
|
}
|
|
if value, ok := _u.mutation.AddedUpdatedAt(); ok {
|
|
_spec.AddField(alertrule.FieldUpdatedAt, field.TypeInt64, value)
|
|
}
|
|
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
|
|
fields []string
|
|
hooks []Hook
|
|
mutation *AlertRuleMutation
|
|
}
|
|
|
|
// SetCode sets the "code" field.
|
|
func (_u *AlertRuleUpdateOne) SetCode(v string) *AlertRuleUpdateOne {
|
|
_u.mutation.SetCode(v)
|
|
return _u
|
|
}
|
|
|
|
// SetNillableCode sets the "code" field if the given value is not nil.
|
|
func (_u *AlertRuleUpdateOne) SetNillableCode(v *string) *AlertRuleUpdateOne {
|
|
if v != nil {
|
|
_u.SetCode(*v)
|
|
}
|
|
return _u
|
|
}
|
|
|
|
// 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
|
|
}
|
|
|
|
// 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
|
|
}
|
|
|
|
// SetThreshold sets the "threshold" field.
|
|
func (_u *AlertRuleUpdateOne) SetThreshold(v int) *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 *int) *AlertRuleUpdateOne {
|
|
if v != nil {
|
|
_u.SetThreshold(*v)
|
|
}
|
|
return _u
|
|
}
|
|
|
|
// AddThreshold adds value to the "threshold" field.
|
|
func (_u *AlertRuleUpdateOne) AddThreshold(v int) *AlertRuleUpdateOne {
|
|
_u.mutation.AddThreshold(v)
|
|
return _u
|
|
}
|
|
|
|
// SetRemark sets the "remark" field.
|
|
func (_u *AlertRuleUpdateOne) SetRemark(v string) *AlertRuleUpdateOne {
|
|
_u.mutation.SetRemark(v)
|
|
return _u
|
|
}
|
|
|
|
// SetNillableRemark sets the "remark" field if the given value is not nil.
|
|
func (_u *AlertRuleUpdateOne) SetNillableRemark(v *string) *AlertRuleUpdateOne {
|
|
if v != nil {
|
|
_u.SetRemark(*v)
|
|
}
|
|
return _u
|
|
}
|
|
|
|
// ClearRemark clears the value of the "remark" field.
|
|
func (_u *AlertRuleUpdateOne) ClearRemark() *AlertRuleUpdateOne {
|
|
_u.mutation.ClearRemark()
|
|
return _u
|
|
}
|
|
|
|
// SetCreatedAt sets the "created_at" field.
|
|
func (_u *AlertRuleUpdateOne) SetCreatedAt(v int64) *AlertRuleUpdateOne {
|
|
_u.mutation.ResetCreatedAt()
|
|
_u.mutation.SetCreatedAt(v)
|
|
return _u
|
|
}
|
|
|
|
// SetNillableCreatedAt sets the "created_at" field if the given value is not nil.
|
|
func (_u *AlertRuleUpdateOne) SetNillableCreatedAt(v *int64) *AlertRuleUpdateOne {
|
|
if v != nil {
|
|
_u.SetCreatedAt(*v)
|
|
}
|
|
return _u
|
|
}
|
|
|
|
// AddCreatedAt adds value to the "created_at" field.
|
|
func (_u *AlertRuleUpdateOne) AddCreatedAt(v int64) *AlertRuleUpdateOne {
|
|
_u.mutation.AddCreatedAt(v)
|
|
return _u
|
|
}
|
|
|
|
// SetUpdatedAt sets the "updated_at" field.
|
|
func (_u *AlertRuleUpdateOne) SetUpdatedAt(v int64) *AlertRuleUpdateOne {
|
|
_u.mutation.ResetUpdatedAt()
|
|
_u.mutation.SetUpdatedAt(v)
|
|
return _u
|
|
}
|
|
|
|
// SetNillableUpdatedAt sets the "updated_at" field if the given value is not nil.
|
|
func (_u *AlertRuleUpdateOne) SetNillableUpdatedAt(v *int64) *AlertRuleUpdateOne {
|
|
if v != nil {
|
|
_u.SetUpdatedAt(*v)
|
|
}
|
|
return _u
|
|
}
|
|
|
|
// AddUpdatedAt adds value to the "updated_at" field.
|
|
func (_u *AlertRuleUpdateOne) AddUpdatedAt(v int64) *AlertRuleUpdateOne {
|
|
_u.mutation.AddUpdatedAt(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)
|
|
}
|
|
}
|
|
|
|
func (_u *AlertRuleUpdateOne) sqlSave(ctx context.Context) (_node *AlertRule, err error) {
|
|
_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.Code(); ok {
|
|
_spec.SetField(alertrule.FieldCode, field.TypeString, value)
|
|
}
|
|
if value, ok := _u.mutation.Name(); ok {
|
|
_spec.SetField(alertrule.FieldName, field.TypeString, value)
|
|
}
|
|
if value, ok := _u.mutation.Enabled(); ok {
|
|
_spec.SetField(alertrule.FieldEnabled, field.TypeBool, value)
|
|
}
|
|
if value, ok := _u.mutation.Threshold(); ok {
|
|
_spec.SetField(alertrule.FieldThreshold, field.TypeInt, value)
|
|
}
|
|
if value, ok := _u.mutation.AddedThreshold(); ok {
|
|
_spec.AddField(alertrule.FieldThreshold, field.TypeInt, value)
|
|
}
|
|
if value, ok := _u.mutation.Remark(); ok {
|
|
_spec.SetField(alertrule.FieldRemark, field.TypeString, value)
|
|
}
|
|
if _u.mutation.RemarkCleared() {
|
|
_spec.ClearField(alertrule.FieldRemark, field.TypeString)
|
|
}
|
|
if value, ok := _u.mutation.CreatedAt(); ok {
|
|
_spec.SetField(alertrule.FieldCreatedAt, field.TypeInt64, value)
|
|
}
|
|
if value, ok := _u.mutation.AddedCreatedAt(); ok {
|
|
_spec.AddField(alertrule.FieldCreatedAt, field.TypeInt64, value)
|
|
}
|
|
if value, ok := _u.mutation.UpdatedAt(); ok {
|
|
_spec.SetField(alertrule.FieldUpdatedAt, field.TypeInt64, value)
|
|
}
|
|
if value, ok := _u.mutation.AddedUpdatedAt(); ok {
|
|
_spec.AddField(alertrule.FieldUpdatedAt, field.TypeInt64, value)
|
|
}
|
|
_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
|
|
}
|