label.go 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220
  1. // Code generated by ent, DO NOT EDIT.
  2. package ent
  3. import (
  4. "fmt"
  5. "strings"
  6. "time"
  7. "wechat-api/ent/label"
  8. "entgo.io/ent"
  9. "entgo.io/ent/dialect/sql"
  10. )
  11. // Label is the model entity for the Label schema.
  12. type Label struct {
  13. config `json:"-"`
  14. // ID of the ent.
  15. ID uint64 `json:"id,omitempty"`
  16. // Create Time | 创建日期
  17. CreatedAt time.Time `json:"created_at,omitempty"`
  18. // Update Time | 修改日期
  19. UpdatedAt time.Time `json:"updated_at,omitempty"`
  20. // Status 1: normal 2: ban | 状态 1 正常 2 禁用
  21. Status uint8 `json:"status,omitempty"`
  22. // 标签类型:1好友,2群组,3公众号,4企业微信联系人
  23. Type int `json:"type,omitempty"`
  24. // 标签名称
  25. Name string `json:"name,omitempty"`
  26. // 标签来源:1后台创建 2个微同步
  27. From int `json:"from,omitempty"`
  28. // 标签模式:1动态 2静态
  29. Mode int `json:"mode,omitempty"`
  30. // 标签的触达条件
  31. Conditions string `json:"conditions,omitempty"`
  32. // 机构 ID
  33. OrganizationID uint64 `json:"organization_id,omitempty"`
  34. // Edges holds the relations/edges for other nodes in the graph.
  35. // The values are being populated by the LabelQuery when eager-loading is set.
  36. Edges LabelEdges `json:"edges"`
  37. selectValues sql.SelectValues
  38. }
  39. // LabelEdges holds the relations/edges for other nodes in the graph.
  40. type LabelEdges struct {
  41. // LabelRelationships holds the value of the label_relationships edge.
  42. LabelRelationships []*LabelRelationship `json:"label_relationships,omitempty"`
  43. // loadedTypes holds the information for reporting if a
  44. // type was loaded (or requested) in eager-loading or not.
  45. loadedTypes [1]bool
  46. }
  47. // LabelRelationshipsOrErr returns the LabelRelationships value or an error if the edge
  48. // was not loaded in eager-loading.
  49. func (e LabelEdges) LabelRelationshipsOrErr() ([]*LabelRelationship, error) {
  50. if e.loadedTypes[0] {
  51. return e.LabelRelationships, nil
  52. }
  53. return nil, &NotLoadedError{edge: "label_relationships"}
  54. }
  55. // scanValues returns the types for scanning values from sql.Rows.
  56. func (*Label) scanValues(columns []string) ([]any, error) {
  57. values := make([]any, len(columns))
  58. for i := range columns {
  59. switch columns[i] {
  60. case label.FieldID, label.FieldStatus, label.FieldType, label.FieldFrom, label.FieldMode, label.FieldOrganizationID:
  61. values[i] = new(sql.NullInt64)
  62. case label.FieldName, label.FieldConditions:
  63. values[i] = new(sql.NullString)
  64. case label.FieldCreatedAt, label.FieldUpdatedAt:
  65. values[i] = new(sql.NullTime)
  66. default:
  67. values[i] = new(sql.UnknownType)
  68. }
  69. }
  70. return values, nil
  71. }
  72. // assignValues assigns the values that were returned from sql.Rows (after scanning)
  73. // to the Label fields.
  74. func (l *Label) assignValues(columns []string, values []any) error {
  75. if m, n := len(values), len(columns); m < n {
  76. return fmt.Errorf("mismatch number of scan values: %d != %d", m, n)
  77. }
  78. for i := range columns {
  79. switch columns[i] {
  80. case label.FieldID:
  81. value, ok := values[i].(*sql.NullInt64)
  82. if !ok {
  83. return fmt.Errorf("unexpected type %T for field id", value)
  84. }
  85. l.ID = uint64(value.Int64)
  86. case label.FieldCreatedAt:
  87. if value, ok := values[i].(*sql.NullTime); !ok {
  88. return fmt.Errorf("unexpected type %T for field created_at", values[i])
  89. } else if value.Valid {
  90. l.CreatedAt = value.Time
  91. }
  92. case label.FieldUpdatedAt:
  93. if value, ok := values[i].(*sql.NullTime); !ok {
  94. return fmt.Errorf("unexpected type %T for field updated_at", values[i])
  95. } else if value.Valid {
  96. l.UpdatedAt = value.Time
  97. }
  98. case label.FieldStatus:
  99. if value, ok := values[i].(*sql.NullInt64); !ok {
  100. return fmt.Errorf("unexpected type %T for field status", values[i])
  101. } else if value.Valid {
  102. l.Status = uint8(value.Int64)
  103. }
  104. case label.FieldType:
  105. if value, ok := values[i].(*sql.NullInt64); !ok {
  106. return fmt.Errorf("unexpected type %T for field type", values[i])
  107. } else if value.Valid {
  108. l.Type = int(value.Int64)
  109. }
  110. case label.FieldName:
  111. if value, ok := values[i].(*sql.NullString); !ok {
  112. return fmt.Errorf("unexpected type %T for field name", values[i])
  113. } else if value.Valid {
  114. l.Name = value.String
  115. }
  116. case label.FieldFrom:
  117. if value, ok := values[i].(*sql.NullInt64); !ok {
  118. return fmt.Errorf("unexpected type %T for field from", values[i])
  119. } else if value.Valid {
  120. l.From = int(value.Int64)
  121. }
  122. case label.FieldMode:
  123. if value, ok := values[i].(*sql.NullInt64); !ok {
  124. return fmt.Errorf("unexpected type %T for field mode", values[i])
  125. } else if value.Valid {
  126. l.Mode = int(value.Int64)
  127. }
  128. case label.FieldConditions:
  129. if value, ok := values[i].(*sql.NullString); !ok {
  130. return fmt.Errorf("unexpected type %T for field conditions", values[i])
  131. } else if value.Valid {
  132. l.Conditions = value.String
  133. }
  134. case label.FieldOrganizationID:
  135. if value, ok := values[i].(*sql.NullInt64); !ok {
  136. return fmt.Errorf("unexpected type %T for field organization_id", values[i])
  137. } else if value.Valid {
  138. l.OrganizationID = uint64(value.Int64)
  139. }
  140. default:
  141. l.selectValues.Set(columns[i], values[i])
  142. }
  143. }
  144. return nil
  145. }
  146. // Value returns the ent.Value that was dynamically selected and assigned to the Label.
  147. // This includes values selected through modifiers, order, etc.
  148. func (l *Label) Value(name string) (ent.Value, error) {
  149. return l.selectValues.Get(name)
  150. }
  151. // QueryLabelRelationships queries the "label_relationships" edge of the Label entity.
  152. func (l *Label) QueryLabelRelationships() *LabelRelationshipQuery {
  153. return NewLabelClient(l.config).QueryLabelRelationships(l)
  154. }
  155. // Update returns a builder for updating this Label.
  156. // Note that you need to call Label.Unwrap() before calling this method if this Label
  157. // was returned from a transaction, and the transaction was committed or rolled back.
  158. func (l *Label) Update() *LabelUpdateOne {
  159. return NewLabelClient(l.config).UpdateOne(l)
  160. }
  161. // Unwrap unwraps the Label entity that was returned from a transaction after it was closed,
  162. // so that all future queries will be executed through the driver which created the transaction.
  163. func (l *Label) Unwrap() *Label {
  164. _tx, ok := l.config.driver.(*txDriver)
  165. if !ok {
  166. panic("ent: Label is not a transactional entity")
  167. }
  168. l.config.driver = _tx.drv
  169. return l
  170. }
  171. // String implements the fmt.Stringer.
  172. func (l *Label) String() string {
  173. var builder strings.Builder
  174. builder.WriteString("Label(")
  175. builder.WriteString(fmt.Sprintf("id=%v, ", l.ID))
  176. builder.WriteString("created_at=")
  177. builder.WriteString(l.CreatedAt.Format(time.ANSIC))
  178. builder.WriteString(", ")
  179. builder.WriteString("updated_at=")
  180. builder.WriteString(l.UpdatedAt.Format(time.ANSIC))
  181. builder.WriteString(", ")
  182. builder.WriteString("status=")
  183. builder.WriteString(fmt.Sprintf("%v", l.Status))
  184. builder.WriteString(", ")
  185. builder.WriteString("type=")
  186. builder.WriteString(fmt.Sprintf("%v", l.Type))
  187. builder.WriteString(", ")
  188. builder.WriteString("name=")
  189. builder.WriteString(l.Name)
  190. builder.WriteString(", ")
  191. builder.WriteString("from=")
  192. builder.WriteString(fmt.Sprintf("%v", l.From))
  193. builder.WriteString(", ")
  194. builder.WriteString("mode=")
  195. builder.WriteString(fmt.Sprintf("%v", l.Mode))
  196. builder.WriteString(", ")
  197. builder.WriteString("conditions=")
  198. builder.WriteString(l.Conditions)
  199. builder.WriteString(", ")
  200. builder.WriteString("organization_id=")
  201. builder.WriteString(fmt.Sprintf("%v", l.OrganizationID))
  202. builder.WriteByte(')')
  203. return builder.String()
  204. }
  205. // Labels is a parsable slice of Label.
  206. type Labels []*Label