contactfield.go 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206
  1. // Code generated by ent, DO NOT EDIT.
  2. package ent
  3. import (
  4. "encoding/json"
  5. "fmt"
  6. "strings"
  7. "time"
  8. "wechat-api/ent/contact"
  9. "wechat-api/ent/contactfield"
  10. "entgo.io/ent"
  11. "entgo.io/ent/dialect/sql"
  12. )
  13. // ContactField is the model entity for the ContactField schema.
  14. type ContactField struct {
  15. config `json:"-"`
  16. // ID of the ent.
  17. ID uint64 `json:"id,omitempty"`
  18. // Create Time | 创建日期
  19. CreatedAt time.Time `json:"created_at,omitempty"`
  20. // Update Time | 修改日期
  21. UpdatedAt time.Time `json:"updated_at,omitempty"`
  22. // Status 1: normal 2: ban | 状态 1 正常 2 禁用
  23. Status uint8 `json:"status,omitempty"`
  24. // Delete Time | 删除日期
  25. DeletedAt time.Time `json:"deleted_at,omitempty"`
  26. // 联系人 ID
  27. ContactID uint64 `json:"contact_id,omitempty"`
  28. // 表单 id
  29. FormID string `json:"form_id,omitempty"`
  30. // 表单值
  31. Value []string `json:"value,omitempty"`
  32. // Edges holds the relations/edges for other nodes in the graph.
  33. // The values are being populated by the ContactFieldQuery when eager-loading is set.
  34. Edges ContactFieldEdges `json:"edges"`
  35. selectValues sql.SelectValues
  36. }
  37. // ContactFieldEdges holds the relations/edges for other nodes in the graph.
  38. type ContactFieldEdges struct {
  39. // FieldContact holds the value of the field_contact edge.
  40. FieldContact *Contact `json:"field_contact,omitempty"`
  41. // loadedTypes holds the information for reporting if a
  42. // type was loaded (or requested) in eager-loading or not.
  43. loadedTypes [1]bool
  44. }
  45. // FieldContactOrErr returns the FieldContact value or an error if the edge
  46. // was not loaded in eager-loading, or loaded but was not found.
  47. func (e ContactFieldEdges) FieldContactOrErr() (*Contact, error) {
  48. if e.FieldContact != nil {
  49. return e.FieldContact, nil
  50. } else if e.loadedTypes[0] {
  51. return nil, &NotFoundError{label: contact.Label}
  52. }
  53. return nil, &NotLoadedError{edge: "field_contact"}
  54. }
  55. // scanValues returns the types for scanning values from sql.Rows.
  56. func (*ContactField) scanValues(columns []string) ([]any, error) {
  57. values := make([]any, len(columns))
  58. for i := range columns {
  59. switch columns[i] {
  60. case contactfield.FieldValue:
  61. values[i] = new([]byte)
  62. case contactfield.FieldID, contactfield.FieldStatus, contactfield.FieldContactID:
  63. values[i] = new(sql.NullInt64)
  64. case contactfield.FieldFormID:
  65. values[i] = new(sql.NullString)
  66. case contactfield.FieldCreatedAt, contactfield.FieldUpdatedAt, contactfield.FieldDeletedAt:
  67. values[i] = new(sql.NullTime)
  68. default:
  69. values[i] = new(sql.UnknownType)
  70. }
  71. }
  72. return values, nil
  73. }
  74. // assignValues assigns the values that were returned from sql.Rows (after scanning)
  75. // to the ContactField fields.
  76. func (cf *ContactField) assignValues(columns []string, values []any) 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 contactfield.FieldID:
  83. value, ok := values[i].(*sql.NullInt64)
  84. if !ok {
  85. return fmt.Errorf("unexpected type %T for field id", value)
  86. }
  87. cf.ID = uint64(value.Int64)
  88. case contactfield.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. cf.CreatedAt = value.Time
  93. }
  94. case contactfield.FieldUpdatedAt:
  95. if value, ok := values[i].(*sql.NullTime); !ok {
  96. return fmt.Errorf("unexpected type %T for field updated_at", values[i])
  97. } else if value.Valid {
  98. cf.UpdatedAt = value.Time
  99. }
  100. case contactfield.FieldStatus:
  101. if value, ok := values[i].(*sql.NullInt64); !ok {
  102. return fmt.Errorf("unexpected type %T for field status", values[i])
  103. } else if value.Valid {
  104. cf.Status = uint8(value.Int64)
  105. }
  106. case contactfield.FieldDeletedAt:
  107. if value, ok := values[i].(*sql.NullTime); !ok {
  108. return fmt.Errorf("unexpected type %T for field deleted_at", values[i])
  109. } else if value.Valid {
  110. cf.DeletedAt = value.Time
  111. }
  112. case contactfield.FieldContactID:
  113. if value, ok := values[i].(*sql.NullInt64); !ok {
  114. return fmt.Errorf("unexpected type %T for field contact_id", values[i])
  115. } else if value.Valid {
  116. cf.ContactID = uint64(value.Int64)
  117. }
  118. case contactfield.FieldFormID:
  119. if value, ok := values[i].(*sql.NullString); !ok {
  120. return fmt.Errorf("unexpected type %T for field form_id", values[i])
  121. } else if value.Valid {
  122. cf.FormID = value.String
  123. }
  124. case contactfield.FieldValue:
  125. if value, ok := values[i].(*[]byte); !ok {
  126. return fmt.Errorf("unexpected type %T for field value", values[i])
  127. } else if value != nil && len(*value) > 0 {
  128. if err := json.Unmarshal(*value, &cf.Value); err != nil {
  129. return fmt.Errorf("unmarshal field value: %w", err)
  130. }
  131. }
  132. default:
  133. cf.selectValues.Set(columns[i], values[i])
  134. }
  135. }
  136. return nil
  137. }
  138. // GetValue returns the ent.Value that was dynamically selected and assigned to the ContactField.
  139. // This includes values selected through modifiers, order, etc.
  140. func (cf *ContactField) GetValue(name string) (ent.Value, error) {
  141. return cf.selectValues.Get(name)
  142. }
  143. // QueryFieldContact queries the "field_contact" edge of the ContactField entity.
  144. func (cf *ContactField) QueryFieldContact() *ContactQuery {
  145. return NewContactFieldClient(cf.config).QueryFieldContact(cf)
  146. }
  147. // Update returns a builder for updating this ContactField.
  148. // Note that you need to call ContactField.Unwrap() before calling this method if this ContactField
  149. // was returned from a transaction, and the transaction was committed or rolled back.
  150. func (cf *ContactField) Update() *ContactFieldUpdateOne {
  151. return NewContactFieldClient(cf.config).UpdateOne(cf)
  152. }
  153. // Unwrap unwraps the ContactField entity that was returned from a transaction after it was closed,
  154. // so that all future queries will be executed through the driver which created the transaction.
  155. func (cf *ContactField) Unwrap() *ContactField {
  156. _tx, ok := cf.config.driver.(*txDriver)
  157. if !ok {
  158. panic("ent: ContactField is not a transactional entity")
  159. }
  160. cf.config.driver = _tx.drv
  161. return cf
  162. }
  163. // String implements the fmt.Stringer.
  164. func (cf *ContactField) String() string {
  165. var builder strings.Builder
  166. builder.WriteString("ContactField(")
  167. builder.WriteString(fmt.Sprintf("id=%v, ", cf.ID))
  168. builder.WriteString("created_at=")
  169. builder.WriteString(cf.CreatedAt.Format(time.ANSIC))
  170. builder.WriteString(", ")
  171. builder.WriteString("updated_at=")
  172. builder.WriteString(cf.UpdatedAt.Format(time.ANSIC))
  173. builder.WriteString(", ")
  174. builder.WriteString("status=")
  175. builder.WriteString(fmt.Sprintf("%v", cf.Status))
  176. builder.WriteString(", ")
  177. builder.WriteString("deleted_at=")
  178. builder.WriteString(cf.DeletedAt.Format(time.ANSIC))
  179. builder.WriteString(", ")
  180. builder.WriteString("contact_id=")
  181. builder.WriteString(fmt.Sprintf("%v", cf.ContactID))
  182. builder.WriteString(", ")
  183. builder.WriteString("form_id=")
  184. builder.WriteString(cf.FormID)
  185. builder.WriteString(", ")
  186. builder.WriteString("value=")
  187. builder.WriteString(fmt.Sprintf("%v", cf.Value))
  188. builder.WriteByte(')')
  189. return builder.String()
  190. }
  191. // ContactFields is a parsable slice of ContactField.
  192. type ContactFields []*ContactField