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

     1  // Code generated by entc, DO NOT EDIT.
     2  
     3  package ent
     4  
     5  import (
     6  	"context"
     7  	"errors"
     8  	"fmt"
     9  	"time"
    10  
    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/event"
    16  	"bitbucket.org/Aishee/synsec/pkg/database/ent/machine"
    17  	"bitbucket.org/Aishee/synsec/pkg/database/ent/meta"
    18  )
    19  
    20  // AlertCreate is the builder for creating a Alert entity.
    21  type AlertCreate struct {
    22  	config
    23  	mutation *AlertMutation
    24  	hooks    []Hook
    25  }
    26  
    27  // SetCreatedAt sets the "created_at" field.
    28  func (ac *AlertCreate) SetCreatedAt(t time.Time) *AlertCreate {
    29  	ac.mutation.SetCreatedAt(t)
    30  	return ac
    31  }
    32  
    33  // SetNillableCreatedAt sets the "created_at" field if the given value is not nil.
    34  func (ac *AlertCreate) SetNillableCreatedAt(t *time.Time) *AlertCreate {
    35  	if t != nil {
    36  		ac.SetCreatedAt(*t)
    37  	}
    38  	return ac
    39  }
    40  
    41  // SetUpdatedAt sets the "updated_at" field.
    42  func (ac *AlertCreate) SetUpdatedAt(t time.Time) *AlertCreate {
    43  	ac.mutation.SetUpdatedAt(t)
    44  	return ac
    45  }
    46  
    47  // SetNillableUpdatedAt sets the "updated_at" field if the given value is not nil.
    48  func (ac *AlertCreate) SetNillableUpdatedAt(t *time.Time) *AlertCreate {
    49  	if t != nil {
    50  		ac.SetUpdatedAt(*t)
    51  	}
    52  	return ac
    53  }
    54  
    55  // SetScenario sets the "scenario" field.
    56  func (ac *AlertCreate) SetScenario(s string) *AlertCreate {
    57  	ac.mutation.SetScenario(s)
    58  	return ac
    59  }
    60  
    61  // SetBucketId sets the "bucketId" field.
    62  func (ac *AlertCreate) SetBucketId(s string) *AlertCreate {
    63  	ac.mutation.SetBucketId(s)
    64  	return ac
    65  }
    66  
    67  // SetNillableBucketId sets the "bucketId" field if the given value is not nil.
    68  func (ac *AlertCreate) SetNillableBucketId(s *string) *AlertCreate {
    69  	if s != nil {
    70  		ac.SetBucketId(*s)
    71  	}
    72  	return ac
    73  }
    74  
    75  // SetMessage sets the "message" field.
    76  func (ac *AlertCreate) SetMessage(s string) *AlertCreate {
    77  	ac.mutation.SetMessage(s)
    78  	return ac
    79  }
    80  
    81  // SetNillableMessage sets the "message" field if the given value is not nil.
    82  func (ac *AlertCreate) SetNillableMessage(s *string) *AlertCreate {
    83  	if s != nil {
    84  		ac.SetMessage(*s)
    85  	}
    86  	return ac
    87  }
    88  
    89  // SetEventsCount sets the "eventsCount" field.
    90  func (ac *AlertCreate) SetEventsCount(i int32) *AlertCreate {
    91  	ac.mutation.SetEventsCount(i)
    92  	return ac
    93  }
    94  
    95  // SetNillableEventsCount sets the "eventsCount" field if the given value is not nil.
    96  func (ac *AlertCreate) SetNillableEventsCount(i *int32) *AlertCreate {
    97  	if i != nil {
    98  		ac.SetEventsCount(*i)
    99  	}
   100  	return ac
   101  }
   102  
   103  // SetStartedAt sets the "startedAt" field.
   104  func (ac *AlertCreate) SetStartedAt(t time.Time) *AlertCreate {
   105  	ac.mutation.SetStartedAt(t)
   106  	return ac
   107  }
   108  
   109  // SetNillableStartedAt sets the "startedAt" field if the given value is not nil.
   110  func (ac *AlertCreate) SetNillableStartedAt(t *time.Time) *AlertCreate {
   111  	if t != nil {
   112  		ac.SetStartedAt(*t)
   113  	}
   114  	return ac
   115  }
   116  
   117  // SetStoppedAt sets the "stoppedAt" field.
   118  func (ac *AlertCreate) SetStoppedAt(t time.Time) *AlertCreate {
   119  	ac.mutation.SetStoppedAt(t)
   120  	return ac
   121  }
   122  
   123  // SetNillableStoppedAt sets the "stoppedAt" field if the given value is not nil.
   124  func (ac *AlertCreate) SetNillableStoppedAt(t *time.Time) *AlertCreate {
   125  	if t != nil {
   126  		ac.SetStoppedAt(*t)
   127  	}
   128  	return ac
   129  }
   130  
   131  // SetSourceIp sets the "sourceIp" field.
   132  func (ac *AlertCreate) SetSourceIp(s string) *AlertCreate {
   133  	ac.mutation.SetSourceIp(s)
   134  	return ac
   135  }
   136  
   137  // SetNillableSourceIp sets the "sourceIp" field if the given value is not nil.
   138  func (ac *AlertCreate) SetNillableSourceIp(s *string) *AlertCreate {
   139  	if s != nil {
   140  		ac.SetSourceIp(*s)
   141  	}
   142  	return ac
   143  }
   144  
   145  // SetSourceRange sets the "sourceRange" field.
   146  func (ac *AlertCreate) SetSourceRange(s string) *AlertCreate {
   147  	ac.mutation.SetSourceRange(s)
   148  	return ac
   149  }
   150  
   151  // SetNillableSourceRange sets the "sourceRange" field if the given value is not nil.
   152  func (ac *AlertCreate) SetNillableSourceRange(s *string) *AlertCreate {
   153  	if s != nil {
   154  		ac.SetSourceRange(*s)
   155  	}
   156  	return ac
   157  }
   158  
   159  // SetSourceAsNumber sets the "sourceAsNumber" field.
   160  func (ac *AlertCreate) SetSourceAsNumber(s string) *AlertCreate {
   161  	ac.mutation.SetSourceAsNumber(s)
   162  	return ac
   163  }
   164  
   165  // SetNillableSourceAsNumber sets the "sourceAsNumber" field if the given value is not nil.
   166  func (ac *AlertCreate) SetNillableSourceAsNumber(s *string) *AlertCreate {
   167  	if s != nil {
   168  		ac.SetSourceAsNumber(*s)
   169  	}
   170  	return ac
   171  }
   172  
   173  // SetSourceAsName sets the "sourceAsName" field.
   174  func (ac *AlertCreate) SetSourceAsName(s string) *AlertCreate {
   175  	ac.mutation.SetSourceAsName(s)
   176  	return ac
   177  }
   178  
   179  // SetNillableSourceAsName sets the "sourceAsName" field if the given value is not nil.
   180  func (ac *AlertCreate) SetNillableSourceAsName(s *string) *AlertCreate {
   181  	if s != nil {
   182  		ac.SetSourceAsName(*s)
   183  	}
   184  	return ac
   185  }
   186  
   187  // SetSourceCountry sets the "sourceCountry" field.
   188  func (ac *AlertCreate) SetSourceCountry(s string) *AlertCreate {
   189  	ac.mutation.SetSourceCountry(s)
   190  	return ac
   191  }
   192  
   193  // SetNillableSourceCountry sets the "sourceCountry" field if the given value is not nil.
   194  func (ac *AlertCreate) SetNillableSourceCountry(s *string) *AlertCreate {
   195  	if s != nil {
   196  		ac.SetSourceCountry(*s)
   197  	}
   198  	return ac
   199  }
   200  
   201  // SetSourceLatitude sets the "sourceLatitude" field.
   202  func (ac *AlertCreate) SetSourceLatitude(f float32) *AlertCreate {
   203  	ac.mutation.SetSourceLatitude(f)
   204  	return ac
   205  }
   206  
   207  // SetNillableSourceLatitude sets the "sourceLatitude" field if the given value is not nil.
   208  func (ac *AlertCreate) SetNillableSourceLatitude(f *float32) *AlertCreate {
   209  	if f != nil {
   210  		ac.SetSourceLatitude(*f)
   211  	}
   212  	return ac
   213  }
   214  
   215  // SetSourceLongitude sets the "sourceLongitude" field.
   216  func (ac *AlertCreate) SetSourceLongitude(f float32) *AlertCreate {
   217  	ac.mutation.SetSourceLongitude(f)
   218  	return ac
   219  }
   220  
   221  // SetNillableSourceLongitude sets the "sourceLongitude" field if the given value is not nil.
   222  func (ac *AlertCreate) SetNillableSourceLongitude(f *float32) *AlertCreate {
   223  	if f != nil {
   224  		ac.SetSourceLongitude(*f)
   225  	}
   226  	return ac
   227  }
   228  
   229  // SetSourceScope sets the "sourceScope" field.
   230  func (ac *AlertCreate) SetSourceScope(s string) *AlertCreate {
   231  	ac.mutation.SetSourceScope(s)
   232  	return ac
   233  }
   234  
   235  // SetNillableSourceScope sets the "sourceScope" field if the given value is not nil.
   236  func (ac *AlertCreate) SetNillableSourceScope(s *string) *AlertCreate {
   237  	if s != nil {
   238  		ac.SetSourceScope(*s)
   239  	}
   240  	return ac
   241  }
   242  
   243  // SetSourceValue sets the "sourceValue" field.
   244  func (ac *AlertCreate) SetSourceValue(s string) *AlertCreate {
   245  	ac.mutation.SetSourceValue(s)
   246  	return ac
   247  }
   248  
   249  // SetNillableSourceValue sets the "sourceValue" field if the given value is not nil.
   250  func (ac *AlertCreate) SetNillableSourceValue(s *string) *AlertCreate {
   251  	if s != nil {
   252  		ac.SetSourceValue(*s)
   253  	}
   254  	return ac
   255  }
   256  
   257  // SetCapacity sets the "capacity" field.
   258  func (ac *AlertCreate) SetCapacity(i int32) *AlertCreate {
   259  	ac.mutation.SetCapacity(i)
   260  	return ac
   261  }
   262  
   263  // SetNillableCapacity sets the "capacity" field if the given value is not nil.
   264  func (ac *AlertCreate) SetNillableCapacity(i *int32) *AlertCreate {
   265  	if i != nil {
   266  		ac.SetCapacity(*i)
   267  	}
   268  	return ac
   269  }
   270  
   271  // SetLeakSpeed sets the "leakSpeed" field.
   272  func (ac *AlertCreate) SetLeakSpeed(s string) *AlertCreate {
   273  	ac.mutation.SetLeakSpeed(s)
   274  	return ac
   275  }
   276  
   277  // SetNillableLeakSpeed sets the "leakSpeed" field if the given value is not nil.
   278  func (ac *AlertCreate) SetNillableLeakSpeed(s *string) *AlertCreate {
   279  	if s != nil {
   280  		ac.SetLeakSpeed(*s)
   281  	}
   282  	return ac
   283  }
   284  
   285  // SetScenarioVersion sets the "scenarioVersion" field.
   286  func (ac *AlertCreate) SetScenarioVersion(s string) *AlertCreate {
   287  	ac.mutation.SetScenarioVersion(s)
   288  	return ac
   289  }
   290  
   291  // SetNillableScenarioVersion sets the "scenarioVersion" field if the given value is not nil.
   292  func (ac *AlertCreate) SetNillableScenarioVersion(s *string) *AlertCreate {
   293  	if s != nil {
   294  		ac.SetScenarioVersion(*s)
   295  	}
   296  	return ac
   297  }
   298  
   299  // SetScenarioHash sets the "scenarioHash" field.
   300  func (ac *AlertCreate) SetScenarioHash(s string) *AlertCreate {
   301  	ac.mutation.SetScenarioHash(s)
   302  	return ac
   303  }
   304  
   305  // SetNillableScenarioHash sets the "scenarioHash" field if the given value is not nil.
   306  func (ac *AlertCreate) SetNillableScenarioHash(s *string) *AlertCreate {
   307  	if s != nil {
   308  		ac.SetScenarioHash(*s)
   309  	}
   310  	return ac
   311  }
   312  
   313  // SetSimulated sets the "simulated" field.
   314  func (ac *AlertCreate) SetSimulated(b bool) *AlertCreate {
   315  	ac.mutation.SetSimulated(b)
   316  	return ac
   317  }
   318  
   319  // SetNillableSimulated sets the "simulated" field if the given value is not nil.
   320  func (ac *AlertCreate) SetNillableSimulated(b *bool) *AlertCreate {
   321  	if b != nil {
   322  		ac.SetSimulated(*b)
   323  	}
   324  	return ac
   325  }
   326  
   327  // SetOwnerID sets the "owner" edge to the Machine entity by ID.
   328  func (ac *AlertCreate) SetOwnerID(id int) *AlertCreate {
   329  	ac.mutation.SetOwnerID(id)
   330  	return ac
   331  }
   332  
   333  // SetNillableOwnerID sets the "owner" edge to the Machine entity by ID if the given value is not nil.
   334  func (ac *AlertCreate) SetNillableOwnerID(id *int) *AlertCreate {
   335  	if id != nil {
   336  		ac = ac.SetOwnerID(*id)
   337  	}
   338  	return ac
   339  }
   340  
   341  // SetOwner sets the "owner" edge to the Machine entity.
   342  func (ac *AlertCreate) SetOwner(m *Machine) *AlertCreate {
   343  	return ac.SetOwnerID(m.ID)
   344  }
   345  
   346  // AddDecisionIDs adds the "decisions" edge to the Decision entity by IDs.
   347  func (ac *AlertCreate) AddDecisionIDs(ids ...int) *AlertCreate {
   348  	ac.mutation.AddDecisionIDs(ids...)
   349  	return ac
   350  }
   351  
   352  // AddDecisions adds the "decisions" edges to the Decision entity.
   353  func (ac *AlertCreate) AddDecisions(d ...*Decision) *AlertCreate {
   354  	ids := make([]int, len(d))
   355  	for i := range d {
   356  		ids[i] = d[i].ID
   357  	}
   358  	return ac.AddDecisionIDs(ids...)
   359  }
   360  
   361  // AddEventIDs adds the "events" edge to the Event entity by IDs.
   362  func (ac *AlertCreate) AddEventIDs(ids ...int) *AlertCreate {
   363  	ac.mutation.AddEventIDs(ids...)
   364  	return ac
   365  }
   366  
   367  // AddEvents adds the "events" edges to the Event entity.
   368  func (ac *AlertCreate) AddEvents(e ...*Event) *AlertCreate {
   369  	ids := make([]int, len(e))
   370  	for i := range e {
   371  		ids[i] = e[i].ID
   372  	}
   373  	return ac.AddEventIDs(ids...)
   374  }
   375  
   376  // AddMetaIDs adds the "metas" edge to the Meta entity by IDs.
   377  func (ac *AlertCreate) AddMetaIDs(ids ...int) *AlertCreate {
   378  	ac.mutation.AddMetaIDs(ids...)
   379  	return ac
   380  }
   381  
   382  // AddMetas adds the "metas" edges to the Meta entity.
   383  func (ac *AlertCreate) AddMetas(m ...*Meta) *AlertCreate {
   384  	ids := make([]int, len(m))
   385  	for i := range m {
   386  		ids[i] = m[i].ID
   387  	}
   388  	return ac.AddMetaIDs(ids...)
   389  }
   390  
   391  // Mutation returns the AlertMutation object of the builder.
   392  func (ac *AlertCreate) Mutation() *AlertMutation {
   393  	return ac.mutation
   394  }
   395  
   396  // Save creates the Alert in the database.
   397  func (ac *AlertCreate) Save(ctx context.Context) (*Alert, error) {
   398  	var (
   399  		err  error
   400  		node *Alert
   401  	)
   402  	ac.defaults()
   403  	if len(ac.hooks) == 0 {
   404  		if err = ac.check(); err != nil {
   405  			return nil, err
   406  		}
   407  		node, err = ac.sqlSave(ctx)
   408  	} else {
   409  		var mut Mutator = MutateFunc(func(ctx context.Context, m Mutation) (Value, error) {
   410  			mutation, ok := m.(*AlertMutation)
   411  			if !ok {
   412  				return nil, fmt.Errorf("unexpected mutation type %T", m)
   413  			}
   414  			if err = ac.check(); err != nil {
   415  				return nil, err
   416  			}
   417  			ac.mutation = mutation
   418  			node, err = ac.sqlSave(ctx)
   419  			mutation.done = true
   420  			return node, err
   421  		})
   422  		for i := len(ac.hooks) - 1; i >= 0; i-- {
   423  			mut = ac.hooks[i](mut)
   424  		}
   425  		if _, err := mut.Mutate(ctx, ac.mutation); err != nil {
   426  			return nil, err
   427  		}
   428  	}
   429  	return node, err
   430  }
   431  
   432  // SaveX calls Save and panics if Save returns an error.
   433  func (ac *AlertCreate) SaveX(ctx context.Context) *Alert {
   434  	v, err := ac.Save(ctx)
   435  	if err != nil {
   436  		panic(err)
   437  	}
   438  	return v
   439  }
   440  
   441  // defaults sets the default values of the builder before save.
   442  func (ac *AlertCreate) defaults() {
   443  	if _, ok := ac.mutation.CreatedAt(); !ok {
   444  		v := alert.DefaultCreatedAt()
   445  		ac.mutation.SetCreatedAt(v)
   446  	}
   447  	if _, ok := ac.mutation.UpdatedAt(); !ok {
   448  		v := alert.DefaultUpdatedAt()
   449  		ac.mutation.SetUpdatedAt(v)
   450  	}
   451  	if _, ok := ac.mutation.BucketId(); !ok {
   452  		v := alert.DefaultBucketId
   453  		ac.mutation.SetBucketId(v)
   454  	}
   455  	if _, ok := ac.mutation.Message(); !ok {
   456  		v := alert.DefaultMessage
   457  		ac.mutation.SetMessage(v)
   458  	}
   459  	if _, ok := ac.mutation.EventsCount(); !ok {
   460  		v := alert.DefaultEventsCount
   461  		ac.mutation.SetEventsCount(v)
   462  	}
   463  	if _, ok := ac.mutation.StartedAt(); !ok {
   464  		v := alert.DefaultStartedAt()
   465  		ac.mutation.SetStartedAt(v)
   466  	}
   467  	if _, ok := ac.mutation.StoppedAt(); !ok {
   468  		v := alert.DefaultStoppedAt()
   469  		ac.mutation.SetStoppedAt(v)
   470  	}
   471  	if _, ok := ac.mutation.Simulated(); !ok {
   472  		v := alert.DefaultSimulated
   473  		ac.mutation.SetSimulated(v)
   474  	}
   475  }
   476  
   477  // check runs all checks and user-defined validators on the builder.
   478  func (ac *AlertCreate) check() error {
   479  	if _, ok := ac.mutation.CreatedAt(); !ok {
   480  		return &ValidationError{Name: "created_at", err: errors.New("ent: missing required field \"created_at\"")}
   481  	}
   482  	if _, ok := ac.mutation.UpdatedAt(); !ok {
   483  		return &ValidationError{Name: "updated_at", err: errors.New("ent: missing required field \"updated_at\"")}
   484  	}
   485  	if _, ok := ac.mutation.Scenario(); !ok {
   486  		return &ValidationError{Name: "scenario", err: errors.New("ent: missing required field \"scenario\"")}
   487  	}
   488  	if _, ok := ac.mutation.Simulated(); !ok {
   489  		return &ValidationError{Name: "simulated", err: errors.New("ent: missing required field \"simulated\"")}
   490  	}
   491  	return nil
   492  }
   493  
   494  func (ac *AlertCreate) sqlSave(ctx context.Context) (*Alert, error) {
   495  	_node, _spec := ac.createSpec()
   496  	if err := sqlgraph.CreateNode(ctx, ac.driver, _spec); err != nil {
   497  		if cerr, ok := isSQLConstraintError(err); ok {
   498  			err = cerr
   499  		}
   500  		return nil, err
   501  	}
   502  	id := _spec.ID.Value.(int64)
   503  	_node.ID = int(id)
   504  	return _node, nil
   505  }
   506  
   507  func (ac *AlertCreate) createSpec() (*Alert, *sqlgraph.CreateSpec) {
   508  	var (
   509  		_node = &Alert{config: ac.config}
   510  		_spec = &sqlgraph.CreateSpec{
   511  			Table: alert.Table,
   512  			ID: &sqlgraph.FieldSpec{
   513  				Type:   field.TypeInt,
   514  				Column: alert.FieldID,
   515  			},
   516  		}
   517  	)
   518  	if value, ok := ac.mutation.CreatedAt(); ok {
   519  		_spec.Fields = append(_spec.Fields, &sqlgraph.FieldSpec{
   520  			Type:   field.TypeTime,
   521  			Value:  value,
   522  			Column: alert.FieldCreatedAt,
   523  		})
   524  		_node.CreatedAt = value
   525  	}
   526  	if value, ok := ac.mutation.UpdatedAt(); ok {
   527  		_spec.Fields = append(_spec.Fields, &sqlgraph.FieldSpec{
   528  			Type:   field.TypeTime,
   529  			Value:  value,
   530  			Column: alert.FieldUpdatedAt,
   531  		})
   532  		_node.UpdatedAt = value
   533  	}
   534  	if value, ok := ac.mutation.Scenario(); ok {
   535  		_spec.Fields = append(_spec.Fields, &sqlgraph.FieldSpec{
   536  			Type:   field.TypeString,
   537  			Value:  value,
   538  			Column: alert.FieldScenario,
   539  		})
   540  		_node.Scenario = value
   541  	}
   542  	if value, ok := ac.mutation.BucketId(); ok {
   543  		_spec.Fields = append(_spec.Fields, &sqlgraph.FieldSpec{
   544  			Type:   field.TypeString,
   545  			Value:  value,
   546  			Column: alert.FieldBucketId,
   547  		})
   548  		_node.BucketId = value
   549  	}
   550  	if value, ok := ac.mutation.Message(); ok {
   551  		_spec.Fields = append(_spec.Fields, &sqlgraph.FieldSpec{
   552  			Type:   field.TypeString,
   553  			Value:  value,
   554  			Column: alert.FieldMessage,
   555  		})
   556  		_node.Message = value
   557  	}
   558  	if value, ok := ac.mutation.EventsCount(); ok {
   559  		_spec.Fields = append(_spec.Fields, &sqlgraph.FieldSpec{
   560  			Type:   field.TypeInt32,
   561  			Value:  value,
   562  			Column: alert.FieldEventsCount,
   563  		})
   564  		_node.EventsCount = value
   565  	}
   566  	if value, ok := ac.mutation.StartedAt(); ok {
   567  		_spec.Fields = append(_spec.Fields, &sqlgraph.FieldSpec{
   568  			Type:   field.TypeTime,
   569  			Value:  value,
   570  			Column: alert.FieldStartedAt,
   571  		})
   572  		_node.StartedAt = value
   573  	}
   574  	if value, ok := ac.mutation.StoppedAt(); ok {
   575  		_spec.Fields = append(_spec.Fields, &sqlgraph.FieldSpec{
   576  			Type:   field.TypeTime,
   577  			Value:  value,
   578  			Column: alert.FieldStoppedAt,
   579  		})
   580  		_node.StoppedAt = value
   581  	}
   582  	if value, ok := ac.mutation.SourceIp(); ok {
   583  		_spec.Fields = append(_spec.Fields, &sqlgraph.FieldSpec{
   584  			Type:   field.TypeString,
   585  			Value:  value,
   586  			Column: alert.FieldSourceIp,
   587  		})
   588  		_node.SourceIp = value
   589  	}
   590  	if value, ok := ac.mutation.SourceRange(); ok {
   591  		_spec.Fields = append(_spec.Fields, &sqlgraph.FieldSpec{
   592  			Type:   field.TypeString,
   593  			Value:  value,
   594  			Column: alert.FieldSourceRange,
   595  		})
   596  		_node.SourceRange = value
   597  	}
   598  	if value, ok := ac.mutation.SourceAsNumber(); ok {
   599  		_spec.Fields = append(_spec.Fields, &sqlgraph.FieldSpec{
   600  			Type:   field.TypeString,
   601  			Value:  value,
   602  			Column: alert.FieldSourceAsNumber,
   603  		})
   604  		_node.SourceAsNumber = value
   605  	}
   606  	if value, ok := ac.mutation.SourceAsName(); ok {
   607  		_spec.Fields = append(_spec.Fields, &sqlgraph.FieldSpec{
   608  			Type:   field.TypeString,
   609  			Value:  value,
   610  			Column: alert.FieldSourceAsName,
   611  		})
   612  		_node.SourceAsName = value
   613  	}
   614  	if value, ok := ac.mutation.SourceCountry(); ok {
   615  		_spec.Fields = append(_spec.Fields, &sqlgraph.FieldSpec{
   616  			Type:   field.TypeString,
   617  			Value:  value,
   618  			Column: alert.FieldSourceCountry,
   619  		})
   620  		_node.SourceCountry = value
   621  	}
   622  	if value, ok := ac.mutation.SourceLatitude(); ok {
   623  		_spec.Fields = append(_spec.Fields, &sqlgraph.FieldSpec{
   624  			Type:   field.TypeFloat32,
   625  			Value:  value,
   626  			Column: alert.FieldSourceLatitude,
   627  		})
   628  		_node.SourceLatitude = value
   629  	}
   630  	if value, ok := ac.mutation.SourceLongitude(); ok {
   631  		_spec.Fields = append(_spec.Fields, &sqlgraph.FieldSpec{
   632  			Type:   field.TypeFloat32,
   633  			Value:  value,
   634  			Column: alert.FieldSourceLongitude,
   635  		})
   636  		_node.SourceLongitude = value
   637  	}
   638  	if value, ok := ac.mutation.SourceScope(); ok {
   639  		_spec.Fields = append(_spec.Fields, &sqlgraph.FieldSpec{
   640  			Type:   field.TypeString,
   641  			Value:  value,
   642  			Column: alert.FieldSourceScope,
   643  		})
   644  		_node.SourceScope = value
   645  	}
   646  	if value, ok := ac.mutation.SourceValue(); ok {
   647  		_spec.Fields = append(_spec.Fields, &sqlgraph.FieldSpec{
   648  			Type:   field.TypeString,
   649  			Value:  value,
   650  			Column: alert.FieldSourceValue,
   651  		})
   652  		_node.SourceValue = value
   653  	}
   654  	if value, ok := ac.mutation.Capacity(); ok {
   655  		_spec.Fields = append(_spec.Fields, &sqlgraph.FieldSpec{
   656  			Type:   field.TypeInt32,
   657  			Value:  value,
   658  			Column: alert.FieldCapacity,
   659  		})
   660  		_node.Capacity = value
   661  	}
   662  	if value, ok := ac.mutation.LeakSpeed(); ok {
   663  		_spec.Fields = append(_spec.Fields, &sqlgraph.FieldSpec{
   664  			Type:   field.TypeString,
   665  			Value:  value,
   666  			Column: alert.FieldLeakSpeed,
   667  		})
   668  		_node.LeakSpeed = value
   669  	}
   670  	if value, ok := ac.mutation.ScenarioVersion(); ok {
   671  		_spec.Fields = append(_spec.Fields, &sqlgraph.FieldSpec{
   672  			Type:   field.TypeString,
   673  			Value:  value,
   674  			Column: alert.FieldScenarioVersion,
   675  		})
   676  		_node.ScenarioVersion = value
   677  	}
   678  	if value, ok := ac.mutation.ScenarioHash(); ok {
   679  		_spec.Fields = append(_spec.Fields, &sqlgraph.FieldSpec{
   680  			Type:   field.TypeString,
   681  			Value:  value,
   682  			Column: alert.FieldScenarioHash,
   683  		})
   684  		_node.ScenarioHash = value
   685  	}
   686  	if value, ok := ac.mutation.Simulated(); ok {
   687  		_spec.Fields = append(_spec.Fields, &sqlgraph.FieldSpec{
   688  			Type:   field.TypeBool,
   689  			Value:  value,
   690  			Column: alert.FieldSimulated,
   691  		})
   692  		_node.Simulated = value
   693  	}
   694  	if nodes := ac.mutation.OwnerIDs(); len(nodes) > 0 {
   695  		edge := &sqlgraph.EdgeSpec{
   696  			Rel:     sqlgraph.M2O,
   697  			Inverse: true,
   698  			Table:   alert.OwnerTable,
   699  			Columns: []string{alert.OwnerColumn},
   700  			Bidi:    false,
   701  			Target: &sqlgraph.EdgeTarget{
   702  				IDSpec: &sqlgraph.FieldSpec{
   703  					Type:   field.TypeInt,
   704  					Column: machine.FieldID,
   705  				},
   706  			},
   707  		}
   708  		for _, k := range nodes {
   709  			edge.Target.Nodes = append(edge.Target.Nodes, k)
   710  		}
   711  		_node.machine_alerts = &nodes[0]
   712  		_spec.Edges = append(_spec.Edges, edge)
   713  	}
   714  	if nodes := ac.mutation.DecisionsIDs(); len(nodes) > 0 {
   715  		edge := &sqlgraph.EdgeSpec{
   716  			Rel:     sqlgraph.O2M,
   717  			Inverse: false,
   718  			Table:   alert.DecisionsTable,
   719  			Columns: []string{alert.DecisionsColumn},
   720  			Bidi:    false,
   721  			Target: &sqlgraph.EdgeTarget{
   722  				IDSpec: &sqlgraph.FieldSpec{
   723  					Type:   field.TypeInt,
   724  					Column: decision.FieldID,
   725  				},
   726  			},
   727  		}
   728  		for _, k := range nodes {
   729  			edge.Target.Nodes = append(edge.Target.Nodes, k)
   730  		}
   731  		_spec.Edges = append(_spec.Edges, edge)
   732  	}
   733  	if nodes := ac.mutation.EventsIDs(); len(nodes) > 0 {
   734  		edge := &sqlgraph.EdgeSpec{
   735  			Rel:     sqlgraph.O2M,
   736  			Inverse: false,
   737  			Table:   alert.EventsTable,
   738  			Columns: []string{alert.EventsColumn},
   739  			Bidi:    false,
   740  			Target: &sqlgraph.EdgeTarget{
   741  				IDSpec: &sqlgraph.FieldSpec{
   742  					Type:   field.TypeInt,
   743  					Column: event.FieldID,
   744  				},
   745  			},
   746  		}
   747  		for _, k := range nodes {
   748  			edge.Target.Nodes = append(edge.Target.Nodes, k)
   749  		}
   750  		_spec.Edges = append(_spec.Edges, edge)
   751  	}
   752  	if nodes := ac.mutation.MetasIDs(); len(nodes) > 0 {
   753  		edge := &sqlgraph.EdgeSpec{
   754  			Rel:     sqlgraph.O2M,
   755  			Inverse: false,
   756  			Table:   alert.MetasTable,
   757  			Columns: []string{alert.MetasColumn},
   758  			Bidi:    false,
   759  			Target: &sqlgraph.EdgeTarget{
   760  				IDSpec: &sqlgraph.FieldSpec{
   761  					Type:   field.TypeInt,
   762  					Column: meta.FieldID,
   763  				},
   764  			},
   765  		}
   766  		for _, k := range nodes {
   767  			edge.Target.Nodes = append(edge.Target.Nodes, k)
   768  		}
   769  		_spec.Edges = append(_spec.Edges, edge)
   770  	}
   771  	return _node, _spec
   772  }
   773  
   774  // AlertCreateBulk is the builder for creating many Alert entities in bulk.
   775  type AlertCreateBulk struct {
   776  	config
   777  	builders []*AlertCreate
   778  }
   779  
   780  // Save creates the Alert entities in the database.
   781  func (acb *AlertCreateBulk) Save(ctx context.Context) ([]*Alert, error) {
   782  	specs := make([]*sqlgraph.CreateSpec, len(acb.builders))
   783  	nodes := make([]*Alert, len(acb.builders))
   784  	mutators := make([]Mutator, len(acb.builders))
   785  	for i := range acb.builders {
   786  		func(i int, root context.Context) {
   787  			builder := acb.builders[i]
   788  			builder.defaults()
   789  			var mut Mutator = MutateFunc(func(ctx context.Context, m Mutation) (Value, error) {
   790  				mutation, ok := m.(*AlertMutation)
   791  				if !ok {
   792  					return nil, fmt.Errorf("unexpected mutation type %T", m)
   793  				}
   794  				if err := builder.check(); err != nil {
   795  					return nil, err
   796  				}
   797  				builder.mutation = mutation
   798  				nodes[i], specs[i] = builder.createSpec()
   799  				var err error
   800  				if i < len(mutators)-1 {
   801  					_, err = mutators[i+1].Mutate(root, acb.builders[i+1].mutation)
   802  				} else {
   803  					// Invoke the actual operation on the latest mutation in the chain.
   804  					if err = sqlgraph.BatchCreate(ctx, acb.driver, &sqlgraph.BatchCreateSpec{Nodes: specs}); err != nil {
   805  						if cerr, ok := isSQLConstraintError(err); ok {
   806  							err = cerr
   807  						}
   808  					}
   809  				}
   810  				mutation.done = true
   811  				if err != nil {
   812  					return nil, err
   813  				}
   814  				id := specs[i].ID.Value.(int64)
   815  				nodes[i].ID = int(id)
   816  				return nodes[i], nil
   817  			})
   818  			for i := len(builder.hooks) - 1; i >= 0; i-- {
   819  				mut = builder.hooks[i](mut)
   820  			}
   821  			mutators[i] = mut
   822  		}(i, ctx)
   823  	}
   824  	if len(mutators) > 0 {
   825  		if _, err := mutators[0].Mutate(ctx, acb.builders[0].mutation); err != nil {
   826  			return nil, err
   827  		}
   828  	}
   829  	return nodes, nil
   830  }
   831  
   832  // SaveX is like Save, but panics if an error occurs.
   833  func (acb *AlertCreateBulk) SaveX(ctx context.Context) []*Alert {
   834  	v, err := acb.Save(ctx)
   835  	if err != nil {
   836  		panic(err)
   837  	}
   838  	return v
   839  }