bitbucket.org/Aishee/synsec@v0.0.0-20210414005726-236fc01a153d/pkg/database/ent/machine.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/machine" 12 ) 13 14 // Machine is the model entity for the Machine schema. 15 type Machine struct { 16 config `json:"-"` 17 // ID of the ent. 18 ID int `json:"id,omitempty"` 19 // CreatedAt holds the value of the "created_at" field. 20 CreatedAt time.Time `json:"created_at,omitempty"` 21 // UpdatedAt holds the value of the "updated_at" field. 22 UpdatedAt time.Time `json:"updated_at,omitempty"` 23 // MachineId holds the value of the "machineId" field. 24 MachineId string `json:"machineId,omitempty"` 25 // Password holds the value of the "password" field. 26 Password string `json:"-"` 27 // IpAddress holds the value of the "ipAddress" field. 28 IpAddress string `json:"ipAddress,omitempty"` 29 // Scenarios holds the value of the "scenarios" field. 30 Scenarios string `json:"scenarios,omitempty"` 31 // Version holds the value of the "version" field. 32 Version string `json:"version,omitempty"` 33 // IsValidated holds the value of the "isValidated" field. 34 IsValidated bool `json:"isValidated,omitempty"` 35 // Status holds the value of the "status" field. 36 Status string `json:"status,omitempty"` 37 // Edges holds the relations/edges for other nodes in the graph. 38 // The values are being populated by the MachineQuery when eager-loading is set. 39 Edges MachineEdges `json:"edges"` 40 } 41 42 // MachineEdges holds the relations/edges for other nodes in the graph. 43 type MachineEdges struct { 44 // Alerts holds the value of the alerts edge. 45 Alerts []*Alert `json:"alerts,omitempty"` 46 // loadedTypes holds the information for reporting if a 47 // type was loaded (or requested) in eager-loading or not. 48 loadedTypes [1]bool 49 } 50 51 // AlertsOrErr returns the Alerts value or an error if the edge 52 // was not loaded in eager-loading. 53 func (e MachineEdges) AlertsOrErr() ([]*Alert, error) { 54 if e.loadedTypes[0] { 55 return e.Alerts, nil 56 } 57 return nil, &NotLoadedError{edge: "alerts"} 58 } 59 60 // scanValues returns the types for scanning values from sql.Rows. 61 func (*Machine) scanValues(columns []string) ([]interface{}, error) { 62 values := make([]interface{}, len(columns)) 63 for i := range columns { 64 switch columns[i] { 65 case machine.FieldIsValidated: 66 values[i] = &sql.NullBool{} 67 case machine.FieldID: 68 values[i] = &sql.NullInt64{} 69 case machine.FieldMachineId, machine.FieldPassword, machine.FieldIpAddress, machine.FieldScenarios, machine.FieldVersion, machine.FieldStatus: 70 values[i] = &sql.NullString{} 71 case machine.FieldCreatedAt, machine.FieldUpdatedAt: 72 values[i] = &sql.NullTime{} 73 default: 74 return nil, fmt.Errorf("unexpected column %q for type Machine", columns[i]) 75 } 76 } 77 return values, nil 78 } 79 80 // assignValues assigns the values that were returned from sql.Rows (after scanning) 81 // to the Machine fields. 82 func (m *Machine) assignValues(columns []string, values []interface{}) error { 83 if m, n := len(values), len(columns); m < n { 84 return fmt.Errorf("mismatch number of scan values: %d != %d", m, n) 85 } 86 for i := range columns { 87 switch columns[i] { 88 case machine.FieldID: 89 value, ok := values[i].(*sql.NullInt64) 90 if !ok { 91 return fmt.Errorf("unexpected type %T for field id", value) 92 } 93 m.ID = int(value.Int64) 94 case machine.FieldCreatedAt: 95 if value, ok := values[i].(*sql.NullTime); !ok { 96 return fmt.Errorf("unexpected type %T for field created_at", values[i]) 97 } else if value.Valid { 98 m.CreatedAt = value.Time 99 } 100 case machine.FieldUpdatedAt: 101 if value, ok := values[i].(*sql.NullTime); !ok { 102 return fmt.Errorf("unexpected type %T for field updated_at", values[i]) 103 } else if value.Valid { 104 m.UpdatedAt = value.Time 105 } 106 case machine.FieldMachineId: 107 if value, ok := values[i].(*sql.NullString); !ok { 108 return fmt.Errorf("unexpected type %T for field machineId", values[i]) 109 } else if value.Valid { 110 m.MachineId = value.String 111 } 112 case machine.FieldPassword: 113 if value, ok := values[i].(*sql.NullString); !ok { 114 return fmt.Errorf("unexpected type %T for field password", values[i]) 115 } else if value.Valid { 116 m.Password = value.String 117 } 118 case machine.FieldIpAddress: 119 if value, ok := values[i].(*sql.NullString); !ok { 120 return fmt.Errorf("unexpected type %T for field ipAddress", values[i]) 121 } else if value.Valid { 122 m.IpAddress = value.String 123 } 124 case machine.FieldScenarios: 125 if value, ok := values[i].(*sql.NullString); !ok { 126 return fmt.Errorf("unexpected type %T for field scenarios", values[i]) 127 } else if value.Valid { 128 m.Scenarios = value.String 129 } 130 case machine.FieldVersion: 131 if value, ok := values[i].(*sql.NullString); !ok { 132 return fmt.Errorf("unexpected type %T for field version", values[i]) 133 } else if value.Valid { 134 m.Version = value.String 135 } 136 case machine.FieldIsValidated: 137 if value, ok := values[i].(*sql.NullBool); !ok { 138 return fmt.Errorf("unexpected type %T for field isValidated", values[i]) 139 } else if value.Valid { 140 m.IsValidated = value.Bool 141 } 142 case machine.FieldStatus: 143 if value, ok := values[i].(*sql.NullString); !ok { 144 return fmt.Errorf("unexpected type %T for field status", values[i]) 145 } else if value.Valid { 146 m.Status = value.String 147 } 148 } 149 } 150 return nil 151 } 152 153 // QueryAlerts queries the "alerts" edge of the Machine entity. 154 func (m *Machine) QueryAlerts() *AlertQuery { 155 return (&MachineClient{config: m.config}).QueryAlerts(m) 156 } 157 158 // Update returns a builder for updating this Machine. 159 // Note that you need to call Machine.Unwrap() before calling this method if this Machine 160 // was returned from a transaction, and the transaction was committed or rolled back. 161 func (m *Machine) Update() *MachineUpdateOne { 162 return (&MachineClient{config: m.config}).UpdateOne(m) 163 } 164 165 // Unwrap unwraps the Machine entity that was returned from a transaction after it was closed, 166 // so that all future queries will be executed through the driver which created the transaction. 167 func (m *Machine) Unwrap() *Machine { 168 tx, ok := m.config.driver.(*txDriver) 169 if !ok { 170 panic("ent: Machine is not a transactional entity") 171 } 172 m.config.driver = tx.drv 173 return m 174 } 175 176 // String implements the fmt.Stringer. 177 func (m *Machine) String() string { 178 var builder strings.Builder 179 builder.WriteString("Machine(") 180 builder.WriteString(fmt.Sprintf("id=%v", m.ID)) 181 builder.WriteString(", created_at=") 182 builder.WriteString(m.CreatedAt.Format(time.ANSIC)) 183 builder.WriteString(", updated_at=") 184 builder.WriteString(m.UpdatedAt.Format(time.ANSIC)) 185 builder.WriteString(", machineId=") 186 builder.WriteString(m.MachineId) 187 builder.WriteString(", password=<sensitive>") 188 builder.WriteString(", ipAddress=") 189 builder.WriteString(m.IpAddress) 190 builder.WriteString(", scenarios=") 191 builder.WriteString(m.Scenarios) 192 builder.WriteString(", version=") 193 builder.WriteString(m.Version) 194 builder.WriteString(", isValidated=") 195 builder.WriteString(fmt.Sprintf("%v", m.IsValidated)) 196 builder.WriteString(", status=") 197 builder.WriteString(m.Status) 198 builder.WriteByte(')') 199 return builder.String() 200 } 201 202 // Machines is a parsable slice of Machine. 203 type Machines []*Machine 204 205 func (m Machines) config(cfg config) { 206 for _i := range m { 207 m[_i].config = cfg 208 } 209 }