contactfieldtemplate.go 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165
  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/contactfieldtemplate"
  9. "wechat-api/ent/custom_types"
  10. "entgo.io/ent"
  11. "entgo.io/ent/dialect/sql"
  12. )
  13. // ContactFieldTemplate is the model entity for the ContactFieldTemplate schema.
  14. type ContactFieldTemplate 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. OrganizationID uint64 `json:"organization_id,omitempty"`
  28. // 模板
  29. Template []custom_types.ContactFieldTemplate `json:"template,omitempty"`
  30. selectValues sql.SelectValues
  31. }
  32. // scanValues returns the types for scanning values from sql.Rows.
  33. func (*ContactFieldTemplate) scanValues(columns []string) ([]any, error) {
  34. values := make([]any, len(columns))
  35. for i := range columns {
  36. switch columns[i] {
  37. case contactfieldtemplate.FieldTemplate:
  38. values[i] = new([]byte)
  39. case contactfieldtemplate.FieldID, contactfieldtemplate.FieldStatus, contactfieldtemplate.FieldOrganizationID:
  40. values[i] = new(sql.NullInt64)
  41. case contactfieldtemplate.FieldCreatedAt, contactfieldtemplate.FieldUpdatedAt, contactfieldtemplate.FieldDeletedAt:
  42. values[i] = new(sql.NullTime)
  43. default:
  44. values[i] = new(sql.UnknownType)
  45. }
  46. }
  47. return values, nil
  48. }
  49. // assignValues assigns the values that were returned from sql.Rows (after scanning)
  50. // to the ContactFieldTemplate fields.
  51. func (cft *ContactFieldTemplate) assignValues(columns []string, values []any) error {
  52. if m, n := len(values), len(columns); m < n {
  53. return fmt.Errorf("mismatch number of scan values: %d != %d", m, n)
  54. }
  55. for i := range columns {
  56. switch columns[i] {
  57. case contactfieldtemplate.FieldID:
  58. value, ok := values[i].(*sql.NullInt64)
  59. if !ok {
  60. return fmt.Errorf("unexpected type %T for field id", value)
  61. }
  62. cft.ID = uint64(value.Int64)
  63. case contactfieldtemplate.FieldCreatedAt:
  64. if value, ok := values[i].(*sql.NullTime); !ok {
  65. return fmt.Errorf("unexpected type %T for field created_at", values[i])
  66. } else if value.Valid {
  67. cft.CreatedAt = value.Time
  68. }
  69. case contactfieldtemplate.FieldUpdatedAt:
  70. if value, ok := values[i].(*sql.NullTime); !ok {
  71. return fmt.Errorf("unexpected type %T for field updated_at", values[i])
  72. } else if value.Valid {
  73. cft.UpdatedAt = value.Time
  74. }
  75. case contactfieldtemplate.FieldStatus:
  76. if value, ok := values[i].(*sql.NullInt64); !ok {
  77. return fmt.Errorf("unexpected type %T for field status", values[i])
  78. } else if value.Valid {
  79. cft.Status = uint8(value.Int64)
  80. }
  81. case contactfieldtemplate.FieldDeletedAt:
  82. if value, ok := values[i].(*sql.NullTime); !ok {
  83. return fmt.Errorf("unexpected type %T for field deleted_at", values[i])
  84. } else if value.Valid {
  85. cft.DeletedAt = value.Time
  86. }
  87. case contactfieldtemplate.FieldOrganizationID:
  88. if value, ok := values[i].(*sql.NullInt64); !ok {
  89. return fmt.Errorf("unexpected type %T for field organization_id", values[i])
  90. } else if value.Valid {
  91. cft.OrganizationID = uint64(value.Int64)
  92. }
  93. case contactfieldtemplate.FieldTemplate:
  94. if value, ok := values[i].(*[]byte); !ok {
  95. return fmt.Errorf("unexpected type %T for field template", values[i])
  96. } else if value != nil && len(*value) > 0 {
  97. if err := json.Unmarshal(*value, &cft.Template); err != nil {
  98. return fmt.Errorf("unmarshal field template: %w", err)
  99. }
  100. }
  101. default:
  102. cft.selectValues.Set(columns[i], values[i])
  103. }
  104. }
  105. return nil
  106. }
  107. // Value returns the ent.Value that was dynamically selected and assigned to the ContactFieldTemplate.
  108. // This includes values selected through modifiers, order, etc.
  109. func (cft *ContactFieldTemplate) Value(name string) (ent.Value, error) {
  110. return cft.selectValues.Get(name)
  111. }
  112. // Update returns a builder for updating this ContactFieldTemplate.
  113. // Note that you need to call ContactFieldTemplate.Unwrap() before calling this method if this ContactFieldTemplate
  114. // was returned from a transaction, and the transaction was committed or rolled back.
  115. func (cft *ContactFieldTemplate) Update() *ContactFieldTemplateUpdateOne {
  116. return NewContactFieldTemplateClient(cft.config).UpdateOne(cft)
  117. }
  118. // Unwrap unwraps the ContactFieldTemplate entity that was returned from a transaction after it was closed,
  119. // so that all future queries will be executed through the driver which created the transaction.
  120. func (cft *ContactFieldTemplate) Unwrap() *ContactFieldTemplate {
  121. _tx, ok := cft.config.driver.(*txDriver)
  122. if !ok {
  123. panic("ent: ContactFieldTemplate is not a transactional entity")
  124. }
  125. cft.config.driver = _tx.drv
  126. return cft
  127. }
  128. // String implements the fmt.Stringer.
  129. func (cft *ContactFieldTemplate) String() string {
  130. var builder strings.Builder
  131. builder.WriteString("ContactFieldTemplate(")
  132. builder.WriteString(fmt.Sprintf("id=%v, ", cft.ID))
  133. builder.WriteString("created_at=")
  134. builder.WriteString(cft.CreatedAt.Format(time.ANSIC))
  135. builder.WriteString(", ")
  136. builder.WriteString("updated_at=")
  137. builder.WriteString(cft.UpdatedAt.Format(time.ANSIC))
  138. builder.WriteString(", ")
  139. builder.WriteString("status=")
  140. builder.WriteString(fmt.Sprintf("%v", cft.Status))
  141. builder.WriteString(", ")
  142. builder.WriteString("deleted_at=")
  143. builder.WriteString(cft.DeletedAt.Format(time.ANSIC))
  144. builder.WriteString(", ")
  145. builder.WriteString("organization_id=")
  146. builder.WriteString(fmt.Sprintf("%v", cft.OrganizationID))
  147. builder.WriteString(", ")
  148. builder.WriteString("template=")
  149. builder.WriteString(fmt.Sprintf("%v", cft.Template))
  150. builder.WriteByte(')')
  151. return builder.String()
  152. }
  153. // ContactFieldTemplates is a parsable slice of ContactFieldTemplate.
  154. type ContactFieldTemplates []*ContactFieldTemplate