bitbucket.org/Aishee/synsec@v0.0.0-20210414005726-236fc01a153d/pkg/database/ent/decision.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/decision"
    13  )
    14  
    15  // Decision is the model entity for the Decision schema.
    16  type Decision 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  	// Until holds the value of the "until" field.
    25  	Until time.Time `json:"until,omitempty"`
    26  	// Scenario holds the value of the "scenario" field.
    27  	Scenario string `json:"scenario,omitempty"`
    28  	// Type holds the value of the "type" field.
    29  	Type string `json:"type,omitempty"`
    30  	// StartIP holds the value of the "start_ip" field.
    31  	StartIP int64 `json:"start_ip,omitempty"`
    32  	// EndIP holds the value of the "end_ip" field.
    33  	EndIP int64 `json:"end_ip,omitempty"`
    34  	// StartSuffix holds the value of the "start_suffix" field.
    35  	StartSuffix int64 `json:"start_suffix,omitempty"`
    36  	// EndSuffix holds the value of the "end_suffix" field.
    37  	EndSuffix int64 `json:"end_suffix,omitempty"`
    38  	// IPSize holds the value of the "ip_size" field.
    39  	IPSize int64 `json:"ip_size,omitempty"`
    40  	// Scope holds the value of the "scope" field.
    41  	Scope string `json:"scope,omitempty"`
    42  	// Value holds the value of the "value" field.
    43  	Value string `json:"value,omitempty"`
    44  	// Origin holds the value of the "origin" field.
    45  	Origin string `json:"origin,omitempty"`
    46  	// Simulated holds the value of the "simulated" field.
    47  	Simulated bool `json:"simulated,omitempty"`
    48  	// Edges holds the relations/edges for other nodes in the graph.
    49  	// The values are being populated by the DecisionQuery when eager-loading is set.
    50  	Edges           DecisionEdges `json:"edges"`
    51  	alert_decisions *int
    52  }
    53  
    54  // DecisionEdges holds the relations/edges for other nodes in the graph.
    55  type DecisionEdges struct {
    56  	// Owner holds the value of the owner edge.
    57  	Owner *Alert `json:"owner,omitempty"`
    58  	// loadedTypes holds the information for reporting if a
    59  	// type was loaded (or requested) in eager-loading or not.
    60  	loadedTypes [1]bool
    61  }
    62  
    63  // OwnerOrErr returns the Owner value or an error if the edge
    64  // was not loaded in eager-loading, or loaded but was not found.
    65  func (e DecisionEdges) OwnerOrErr() (*Alert, error) {
    66  	if e.loadedTypes[0] {
    67  		if e.Owner == nil {
    68  			// The edge owner was loaded in eager-loading,
    69  			// but was not found.
    70  			return nil, &NotFoundError{label: alert.Label}
    71  		}
    72  		return e.Owner, nil
    73  	}
    74  	return nil, &NotLoadedError{edge: "owner"}
    75  }
    76  
    77  // scanValues returns the types for scanning values from sql.Rows.
    78  func (*Decision) scanValues(columns []string) ([]interface{}, error) {
    79  	values := make([]interface{}, len(columns))
    80  	for i := range columns {
    81  		switch columns[i] {
    82  		case decision.FieldSimulated:
    83  			values[i] = &sql.NullBool{}
    84  		case decision.FieldID, decision.FieldStartIP, decision.FieldEndIP, decision.FieldStartSuffix, decision.FieldEndSuffix, decision.FieldIPSize:
    85  			values[i] = &sql.NullInt64{}
    86  		case decision.FieldScenario, decision.FieldType, decision.FieldScope, decision.FieldValue, decision.FieldOrigin:
    87  			values[i] = &sql.NullString{}
    88  		case decision.FieldCreatedAt, decision.FieldUpdatedAt, decision.FieldUntil:
    89  			values[i] = &sql.NullTime{}
    90  		case decision.ForeignKeys[0]: // alert_decisions
    91  			values[i] = &sql.NullInt64{}
    92  		default:
    93  			return nil, fmt.Errorf("unexpected column %q for type Decision", columns[i])
    94  		}
    95  	}
    96  	return values, nil
    97  }
    98  
    99  // assignValues assigns the values that were returned from sql.Rows (after scanning)
   100  // to the Decision fields.
   101  func (d *Decision) assignValues(columns []string, values []interface{}) error {
   102  	if m, n := len(values), len(columns); m < n {
   103  		return fmt.Errorf("mismatch number of scan values: %d != %d", m, n)
   104  	}
   105  	for i := range columns {
   106  		switch columns[i] {
   107  		case decision.FieldID:
   108  			value, ok := values[i].(*sql.NullInt64)
   109  			if !ok {
   110  				return fmt.Errorf("unexpected type %T for field id", value)
   111  			}
   112  			d.ID = int(value.Int64)
   113  		case decision.FieldCreatedAt:
   114  			if value, ok := values[i].(*sql.NullTime); !ok {
   115  				return fmt.Errorf("unexpected type %T for field created_at", values[i])
   116  			} else if value.Valid {
   117  				d.CreatedAt = value.Time
   118  			}
   119  		case decision.FieldUpdatedAt:
   120  			if value, ok := values[i].(*sql.NullTime); !ok {
   121  				return fmt.Errorf("unexpected type %T for field updated_at", values[i])
   122  			} else if value.Valid {
   123  				d.UpdatedAt = value.Time
   124  			}
   125  		case decision.FieldUntil:
   126  			if value, ok := values[i].(*sql.NullTime); !ok {
   127  				return fmt.Errorf("unexpected type %T for field until", values[i])
   128  			} else if value.Valid {
   129  				d.Until = value.Time
   130  			}
   131  		case decision.FieldScenario:
   132  			if value, ok := values[i].(*sql.NullString); !ok {
   133  				return fmt.Errorf("unexpected type %T for field scenario", values[i])
   134  			} else if value.Valid {
   135  				d.Scenario = value.String
   136  			}
   137  		case decision.FieldType:
   138  			if value, ok := values[i].(*sql.NullString); !ok {
   139  				return fmt.Errorf("unexpected type %T for field type", values[i])
   140  			} else if value.Valid {
   141  				d.Type = value.String
   142  			}
   143  		case decision.FieldStartIP:
   144  			if value, ok := values[i].(*sql.NullInt64); !ok {
   145  				return fmt.Errorf("unexpected type %T for field start_ip", values[i])
   146  			} else if value.Valid {
   147  				d.StartIP = value.Int64
   148  			}
   149  		case decision.FieldEndIP:
   150  			if value, ok := values[i].(*sql.NullInt64); !ok {
   151  				return fmt.Errorf("unexpected type %T for field end_ip", values[i])
   152  			} else if value.Valid {
   153  				d.EndIP = value.Int64
   154  			}
   155  		case decision.FieldStartSuffix:
   156  			if value, ok := values[i].(*sql.NullInt64); !ok {
   157  				return fmt.Errorf("unexpected type %T for field start_suffix", values[i])
   158  			} else if value.Valid {
   159  				d.StartSuffix = value.Int64
   160  			}
   161  		case decision.FieldEndSuffix:
   162  			if value, ok := values[i].(*sql.NullInt64); !ok {
   163  				return fmt.Errorf("unexpected type %T for field end_suffix", values[i])
   164  			} else if value.Valid {
   165  				d.EndSuffix = value.Int64
   166  			}
   167  		case decision.FieldIPSize:
   168  			if value, ok := values[i].(*sql.NullInt64); !ok {
   169  				return fmt.Errorf("unexpected type %T for field ip_size", values[i])
   170  			} else if value.Valid {
   171  				d.IPSize = value.Int64
   172  			}
   173  		case decision.FieldScope:
   174  			if value, ok := values[i].(*sql.NullString); !ok {
   175  				return fmt.Errorf("unexpected type %T for field scope", values[i])
   176  			} else if value.Valid {
   177  				d.Scope = value.String
   178  			}
   179  		case decision.FieldValue:
   180  			if value, ok := values[i].(*sql.NullString); !ok {
   181  				return fmt.Errorf("unexpected type %T for field value", values[i])
   182  			} else if value.Valid {
   183  				d.Value = value.String
   184  			}
   185  		case decision.FieldOrigin:
   186  			if value, ok := values[i].(*sql.NullString); !ok {
   187  				return fmt.Errorf("unexpected type %T for field origin", values[i])
   188  			} else if value.Valid {
   189  				d.Origin = value.String
   190  			}
   191  		case decision.FieldSimulated:
   192  			if value, ok := values[i].(*sql.NullBool); !ok {
   193  				return fmt.Errorf("unexpected type %T for field simulated", values[i])
   194  			} else if value.Valid {
   195  				d.Simulated = value.Bool
   196  			}
   197  		case decision.ForeignKeys[0]:
   198  			if value, ok := values[i].(*sql.NullInt64); !ok {
   199  				return fmt.Errorf("unexpected type %T for edge-field alert_decisions", value)
   200  			} else if value.Valid {
   201  				d.alert_decisions = new(int)
   202  				*d.alert_decisions = int(value.Int64)
   203  			}
   204  		}
   205  	}
   206  	return nil
   207  }
   208  
   209  // QueryOwner queries the "owner" edge of the Decision entity.
   210  func (d *Decision) QueryOwner() *AlertQuery {
   211  	return (&DecisionClient{config: d.config}).QueryOwner(d)
   212  }
   213  
   214  // Update returns a builder for updating this Decision.
   215  // Note that you need to call Decision.Unwrap() before calling this method if this Decision
   216  // was returned from a transaction, and the transaction was committed or rolled back.
   217  func (d *Decision) Update() *DecisionUpdateOne {
   218  	return (&DecisionClient{config: d.config}).UpdateOne(d)
   219  }
   220  
   221  // Unwrap unwraps the Decision entity that was returned from a transaction after it was closed,
   222  // so that all future queries will be executed through the driver which created the transaction.
   223  func (d *Decision) Unwrap() *Decision {
   224  	tx, ok := d.config.driver.(*txDriver)
   225  	if !ok {
   226  		panic("ent: Decision is not a transactional entity")
   227  	}
   228  	d.config.driver = tx.drv
   229  	return d
   230  }
   231  
   232  // String implements the fmt.Stringer.
   233  func (d *Decision) String() string {
   234  	var builder strings.Builder
   235  	builder.WriteString("Decision(")
   236  	builder.WriteString(fmt.Sprintf("id=%v", d.ID))
   237  	builder.WriteString(", created_at=")
   238  	builder.WriteString(d.CreatedAt.Format(time.ANSIC))
   239  	builder.WriteString(", updated_at=")
   240  	builder.WriteString(d.UpdatedAt.Format(time.ANSIC))
   241  	builder.WriteString(", until=")
   242  	builder.WriteString(d.Until.Format(time.ANSIC))
   243  	builder.WriteString(", scenario=")
   244  	builder.WriteString(d.Scenario)
   245  	builder.WriteString(", type=")
   246  	builder.WriteString(d.Type)
   247  	builder.WriteString(", start_ip=")
   248  	builder.WriteString(fmt.Sprintf("%v", d.StartIP))
   249  	builder.WriteString(", end_ip=")
   250  	builder.WriteString(fmt.Sprintf("%v", d.EndIP))
   251  	builder.WriteString(", start_suffix=")
   252  	builder.WriteString(fmt.Sprintf("%v", d.StartSuffix))
   253  	builder.WriteString(", end_suffix=")
   254  	builder.WriteString(fmt.Sprintf("%v", d.EndSuffix))
   255  	builder.WriteString(", ip_size=")
   256  	builder.WriteString(fmt.Sprintf("%v", d.IPSize))
   257  	builder.WriteString(", scope=")
   258  	builder.WriteString(d.Scope)
   259  	builder.WriteString(", value=")
   260  	builder.WriteString(d.Value)
   261  	builder.WriteString(", origin=")
   262  	builder.WriteString(d.Origin)
   263  	builder.WriteString(", simulated=")
   264  	builder.WriteString(fmt.Sprintf("%v", d.Simulated))
   265  	builder.WriteByte(')')
   266  	return builder.String()
   267  }
   268  
   269  // Decisions is a parsable slice of Decision.
   270  type Decisions []*Decision
   271  
   272  func (d Decisions) config(cfg config) {
   273  	for _i := range d {
   274  		d[_i].config = cfg
   275  	}
   276  }