batchimageevent.go 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  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/batchimageevent"
  11. )
  12. // BatchImageEvent is the model entity for the BatchImageEvent schema.
  13. type BatchImageEvent struct {
  14. config `json:"-"`
  15. // ID of the ent.
  16. ID int64 `json:"id,omitempty"`
  17. // JobID holds the value of the "job_id" field.
  18. JobID string `json:"job_id,omitempty"`
  19. // EventType holds the value of the "event_type" field.
  20. EventType string `json:"event_type,omitempty"`
  21. // Payload holds the value of the "payload" field.
  22. Payload map[string]interface{} `json:"payload,omitempty"`
  23. // EventHash holds the value of the "event_hash" field.
  24. EventHash *string `json:"event_hash,omitempty"`
  25. // CreatedAt holds the value of the "created_at" field.
  26. CreatedAt time.Time `json:"created_at,omitempty"`
  27. selectValues sql.SelectValues
  28. }
  29. // scanValues returns the types for scanning values from sql.Rows.
  30. func (*BatchImageEvent) scanValues(columns []string) ([]any, error) {
  31. values := make([]any, len(columns))
  32. for i := range columns {
  33. switch columns[i] {
  34. case batchimageevent.FieldPayload:
  35. values[i] = new([]byte)
  36. case batchimageevent.FieldID:
  37. values[i] = new(sql.NullInt64)
  38. case batchimageevent.FieldJobID, batchimageevent.FieldEventType, batchimageevent.FieldEventHash:
  39. values[i] = new(sql.NullString)
  40. case batchimageevent.FieldCreatedAt:
  41. values[i] = new(sql.NullTime)
  42. default:
  43. values[i] = new(sql.UnknownType)
  44. }
  45. }
  46. return values, nil
  47. }
  48. // assignValues assigns the values that were returned from sql.Rows (after scanning)
  49. // to the BatchImageEvent fields.
  50. func (_m *BatchImageEvent) assignValues(columns []string, values []any) error {
  51. if m, n := len(values), len(columns); m < n {
  52. return fmt.Errorf("mismatch number of scan values: %d != %d", m, n)
  53. }
  54. for i := range columns {
  55. switch columns[i] {
  56. case batchimageevent.FieldID:
  57. value, ok := values[i].(*sql.NullInt64)
  58. if !ok {
  59. return fmt.Errorf("unexpected type %T for field id", value)
  60. }
  61. _m.ID = int64(value.Int64)
  62. case batchimageevent.FieldJobID:
  63. if value, ok := values[i].(*sql.NullString); !ok {
  64. return fmt.Errorf("unexpected type %T for field job_id", values[i])
  65. } else if value.Valid {
  66. _m.JobID = value.String
  67. }
  68. case batchimageevent.FieldEventType:
  69. if value, ok := values[i].(*sql.NullString); !ok {
  70. return fmt.Errorf("unexpected type %T for field event_type", values[i])
  71. } else if value.Valid {
  72. _m.EventType = value.String
  73. }
  74. case batchimageevent.FieldPayload:
  75. if value, ok := values[i].(*[]byte); !ok {
  76. return fmt.Errorf("unexpected type %T for field payload", values[i])
  77. } else if value != nil && len(*value) > 0 {
  78. if err := json.Unmarshal(*value, &_m.Payload); err != nil {
  79. return fmt.Errorf("unmarshal field payload: %w", err)
  80. }
  81. }
  82. case batchimageevent.FieldEventHash:
  83. if value, ok := values[i].(*sql.NullString); !ok {
  84. return fmt.Errorf("unexpected type %T for field event_hash", values[i])
  85. } else if value.Valid {
  86. _m.EventHash = new(string)
  87. *_m.EventHash = value.String
  88. }
  89. case batchimageevent.FieldCreatedAt:
  90. if value, ok := values[i].(*sql.NullTime); !ok {
  91. return fmt.Errorf("unexpected type %T for field created_at", values[i])
  92. } else if value.Valid {
  93. _m.CreatedAt = value.Time
  94. }
  95. default:
  96. _m.selectValues.Set(columns[i], values[i])
  97. }
  98. }
  99. return nil
  100. }
  101. // Value returns the ent.Value that was dynamically selected and assigned to the BatchImageEvent.
  102. // This includes values selected through modifiers, order, etc.
  103. func (_m *BatchImageEvent) Value(name string) (ent.Value, error) {
  104. return _m.selectValues.Get(name)
  105. }
  106. // Update returns a builder for updating this BatchImageEvent.
  107. // Note that you need to call BatchImageEvent.Unwrap() before calling this method if this BatchImageEvent
  108. // was returned from a transaction, and the transaction was committed or rolled back.
  109. func (_m *BatchImageEvent) Update() *BatchImageEventUpdateOne {
  110. return NewBatchImageEventClient(_m.config).UpdateOne(_m)
  111. }
  112. // Unwrap unwraps the BatchImageEvent entity that was returned from a transaction after it was closed,
  113. // so that all future queries will be executed through the driver which created the transaction.
  114. func (_m *BatchImageEvent) Unwrap() *BatchImageEvent {
  115. _tx, ok := _m.config.driver.(*txDriver)
  116. if !ok {
  117. panic("ent: BatchImageEvent is not a transactional entity")
  118. }
  119. _m.config.driver = _tx.drv
  120. return _m
  121. }
  122. // String implements the fmt.Stringer.
  123. func (_m *BatchImageEvent) String() string {
  124. var builder strings.Builder
  125. builder.WriteString("BatchImageEvent(")
  126. builder.WriteString(fmt.Sprintf("id=%v, ", _m.ID))
  127. builder.WriteString("job_id=")
  128. builder.WriteString(_m.JobID)
  129. builder.WriteString(", ")
  130. builder.WriteString("event_type=")
  131. builder.WriteString(_m.EventType)
  132. builder.WriteString(", ")
  133. builder.WriteString("payload=")
  134. builder.WriteString(fmt.Sprintf("%v", _m.Payload))
  135. builder.WriteString(", ")
  136. if v := _m.EventHash; v != nil {
  137. builder.WriteString("event_hash=")
  138. builder.WriteString(*v)
  139. }
  140. builder.WriteString(", ")
  141. builder.WriteString("created_at=")
  142. builder.WriteString(_m.CreatedAt.Format(time.ANSIC))
  143. builder.WriteByte(')')
  144. return builder.String()
  145. }
  146. // BatchImageEvents is a parsable slice of BatchImageEvent.
  147. type BatchImageEvents []*BatchImageEvent