bitbucket.org/Aishee/synsec@v0.0.0-20210414005726-236fc01a153d/pkg/database/ent/decision_update.go (about)

     1  // Code generated by entc, DO NOT EDIT.
     2  
     3  package ent
     4  
     5  import (
     6  	"context"
     7  	"fmt"
     8  	"time"
     9  
    10  	"entgo.io/ent/dialect/sql"
    11  	"entgo.io/ent/dialect/sql/sqlgraph"
    12  	"entgo.io/ent/schema/field"
    13  	"bitbucket.org/Aishee/synsec/pkg/database/ent/alert"
    14  	"bitbucket.org/Aishee/synsec/pkg/database/ent/decision"
    15  	"bitbucket.org/Aishee/synsec/pkg/database/ent/predicate"
    16  )
    17  
    18  // DecisionUpdate is the builder for updating Decision entities.
    19  type DecisionUpdate struct {
    20  	config
    21  	hooks    []Hook
    22  	mutation *DecisionMutation
    23  }
    24  
    25  // Where adds a new predicate for the DecisionUpdate builder.
    26  func (du *DecisionUpdate) Where(ps ...predicate.Decision) *DecisionUpdate {
    27  	du.mutation.predicates = append(du.mutation.predicates, ps...)
    28  	return du
    29  }
    30  
    31  // SetCreatedAt sets the "created_at" field.
    32  func (du *DecisionUpdate) SetCreatedAt(t time.Time) *DecisionUpdate {
    33  	du.mutation.SetCreatedAt(t)
    34  	return du
    35  }
    36  
    37  // SetNillableCreatedAt sets the "created_at" field if the given value is not nil.
    38  func (du *DecisionUpdate) SetNillableCreatedAt(t *time.Time) *DecisionUpdate {
    39  	if t != nil {
    40  		du.SetCreatedAt(*t)
    41  	}
    42  	return du
    43  }
    44  
    45  // SetUpdatedAt sets the "updated_at" field.
    46  func (du *DecisionUpdate) SetUpdatedAt(t time.Time) *DecisionUpdate {
    47  	du.mutation.SetUpdatedAt(t)
    48  	return du
    49  }
    50  
    51  // SetNillableUpdatedAt sets the "updated_at" field if the given value is not nil.
    52  func (du *DecisionUpdate) SetNillableUpdatedAt(t *time.Time) *DecisionUpdate {
    53  	if t != nil {
    54  		du.SetUpdatedAt(*t)
    55  	}
    56  	return du
    57  }
    58  
    59  // SetUntil sets the "until" field.
    60  func (du *DecisionUpdate) SetUntil(t time.Time) *DecisionUpdate {
    61  	du.mutation.SetUntil(t)
    62  	return du
    63  }
    64  
    65  // SetScenario sets the "scenario" field.
    66  func (du *DecisionUpdate) SetScenario(s string) *DecisionUpdate {
    67  	du.mutation.SetScenario(s)
    68  	return du
    69  }
    70  
    71  // SetType sets the "type" field.
    72  func (du *DecisionUpdate) SetType(s string) *DecisionUpdate {
    73  	du.mutation.SetType(s)
    74  	return du
    75  }
    76  
    77  // SetStartIP sets the "start_ip" field.
    78  func (du *DecisionUpdate) SetStartIP(i int64) *DecisionUpdate {
    79  	du.mutation.ResetStartIP()
    80  	du.mutation.SetStartIP(i)
    81  	return du
    82  }
    83  
    84  // SetNillableStartIP sets the "start_ip" field if the given value is not nil.
    85  func (du *DecisionUpdate) SetNillableStartIP(i *int64) *DecisionUpdate {
    86  	if i != nil {
    87  		du.SetStartIP(*i)
    88  	}
    89  	return du
    90  }
    91  
    92  // AddStartIP adds i to the "start_ip" field.
    93  func (du *DecisionUpdate) AddStartIP(i int64) *DecisionUpdate {
    94  	du.mutation.AddStartIP(i)
    95  	return du
    96  }
    97  
    98  // ClearStartIP clears the value of the "start_ip" field.
    99  func (du *DecisionUpdate) ClearStartIP() *DecisionUpdate {
   100  	du.mutation.ClearStartIP()
   101  	return du
   102  }
   103  
   104  // SetEndIP sets the "end_ip" field.
   105  func (du *DecisionUpdate) SetEndIP(i int64) *DecisionUpdate {
   106  	du.mutation.ResetEndIP()
   107  	du.mutation.SetEndIP(i)
   108  	return du
   109  }
   110  
   111  // SetNillableEndIP sets the "end_ip" field if the given value is not nil.
   112  func (du *DecisionUpdate) SetNillableEndIP(i *int64) *DecisionUpdate {
   113  	if i != nil {
   114  		du.SetEndIP(*i)
   115  	}
   116  	return du
   117  }
   118  
   119  // AddEndIP adds i to the "end_ip" field.
   120  func (du *DecisionUpdate) AddEndIP(i int64) *DecisionUpdate {
   121  	du.mutation.AddEndIP(i)
   122  	return du
   123  }
   124  
   125  // ClearEndIP clears the value of the "end_ip" field.
   126  func (du *DecisionUpdate) ClearEndIP() *DecisionUpdate {
   127  	du.mutation.ClearEndIP()
   128  	return du
   129  }
   130  
   131  // SetStartSuffix sets the "start_suffix" field.
   132  func (du *DecisionUpdate) SetStartSuffix(i int64) *DecisionUpdate {
   133  	du.mutation.ResetStartSuffix()
   134  	du.mutation.SetStartSuffix(i)
   135  	return du
   136  }
   137  
   138  // SetNillableStartSuffix sets the "start_suffix" field if the given value is not nil.
   139  func (du *DecisionUpdate) SetNillableStartSuffix(i *int64) *DecisionUpdate {
   140  	if i != nil {
   141  		du.SetStartSuffix(*i)
   142  	}
   143  	return du
   144  }
   145  
   146  // AddStartSuffix adds i to the "start_suffix" field.
   147  func (du *DecisionUpdate) AddStartSuffix(i int64) *DecisionUpdate {
   148  	du.mutation.AddStartSuffix(i)
   149  	return du
   150  }
   151  
   152  // ClearStartSuffix clears the value of the "start_suffix" field.
   153  func (du *DecisionUpdate) ClearStartSuffix() *DecisionUpdate {
   154  	du.mutation.ClearStartSuffix()
   155  	return du
   156  }
   157  
   158  // SetEndSuffix sets the "end_suffix" field.
   159  func (du *DecisionUpdate) SetEndSuffix(i int64) *DecisionUpdate {
   160  	du.mutation.ResetEndSuffix()
   161  	du.mutation.SetEndSuffix(i)
   162  	return du
   163  }
   164  
   165  // SetNillableEndSuffix sets the "end_suffix" field if the given value is not nil.
   166  func (du *DecisionUpdate) SetNillableEndSuffix(i *int64) *DecisionUpdate {
   167  	if i != nil {
   168  		du.SetEndSuffix(*i)
   169  	}
   170  	return du
   171  }
   172  
   173  // AddEndSuffix adds i to the "end_suffix" field.
   174  func (du *DecisionUpdate) AddEndSuffix(i int64) *DecisionUpdate {
   175  	du.mutation.AddEndSuffix(i)
   176  	return du
   177  }
   178  
   179  // ClearEndSuffix clears the value of the "end_suffix" field.
   180  func (du *DecisionUpdate) ClearEndSuffix() *DecisionUpdate {
   181  	du.mutation.ClearEndSuffix()
   182  	return du
   183  }
   184  
   185  // SetIPSize sets the "ip_size" field.
   186  func (du *DecisionUpdate) SetIPSize(i int64) *DecisionUpdate {
   187  	du.mutation.ResetIPSize()
   188  	du.mutation.SetIPSize(i)
   189  	return du
   190  }
   191  
   192  // SetNillableIPSize sets the "ip_size" field if the given value is not nil.
   193  func (du *DecisionUpdate) SetNillableIPSize(i *int64) *DecisionUpdate {
   194  	if i != nil {
   195  		du.SetIPSize(*i)
   196  	}
   197  	return du
   198  }
   199  
   200  // AddIPSize adds i to the "ip_size" field.
   201  func (du *DecisionUpdate) AddIPSize(i int64) *DecisionUpdate {
   202  	du.mutation.AddIPSize(i)
   203  	return du
   204  }
   205  
   206  // ClearIPSize clears the value of the "ip_size" field.
   207  func (du *DecisionUpdate) ClearIPSize() *DecisionUpdate {
   208  	du.mutation.ClearIPSize()
   209  	return du
   210  }
   211  
   212  // SetScope sets the "scope" field.
   213  func (du *DecisionUpdate) SetScope(s string) *DecisionUpdate {
   214  	du.mutation.SetScope(s)
   215  	return du
   216  }
   217  
   218  // SetValue sets the "value" field.
   219  func (du *DecisionUpdate) SetValue(s string) *DecisionUpdate {
   220  	du.mutation.SetValue(s)
   221  	return du
   222  }
   223  
   224  // SetOrigin sets the "origin" field.
   225  func (du *DecisionUpdate) SetOrigin(s string) *DecisionUpdate {
   226  	du.mutation.SetOrigin(s)
   227  	return du
   228  }
   229  
   230  // SetSimulated sets the "simulated" field.
   231  func (du *DecisionUpdate) SetSimulated(b bool) *DecisionUpdate {
   232  	du.mutation.SetSimulated(b)
   233  	return du
   234  }
   235  
   236  // SetNillableSimulated sets the "simulated" field if the given value is not nil.
   237  func (du *DecisionUpdate) SetNillableSimulated(b *bool) *DecisionUpdate {
   238  	if b != nil {
   239  		du.SetSimulated(*b)
   240  	}
   241  	return du
   242  }
   243  
   244  // SetOwnerID sets the "owner" edge to the Alert entity by ID.
   245  func (du *DecisionUpdate) SetOwnerID(id int) *DecisionUpdate {
   246  	du.mutation.SetOwnerID(id)
   247  	return du
   248  }
   249  
   250  // SetNillableOwnerID sets the "owner" edge to the Alert entity by ID if the given value is not nil.
   251  func (du *DecisionUpdate) SetNillableOwnerID(id *int) *DecisionUpdate {
   252  	if id != nil {
   253  		du = du.SetOwnerID(*id)
   254  	}
   255  	return du
   256  }
   257  
   258  // SetOwner sets the "owner" edge to the Alert entity.
   259  func (du *DecisionUpdate) SetOwner(a *Alert) *DecisionUpdate {
   260  	return du.SetOwnerID(a.ID)
   261  }
   262  
   263  // Mutation returns the DecisionMutation object of the builder.
   264  func (du *DecisionUpdate) Mutation() *DecisionMutation {
   265  	return du.mutation
   266  }
   267  
   268  // ClearOwner clears the "owner" edge to the Alert entity.
   269  func (du *DecisionUpdate) ClearOwner() *DecisionUpdate {
   270  	du.mutation.ClearOwner()
   271  	return du
   272  }
   273  
   274  // Save executes the query and returns the number of nodes affected by the update operation.
   275  func (du *DecisionUpdate) Save(ctx context.Context) (int, error) {
   276  	var (
   277  		err      error
   278  		affected int
   279  	)
   280  	if len(du.hooks) == 0 {
   281  		affected, err = du.sqlSave(ctx)
   282  	} else {
   283  		var mut Mutator = MutateFunc(func(ctx context.Context, m Mutation) (Value, error) {
   284  			mutation, ok := m.(*DecisionMutation)
   285  			if !ok {
   286  				return nil, fmt.Errorf("unexpected mutation type %T", m)
   287  			}
   288  			du.mutation = mutation
   289  			affected, err = du.sqlSave(ctx)
   290  			mutation.done = true
   291  			return affected, err
   292  		})
   293  		for i := len(du.hooks) - 1; i >= 0; i-- {
   294  			mut = du.hooks[i](mut)
   295  		}
   296  		if _, err := mut.Mutate(ctx, du.mutation); err != nil {
   297  			return 0, err
   298  		}
   299  	}
   300  	return affected, err
   301  }
   302  
   303  // SaveX is like Save, but panics if an error occurs.
   304  func (du *DecisionUpdate) SaveX(ctx context.Context) int {
   305  	affected, err := du.Save(ctx)
   306  	if err != nil {
   307  		panic(err)
   308  	}
   309  	return affected
   310  }
   311  
   312  // Exec executes the query.
   313  func (du *DecisionUpdate) Exec(ctx context.Context) error {
   314  	_, err := du.Save(ctx)
   315  	return err
   316  }
   317  
   318  // ExecX is like Exec, but panics if an error occurs.
   319  func (du *DecisionUpdate) ExecX(ctx context.Context) {
   320  	if err := du.Exec(ctx); err != nil {
   321  		panic(err)
   322  	}
   323  }
   324  
   325  func (du *DecisionUpdate) sqlSave(ctx context.Context) (n int, err error) {
   326  	_spec := &sqlgraph.UpdateSpec{
   327  		Node: &sqlgraph.NodeSpec{
   328  			Table:   decision.Table,
   329  			Columns: decision.Columns,
   330  			ID: &sqlgraph.FieldSpec{
   331  				Type:   field.TypeInt,
   332  				Column: decision.FieldID,
   333  			},
   334  		},
   335  	}
   336  	if ps := du.mutation.predicates; len(ps) > 0 {
   337  		_spec.Predicate = func(selector *sql.Selector) {
   338  			for i := range ps {
   339  				ps[i](selector)
   340  			}
   341  		}
   342  	}
   343  	if value, ok := du.mutation.CreatedAt(); ok {
   344  		_spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{
   345  			Type:   field.TypeTime,
   346  			Value:  value,
   347  			Column: decision.FieldCreatedAt,
   348  		})
   349  	}
   350  	if value, ok := du.mutation.UpdatedAt(); ok {
   351  		_spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{
   352  			Type:   field.TypeTime,
   353  			Value:  value,
   354  			Column: decision.FieldUpdatedAt,
   355  		})
   356  	}
   357  	if value, ok := du.mutation.Until(); ok {
   358  		_spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{
   359  			Type:   field.TypeTime,
   360  			Value:  value,
   361  			Column: decision.FieldUntil,
   362  		})
   363  	}
   364  	if value, ok := du.mutation.Scenario(); ok {
   365  		_spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{
   366  			Type:   field.TypeString,
   367  			Value:  value,
   368  			Column: decision.FieldScenario,
   369  		})
   370  	}
   371  	if value, ok := du.mutation.GetType(); ok {
   372  		_spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{
   373  			Type:   field.TypeString,
   374  			Value:  value,
   375  			Column: decision.FieldType,
   376  		})
   377  	}
   378  	if value, ok := du.mutation.StartIP(); ok {
   379  		_spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{
   380  			Type:   field.TypeInt64,
   381  			Value:  value,
   382  			Column: decision.FieldStartIP,
   383  		})
   384  	}
   385  	if value, ok := du.mutation.AddedStartIP(); ok {
   386  		_spec.Fields.Add = append(_spec.Fields.Add, &sqlgraph.FieldSpec{
   387  			Type:   field.TypeInt64,
   388  			Value:  value,
   389  			Column: decision.FieldStartIP,
   390  		})
   391  	}
   392  	if du.mutation.StartIPCleared() {
   393  		_spec.Fields.Clear = append(_spec.Fields.Clear, &sqlgraph.FieldSpec{
   394  			Type:   field.TypeInt64,
   395  			Column: decision.FieldStartIP,
   396  		})
   397  	}
   398  	if value, ok := du.mutation.EndIP(); ok {
   399  		_spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{
   400  			Type:   field.TypeInt64,
   401  			Value:  value,
   402  			Column: decision.FieldEndIP,
   403  		})
   404  	}
   405  	if value, ok := du.mutation.AddedEndIP(); ok {
   406  		_spec.Fields.Add = append(_spec.Fields.Add, &sqlgraph.FieldSpec{
   407  			Type:   field.TypeInt64,
   408  			Value:  value,
   409  			Column: decision.FieldEndIP,
   410  		})
   411  	}
   412  	if du.mutation.EndIPCleared() {
   413  		_spec.Fields.Clear = append(_spec.Fields.Clear, &sqlgraph.FieldSpec{
   414  			Type:   field.TypeInt64,
   415  			Column: decision.FieldEndIP,
   416  		})
   417  	}
   418  	if value, ok := du.mutation.StartSuffix(); ok {
   419  		_spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{
   420  			Type:   field.TypeInt64,
   421  			Value:  value,
   422  			Column: decision.FieldStartSuffix,
   423  		})
   424  	}
   425  	if value, ok := du.mutation.AddedStartSuffix(); ok {
   426  		_spec.Fields.Add = append(_spec.Fields.Add, &sqlgraph.FieldSpec{
   427  			Type:   field.TypeInt64,
   428  			Value:  value,
   429  			Column: decision.FieldStartSuffix,
   430  		})
   431  	}
   432  	if du.mutation.StartSuffixCleared() {
   433  		_spec.Fields.Clear = append(_spec.Fields.Clear, &sqlgraph.FieldSpec{
   434  			Type:   field.TypeInt64,
   435  			Column: decision.FieldStartSuffix,
   436  		})
   437  	}
   438  	if value, ok := du.mutation.EndSuffix(); ok {
   439  		_spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{
   440  			Type:   field.TypeInt64,
   441  			Value:  value,
   442  			Column: decision.FieldEndSuffix,
   443  		})
   444  	}
   445  	if value, ok := du.mutation.AddedEndSuffix(); ok {
   446  		_spec.Fields.Add = append(_spec.Fields.Add, &sqlgraph.FieldSpec{
   447  			Type:   field.TypeInt64,
   448  			Value:  value,
   449  			Column: decision.FieldEndSuffix,
   450  		})
   451  	}
   452  	if du.mutation.EndSuffixCleared() {
   453  		_spec.Fields.Clear = append(_spec.Fields.Clear, &sqlgraph.FieldSpec{
   454  			Type:   field.TypeInt64,
   455  			Column: decision.FieldEndSuffix,
   456  		})
   457  	}
   458  	if value, ok := du.mutation.IPSize(); ok {
   459  		_spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{
   460  			Type:   field.TypeInt64,
   461  			Value:  value,
   462  			Column: decision.FieldIPSize,
   463  		})
   464  	}
   465  	if value, ok := du.mutation.AddedIPSize(); ok {
   466  		_spec.Fields.Add = append(_spec.Fields.Add, &sqlgraph.FieldSpec{
   467  			Type:   field.TypeInt64,
   468  			Value:  value,
   469  			Column: decision.FieldIPSize,
   470  		})
   471  	}
   472  	if du.mutation.IPSizeCleared() {
   473  		_spec.Fields.Clear = append(_spec.Fields.Clear, &sqlgraph.FieldSpec{
   474  			Type:   field.TypeInt64,
   475  			Column: decision.FieldIPSize,
   476  		})
   477  	}
   478  	if value, ok := du.mutation.Scope(); ok {
   479  		_spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{
   480  			Type:   field.TypeString,
   481  			Value:  value,
   482  			Column: decision.FieldScope,
   483  		})
   484  	}
   485  	if value, ok := du.mutation.Value(); ok {
   486  		_spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{
   487  			Type:   field.TypeString,
   488  			Value:  value,
   489  			Column: decision.FieldValue,
   490  		})
   491  	}
   492  	if value, ok := du.mutation.Origin(); ok {
   493  		_spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{
   494  			Type:   field.TypeString,
   495  			Value:  value,
   496  			Column: decision.FieldOrigin,
   497  		})
   498  	}
   499  	if value, ok := du.mutation.Simulated(); ok {
   500  		_spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{
   501  			Type:   field.TypeBool,
   502  			Value:  value,
   503  			Column: decision.FieldSimulated,
   504  		})
   505  	}
   506  	if du.mutation.OwnerCleared() {
   507  		edge := &sqlgraph.EdgeSpec{
   508  			Rel:     sqlgraph.M2O,
   509  			Inverse: true,
   510  			Table:   decision.OwnerTable,
   511  			Columns: []string{decision.OwnerColumn},
   512  			Bidi:    false,
   513  			Target: &sqlgraph.EdgeTarget{
   514  				IDSpec: &sqlgraph.FieldSpec{
   515  					Type:   field.TypeInt,
   516  					Column: alert.FieldID,
   517  				},
   518  			},
   519  		}
   520  		_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
   521  	}
   522  	if nodes := du.mutation.OwnerIDs(); len(nodes) > 0 {
   523  		edge := &sqlgraph.EdgeSpec{
   524  			Rel:     sqlgraph.M2O,
   525  			Inverse: true,
   526  			Table:   decision.OwnerTable,
   527  			Columns: []string{decision.OwnerColumn},
   528  			Bidi:    false,
   529  			Target: &sqlgraph.EdgeTarget{
   530  				IDSpec: &sqlgraph.FieldSpec{
   531  					Type:   field.TypeInt,
   532  					Column: alert.FieldID,
   533  				},
   534  			},
   535  		}
   536  		for _, k := range nodes {
   537  			edge.Target.Nodes = append(edge.Target.Nodes, k)
   538  		}
   539  		_spec.Edges.Add = append(_spec.Edges.Add, edge)
   540  	}
   541  	if n, err = sqlgraph.UpdateNodes(ctx, du.driver, _spec); err != nil {
   542  		if _, ok := err.(*sqlgraph.NotFoundError); ok {
   543  			err = &NotFoundError{decision.Label}
   544  		} else if cerr, ok := isSQLConstraintError(err); ok {
   545  			err = cerr
   546  		}
   547  		return 0, err
   548  	}
   549  	return n, nil
   550  }
   551  
   552  // DecisionUpdateOne is the builder for updating a single Decision entity.
   553  type DecisionUpdateOne struct {
   554  	config
   555  	hooks    []Hook
   556  	mutation *DecisionMutation
   557  }
   558  
   559  // SetCreatedAt sets the "created_at" field.
   560  func (duo *DecisionUpdateOne) SetCreatedAt(t time.Time) *DecisionUpdateOne {
   561  	duo.mutation.SetCreatedAt(t)
   562  	return duo
   563  }
   564  
   565  // SetNillableCreatedAt sets the "created_at" field if the given value is not nil.
   566  func (duo *DecisionUpdateOne) SetNillableCreatedAt(t *time.Time) *DecisionUpdateOne {
   567  	if t != nil {
   568  		duo.SetCreatedAt(*t)
   569  	}
   570  	return duo
   571  }
   572  
   573  // SetUpdatedAt sets the "updated_at" field.
   574  func (duo *DecisionUpdateOne) SetUpdatedAt(t time.Time) *DecisionUpdateOne {
   575  	duo.mutation.SetUpdatedAt(t)
   576  	return duo
   577  }
   578  
   579  // SetNillableUpdatedAt sets the "updated_at" field if the given value is not nil.
   580  func (duo *DecisionUpdateOne) SetNillableUpdatedAt(t *time.Time) *DecisionUpdateOne {
   581  	if t != nil {
   582  		duo.SetUpdatedAt(*t)
   583  	}
   584  	return duo
   585  }
   586  
   587  // SetUntil sets the "until" field.
   588  func (duo *DecisionUpdateOne) SetUntil(t time.Time) *DecisionUpdateOne {
   589  	duo.mutation.SetUntil(t)
   590  	return duo
   591  }
   592  
   593  // SetScenario sets the "scenario" field.
   594  func (duo *DecisionUpdateOne) SetScenario(s string) *DecisionUpdateOne {
   595  	duo.mutation.SetScenario(s)
   596  	return duo
   597  }
   598  
   599  // SetType sets the "type" field.
   600  func (duo *DecisionUpdateOne) SetType(s string) *DecisionUpdateOne {
   601  	duo.mutation.SetType(s)
   602  	return duo
   603  }
   604  
   605  // SetStartIP sets the "start_ip" field.
   606  func (duo *DecisionUpdateOne) SetStartIP(i int64) *DecisionUpdateOne {
   607  	duo.mutation.ResetStartIP()
   608  	duo.mutation.SetStartIP(i)
   609  	return duo
   610  }
   611  
   612  // SetNillableStartIP sets the "start_ip" field if the given value is not nil.
   613  func (duo *DecisionUpdateOne) SetNillableStartIP(i *int64) *DecisionUpdateOne {
   614  	if i != nil {
   615  		duo.SetStartIP(*i)
   616  	}
   617  	return duo
   618  }
   619  
   620  // AddStartIP adds i to the "start_ip" field.
   621  func (duo *DecisionUpdateOne) AddStartIP(i int64) *DecisionUpdateOne {
   622  	duo.mutation.AddStartIP(i)
   623  	return duo
   624  }
   625  
   626  // ClearStartIP clears the value of the "start_ip" field.
   627  func (duo *DecisionUpdateOne) ClearStartIP() *DecisionUpdateOne {
   628  	duo.mutation.ClearStartIP()
   629  	return duo
   630  }
   631  
   632  // SetEndIP sets the "end_ip" field.
   633  func (duo *DecisionUpdateOne) SetEndIP(i int64) *DecisionUpdateOne {
   634  	duo.mutation.ResetEndIP()
   635  	duo.mutation.SetEndIP(i)
   636  	return duo
   637  }
   638  
   639  // SetNillableEndIP sets the "end_ip" field if the given value is not nil.
   640  func (duo *DecisionUpdateOne) SetNillableEndIP(i *int64) *DecisionUpdateOne {
   641  	if i != nil {
   642  		duo.SetEndIP(*i)
   643  	}
   644  	return duo
   645  }
   646  
   647  // AddEndIP adds i to the "end_ip" field.
   648  func (duo *DecisionUpdateOne) AddEndIP(i int64) *DecisionUpdateOne {
   649  	duo.mutation.AddEndIP(i)
   650  	return duo
   651  }
   652  
   653  // ClearEndIP clears the value of the "end_ip" field.
   654  func (duo *DecisionUpdateOne) ClearEndIP() *DecisionUpdateOne {
   655  	duo.mutation.ClearEndIP()
   656  	return duo
   657  }
   658  
   659  // SetStartSuffix sets the "start_suffix" field.
   660  func (duo *DecisionUpdateOne) SetStartSuffix(i int64) *DecisionUpdateOne {
   661  	duo.mutation.ResetStartSuffix()
   662  	duo.mutation.SetStartSuffix(i)
   663  	return duo
   664  }
   665  
   666  // SetNillableStartSuffix sets the "start_suffix" field if the given value is not nil.
   667  func (duo *DecisionUpdateOne) SetNillableStartSuffix(i *int64) *DecisionUpdateOne {
   668  	if i != nil {
   669  		duo.SetStartSuffix(*i)
   670  	}
   671  	return duo
   672  }
   673  
   674  // AddStartSuffix adds i to the "start_suffix" field.
   675  func (duo *DecisionUpdateOne) AddStartSuffix(i int64) *DecisionUpdateOne {
   676  	duo.mutation.AddStartSuffix(i)
   677  	return duo
   678  }
   679  
   680  // ClearStartSuffix clears the value of the "start_suffix" field.
   681  func (duo *DecisionUpdateOne) ClearStartSuffix() *DecisionUpdateOne {
   682  	duo.mutation.ClearStartSuffix()
   683  	return duo
   684  }
   685  
   686  // SetEndSuffix sets the "end_suffix" field.
   687  func (duo *DecisionUpdateOne) SetEndSuffix(i int64) *DecisionUpdateOne {
   688  	duo.mutation.ResetEndSuffix()
   689  	duo.mutation.SetEndSuffix(i)
   690  	return duo
   691  }
   692  
   693  // SetNillableEndSuffix sets the "end_suffix" field if the given value is not nil.
   694  func (duo *DecisionUpdateOne) SetNillableEndSuffix(i *int64) *DecisionUpdateOne {
   695  	if i != nil {
   696  		duo.SetEndSuffix(*i)
   697  	}
   698  	return duo
   699  }
   700  
   701  // AddEndSuffix adds i to the "end_suffix" field.
   702  func (duo *DecisionUpdateOne) AddEndSuffix(i int64) *DecisionUpdateOne {
   703  	duo.mutation.AddEndSuffix(i)
   704  	return duo
   705  }
   706  
   707  // ClearEndSuffix clears the value of the "end_suffix" field.
   708  func (duo *DecisionUpdateOne) ClearEndSuffix() *DecisionUpdateOne {
   709  	duo.mutation.ClearEndSuffix()
   710  	return duo
   711  }
   712  
   713  // SetIPSize sets the "ip_size" field.
   714  func (duo *DecisionUpdateOne) SetIPSize(i int64) *DecisionUpdateOne {
   715  	duo.mutation.ResetIPSize()
   716  	duo.mutation.SetIPSize(i)
   717  	return duo
   718  }
   719  
   720  // SetNillableIPSize sets the "ip_size" field if the given value is not nil.
   721  func (duo *DecisionUpdateOne) SetNillableIPSize(i *int64) *DecisionUpdateOne {
   722  	if i != nil {
   723  		duo.SetIPSize(*i)
   724  	}
   725  	return duo
   726  }
   727  
   728  // AddIPSize adds i to the "ip_size" field.
   729  func (duo *DecisionUpdateOne) AddIPSize(i int64) *DecisionUpdateOne {
   730  	duo.mutation.AddIPSize(i)
   731  	return duo
   732  }
   733  
   734  // ClearIPSize clears the value of the "ip_size" field.
   735  func (duo *DecisionUpdateOne) ClearIPSize() *DecisionUpdateOne {
   736  	duo.mutation.ClearIPSize()
   737  	return duo
   738  }
   739  
   740  // SetScope sets the "scope" field.
   741  func (duo *DecisionUpdateOne) SetScope(s string) *DecisionUpdateOne {
   742  	duo.mutation.SetScope(s)
   743  	return duo
   744  }
   745  
   746  // SetValue sets the "value" field.
   747  func (duo *DecisionUpdateOne) SetValue(s string) *DecisionUpdateOne {
   748  	duo.mutation.SetValue(s)
   749  	return duo
   750  }
   751  
   752  // SetOrigin sets the "origin" field.
   753  func (duo *DecisionUpdateOne) SetOrigin(s string) *DecisionUpdateOne {
   754  	duo.mutation.SetOrigin(s)
   755  	return duo
   756  }
   757  
   758  // SetSimulated sets the "simulated" field.
   759  func (duo *DecisionUpdateOne) SetSimulated(b bool) *DecisionUpdateOne {
   760  	duo.mutation.SetSimulated(b)
   761  	return duo
   762  }
   763  
   764  // SetNillableSimulated sets the "simulated" field if the given value is not nil.
   765  func (duo *DecisionUpdateOne) SetNillableSimulated(b *bool) *DecisionUpdateOne {
   766  	if b != nil {
   767  		duo.SetSimulated(*b)
   768  	}
   769  	return duo
   770  }
   771  
   772  // SetOwnerID sets the "owner" edge to the Alert entity by ID.
   773  func (duo *DecisionUpdateOne) SetOwnerID(id int) *DecisionUpdateOne {
   774  	duo.mutation.SetOwnerID(id)
   775  	return duo
   776  }
   777  
   778  // SetNillableOwnerID sets the "owner" edge to the Alert entity by ID if the given value is not nil.
   779  func (duo *DecisionUpdateOne) SetNillableOwnerID(id *int) *DecisionUpdateOne {
   780  	if id != nil {
   781  		duo = duo.SetOwnerID(*id)
   782  	}
   783  	return duo
   784  }
   785  
   786  // SetOwner sets the "owner" edge to the Alert entity.
   787  func (duo *DecisionUpdateOne) SetOwner(a *Alert) *DecisionUpdateOne {
   788  	return duo.SetOwnerID(a.ID)
   789  }
   790  
   791  // Mutation returns the DecisionMutation object of the builder.
   792  func (duo *DecisionUpdateOne) Mutation() *DecisionMutation {
   793  	return duo.mutation
   794  }
   795  
   796  // ClearOwner clears the "owner" edge to the Alert entity.
   797  func (duo *DecisionUpdateOne) ClearOwner() *DecisionUpdateOne {
   798  	duo.mutation.ClearOwner()
   799  	return duo
   800  }
   801  
   802  // Save executes the query and returns the updated Decision entity.
   803  func (duo *DecisionUpdateOne) Save(ctx context.Context) (*Decision, error) {
   804  	var (
   805  		err  error
   806  		node *Decision
   807  	)
   808  	if len(duo.hooks) == 0 {
   809  		node, err = duo.sqlSave(ctx)
   810  	} else {
   811  		var mut Mutator = MutateFunc(func(ctx context.Context, m Mutation) (Value, error) {
   812  			mutation, ok := m.(*DecisionMutation)
   813  			if !ok {
   814  				return nil, fmt.Errorf("unexpected mutation type %T", m)
   815  			}
   816  			duo.mutation = mutation
   817  			node, err = duo.sqlSave(ctx)
   818  			mutation.done = true
   819  			return node, err
   820  		})
   821  		for i := len(duo.hooks) - 1; i >= 0; i-- {
   822  			mut = duo.hooks[i](mut)
   823  		}
   824  		if _, err := mut.Mutate(ctx, duo.mutation); err != nil {
   825  			return nil, err
   826  		}
   827  	}
   828  	return node, err
   829  }
   830  
   831  // SaveX is like Save, but panics if an error occurs.
   832  func (duo *DecisionUpdateOne) SaveX(ctx context.Context) *Decision {
   833  	node, err := duo.Save(ctx)
   834  	if err != nil {
   835  		panic(err)
   836  	}
   837  	return node
   838  }
   839  
   840  // Exec executes the query on the entity.
   841  func (duo *DecisionUpdateOne) Exec(ctx context.Context) error {
   842  	_, err := duo.Save(ctx)
   843  	return err
   844  }
   845  
   846  // ExecX is like Exec, but panics if an error occurs.
   847  func (duo *DecisionUpdateOne) ExecX(ctx context.Context) {
   848  	if err := duo.Exec(ctx); err != nil {
   849  		panic(err)
   850  	}
   851  }
   852  
   853  func (duo *DecisionUpdateOne) sqlSave(ctx context.Context) (_node *Decision, err error) {
   854  	_spec := &sqlgraph.UpdateSpec{
   855  		Node: &sqlgraph.NodeSpec{
   856  			Table:   decision.Table,
   857  			Columns: decision.Columns,
   858  			ID: &sqlgraph.FieldSpec{
   859  				Type:   field.TypeInt,
   860  				Column: decision.FieldID,
   861  			},
   862  		},
   863  	}
   864  	id, ok := duo.mutation.ID()
   865  	if !ok {
   866  		return nil, &ValidationError{Name: "ID", err: fmt.Errorf("missing Decision.ID for update")}
   867  	}
   868  	_spec.Node.ID.Value = id
   869  	if ps := duo.mutation.predicates; len(ps) > 0 {
   870  		_spec.Predicate = func(selector *sql.Selector) {
   871  			for i := range ps {
   872  				ps[i](selector)
   873  			}
   874  		}
   875  	}
   876  	if value, ok := duo.mutation.CreatedAt(); ok {
   877  		_spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{
   878  			Type:   field.TypeTime,
   879  			Value:  value,
   880  			Column: decision.FieldCreatedAt,
   881  		})
   882  	}
   883  	if value, ok := duo.mutation.UpdatedAt(); ok {
   884  		_spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{
   885  			Type:   field.TypeTime,
   886  			Value:  value,
   887  			Column: decision.FieldUpdatedAt,
   888  		})
   889  	}
   890  	if value, ok := duo.mutation.Until(); ok {
   891  		_spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{
   892  			Type:   field.TypeTime,
   893  			Value:  value,
   894  			Column: decision.FieldUntil,
   895  		})
   896  	}
   897  	if value, ok := duo.mutation.Scenario(); ok {
   898  		_spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{
   899  			Type:   field.TypeString,
   900  			Value:  value,
   901  			Column: decision.FieldScenario,
   902  		})
   903  	}
   904  	if value, ok := duo.mutation.GetType(); ok {
   905  		_spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{
   906  			Type:   field.TypeString,
   907  			Value:  value,
   908  			Column: decision.FieldType,
   909  		})
   910  	}
   911  	if value, ok := duo.mutation.StartIP(); ok {
   912  		_spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{
   913  			Type:   field.TypeInt64,
   914  			Value:  value,
   915  			Column: decision.FieldStartIP,
   916  		})
   917  	}
   918  	if value, ok := duo.mutation.AddedStartIP(); ok {
   919  		_spec.Fields.Add = append(_spec.Fields.Add, &sqlgraph.FieldSpec{
   920  			Type:   field.TypeInt64,
   921  			Value:  value,
   922  			Column: decision.FieldStartIP,
   923  		})
   924  	}
   925  	if duo.mutation.StartIPCleared() {
   926  		_spec.Fields.Clear = append(_spec.Fields.Clear, &sqlgraph.FieldSpec{
   927  			Type:   field.TypeInt64,
   928  			Column: decision.FieldStartIP,
   929  		})
   930  	}
   931  	if value, ok := duo.mutation.EndIP(); ok {
   932  		_spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{
   933  			Type:   field.TypeInt64,
   934  			Value:  value,
   935  			Column: decision.FieldEndIP,
   936  		})
   937  	}
   938  	if value, ok := duo.mutation.AddedEndIP(); ok {
   939  		_spec.Fields.Add = append(_spec.Fields.Add, &sqlgraph.FieldSpec{
   940  			Type:   field.TypeInt64,
   941  			Value:  value,
   942  			Column: decision.FieldEndIP,
   943  		})
   944  	}
   945  	if duo.mutation.EndIPCleared() {
   946  		_spec.Fields.Clear = append(_spec.Fields.Clear, &sqlgraph.FieldSpec{
   947  			Type:   field.TypeInt64,
   948  			Column: decision.FieldEndIP,
   949  		})
   950  	}
   951  	if value, ok := duo.mutation.StartSuffix(); ok {
   952  		_spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{
   953  			Type:   field.TypeInt64,
   954  			Value:  value,
   955  			Column: decision.FieldStartSuffix,
   956  		})
   957  	}
   958  	if value, ok := duo.mutation.AddedStartSuffix(); ok {
   959  		_spec.Fields.Add = append(_spec.Fields.Add, &sqlgraph.FieldSpec{
   960  			Type:   field.TypeInt64,
   961  			Value:  value,
   962  			Column: decision.FieldStartSuffix,
   963  		})
   964  	}
   965  	if duo.mutation.StartSuffixCleared() {
   966  		_spec.Fields.Clear = append(_spec.Fields.Clear, &sqlgraph.FieldSpec{
   967  			Type:   field.TypeInt64,
   968  			Column: decision.FieldStartSuffix,
   969  		})
   970  	}
   971  	if value, ok := duo.mutation.EndSuffix(); ok {
   972  		_spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{
   973  			Type:   field.TypeInt64,
   974  			Value:  value,
   975  			Column: decision.FieldEndSuffix,
   976  		})
   977  	}
   978  	if value, ok := duo.mutation.AddedEndSuffix(); ok {
   979  		_spec.Fields.Add = append(_spec.Fields.Add, &sqlgraph.FieldSpec{
   980  			Type:   field.TypeInt64,
   981  			Value:  value,
   982  			Column: decision.FieldEndSuffix,
   983  		})
   984  	}
   985  	if duo.mutation.EndSuffixCleared() {
   986  		_spec.Fields.Clear = append(_spec.Fields.Clear, &sqlgraph.FieldSpec{
   987  			Type:   field.TypeInt64,
   988  			Column: decision.FieldEndSuffix,
   989  		})
   990  	}
   991  	if value, ok := duo.mutation.IPSize(); ok {
   992  		_spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{
   993  			Type:   field.TypeInt64,
   994  			Value:  value,
   995  			Column: decision.FieldIPSize,
   996  		})
   997  	}
   998  	if value, ok := duo.mutation.AddedIPSize(); ok {
   999  		_spec.Fields.Add = append(_spec.Fields.Add, &sqlgraph.FieldSpec{
  1000  			Type:   field.TypeInt64,
  1001  			Value:  value,
  1002  			Column: decision.FieldIPSize,
  1003  		})
  1004  	}
  1005  	if duo.mutation.IPSizeCleared() {
  1006  		_spec.Fields.Clear = append(_spec.Fields.Clear, &sqlgraph.FieldSpec{
  1007  			Type:   field.TypeInt64,
  1008  			Column: decision.FieldIPSize,
  1009  		})
  1010  	}
  1011  	if value, ok := duo.mutation.Scope(); ok {
  1012  		_spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{
  1013  			Type:   field.TypeString,
  1014  			Value:  value,
  1015  			Column: decision.FieldScope,
  1016  		})
  1017  	}
  1018  	if value, ok := duo.mutation.Value(); ok {
  1019  		_spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{
  1020  			Type:   field.TypeString,
  1021  			Value:  value,
  1022  			Column: decision.FieldValue,
  1023  		})
  1024  	}
  1025  	if value, ok := duo.mutation.Origin(); ok {
  1026  		_spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{
  1027  			Type:   field.TypeString,
  1028  			Value:  value,
  1029  			Column: decision.FieldOrigin,
  1030  		})
  1031  	}
  1032  	if value, ok := duo.mutation.Simulated(); ok {
  1033  		_spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{
  1034  			Type:   field.TypeBool,
  1035  			Value:  value,
  1036  			Column: decision.FieldSimulated,
  1037  		})
  1038  	}
  1039  	if duo.mutation.OwnerCleared() {
  1040  		edge := &sqlgraph.EdgeSpec{
  1041  			Rel:     sqlgraph.M2O,
  1042  			Inverse: true,
  1043  			Table:   decision.OwnerTable,
  1044  			Columns: []string{decision.OwnerColumn},
  1045  			Bidi:    false,
  1046  			Target: &sqlgraph.EdgeTarget{
  1047  				IDSpec: &sqlgraph.FieldSpec{
  1048  					Type:   field.TypeInt,
  1049  					Column: alert.FieldID,
  1050  				},
  1051  			},
  1052  		}
  1053  		_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
  1054  	}
  1055  	if nodes := duo.mutation.OwnerIDs(); len(nodes) > 0 {
  1056  		edge := &sqlgraph.EdgeSpec{
  1057  			Rel:     sqlgraph.M2O,
  1058  			Inverse: true,
  1059  			Table:   decision.OwnerTable,
  1060  			Columns: []string{decision.OwnerColumn},
  1061  			Bidi:    false,
  1062  			Target: &sqlgraph.EdgeTarget{
  1063  				IDSpec: &sqlgraph.FieldSpec{
  1064  					Type:   field.TypeInt,
  1065  					Column: alert.FieldID,
  1066  				},
  1067  			},
  1068  		}
  1069  		for _, k := range nodes {
  1070  			edge.Target.Nodes = append(edge.Target.Nodes, k)
  1071  		}
  1072  		_spec.Edges.Add = append(_spec.Edges.Add, edge)
  1073  	}
  1074  	_node = &Decision{config: duo.config}
  1075  	_spec.Assign = _node.assignValues
  1076  	_spec.ScanValues = _node.scanValues
  1077  	if err = sqlgraph.UpdateNode(ctx, duo.driver, _spec); err != nil {
  1078  		if _, ok := err.(*sqlgraph.NotFoundError); ok {
  1079  			err = &NotFoundError{decision.Label}
  1080  		} else if cerr, ok := isSQLConstraintError(err); ok {
  1081  			err = cerr
  1082  		}
  1083  		return nil, err
  1084  	}
  1085  	return _node, nil
  1086  }