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

     1  // Code generated by entc, DO NOT EDIT.
     2  
     3  package ent
     4  
     5  import (
     6  	"fmt"
     7  	"strings"
     8  	"time"
     9  
    10  	"entgo.io/ent/dialect/sql"
    11  	"bitbucket.org/Aishee/synsec/pkg/database/ent/alert"
    12  	"bitbucket.org/Aishee/synsec/pkg/database/ent/machine"
    13  )
    14  
    15  // Alert is the model entity for the Alert schema.
    16  type Alert struct {
    17  	config `json:"-"`
    18  	// ID of the ent.
    19  	ID int `json:"id,omitempty"`
    20  	// CreatedAt holds the value of the "created_at" field.
    21  	CreatedAt time.Time `json:"created_at,omitempty"`
    22  	// UpdatedAt holds the value of the "updated_at" field.
    23  	UpdatedAt time.Time `json:"updated_at,omitempty"`
    24  	// Scenario holds the value of the "scenario" field.
    25  	Scenario string `json:"scenario,omitempty"`
    26  	// BucketId holds the value of the "bucketId" field.
    27  	BucketId string `json:"bucketId,omitempty"`
    28  	// Message holds the value of the "message" field.
    29  	Message string `json:"message,omitempty"`
    30  	// EventsCount holds the value of the "eventsCount" field.
    31  	EventsCount int32 `json:"eventsCount,omitempty"`
    32  	// StartedAt holds the value of the "startedAt" field.
    33  	StartedAt time.Time `json:"startedAt,omitempty"`
    34  	// StoppedAt holds the value of the "stoppedAt" field.
    35  	StoppedAt time.Time `json:"stoppedAt,omitempty"`
    36  	// SourceIp holds the value of the "sourceIp" field.
    37  	SourceIp string `json:"sourceIp,omitempty"`
    38  	// SourceRange holds the value of the "sourceRange" field.
    39  	SourceRange string `json:"sourceRange,omitempty"`
    40  	// SourceAsNumber holds the value of the "sourceAsNumber" field.
    41  	SourceAsNumber string `json:"sourceAsNumber,omitempty"`
    42  	// SourceAsName holds the value of the "sourceAsName" field.
    43  	SourceAsName string `json:"sourceAsName,omitempty"`
    44  	// SourceCountry holds the value of the "sourceCountry" field.
    45  	SourceCountry string `json:"sourceCountry,omitempty"`
    46  	// SourceLatitude holds the value of the "sourceLatitude" field.
    47  	SourceLatitude float32 `json:"sourceLatitude,omitempty"`
    48  	// SourceLongitude holds the value of the "sourceLongitude" field.
    49  	SourceLongitude float32 `json:"sourceLongitude,omitempty"`
    50  	// SourceScope holds the value of the "sourceScope" field.
    51  	SourceScope string `json:"sourceScope,omitempty"`
    52  	// SourceValue holds the value of the "sourceValue" field.
    53  	SourceValue string `json:"sourceValue,omitempty"`
    54  	// Capacity holds the value of the "capacity" field.
    55  	Capacity int32 `json:"capacity,omitempty"`
    56  	// LeakSpeed holds the value of the "leakSpeed" field.
    57  	LeakSpeed string `json:"leakSpeed,omitempty"`
    58  	// ScenarioVersion holds the value of the "scenarioVersion" field.
    59  	ScenarioVersion string `json:"scenarioVersion,omitempty"`
    60  	// ScenarioHash holds the value of the "scenarioHash" field.
    61  	ScenarioHash string `json:"scenarioHash,omitempty"`
    62  	// Simulated holds the value of the "simulated" field.
    63  	Simulated bool `json:"simulated,omitempty"`
    64  	// Edges holds the relations/edges for other nodes in the graph.
    65  	// The values are being populated by the AlertQuery when eager-loading is set.
    66  	Edges          AlertEdges `json:"edges"`
    67  	machine_alerts *int
    68  }
    69  
    70  // AlertEdges holds the relations/edges for other nodes in the graph.
    71  type AlertEdges struct {
    72  	// Owner holds the value of the owner edge.
    73  	Owner *Machine `json:"owner,omitempty"`
    74  	// Decisions holds the value of the decisions edge.
    75  	Decisions []*Decision `json:"decisions,omitempty"`
    76  	// Events holds the value of the events edge.
    77  	Events []*Event `json:"events,omitempty"`
    78  	// Metas holds the value of the metas edge.
    79  	Metas []*Meta `json:"metas,omitempty"`
    80  	// loadedTypes holds the information for reporting if a
    81  	// type was loaded (or requested) in eager-loading or not.
    82  	loadedTypes [4]bool
    83  }
    84  
    85  // OwnerOrErr returns the Owner value or an error if the edge
    86  // was not loaded in eager-loading, or loaded but was not found.
    87  func (e AlertEdges) OwnerOrErr() (*Machine, error) {
    88  	if e.loadedTypes[0] {
    89  		if e.Owner == nil {
    90  			// The edge owner was loaded in eager-loading,
    91  			// but was not found.
    92  			return nil, &NotFoundError{label: machine.Label}
    93  		}
    94  		return e.Owner, nil
    95  	}
    96  	return nil, &NotLoadedError{edge: "owner"}
    97  }
    98  
    99  // DecisionsOrErr returns the Decisions value or an error if the edge
   100  // was not loaded in eager-loading.
   101  func (e AlertEdges) DecisionsOrErr() ([]*Decision, error) {
   102  	if e.loadedTypes[1] {
   103  		return e.Decisions, nil
   104  	}
   105  	return nil, &NotLoadedError{edge: "decisions"}
   106  }
   107  
   108  // EventsOrErr returns the Events value or an error if the edge
   109  // was not loaded in eager-loading.
   110  func (e AlertEdges) EventsOrErr() ([]*Event, error) {
   111  	if e.loadedTypes[2] {
   112  		return e.Events, nil
   113  	}
   114  	return nil, &NotLoadedError{edge: "events"}
   115  }
   116  
   117  // MetasOrErr returns the Metas value or an error if the edge
   118  // was not loaded in eager-loading.
   119  func (e AlertEdges) MetasOrErr() ([]*Meta, error) {
   120  	if e.loadedTypes[3] {
   121  		return e.Metas, nil
   122  	}
   123  	return nil, &NotLoadedError{edge: "metas"}
   124  }
   125  
   126  // scanValues returns the types for scanning values from sql.Rows.
   127  func (*Alert) scanValues(columns []string) ([]interface{}, error) {
   128  	values := make([]interface{}, len(columns))
   129  	for i := range columns {
   130  		switch columns[i] {
   131  		case alert.FieldSimulated:
   132  			values[i] = &sql.NullBool{}
   133  		case alert.FieldSourceLatitude, alert.FieldSourceLongitude:
   134  			values[i] = &sql.NullFloat64{}
   135  		case alert.FieldID, alert.FieldEventsCount, alert.FieldCapacity:
   136  			values[i] = &sql.NullInt64{}
   137  		case alert.FieldScenario, alert.FieldBucketId, alert.FieldMessage, alert.FieldSourceIp, alert.FieldSourceRange, alert.FieldSourceAsNumber, alert.FieldSourceAsName, alert.FieldSourceCountry, alert.FieldSourceScope, alert.FieldSourceValue, alert.FieldLeakSpeed, alert.FieldScenarioVersion, alert.FieldScenarioHash:
   138  			values[i] = &sql.NullString{}
   139  		case alert.FieldCreatedAt, alert.FieldUpdatedAt, alert.FieldStartedAt, alert.FieldStoppedAt:
   140  			values[i] = &sql.NullTime{}
   141  		case alert.ForeignKeys[0]: // machine_alerts
   142  			values[i] = &sql.NullInt64{}
   143  		default:
   144  			return nil, fmt.Errorf("unexpected column %q for type Alert", columns[i])
   145  		}
   146  	}
   147  	return values, nil
   148  }
   149  
   150  // assignValues assigns the values that were returned from sql.Rows (after scanning)
   151  // to the Alert fields.
   152  func (a *Alert) assignValues(columns []string, values []interface{}) error {
   153  	if m, n := len(values), len(columns); m < n {
   154  		return fmt.Errorf("mismatch number of scan values: %d != %d", m, n)
   155  	}
   156  	for i := range columns {
   157  		switch columns[i] {
   158  		case alert.FieldID:
   159  			value, ok := values[i].(*sql.NullInt64)
   160  			if !ok {
   161  				return fmt.Errorf("unexpected type %T for field id", value)
   162  			}
   163  			a.ID = int(value.Int64)
   164  		case alert.FieldCreatedAt:
   165  			if value, ok := values[i].(*sql.NullTime); !ok {
   166  				return fmt.Errorf("unexpected type %T for field created_at", values[i])
   167  			} else if value.Valid {
   168  				a.CreatedAt = value.Time
   169  			}
   170  		case alert.FieldUpdatedAt:
   171  			if value, ok := values[i].(*sql.NullTime); !ok {
   172  				return fmt.Errorf("unexpected type %T for field updated_at", values[i])
   173  			} else if value.Valid {
   174  				a.UpdatedAt = value.Time
   175  			}
   176  		case alert.FieldScenario:
   177  			if value, ok := values[i].(*sql.NullString); !ok {
   178  				return fmt.Errorf("unexpected type %T for field scenario", values[i])
   179  			} else if value.Valid {
   180  				a.Scenario = value.String
   181  			}
   182  		case alert.FieldBucketId:
   183  			if value, ok := values[i].(*sql.NullString); !ok {
   184  				return fmt.Errorf("unexpected type %T for field bucketId", values[i])
   185  			} else if value.Valid {
   186  				a.BucketId = value.String
   187  			}
   188  		case alert.FieldMessage:
   189  			if value, ok := values[i].(*sql.NullString); !ok {
   190  				return fmt.Errorf("unexpected type %T for field message", values[i])
   191  			} else if value.Valid {
   192  				a.Message = value.String
   193  			}
   194  		case alert.FieldEventsCount:
   195  			if value, ok := values[i].(*sql.NullInt64); !ok {
   196  				return fmt.Errorf("unexpected type %T for field eventsCount", values[i])
   197  			} else if value.Valid {
   198  				a.EventsCount = int32(value.Int64)
   199  			}
   200  		case alert.FieldStartedAt:
   201  			if value, ok := values[i].(*sql.NullTime); !ok {
   202  				return fmt.Errorf("unexpected type %T for field startedAt", values[i])
   203  			} else if value.Valid {
   204  				a.StartedAt = value.Time
   205  			}
   206  		case alert.FieldStoppedAt:
   207  			if value, ok := values[i].(*sql.NullTime); !ok {
   208  				return fmt.Errorf("unexpected type %T for field stoppedAt", values[i])
   209  			} else if value.Valid {
   210  				a.StoppedAt = value.Time
   211  			}
   212  		case alert.FieldSourceIp:
   213  			if value, ok := values[i].(*sql.NullString); !ok {
   214  				return fmt.Errorf("unexpected type %T for field sourceIp", values[i])
   215  			} else if value.Valid {
   216  				a.SourceIp = value.String
   217  			}
   218  		case alert.FieldSourceRange:
   219  			if value, ok := values[i].(*sql.NullString); !ok {
   220  				return fmt.Errorf("unexpected type %T for field sourceRange", values[i])
   221  			} else if value.Valid {
   222  				a.SourceRange = value.String
   223  			}
   224  		case alert.FieldSourceAsNumber:
   225  			if value, ok := values[i].(*sql.NullString); !ok {
   226  				return fmt.Errorf("unexpected type %T for field sourceAsNumber", values[i])
   227  			} else if value.Valid {
   228  				a.SourceAsNumber = value.String
   229  			}
   230  		case alert.FieldSourceAsName:
   231  			if value, ok := values[i].(*sql.NullString); !ok {
   232  				return fmt.Errorf("unexpected type %T for field sourceAsName", values[i])
   233  			} else if value.Valid {
   234  				a.SourceAsName = value.String
   235  			}
   236  		case alert.FieldSourceCountry:
   237  			if value, ok := values[i].(*sql.NullString); !ok {
   238  				return fmt.Errorf("unexpected type %T for field sourceCountry", values[i])
   239  			} else if value.Valid {
   240  				a.SourceCountry = value.String
   241  			}
   242  		case alert.FieldSourceLatitude:
   243  			if value, ok := values[i].(*sql.NullFloat64); !ok {
   244  				return fmt.Errorf("unexpected type %T for field sourceLatitude", values[i])
   245  			} else if value.Valid {
   246  				a.SourceLatitude = float32(value.Float64)
   247  			}
   248  		case alert.FieldSourceLongitude:
   249  			if value, ok := values[i].(*sql.NullFloat64); !ok {
   250  				return fmt.Errorf("unexpected type %T for field sourceLongitude", values[i])
   251  			} else if value.Valid {
   252  				a.SourceLongitude = float32(value.Float64)
   253  			}
   254  		case alert.FieldSourceScope:
   255  			if value, ok := values[i].(*sql.NullString); !ok {
   256  				return fmt.Errorf("unexpected type %T for field sourceScope", values[i])
   257  			} else if value.Valid {
   258  				a.SourceScope = value.String
   259  			}
   260  		case alert.FieldSourceValue:
   261  			if value, ok := values[i].(*sql.NullString); !ok {
   262  				return fmt.Errorf("unexpected type %T for field sourceValue", values[i])
   263  			} else if value.Valid {
   264  				a.SourceValue = value.String
   265  			}
   266  		case alert.FieldCapacity:
   267  			if value, ok := values[i].(*sql.NullInt64); !ok {
   268  				return fmt.Errorf("unexpected type %T for field capacity", values[i])
   269  			} else if value.Valid {
   270  				a.Capacity = int32(value.Int64)
   271  			}
   272  		case alert.FieldLeakSpeed:
   273  			if value, ok := values[i].(*sql.NullString); !ok {
   274  				return fmt.Errorf("unexpected type %T for field leakSpeed", values[i])
   275  			} else if value.Valid {
   276  				a.LeakSpeed = value.String
   277  			}
   278  		case alert.FieldScenarioVersion:
   279  			if value, ok := values[i].(*sql.NullString); !ok {
   280  				return fmt.Errorf("unexpected type %T for field scenarioVersion", values[i])
   281  			} else if value.Valid {
   282  				a.ScenarioVersion = value.String
   283  			}
   284  		case alert.FieldScenarioHash:
   285  			if value, ok := values[i].(*sql.NullString); !ok {
   286  				return fmt.Errorf("unexpected type %T for field scenarioHash", values[i])
   287  			} else if value.Valid {
   288  				a.ScenarioHash = value.String
   289  			}
   290  		case alert.FieldSimulated:
   291  			if value, ok := values[i].(*sql.NullBool); !ok {
   292  				return fmt.Errorf("unexpected type %T for field simulated", values[i])
   293  			} else if value.Valid {
   294  				a.Simulated = value.Bool
   295  			}
   296  		case alert.ForeignKeys[0]:
   297  			if value, ok := values[i].(*sql.NullInt64); !ok {
   298  				return fmt.Errorf("unexpected type %T for edge-field machine_alerts", value)
   299  			} else if value.Valid {
   300  				a.machine_alerts = new(int)
   301  				*a.machine_alerts = int(value.Int64)
   302  			}
   303  		}
   304  	}
   305  	return nil
   306  }
   307  
   308  // QueryOwner queries the "owner" edge of the Alert entity.
   309  func (a *Alert) QueryOwner() *MachineQuery {
   310  	return (&AlertClient{config: a.config}).QueryOwner(a)
   311  }
   312  
   313  // QueryDecisions queries the "decisions" edge of the Alert entity.
   314  func (a *Alert) QueryDecisions() *DecisionQuery {
   315  	return (&AlertClient{config: a.config}).QueryDecisions(a)
   316  }
   317  
   318  // QueryEvents queries the "events" edge of the Alert entity.
   319  func (a *Alert) QueryEvents() *EventQuery {
   320  	return (&AlertClient{config: a.config}).QueryEvents(a)
   321  }
   322  
   323  // QueryMetas queries the "metas" edge of the Alert entity.
   324  func (a *Alert) QueryMetas() *MetaQuery {
   325  	return (&AlertClient{config: a.config}).QueryMetas(a)
   326  }
   327  
   328  // Update returns a builder for updating this Alert.
   329  // Note that you need to call Alert.Unwrap() before calling this method if this Alert
   330  // was returned from a transaction, and the transaction was committed or rolled back.
   331  func (a *Alert) Update() *AlertUpdateOne {
   332  	return (&AlertClient{config: a.config}).UpdateOne(a)
   333  }
   334  
   335  // Unwrap unwraps the Alert entity that was returned from a transaction after it was closed,
   336  // so that all future queries will be executed through the driver which created the transaction.
   337  func (a *Alert) Unwrap() *Alert {
   338  	tx, ok := a.config.driver.(*txDriver)
   339  	if !ok {
   340  		panic("ent: Alert is not a transactional entity")
   341  	}
   342  	a.config.driver = tx.drv
   343  	return a
   344  }
   345  
   346  // String implements the fmt.Stringer.
   347  func (a *Alert) String() string {
   348  	var builder strings.Builder
   349  	builder.WriteString("Alert(")
   350  	builder.WriteString(fmt.Sprintf("id=%v", a.ID))
   351  	builder.WriteString(", created_at=")
   352  	builder.WriteString(a.CreatedAt.Format(time.ANSIC))
   353  	builder.WriteString(", updated_at=")
   354  	builder.WriteString(a.UpdatedAt.Format(time.ANSIC))
   355  	builder.WriteString(", scenario=")
   356  	builder.WriteString(a.Scenario)
   357  	builder.WriteString(", bucketId=")
   358  	builder.WriteString(a.BucketId)
   359  	builder.WriteString(", message=")
   360  	builder.WriteString(a.Message)
   361  	builder.WriteString(", eventsCount=")
   362  	builder.WriteString(fmt.Sprintf("%v", a.EventsCount))
   363  	builder.WriteString(", startedAt=")
   364  	builder.WriteString(a.StartedAt.Format(time.ANSIC))
   365  	builder.WriteString(", stoppedAt=")
   366  	builder.WriteString(a.StoppedAt.Format(time.ANSIC))
   367  	builder.WriteString(", sourceIp=")
   368  	builder.WriteString(a.SourceIp)
   369  	builder.WriteString(", sourceRange=")
   370  	builder.WriteString(a.SourceRange)
   371  	builder.WriteString(", sourceAsNumber=")
   372  	builder.WriteString(a.SourceAsNumber)
   373  	builder.WriteString(", sourceAsName=")
   374  	builder.WriteString(a.SourceAsName)
   375  	builder.WriteString(", sourceCountry=")
   376  	builder.WriteString(a.SourceCountry)
   377  	builder.WriteString(", sourceLatitude=")
   378  	builder.WriteString(fmt.Sprintf("%v", a.SourceLatitude))
   379  	builder.WriteString(", sourceLongitude=")
   380  	builder.WriteString(fmt.Sprintf("%v", a.SourceLongitude))
   381  	builder.WriteString(", sourceScope=")
   382  	builder.WriteString(a.SourceScope)
   383  	builder.WriteString(", sourceValue=")
   384  	builder.WriteString(a.SourceValue)
   385  	builder.WriteString(", capacity=")
   386  	builder.WriteString(fmt.Sprintf("%v", a.Capacity))
   387  	builder.WriteString(", leakSpeed=")
   388  	builder.WriteString(a.LeakSpeed)
   389  	builder.WriteString(", scenarioVersion=")
   390  	builder.WriteString(a.ScenarioVersion)
   391  	builder.WriteString(", scenarioHash=")
   392  	builder.WriteString(a.ScenarioHash)
   393  	builder.WriteString(", simulated=")
   394  	builder.WriteString(fmt.Sprintf("%v", a.Simulated))
   395  	builder.WriteByte(')')
   396  	return builder.String()
   397  }
   398  
   399  // Alerts is a parsable slice of Alert.
   400  type Alerts []*Alert
   401  
   402  func (a Alerts) config(cfg config) {
   403  	for _i := range a {
   404  		a[_i].config = cfg
   405  	}
   406  }