machine.go 7.7 KB

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