meta.go 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180
  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/alert"
  9. "github.com/crowdsecurity/crowdsec/pkg/database/ent/meta"
  10. )
  11. // Meta is the model entity for the Meta schema.
  12. type Meta struct {
  13. config `json:"-"`
  14. // ID of the ent.
  15. ID int `json:"id,omitempty"`
  16. // CreatedAt holds the value of the "created_at" field.
  17. CreatedAt *time.Time `json:"created_at,omitempty"`
  18. // UpdatedAt holds the value of the "updated_at" field.
  19. UpdatedAt *time.Time `json:"updated_at,omitempty"`
  20. // Key holds the value of the "key" field.
  21. Key string `json:"key,omitempty"`
  22. // Value holds the value of the "value" field.
  23. Value string `json:"value,omitempty"`
  24. // Edges holds the relations/edges for other nodes in the graph.
  25. // The values are being populated by the MetaQuery when eager-loading is set.
  26. Edges MetaEdges `json:"edges"`
  27. alert_metas *int
  28. }
  29. // MetaEdges holds the relations/edges for other nodes in the graph.
  30. type MetaEdges struct {
  31. // Owner holds the value of the owner edge.
  32. Owner *Alert `json:"owner,omitempty"`
  33. // loadedTypes holds the information for reporting if a
  34. // type was loaded (or requested) in eager-loading or not.
  35. loadedTypes [1]bool
  36. }
  37. // OwnerOrErr returns the Owner value or an error if the edge
  38. // was not loaded in eager-loading, or loaded but was not found.
  39. func (e MetaEdges) OwnerOrErr() (*Alert, error) {
  40. if e.loadedTypes[0] {
  41. if e.Owner == nil {
  42. // The edge owner was loaded in eager-loading,
  43. // but was not found.
  44. return nil, &NotFoundError{label: alert.Label}
  45. }
  46. return e.Owner, nil
  47. }
  48. return nil, &NotLoadedError{edge: "owner"}
  49. }
  50. // scanValues returns the types for scanning values from sql.Rows.
  51. func (*Meta) scanValues(columns []string) ([]interface{}, error) {
  52. values := make([]interface{}, len(columns))
  53. for i := range columns {
  54. switch columns[i] {
  55. case meta.FieldID:
  56. values[i] = new(sql.NullInt64)
  57. case meta.FieldKey, meta.FieldValue:
  58. values[i] = new(sql.NullString)
  59. case meta.FieldCreatedAt, meta.FieldUpdatedAt:
  60. values[i] = new(sql.NullTime)
  61. case meta.ForeignKeys[0]: // alert_metas
  62. values[i] = new(sql.NullInt64)
  63. default:
  64. return nil, fmt.Errorf("unexpected column %q for type Meta", columns[i])
  65. }
  66. }
  67. return values, nil
  68. }
  69. // assignValues assigns the values that were returned from sql.Rows (after scanning)
  70. // to the Meta fields.
  71. func (m *Meta) assignValues(columns []string, values []interface{}) error {
  72. if m, n := len(values), len(columns); m < n {
  73. return fmt.Errorf("mismatch number of scan values: %d != %d", m, n)
  74. }
  75. for i := range columns {
  76. switch columns[i] {
  77. case meta.FieldID:
  78. value, ok := values[i].(*sql.NullInt64)
  79. if !ok {
  80. return fmt.Errorf("unexpected type %T for field id", value)
  81. }
  82. m.ID = int(value.Int64)
  83. case meta.FieldCreatedAt:
  84. if value, ok := values[i].(*sql.NullTime); !ok {
  85. return fmt.Errorf("unexpected type %T for field created_at", values[i])
  86. } else if value.Valid {
  87. m.CreatedAt = new(time.Time)
  88. *m.CreatedAt = value.Time
  89. }
  90. case meta.FieldUpdatedAt:
  91. if value, ok := values[i].(*sql.NullTime); !ok {
  92. return fmt.Errorf("unexpected type %T for field updated_at", values[i])
  93. } else if value.Valid {
  94. m.UpdatedAt = new(time.Time)
  95. *m.UpdatedAt = value.Time
  96. }
  97. case meta.FieldKey:
  98. if value, ok := values[i].(*sql.NullString); !ok {
  99. return fmt.Errorf("unexpected type %T for field key", values[i])
  100. } else if value.Valid {
  101. m.Key = value.String
  102. }
  103. case meta.FieldValue:
  104. if value, ok := values[i].(*sql.NullString); !ok {
  105. return fmt.Errorf("unexpected type %T for field value", values[i])
  106. } else if value.Valid {
  107. m.Value = value.String
  108. }
  109. case meta.ForeignKeys[0]:
  110. if value, ok := values[i].(*sql.NullInt64); !ok {
  111. return fmt.Errorf("unexpected type %T for edge-field alert_metas", value)
  112. } else if value.Valid {
  113. m.alert_metas = new(int)
  114. *m.alert_metas = int(value.Int64)
  115. }
  116. }
  117. }
  118. return nil
  119. }
  120. // QueryOwner queries the "owner" edge of the Meta entity.
  121. func (m *Meta) QueryOwner() *AlertQuery {
  122. return (&MetaClient{config: m.config}).QueryOwner(m)
  123. }
  124. // Update returns a builder for updating this Meta.
  125. // Note that you need to call Meta.Unwrap() before calling this method if this Meta
  126. // was returned from a transaction, and the transaction was committed or rolled back.
  127. func (m *Meta) Update() *MetaUpdateOne {
  128. return (&MetaClient{config: m.config}).UpdateOne(m)
  129. }
  130. // Unwrap unwraps the Meta entity that was returned from a transaction after it was closed,
  131. // so that all future queries will be executed through the driver which created the transaction.
  132. func (m *Meta) Unwrap() *Meta {
  133. tx, ok := m.config.driver.(*txDriver)
  134. if !ok {
  135. panic("ent: Meta is not a transactional entity")
  136. }
  137. m.config.driver = tx.drv
  138. return m
  139. }
  140. // String implements the fmt.Stringer.
  141. func (m *Meta) String() string {
  142. var builder strings.Builder
  143. builder.WriteString("Meta(")
  144. builder.WriteString(fmt.Sprintf("id=%v", m.ID))
  145. if v := m.CreatedAt; v != nil {
  146. builder.WriteString(", created_at=")
  147. builder.WriteString(v.Format(time.ANSIC))
  148. }
  149. if v := m.UpdatedAt; v != nil {
  150. builder.WriteString(", updated_at=")
  151. builder.WriteString(v.Format(time.ANSIC))
  152. }
  153. builder.WriteString(", key=")
  154. builder.WriteString(m.Key)
  155. builder.WriteString(", value=")
  156. builder.WriteString(m.Value)
  157. builder.WriteByte(')')
  158. return builder.String()
  159. }
  160. // MetaSlice is a parsable slice of Meta.
  161. type MetaSlice []*Meta
  162. func (m MetaSlice) config(cfg config) {
  163. for _i := range m {
  164. m[_i].config = cfg
  165. }
  166. }