label.go 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231
  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. // 内容类型:1-微信 2-whatsapp
  35. Ctype uint64 `json:"ctype,omitempty"`
  36. // Edges holds the relations/edges for other nodes in the graph.
  37. // The values are being populated by the LabelQuery when eager-loading is set.
  38. Edges LabelEdges `json:"edges"`
  39. selectValues sql.SelectValues
  40. }
  41. // LabelEdges holds the relations/edges for other nodes in the graph.
  42. type LabelEdges struct {
  43. // LabelRelationships holds the value of the label_relationships edge.
  44. LabelRelationships []*LabelRelationship `json:"label_relationships,omitempty"`
  45. // loadedTypes holds the information for reporting if a
  46. // type was loaded (or requested) in eager-loading or not.
  47. loadedTypes [1]bool
  48. }
  49. // LabelRelationshipsOrErr returns the LabelRelationships value or an error if the edge
  50. // was not loaded in eager-loading.
  51. func (e LabelEdges) LabelRelationshipsOrErr() ([]*LabelRelationship, error) {
  52. if e.loadedTypes[0] {
  53. return e.LabelRelationships, nil
  54. }
  55. return nil, &NotLoadedError{edge: "label_relationships"}
  56. }
  57. // scanValues returns the types for scanning values from sql.Rows.
  58. func (*Label) scanValues(columns []string) ([]any, error) {
  59. values := make([]any, len(columns))
  60. for i := range columns {
  61. switch columns[i] {
  62. case label.FieldID, label.FieldStatus, label.FieldType, label.FieldFrom, label.FieldMode, label.FieldOrganizationID, label.FieldCtype:
  63. values[i] = new(sql.NullInt64)
  64. case label.FieldName, label.FieldConditions:
  65. values[i] = new(sql.NullString)
  66. case label.FieldCreatedAt, label.FieldUpdatedAt:
  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 Label fields.
  76. func (l *Label) 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 label.FieldID:
  83. value, ok := values[i].(*sql.NullInt64)
  84. if !ok {
  85. return fmt.Errorf("unexpected type %T for field id", value)
  86. }
  87. l.ID = uint64(value.Int64)
  88. case label.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. l.CreatedAt = value.Time
  93. }
  94. case label.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. l.UpdatedAt = value.Time
  99. }
  100. case label.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. l.Status = uint8(value.Int64)
  105. }
  106. case label.FieldType:
  107. if value, ok := values[i].(*sql.NullInt64); !ok {
  108. return fmt.Errorf("unexpected type %T for field type", values[i])
  109. } else if value.Valid {
  110. l.Type = int(value.Int64)
  111. }
  112. case label.FieldName:
  113. if value, ok := values[i].(*sql.NullString); !ok {
  114. return fmt.Errorf("unexpected type %T for field name", values[i])
  115. } else if value.Valid {
  116. l.Name = value.String
  117. }
  118. case label.FieldFrom:
  119. if value, ok := values[i].(*sql.NullInt64); !ok {
  120. return fmt.Errorf("unexpected type %T for field from", values[i])
  121. } else if value.Valid {
  122. l.From = int(value.Int64)
  123. }
  124. case label.FieldMode:
  125. if value, ok := values[i].(*sql.NullInt64); !ok {
  126. return fmt.Errorf("unexpected type %T for field mode", values[i])
  127. } else if value.Valid {
  128. l.Mode = int(value.Int64)
  129. }
  130. case label.FieldConditions:
  131. if value, ok := values[i].(*sql.NullString); !ok {
  132. return fmt.Errorf("unexpected type %T for field conditions", values[i])
  133. } else if value.Valid {
  134. l.Conditions = value.String
  135. }
  136. case label.FieldOrganizationID:
  137. if value, ok := values[i].(*sql.NullInt64); !ok {
  138. return fmt.Errorf("unexpected type %T for field organization_id", values[i])
  139. } else if value.Valid {
  140. l.OrganizationID = uint64(value.Int64)
  141. }
  142. case label.FieldCtype:
  143. if value, ok := values[i].(*sql.NullInt64); !ok {
  144. return fmt.Errorf("unexpected type %T for field ctype", values[i])
  145. } else if value.Valid {
  146. l.Ctype = uint64(value.Int64)
  147. }
  148. default:
  149. l.selectValues.Set(columns[i], values[i])
  150. }
  151. }
  152. return nil
  153. }
  154. // Value returns the ent.Value that was dynamically selected and assigned to the Label.
  155. // This includes values selected through modifiers, order, etc.
  156. func (l *Label) Value(name string) (ent.Value, error) {
  157. return l.selectValues.Get(name)
  158. }
  159. // QueryLabelRelationships queries the "label_relationships" edge of the Label entity.
  160. func (l *Label) QueryLabelRelationships() *LabelRelationshipQuery {
  161. return NewLabelClient(l.config).QueryLabelRelationships(l)
  162. }
  163. // Update returns a builder for updating this Label.
  164. // Note that you need to call Label.Unwrap() before calling this method if this Label
  165. // was returned from a transaction, and the transaction was committed or rolled back.
  166. func (l *Label) Update() *LabelUpdateOne {
  167. return NewLabelClient(l.config).UpdateOne(l)
  168. }
  169. // Unwrap unwraps the Label entity that was returned from a transaction after it was closed,
  170. // so that all future queries will be executed through the driver which created the transaction.
  171. func (l *Label) Unwrap() *Label {
  172. _tx, ok := l.config.driver.(*txDriver)
  173. if !ok {
  174. panic("ent: Label is not a transactional entity")
  175. }
  176. l.config.driver = _tx.drv
  177. return l
  178. }
  179. // String implements the fmt.Stringer.
  180. func (l *Label) String() string {
  181. var builder strings.Builder
  182. builder.WriteString("Label(")
  183. builder.WriteString(fmt.Sprintf("id=%v, ", l.ID))
  184. builder.WriteString("created_at=")
  185. builder.WriteString(l.CreatedAt.Format(time.ANSIC))
  186. builder.WriteString(", ")
  187. builder.WriteString("updated_at=")
  188. builder.WriteString(l.UpdatedAt.Format(time.ANSIC))
  189. builder.WriteString(", ")
  190. builder.WriteString("status=")
  191. builder.WriteString(fmt.Sprintf("%v", l.Status))
  192. builder.WriteString(", ")
  193. builder.WriteString("type=")
  194. builder.WriteString(fmt.Sprintf("%v", l.Type))
  195. builder.WriteString(", ")
  196. builder.WriteString("name=")
  197. builder.WriteString(l.Name)
  198. builder.WriteString(", ")
  199. builder.WriteString("from=")
  200. builder.WriteString(fmt.Sprintf("%v", l.From))
  201. builder.WriteString(", ")
  202. builder.WriteString("mode=")
  203. builder.WriteString(fmt.Sprintf("%v", l.Mode))
  204. builder.WriteString(", ")
  205. builder.WriteString("conditions=")
  206. builder.WriteString(l.Conditions)
  207. builder.WriteString(", ")
  208. builder.WriteString("organization_id=")
  209. builder.WriteString(fmt.Sprintf("%v", l.OrganizationID))
  210. builder.WriteString(", ")
  211. builder.WriteString("ctype=")
  212. builder.WriteString(fmt.Sprintf("%v", l.Ctype))
  213. builder.WriteByte(')')
  214. return builder.String()
  215. }
  216. // Labels is a parsable slice of Label.
  217. type Labels []*Label