542 lines
15 KiB
Go
542 lines
15 KiB
Go
// Code generated by ent, DO NOT EDIT.
|
|
|
|
package ent
|
|
|
|
import (
|
|
"bj_power_wms/ent/alert"
|
|
"bj_power_wms/ent/predicate"
|
|
"context"
|
|
"errors"
|
|
"fmt"
|
|
|
|
"entgo.io/ent/dialect/sql"
|
|
"entgo.io/ent/dialect/sql/sqlgraph"
|
|
"entgo.io/ent/schema/field"
|
|
)
|
|
|
|
// AlertUpdate is the builder for updating Alert entities.
|
|
type AlertUpdate struct {
|
|
config
|
|
hooks []Hook
|
|
mutation *AlertMutation
|
|
}
|
|
|
|
// Where appends a list predicates to the AlertUpdate builder.
|
|
func (_u *AlertUpdate) Where(ps ...predicate.Alert) *AlertUpdate {
|
|
_u.mutation.Where(ps...)
|
|
return _u
|
|
}
|
|
|
|
// SetRuleCode sets the "rule_code" field.
|
|
func (_u *AlertUpdate) SetRuleCode(v string) *AlertUpdate {
|
|
_u.mutation.SetRuleCode(v)
|
|
return _u
|
|
}
|
|
|
|
// SetNillableRuleCode sets the "rule_code" field if the given value is not nil.
|
|
func (_u *AlertUpdate) SetNillableRuleCode(v *string) *AlertUpdate {
|
|
if v != nil {
|
|
_u.SetRuleCode(*v)
|
|
}
|
|
return _u
|
|
}
|
|
|
|
// SetLevel sets the "level" field.
|
|
func (_u *AlertUpdate) SetLevel(v string) *AlertUpdate {
|
|
_u.mutation.SetLevel(v)
|
|
return _u
|
|
}
|
|
|
|
// SetNillableLevel sets the "level" field if the given value is not nil.
|
|
func (_u *AlertUpdate) SetNillableLevel(v *string) *AlertUpdate {
|
|
if v != nil {
|
|
_u.SetLevel(*v)
|
|
}
|
|
return _u
|
|
}
|
|
|
|
// SetTitle sets the "title" field.
|
|
func (_u *AlertUpdate) SetTitle(v string) *AlertUpdate {
|
|
_u.mutation.SetTitle(v)
|
|
return _u
|
|
}
|
|
|
|
// SetNillableTitle sets the "title" field if the given value is not nil.
|
|
func (_u *AlertUpdate) SetNillableTitle(v *string) *AlertUpdate {
|
|
if v != nil {
|
|
_u.SetTitle(*v)
|
|
}
|
|
return _u
|
|
}
|
|
|
|
// SetContent sets the "content" field.
|
|
func (_u *AlertUpdate) SetContent(v string) *AlertUpdate {
|
|
_u.mutation.SetContent(v)
|
|
return _u
|
|
}
|
|
|
|
// SetNillableContent sets the "content" field if the given value is not nil.
|
|
func (_u *AlertUpdate) SetNillableContent(v *string) *AlertUpdate {
|
|
if v != nil {
|
|
_u.SetContent(*v)
|
|
}
|
|
return _u
|
|
}
|
|
|
|
// SetTarget sets the "target" field.
|
|
func (_u *AlertUpdate) SetTarget(v string) *AlertUpdate {
|
|
_u.mutation.SetTarget(v)
|
|
return _u
|
|
}
|
|
|
|
// SetNillableTarget sets the "target" field if the given value is not nil.
|
|
func (_u *AlertUpdate) SetNillableTarget(v *string) *AlertUpdate {
|
|
if v != nil {
|
|
_u.SetTarget(*v)
|
|
}
|
|
return _u
|
|
}
|
|
|
|
// ClearTarget clears the value of the "target" field.
|
|
func (_u *AlertUpdate) ClearTarget() *AlertUpdate {
|
|
_u.mutation.ClearTarget()
|
|
return _u
|
|
}
|
|
|
|
// SetStatus sets the "status" field.
|
|
func (_u *AlertUpdate) SetStatus(v string) *AlertUpdate {
|
|
_u.mutation.SetStatus(v)
|
|
return _u
|
|
}
|
|
|
|
// SetNillableStatus sets the "status" field if the given value is not nil.
|
|
func (_u *AlertUpdate) SetNillableStatus(v *string) *AlertUpdate {
|
|
if v != nil {
|
|
_u.SetStatus(*v)
|
|
}
|
|
return _u
|
|
}
|
|
|
|
// SetCreatedAt sets the "created_at" field.
|
|
func (_u *AlertUpdate) SetCreatedAt(v int64) *AlertUpdate {
|
|
_u.mutation.ResetCreatedAt()
|
|
_u.mutation.SetCreatedAt(v)
|
|
return _u
|
|
}
|
|
|
|
// SetNillableCreatedAt sets the "created_at" field if the given value is not nil.
|
|
func (_u *AlertUpdate) SetNillableCreatedAt(v *int64) *AlertUpdate {
|
|
if v != nil {
|
|
_u.SetCreatedAt(*v)
|
|
}
|
|
return _u
|
|
}
|
|
|
|
// AddCreatedAt adds value to the "created_at" field.
|
|
func (_u *AlertUpdate) AddCreatedAt(v int64) *AlertUpdate {
|
|
_u.mutation.AddCreatedAt(v)
|
|
return _u
|
|
}
|
|
|
|
// SetUpdatedAt sets the "updated_at" field.
|
|
func (_u *AlertUpdate) SetUpdatedAt(v int64) *AlertUpdate {
|
|
_u.mutation.ResetUpdatedAt()
|
|
_u.mutation.SetUpdatedAt(v)
|
|
return _u
|
|
}
|
|
|
|
// SetNillableUpdatedAt sets the "updated_at" field if the given value is not nil.
|
|
func (_u *AlertUpdate) SetNillableUpdatedAt(v *int64) *AlertUpdate {
|
|
if v != nil {
|
|
_u.SetUpdatedAt(*v)
|
|
}
|
|
return _u
|
|
}
|
|
|
|
// AddUpdatedAt adds value to the "updated_at" field.
|
|
func (_u *AlertUpdate) AddUpdatedAt(v int64) *AlertUpdate {
|
|
_u.mutation.AddUpdatedAt(v)
|
|
return _u
|
|
}
|
|
|
|
// Mutation returns the AlertMutation object of the builder.
|
|
func (_u *AlertUpdate) Mutation() *AlertMutation {
|
|
return _u.mutation
|
|
}
|
|
|
|
// Save executes the query and returns the number of nodes affected by the update operation.
|
|
func (_u *AlertUpdate) 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 *AlertUpdate) SaveX(ctx context.Context) int {
|
|
affected, err := _u.Save(ctx)
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
return affected
|
|
}
|
|
|
|
// Exec executes the query.
|
|
func (_u *AlertUpdate) Exec(ctx context.Context) error {
|
|
_, err := _u.Save(ctx)
|
|
return err
|
|
}
|
|
|
|
// ExecX is like Exec, but panics if an error occurs.
|
|
func (_u *AlertUpdate) 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 *AlertUpdate) check() error {
|
|
if v, ok := _u.mutation.Level(); ok {
|
|
if err := alert.LevelValidator(v); err != nil {
|
|
return &ValidationError{Name: "level", err: fmt.Errorf(`ent: validator failed for field "Alert.level": %w`, err)}
|
|
}
|
|
}
|
|
if v, ok := _u.mutation.Status(); ok {
|
|
if err := alert.StatusValidator(v); err != nil {
|
|
return &ValidationError{Name: "status", err: fmt.Errorf(`ent: validator failed for field "Alert.status": %w`, err)}
|
|
}
|
|
}
|
|
return nil
|
|
}
|
|
|
|
func (_u *AlertUpdate) sqlSave(ctx context.Context) (_node int, err error) {
|
|
if err := _u.check(); err != nil {
|
|
return _node, err
|
|
}
|
|
_spec := sqlgraph.NewUpdateSpec(alert.Table, alert.Columns, sqlgraph.NewFieldSpec(alert.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.RuleCode(); ok {
|
|
_spec.SetField(alert.FieldRuleCode, field.TypeString, value)
|
|
}
|
|
if value, ok := _u.mutation.Level(); ok {
|
|
_spec.SetField(alert.FieldLevel, field.TypeString, value)
|
|
}
|
|
if value, ok := _u.mutation.Title(); ok {
|
|
_spec.SetField(alert.FieldTitle, field.TypeString, value)
|
|
}
|
|
if value, ok := _u.mutation.Content(); ok {
|
|
_spec.SetField(alert.FieldContent, field.TypeString, value)
|
|
}
|
|
if value, ok := _u.mutation.Target(); ok {
|
|
_spec.SetField(alert.FieldTarget, field.TypeString, value)
|
|
}
|
|
if _u.mutation.TargetCleared() {
|
|
_spec.ClearField(alert.FieldTarget, field.TypeString)
|
|
}
|
|
if value, ok := _u.mutation.Status(); ok {
|
|
_spec.SetField(alert.FieldStatus, field.TypeString, value)
|
|
}
|
|
if value, ok := _u.mutation.CreatedAt(); ok {
|
|
_spec.SetField(alert.FieldCreatedAt, field.TypeInt64, value)
|
|
}
|
|
if value, ok := _u.mutation.AddedCreatedAt(); ok {
|
|
_spec.AddField(alert.FieldCreatedAt, field.TypeInt64, value)
|
|
}
|
|
if value, ok := _u.mutation.UpdatedAt(); ok {
|
|
_spec.SetField(alert.FieldUpdatedAt, field.TypeInt64, value)
|
|
}
|
|
if value, ok := _u.mutation.AddedUpdatedAt(); ok {
|
|
_spec.AddField(alert.FieldUpdatedAt, field.TypeInt64, value)
|
|
}
|
|
if _node, err = sqlgraph.UpdateNodes(ctx, _u.driver, _spec); err != nil {
|
|
if _, ok := err.(*sqlgraph.NotFoundError); ok {
|
|
err = &NotFoundError{alert.Label}
|
|
} else if sqlgraph.IsConstraintError(err) {
|
|
err = &ConstraintError{msg: err.Error(), wrap: err}
|
|
}
|
|
return 0, err
|
|
}
|
|
_u.mutation.done = true
|
|
return _node, nil
|
|
}
|
|
|
|
// AlertUpdateOne is the builder for updating a single Alert entity.
|
|
type AlertUpdateOne struct {
|
|
config
|
|
fields []string
|
|
hooks []Hook
|
|
mutation *AlertMutation
|
|
}
|
|
|
|
// SetRuleCode sets the "rule_code" field.
|
|
func (_u *AlertUpdateOne) SetRuleCode(v string) *AlertUpdateOne {
|
|
_u.mutation.SetRuleCode(v)
|
|
return _u
|
|
}
|
|
|
|
// SetNillableRuleCode sets the "rule_code" field if the given value is not nil.
|
|
func (_u *AlertUpdateOne) SetNillableRuleCode(v *string) *AlertUpdateOne {
|
|
if v != nil {
|
|
_u.SetRuleCode(*v)
|
|
}
|
|
return _u
|
|
}
|
|
|
|
// SetLevel sets the "level" field.
|
|
func (_u *AlertUpdateOne) SetLevel(v string) *AlertUpdateOne {
|
|
_u.mutation.SetLevel(v)
|
|
return _u
|
|
}
|
|
|
|
// SetNillableLevel sets the "level" field if the given value is not nil.
|
|
func (_u *AlertUpdateOne) SetNillableLevel(v *string) *AlertUpdateOne {
|
|
if v != nil {
|
|
_u.SetLevel(*v)
|
|
}
|
|
return _u
|
|
}
|
|
|
|
// SetTitle sets the "title" field.
|
|
func (_u *AlertUpdateOne) SetTitle(v string) *AlertUpdateOne {
|
|
_u.mutation.SetTitle(v)
|
|
return _u
|
|
}
|
|
|
|
// SetNillableTitle sets the "title" field if the given value is not nil.
|
|
func (_u *AlertUpdateOne) SetNillableTitle(v *string) *AlertUpdateOne {
|
|
if v != nil {
|
|
_u.SetTitle(*v)
|
|
}
|
|
return _u
|
|
}
|
|
|
|
// SetContent sets the "content" field.
|
|
func (_u *AlertUpdateOne) SetContent(v string) *AlertUpdateOne {
|
|
_u.mutation.SetContent(v)
|
|
return _u
|
|
}
|
|
|
|
// SetNillableContent sets the "content" field if the given value is not nil.
|
|
func (_u *AlertUpdateOne) SetNillableContent(v *string) *AlertUpdateOne {
|
|
if v != nil {
|
|
_u.SetContent(*v)
|
|
}
|
|
return _u
|
|
}
|
|
|
|
// SetTarget sets the "target" field.
|
|
func (_u *AlertUpdateOne) SetTarget(v string) *AlertUpdateOne {
|
|
_u.mutation.SetTarget(v)
|
|
return _u
|
|
}
|
|
|
|
// SetNillableTarget sets the "target" field if the given value is not nil.
|
|
func (_u *AlertUpdateOne) SetNillableTarget(v *string) *AlertUpdateOne {
|
|
if v != nil {
|
|
_u.SetTarget(*v)
|
|
}
|
|
return _u
|
|
}
|
|
|
|
// ClearTarget clears the value of the "target" field.
|
|
func (_u *AlertUpdateOne) ClearTarget() *AlertUpdateOne {
|
|
_u.mutation.ClearTarget()
|
|
return _u
|
|
}
|
|
|
|
// SetStatus sets the "status" field.
|
|
func (_u *AlertUpdateOne) SetStatus(v string) *AlertUpdateOne {
|
|
_u.mutation.SetStatus(v)
|
|
return _u
|
|
}
|
|
|
|
// SetNillableStatus sets the "status" field if the given value is not nil.
|
|
func (_u *AlertUpdateOne) SetNillableStatus(v *string) *AlertUpdateOne {
|
|
if v != nil {
|
|
_u.SetStatus(*v)
|
|
}
|
|
return _u
|
|
}
|
|
|
|
// SetCreatedAt sets the "created_at" field.
|
|
func (_u *AlertUpdateOne) SetCreatedAt(v int64) *AlertUpdateOne {
|
|
_u.mutation.ResetCreatedAt()
|
|
_u.mutation.SetCreatedAt(v)
|
|
return _u
|
|
}
|
|
|
|
// SetNillableCreatedAt sets the "created_at" field if the given value is not nil.
|
|
func (_u *AlertUpdateOne) SetNillableCreatedAt(v *int64) *AlertUpdateOne {
|
|
if v != nil {
|
|
_u.SetCreatedAt(*v)
|
|
}
|
|
return _u
|
|
}
|
|
|
|
// AddCreatedAt adds value to the "created_at" field.
|
|
func (_u *AlertUpdateOne) AddCreatedAt(v int64) *AlertUpdateOne {
|
|
_u.mutation.AddCreatedAt(v)
|
|
return _u
|
|
}
|
|
|
|
// SetUpdatedAt sets the "updated_at" field.
|
|
func (_u *AlertUpdateOne) SetUpdatedAt(v int64) *AlertUpdateOne {
|
|
_u.mutation.ResetUpdatedAt()
|
|
_u.mutation.SetUpdatedAt(v)
|
|
return _u
|
|
}
|
|
|
|
// SetNillableUpdatedAt sets the "updated_at" field if the given value is not nil.
|
|
func (_u *AlertUpdateOne) SetNillableUpdatedAt(v *int64) *AlertUpdateOne {
|
|
if v != nil {
|
|
_u.SetUpdatedAt(*v)
|
|
}
|
|
return _u
|
|
}
|
|
|
|
// AddUpdatedAt adds value to the "updated_at" field.
|
|
func (_u *AlertUpdateOne) AddUpdatedAt(v int64) *AlertUpdateOne {
|
|
_u.mutation.AddUpdatedAt(v)
|
|
return _u
|
|
}
|
|
|
|
// Mutation returns the AlertMutation object of the builder.
|
|
func (_u *AlertUpdateOne) Mutation() *AlertMutation {
|
|
return _u.mutation
|
|
}
|
|
|
|
// Where appends a list predicates to the AlertUpdate builder.
|
|
func (_u *AlertUpdateOne) Where(ps ...predicate.Alert) *AlertUpdateOne {
|
|
_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 *AlertUpdateOne) Select(field string, fields ...string) *AlertUpdateOne {
|
|
_u.fields = append([]string{field}, fields...)
|
|
return _u
|
|
}
|
|
|
|
// Save executes the query and returns the updated Alert entity.
|
|
func (_u *AlertUpdateOne) Save(ctx context.Context) (*Alert, error) {
|
|
return withHooks(ctx, _u.sqlSave, _u.mutation, _u.hooks)
|
|
}
|
|
|
|
// SaveX is like Save, but panics if an error occurs.
|
|
func (_u *AlertUpdateOne) SaveX(ctx context.Context) *Alert {
|
|
node, err := _u.Save(ctx)
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
return node
|
|
}
|
|
|
|
// Exec executes the query on the entity.
|
|
func (_u *AlertUpdateOne) Exec(ctx context.Context) error {
|
|
_, err := _u.Save(ctx)
|
|
return err
|
|
}
|
|
|
|
// ExecX is like Exec, but panics if an error occurs.
|
|
func (_u *AlertUpdateOne) 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 *AlertUpdateOne) check() error {
|
|
if v, ok := _u.mutation.Level(); ok {
|
|
if err := alert.LevelValidator(v); err != nil {
|
|
return &ValidationError{Name: "level", err: fmt.Errorf(`ent: validator failed for field "Alert.level": %w`, err)}
|
|
}
|
|
}
|
|
if v, ok := _u.mutation.Status(); ok {
|
|
if err := alert.StatusValidator(v); err != nil {
|
|
return &ValidationError{Name: "status", err: fmt.Errorf(`ent: validator failed for field "Alert.status": %w`, err)}
|
|
}
|
|
}
|
|
return nil
|
|
}
|
|
|
|
func (_u *AlertUpdateOne) sqlSave(ctx context.Context) (_node *Alert, err error) {
|
|
if err := _u.check(); err != nil {
|
|
return _node, err
|
|
}
|
|
_spec := sqlgraph.NewUpdateSpec(alert.Table, alert.Columns, sqlgraph.NewFieldSpec(alert.FieldID, field.TypeInt))
|
|
id, ok := _u.mutation.ID()
|
|
if !ok {
|
|
return nil, &ValidationError{Name: "id", err: errors.New(`ent: missing "Alert.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, alert.FieldID)
|
|
for _, f := range fields {
|
|
if !alert.ValidColumn(f) {
|
|
return nil, &ValidationError{Name: f, err: fmt.Errorf("ent: invalid field %q for query", f)}
|
|
}
|
|
if f != alert.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.RuleCode(); ok {
|
|
_spec.SetField(alert.FieldRuleCode, field.TypeString, value)
|
|
}
|
|
if value, ok := _u.mutation.Level(); ok {
|
|
_spec.SetField(alert.FieldLevel, field.TypeString, value)
|
|
}
|
|
if value, ok := _u.mutation.Title(); ok {
|
|
_spec.SetField(alert.FieldTitle, field.TypeString, value)
|
|
}
|
|
if value, ok := _u.mutation.Content(); ok {
|
|
_spec.SetField(alert.FieldContent, field.TypeString, value)
|
|
}
|
|
if value, ok := _u.mutation.Target(); ok {
|
|
_spec.SetField(alert.FieldTarget, field.TypeString, value)
|
|
}
|
|
if _u.mutation.TargetCleared() {
|
|
_spec.ClearField(alert.FieldTarget, field.TypeString)
|
|
}
|
|
if value, ok := _u.mutation.Status(); ok {
|
|
_spec.SetField(alert.FieldStatus, field.TypeString, value)
|
|
}
|
|
if value, ok := _u.mutation.CreatedAt(); ok {
|
|
_spec.SetField(alert.FieldCreatedAt, field.TypeInt64, value)
|
|
}
|
|
if value, ok := _u.mutation.AddedCreatedAt(); ok {
|
|
_spec.AddField(alert.FieldCreatedAt, field.TypeInt64, value)
|
|
}
|
|
if value, ok := _u.mutation.UpdatedAt(); ok {
|
|
_spec.SetField(alert.FieldUpdatedAt, field.TypeInt64, value)
|
|
}
|
|
if value, ok := _u.mutation.AddedUpdatedAt(); ok {
|
|
_spec.AddField(alert.FieldUpdatedAt, field.TypeInt64, value)
|
|
}
|
|
_node = &Alert{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{alert.Label}
|
|
} else if sqlgraph.IsConstraintError(err) {
|
|
err = &ConstraintError{msg: err.Error(), wrap: err}
|
|
}
|
|
return nil, err
|
|
}
|
|
_u.mutation.done = true
|
|
return _node, nil
|
|
}
|