idempotencyrecord.go 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228
  1. // Code generated by ent, DO NOT EDIT.
  2. package ent
  3. import (
  4. "fmt"
  5. "strings"
  6. "time"
  7. "entgo.io/ent"
  8. "entgo.io/ent/dialect/sql"
  9. "github.com/Wei-Shaw/sub2api/ent/idempotencyrecord"
  10. )
  11. // IdempotencyRecord is the model entity for the IdempotencyRecord schema.
  12. type IdempotencyRecord struct {
  13. config `json:"-"`
  14. // ID of the ent.
  15. ID int64 `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. // Scope holds the value of the "scope" field.
  21. Scope string `json:"scope,omitempty"`
  22. // IdempotencyKeyHash holds the value of the "idempotency_key_hash" field.
  23. IdempotencyKeyHash string `json:"idempotency_key_hash,omitempty"`
  24. // RequestFingerprint holds the value of the "request_fingerprint" field.
  25. RequestFingerprint string `json:"request_fingerprint,omitempty"`
  26. // Status holds the value of the "status" field.
  27. Status string `json:"status,omitempty"`
  28. // ResponseStatus holds the value of the "response_status" field.
  29. ResponseStatus *int `json:"response_status,omitempty"`
  30. // ResponseBody holds the value of the "response_body" field.
  31. ResponseBody *string `json:"response_body,omitempty"`
  32. // ErrorReason holds the value of the "error_reason" field.
  33. ErrorReason *string `json:"error_reason,omitempty"`
  34. // LockedUntil holds the value of the "locked_until" field.
  35. LockedUntil *time.Time `json:"locked_until,omitempty"`
  36. // ExpiresAt holds the value of the "expires_at" field.
  37. ExpiresAt time.Time `json:"expires_at,omitempty"`
  38. selectValues sql.SelectValues
  39. }
  40. // scanValues returns the types for scanning values from sql.Rows.
  41. func (*IdempotencyRecord) scanValues(columns []string) ([]any, error) {
  42. values := make([]any, len(columns))
  43. for i := range columns {
  44. switch columns[i] {
  45. case idempotencyrecord.FieldID, idempotencyrecord.FieldResponseStatus:
  46. values[i] = new(sql.NullInt64)
  47. case idempotencyrecord.FieldScope, idempotencyrecord.FieldIdempotencyKeyHash, idempotencyrecord.FieldRequestFingerprint, idempotencyrecord.FieldStatus, idempotencyrecord.FieldResponseBody, idempotencyrecord.FieldErrorReason:
  48. values[i] = new(sql.NullString)
  49. case idempotencyrecord.FieldCreatedAt, idempotencyrecord.FieldUpdatedAt, idempotencyrecord.FieldLockedUntil, idempotencyrecord.FieldExpiresAt:
  50. values[i] = new(sql.NullTime)
  51. default:
  52. values[i] = new(sql.UnknownType)
  53. }
  54. }
  55. return values, nil
  56. }
  57. // assignValues assigns the values that were returned from sql.Rows (after scanning)
  58. // to the IdempotencyRecord fields.
  59. func (_m *IdempotencyRecord) assignValues(columns []string, values []any) error {
  60. if m, n := len(values), len(columns); m < n {
  61. return fmt.Errorf("mismatch number of scan values: %d != %d", m, n)
  62. }
  63. for i := range columns {
  64. switch columns[i] {
  65. case idempotencyrecord.FieldID:
  66. value, ok := values[i].(*sql.NullInt64)
  67. if !ok {
  68. return fmt.Errorf("unexpected type %T for field id", value)
  69. }
  70. _m.ID = int64(value.Int64)
  71. case idempotencyrecord.FieldCreatedAt:
  72. if value, ok := values[i].(*sql.NullTime); !ok {
  73. return fmt.Errorf("unexpected type %T for field created_at", values[i])
  74. } else if value.Valid {
  75. _m.CreatedAt = value.Time
  76. }
  77. case idempotencyrecord.FieldUpdatedAt:
  78. if value, ok := values[i].(*sql.NullTime); !ok {
  79. return fmt.Errorf("unexpected type %T for field updated_at", values[i])
  80. } else if value.Valid {
  81. _m.UpdatedAt = value.Time
  82. }
  83. case idempotencyrecord.FieldScope:
  84. if value, ok := values[i].(*sql.NullString); !ok {
  85. return fmt.Errorf("unexpected type %T for field scope", values[i])
  86. } else if value.Valid {
  87. _m.Scope = value.String
  88. }
  89. case idempotencyrecord.FieldIdempotencyKeyHash:
  90. if value, ok := values[i].(*sql.NullString); !ok {
  91. return fmt.Errorf("unexpected type %T for field idempotency_key_hash", values[i])
  92. } else if value.Valid {
  93. _m.IdempotencyKeyHash = value.String
  94. }
  95. case idempotencyrecord.FieldRequestFingerprint:
  96. if value, ok := values[i].(*sql.NullString); !ok {
  97. return fmt.Errorf("unexpected type %T for field request_fingerprint", values[i])
  98. } else if value.Valid {
  99. _m.RequestFingerprint = value.String
  100. }
  101. case idempotencyrecord.FieldStatus:
  102. if value, ok := values[i].(*sql.NullString); !ok {
  103. return fmt.Errorf("unexpected type %T for field status", values[i])
  104. } else if value.Valid {
  105. _m.Status = value.String
  106. }
  107. case idempotencyrecord.FieldResponseStatus:
  108. if value, ok := values[i].(*sql.NullInt64); !ok {
  109. return fmt.Errorf("unexpected type %T for field response_status", values[i])
  110. } else if value.Valid {
  111. _m.ResponseStatus = new(int)
  112. *_m.ResponseStatus = int(value.Int64)
  113. }
  114. case idempotencyrecord.FieldResponseBody:
  115. if value, ok := values[i].(*sql.NullString); !ok {
  116. return fmt.Errorf("unexpected type %T for field response_body", values[i])
  117. } else if value.Valid {
  118. _m.ResponseBody = new(string)
  119. *_m.ResponseBody = value.String
  120. }
  121. case idempotencyrecord.FieldErrorReason:
  122. if value, ok := values[i].(*sql.NullString); !ok {
  123. return fmt.Errorf("unexpected type %T for field error_reason", values[i])
  124. } else if value.Valid {
  125. _m.ErrorReason = new(string)
  126. *_m.ErrorReason = value.String
  127. }
  128. case idempotencyrecord.FieldLockedUntil:
  129. if value, ok := values[i].(*sql.NullTime); !ok {
  130. return fmt.Errorf("unexpected type %T for field locked_until", values[i])
  131. } else if value.Valid {
  132. _m.LockedUntil = new(time.Time)
  133. *_m.LockedUntil = value.Time
  134. }
  135. case idempotencyrecord.FieldExpiresAt:
  136. if value, ok := values[i].(*sql.NullTime); !ok {
  137. return fmt.Errorf("unexpected type %T for field expires_at", values[i])
  138. } else if value.Valid {
  139. _m.ExpiresAt = value.Time
  140. }
  141. default:
  142. _m.selectValues.Set(columns[i], values[i])
  143. }
  144. }
  145. return nil
  146. }
  147. // Value returns the ent.Value that was dynamically selected and assigned to the IdempotencyRecord.
  148. // This includes values selected through modifiers, order, etc.
  149. func (_m *IdempotencyRecord) Value(name string) (ent.Value, error) {
  150. return _m.selectValues.Get(name)
  151. }
  152. // Update returns a builder for updating this IdempotencyRecord.
  153. // Note that you need to call IdempotencyRecord.Unwrap() before calling this method if this IdempotencyRecord
  154. // was returned from a transaction, and the transaction was committed or rolled back.
  155. func (_m *IdempotencyRecord) Update() *IdempotencyRecordUpdateOne {
  156. return NewIdempotencyRecordClient(_m.config).UpdateOne(_m)
  157. }
  158. // Unwrap unwraps the IdempotencyRecord entity that was returned from a transaction after it was closed,
  159. // so that all future queries will be executed through the driver which created the transaction.
  160. func (_m *IdempotencyRecord) Unwrap() *IdempotencyRecord {
  161. _tx, ok := _m.config.driver.(*txDriver)
  162. if !ok {
  163. panic("ent: IdempotencyRecord is not a transactional entity")
  164. }
  165. _m.config.driver = _tx.drv
  166. return _m
  167. }
  168. // String implements the fmt.Stringer.
  169. func (_m *IdempotencyRecord) String() string {
  170. var builder strings.Builder
  171. builder.WriteString("IdempotencyRecord(")
  172. builder.WriteString(fmt.Sprintf("id=%v, ", _m.ID))
  173. builder.WriteString("created_at=")
  174. builder.WriteString(_m.CreatedAt.Format(time.ANSIC))
  175. builder.WriteString(", ")
  176. builder.WriteString("updated_at=")
  177. builder.WriteString(_m.UpdatedAt.Format(time.ANSIC))
  178. builder.WriteString(", ")
  179. builder.WriteString("scope=")
  180. builder.WriteString(_m.Scope)
  181. builder.WriteString(", ")
  182. builder.WriteString("idempotency_key_hash=")
  183. builder.WriteString(_m.IdempotencyKeyHash)
  184. builder.WriteString(", ")
  185. builder.WriteString("request_fingerprint=")
  186. builder.WriteString(_m.RequestFingerprint)
  187. builder.WriteString(", ")
  188. builder.WriteString("status=")
  189. builder.WriteString(_m.Status)
  190. builder.WriteString(", ")
  191. if v := _m.ResponseStatus; v != nil {
  192. builder.WriteString("response_status=")
  193. builder.WriteString(fmt.Sprintf("%v", *v))
  194. }
  195. builder.WriteString(", ")
  196. if v := _m.ResponseBody; v != nil {
  197. builder.WriteString("response_body=")
  198. builder.WriteString(*v)
  199. }
  200. builder.WriteString(", ")
  201. if v := _m.ErrorReason; v != nil {
  202. builder.WriteString("error_reason=")
  203. builder.WriteString(*v)
  204. }
  205. builder.WriteString(", ")
  206. if v := _m.LockedUntil; v != nil {
  207. builder.WriteString("locked_until=")
  208. builder.WriteString(v.Format(time.ANSIC))
  209. }
  210. builder.WriteString(", ")
  211. builder.WriteString("expires_at=")
  212. builder.WriteString(_m.ExpiresAt.Format(time.ANSIC))
  213. builder.WriteByte(')')
  214. return builder.String()
  215. }
  216. // IdempotencyRecords is a parsable slice of IdempotencyRecord.
  217. type IdempotencyRecords []*IdempotencyRecord