errorpassthroughrule.go 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280
  1. // Code generated by ent, DO NOT EDIT.
  2. package ent
  3. import (
  4. "encoding/json"
  5. "fmt"
  6. "strings"
  7. "time"
  8. "entgo.io/ent"
  9. "entgo.io/ent/dialect/sql"
  10. "github.com/Wei-Shaw/sub2api/ent/errorpassthroughrule"
  11. )
  12. // ErrorPassthroughRule is the model entity for the ErrorPassthroughRule schema.
  13. type ErrorPassthroughRule struct {
  14. config `json:"-"`
  15. // ID of the ent.
  16. ID int64 `json:"id,omitempty"`
  17. // CreatedAt holds the value of the "created_at" field.
  18. CreatedAt time.Time `json:"created_at,omitempty"`
  19. // UpdatedAt holds the value of the "updated_at" field.
  20. UpdatedAt time.Time `json:"updated_at,omitempty"`
  21. // Name holds the value of the "name" field.
  22. Name string `json:"name,omitempty"`
  23. // Enabled holds the value of the "enabled" field.
  24. Enabled bool `json:"enabled,omitempty"`
  25. // Priority holds the value of the "priority" field.
  26. Priority int `json:"priority,omitempty"`
  27. // ErrorCodes holds the value of the "error_codes" field.
  28. ErrorCodes []int `json:"error_codes,omitempty"`
  29. // Keywords holds the value of the "keywords" field.
  30. Keywords []string `json:"keywords,omitempty"`
  31. // MatchMode holds the value of the "match_mode" field.
  32. MatchMode string `json:"match_mode,omitempty"`
  33. // Platforms holds the value of the "platforms" field.
  34. Platforms []string `json:"platforms,omitempty"`
  35. // PassthroughCode holds the value of the "passthrough_code" field.
  36. PassthroughCode bool `json:"passthrough_code,omitempty"`
  37. // ResponseCode holds the value of the "response_code" field.
  38. ResponseCode *int `json:"response_code,omitempty"`
  39. // PassthroughBody holds the value of the "passthrough_body" field.
  40. PassthroughBody bool `json:"passthrough_body,omitempty"`
  41. // CustomMessage holds the value of the "custom_message" field.
  42. CustomMessage *string `json:"custom_message,omitempty"`
  43. // SkipMonitoring holds the value of the "skip_monitoring" field.
  44. SkipMonitoring bool `json:"skip_monitoring,omitempty"`
  45. // Description holds the value of the "description" field.
  46. Description *string `json:"description,omitempty"`
  47. selectValues sql.SelectValues
  48. }
  49. // scanValues returns the types for scanning values from sql.Rows.
  50. func (*ErrorPassthroughRule) scanValues(columns []string) ([]any, error) {
  51. values := make([]any, len(columns))
  52. for i := range columns {
  53. switch columns[i] {
  54. case errorpassthroughrule.FieldErrorCodes, errorpassthroughrule.FieldKeywords, errorpassthroughrule.FieldPlatforms:
  55. values[i] = new([]byte)
  56. case errorpassthroughrule.FieldEnabled, errorpassthroughrule.FieldPassthroughCode, errorpassthroughrule.FieldPassthroughBody, errorpassthroughrule.FieldSkipMonitoring:
  57. values[i] = new(sql.NullBool)
  58. case errorpassthroughrule.FieldID, errorpassthroughrule.FieldPriority, errorpassthroughrule.FieldResponseCode:
  59. values[i] = new(sql.NullInt64)
  60. case errorpassthroughrule.FieldName, errorpassthroughrule.FieldMatchMode, errorpassthroughrule.FieldCustomMessage, errorpassthroughrule.FieldDescription:
  61. values[i] = new(sql.NullString)
  62. case errorpassthroughrule.FieldCreatedAt, errorpassthroughrule.FieldUpdatedAt:
  63. values[i] = new(sql.NullTime)
  64. default:
  65. values[i] = new(sql.UnknownType)
  66. }
  67. }
  68. return values, nil
  69. }
  70. // assignValues assigns the values that were returned from sql.Rows (after scanning)
  71. // to the ErrorPassthroughRule fields.
  72. func (_m *ErrorPassthroughRule) assignValues(columns []string, values []any) error {
  73. if m, n := len(values), len(columns); m < n {
  74. return fmt.Errorf("mismatch number of scan values: %d != %d", m, n)
  75. }
  76. for i := range columns {
  77. switch columns[i] {
  78. case errorpassthroughrule.FieldID:
  79. value, ok := values[i].(*sql.NullInt64)
  80. if !ok {
  81. return fmt.Errorf("unexpected type %T for field id", value)
  82. }
  83. _m.ID = int64(value.Int64)
  84. case errorpassthroughrule.FieldCreatedAt:
  85. if value, ok := values[i].(*sql.NullTime); !ok {
  86. return fmt.Errorf("unexpected type %T for field created_at", values[i])
  87. } else if value.Valid {
  88. _m.CreatedAt = value.Time
  89. }
  90. case errorpassthroughrule.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 = value.Time
  95. }
  96. case errorpassthroughrule.FieldName:
  97. if value, ok := values[i].(*sql.NullString); !ok {
  98. return fmt.Errorf("unexpected type %T for field name", values[i])
  99. } else if value.Valid {
  100. _m.Name = value.String
  101. }
  102. case errorpassthroughrule.FieldEnabled:
  103. if value, ok := values[i].(*sql.NullBool); !ok {
  104. return fmt.Errorf("unexpected type %T for field enabled", values[i])
  105. } else if value.Valid {
  106. _m.Enabled = value.Bool
  107. }
  108. case errorpassthroughrule.FieldPriority:
  109. if value, ok := values[i].(*sql.NullInt64); !ok {
  110. return fmt.Errorf("unexpected type %T for field priority", values[i])
  111. } else if value.Valid {
  112. _m.Priority = int(value.Int64)
  113. }
  114. case errorpassthroughrule.FieldErrorCodes:
  115. if value, ok := values[i].(*[]byte); !ok {
  116. return fmt.Errorf("unexpected type %T for field error_codes", values[i])
  117. } else if value != nil && len(*value) > 0 {
  118. if err := json.Unmarshal(*value, &_m.ErrorCodes); err != nil {
  119. return fmt.Errorf("unmarshal field error_codes: %w", err)
  120. }
  121. }
  122. case errorpassthroughrule.FieldKeywords:
  123. if value, ok := values[i].(*[]byte); !ok {
  124. return fmt.Errorf("unexpected type %T for field keywords", values[i])
  125. } else if value != nil && len(*value) > 0 {
  126. if err := json.Unmarshal(*value, &_m.Keywords); err != nil {
  127. return fmt.Errorf("unmarshal field keywords: %w", err)
  128. }
  129. }
  130. case errorpassthroughrule.FieldMatchMode:
  131. if value, ok := values[i].(*sql.NullString); !ok {
  132. return fmt.Errorf("unexpected type %T for field match_mode", values[i])
  133. } else if value.Valid {
  134. _m.MatchMode = value.String
  135. }
  136. case errorpassthroughrule.FieldPlatforms:
  137. if value, ok := values[i].(*[]byte); !ok {
  138. return fmt.Errorf("unexpected type %T for field platforms", values[i])
  139. } else if value != nil && len(*value) > 0 {
  140. if err := json.Unmarshal(*value, &_m.Platforms); err != nil {
  141. return fmt.Errorf("unmarshal field platforms: %w", err)
  142. }
  143. }
  144. case errorpassthroughrule.FieldPassthroughCode:
  145. if value, ok := values[i].(*sql.NullBool); !ok {
  146. return fmt.Errorf("unexpected type %T for field passthrough_code", values[i])
  147. } else if value.Valid {
  148. _m.PassthroughCode = value.Bool
  149. }
  150. case errorpassthroughrule.FieldResponseCode:
  151. if value, ok := values[i].(*sql.NullInt64); !ok {
  152. return fmt.Errorf("unexpected type %T for field response_code", values[i])
  153. } else if value.Valid {
  154. _m.ResponseCode = new(int)
  155. *_m.ResponseCode = int(value.Int64)
  156. }
  157. case errorpassthroughrule.FieldPassthroughBody:
  158. if value, ok := values[i].(*sql.NullBool); !ok {
  159. return fmt.Errorf("unexpected type %T for field passthrough_body", values[i])
  160. } else if value.Valid {
  161. _m.PassthroughBody = value.Bool
  162. }
  163. case errorpassthroughrule.FieldCustomMessage:
  164. if value, ok := values[i].(*sql.NullString); !ok {
  165. return fmt.Errorf("unexpected type %T for field custom_message", values[i])
  166. } else if value.Valid {
  167. _m.CustomMessage = new(string)
  168. *_m.CustomMessage = value.String
  169. }
  170. case errorpassthroughrule.FieldSkipMonitoring:
  171. if value, ok := values[i].(*sql.NullBool); !ok {
  172. return fmt.Errorf("unexpected type %T for field skip_monitoring", values[i])
  173. } else if value.Valid {
  174. _m.SkipMonitoring = value.Bool
  175. }
  176. case errorpassthroughrule.FieldDescription:
  177. if value, ok := values[i].(*sql.NullString); !ok {
  178. return fmt.Errorf("unexpected type %T for field description", values[i])
  179. } else if value.Valid {
  180. _m.Description = new(string)
  181. *_m.Description = value.String
  182. }
  183. default:
  184. _m.selectValues.Set(columns[i], values[i])
  185. }
  186. }
  187. return nil
  188. }
  189. // Value returns the ent.Value that was dynamically selected and assigned to the ErrorPassthroughRule.
  190. // This includes values selected through modifiers, order, etc.
  191. func (_m *ErrorPassthroughRule) Value(name string) (ent.Value, error) {
  192. return _m.selectValues.Get(name)
  193. }
  194. // Update returns a builder for updating this ErrorPassthroughRule.
  195. // Note that you need to call ErrorPassthroughRule.Unwrap() before calling this method if this ErrorPassthroughRule
  196. // was returned from a transaction, and the transaction was committed or rolled back.
  197. func (_m *ErrorPassthroughRule) Update() *ErrorPassthroughRuleUpdateOne {
  198. return NewErrorPassthroughRuleClient(_m.config).UpdateOne(_m)
  199. }
  200. // Unwrap unwraps the ErrorPassthroughRule entity that was returned from a transaction after it was closed,
  201. // so that all future queries will be executed through the driver which created the transaction.
  202. func (_m *ErrorPassthroughRule) Unwrap() *ErrorPassthroughRule {
  203. _tx, ok := _m.config.driver.(*txDriver)
  204. if !ok {
  205. panic("ent: ErrorPassthroughRule is not a transactional entity")
  206. }
  207. _m.config.driver = _tx.drv
  208. return _m
  209. }
  210. // String implements the fmt.Stringer.
  211. func (_m *ErrorPassthroughRule) String() string {
  212. var builder strings.Builder
  213. builder.WriteString("ErrorPassthroughRule(")
  214. builder.WriteString(fmt.Sprintf("id=%v, ", _m.ID))
  215. builder.WriteString("created_at=")
  216. builder.WriteString(_m.CreatedAt.Format(time.ANSIC))
  217. builder.WriteString(", ")
  218. builder.WriteString("updated_at=")
  219. builder.WriteString(_m.UpdatedAt.Format(time.ANSIC))
  220. builder.WriteString(", ")
  221. builder.WriteString("name=")
  222. builder.WriteString(_m.Name)
  223. builder.WriteString(", ")
  224. builder.WriteString("enabled=")
  225. builder.WriteString(fmt.Sprintf("%v", _m.Enabled))
  226. builder.WriteString(", ")
  227. builder.WriteString("priority=")
  228. builder.WriteString(fmt.Sprintf("%v", _m.Priority))
  229. builder.WriteString(", ")
  230. builder.WriteString("error_codes=")
  231. builder.WriteString(fmt.Sprintf("%v", _m.ErrorCodes))
  232. builder.WriteString(", ")
  233. builder.WriteString("keywords=")
  234. builder.WriteString(fmt.Sprintf("%v", _m.Keywords))
  235. builder.WriteString(", ")
  236. builder.WriteString("match_mode=")
  237. builder.WriteString(_m.MatchMode)
  238. builder.WriteString(", ")
  239. builder.WriteString("platforms=")
  240. builder.WriteString(fmt.Sprintf("%v", _m.Platforms))
  241. builder.WriteString(", ")
  242. builder.WriteString("passthrough_code=")
  243. builder.WriteString(fmt.Sprintf("%v", _m.PassthroughCode))
  244. builder.WriteString(", ")
  245. if v := _m.ResponseCode; v != nil {
  246. builder.WriteString("response_code=")
  247. builder.WriteString(fmt.Sprintf("%v", *v))
  248. }
  249. builder.WriteString(", ")
  250. builder.WriteString("passthrough_body=")
  251. builder.WriteString(fmt.Sprintf("%v", _m.PassthroughBody))
  252. builder.WriteString(", ")
  253. if v := _m.CustomMessage; v != nil {
  254. builder.WriteString("custom_message=")
  255. builder.WriteString(*v)
  256. }
  257. builder.WriteString(", ")
  258. builder.WriteString("skip_monitoring=")
  259. builder.WriteString(fmt.Sprintf("%v", _m.SkipMonitoring))
  260. builder.WriteString(", ")
  261. if v := _m.Description; v != nil {
  262. builder.WriteString("description=")
  263. builder.WriteString(*v)
  264. }
  265. builder.WriteByte(')')
  266. return builder.String()
  267. }
  268. // ErrorPassthroughRules is a parsable slice of ErrorPassthroughRule.
  269. type ErrorPassthroughRules []*ErrorPassthroughRule