labelrelationship.go 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207
  1. // Code generated by ent, DO NOT EDIT.
  2. package ent
  3. import (
  4. "fmt"
  5. "strings"
  6. "time"
  7. "wechat-api/ent/contact"
  8. "wechat-api/ent/label"
  9. "wechat-api/ent/labelrelationship"
  10. "entgo.io/ent"
  11. "entgo.io/ent/dialect/sql"
  12. )
  13. // LabelRelationship is the model entity for the LabelRelationship schema.
  14. type LabelRelationship 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. // 标签 ID
  25. LabelID uint64 `json:"label_id,omitempty"`
  26. // 联系人 ID
  27. ContactID uint64 `json:"contact_id,omitempty"`
  28. // 机构 ID
  29. OrganizationID uint64 `json:"organization_id,omitempty"`
  30. // Edges holds the relations/edges for other nodes in the graph.
  31. // The values are being populated by the LabelRelationshipQuery when eager-loading is set.
  32. Edges LabelRelationshipEdges `json:"edges"`
  33. selectValues sql.SelectValues
  34. }
  35. // LabelRelationshipEdges holds the relations/edges for other nodes in the graph.
  36. type LabelRelationshipEdges struct {
  37. // Contacts holds the value of the contacts edge.
  38. Contacts *Contact `json:"contacts,omitempty"`
  39. // Labels holds the value of the labels edge.
  40. Labels *Label `json:"labels,omitempty"`
  41. // loadedTypes holds the information for reporting if a
  42. // type was loaded (or requested) in eager-loading or not.
  43. loadedTypes [2]bool
  44. }
  45. // ContactsOrErr returns the Contacts value or an error if the edge
  46. // was not loaded in eager-loading, or loaded but was not found.
  47. func (e LabelRelationshipEdges) ContactsOrErr() (*Contact, error) {
  48. if e.Contacts != nil {
  49. return e.Contacts, nil
  50. } else if e.loadedTypes[0] {
  51. return nil, &NotFoundError{label: contact.Label}
  52. }
  53. return nil, &NotLoadedError{edge: "contacts"}
  54. }
  55. // LabelsOrErr returns the Labels value or an error if the edge
  56. // was not loaded in eager-loading, or loaded but was not found.
  57. func (e LabelRelationshipEdges) LabelsOrErr() (*Label, error) {
  58. if e.Labels != nil {
  59. return e.Labels, nil
  60. } else if e.loadedTypes[1] {
  61. return nil, &NotFoundError{label: label.Label}
  62. }
  63. return nil, &NotLoadedError{edge: "labels"}
  64. }
  65. // scanValues returns the types for scanning values from sql.Rows.
  66. func (*LabelRelationship) scanValues(columns []string) ([]any, error) {
  67. values := make([]any, len(columns))
  68. for i := range columns {
  69. switch columns[i] {
  70. case labelrelationship.FieldID, labelrelationship.FieldStatus, labelrelationship.FieldLabelID, labelrelationship.FieldContactID, labelrelationship.FieldOrganizationID:
  71. values[i] = new(sql.NullInt64)
  72. case labelrelationship.FieldCreatedAt, labelrelationship.FieldUpdatedAt:
  73. values[i] = new(sql.NullTime)
  74. default:
  75. values[i] = new(sql.UnknownType)
  76. }
  77. }
  78. return values, nil
  79. }
  80. // assignValues assigns the values that were returned from sql.Rows (after scanning)
  81. // to the LabelRelationship fields.
  82. func (lr *LabelRelationship) assignValues(columns []string, values []any) error {
  83. if m, n := len(values), len(columns); m < n {
  84. return fmt.Errorf("mismatch number of scan values: %d != %d", m, n)
  85. }
  86. for i := range columns {
  87. switch columns[i] {
  88. case labelrelationship.FieldID:
  89. value, ok := values[i].(*sql.NullInt64)
  90. if !ok {
  91. return fmt.Errorf("unexpected type %T for field id", value)
  92. }
  93. lr.ID = uint64(value.Int64)
  94. case labelrelationship.FieldCreatedAt:
  95. if value, ok := values[i].(*sql.NullTime); !ok {
  96. return fmt.Errorf("unexpected type %T for field created_at", values[i])
  97. } else if value.Valid {
  98. lr.CreatedAt = value.Time
  99. }
  100. case labelrelationship.FieldUpdatedAt:
  101. if value, ok := values[i].(*sql.NullTime); !ok {
  102. return fmt.Errorf("unexpected type %T for field updated_at", values[i])
  103. } else if value.Valid {
  104. lr.UpdatedAt = value.Time
  105. }
  106. case labelrelationship.FieldStatus:
  107. if value, ok := values[i].(*sql.NullInt64); !ok {
  108. return fmt.Errorf("unexpected type %T for field status", values[i])
  109. } else if value.Valid {
  110. lr.Status = uint8(value.Int64)
  111. }
  112. case labelrelationship.FieldLabelID:
  113. if value, ok := values[i].(*sql.NullInt64); !ok {
  114. return fmt.Errorf("unexpected type %T for field label_id", values[i])
  115. } else if value.Valid {
  116. lr.LabelID = uint64(value.Int64)
  117. }
  118. case labelrelationship.FieldContactID:
  119. if value, ok := values[i].(*sql.NullInt64); !ok {
  120. return fmt.Errorf("unexpected type %T for field contact_id", values[i])
  121. } else if value.Valid {
  122. lr.ContactID = uint64(value.Int64)
  123. }
  124. case labelrelationship.FieldOrganizationID:
  125. if value, ok := values[i].(*sql.NullInt64); !ok {
  126. return fmt.Errorf("unexpected type %T for field organization_id", values[i])
  127. } else if value.Valid {
  128. lr.OrganizationID = uint64(value.Int64)
  129. }
  130. default:
  131. lr.selectValues.Set(columns[i], values[i])
  132. }
  133. }
  134. return nil
  135. }
  136. // Value returns the ent.Value that was dynamically selected and assigned to the LabelRelationship.
  137. // This includes values selected through modifiers, order, etc.
  138. func (lr *LabelRelationship) Value(name string) (ent.Value, error) {
  139. return lr.selectValues.Get(name)
  140. }
  141. // QueryContacts queries the "contacts" edge of the LabelRelationship entity.
  142. func (lr *LabelRelationship) QueryContacts() *ContactQuery {
  143. return NewLabelRelationshipClient(lr.config).QueryContacts(lr)
  144. }
  145. // QueryLabels queries the "labels" edge of the LabelRelationship entity.
  146. func (lr *LabelRelationship) QueryLabels() *LabelQuery {
  147. return NewLabelRelationshipClient(lr.config).QueryLabels(lr)
  148. }
  149. // Update returns a builder for updating this LabelRelationship.
  150. // Note that you need to call LabelRelationship.Unwrap() before calling this method if this LabelRelationship
  151. // was returned from a transaction, and the transaction was committed or rolled back.
  152. func (lr *LabelRelationship) Update() *LabelRelationshipUpdateOne {
  153. return NewLabelRelationshipClient(lr.config).UpdateOne(lr)
  154. }
  155. // Unwrap unwraps the LabelRelationship entity that was returned from a transaction after it was closed,
  156. // so that all future queries will be executed through the driver which created the transaction.
  157. func (lr *LabelRelationship) Unwrap() *LabelRelationship {
  158. _tx, ok := lr.config.driver.(*txDriver)
  159. if !ok {
  160. panic("ent: LabelRelationship is not a transactional entity")
  161. }
  162. lr.config.driver = _tx.drv
  163. return lr
  164. }
  165. // String implements the fmt.Stringer.
  166. func (lr *LabelRelationship) String() string {
  167. var builder strings.Builder
  168. builder.WriteString("LabelRelationship(")
  169. builder.WriteString(fmt.Sprintf("id=%v, ", lr.ID))
  170. builder.WriteString("created_at=")
  171. builder.WriteString(lr.CreatedAt.Format(time.ANSIC))
  172. builder.WriteString(", ")
  173. builder.WriteString("updated_at=")
  174. builder.WriteString(lr.UpdatedAt.Format(time.ANSIC))
  175. builder.WriteString(", ")
  176. builder.WriteString("status=")
  177. builder.WriteString(fmt.Sprintf("%v", lr.Status))
  178. builder.WriteString(", ")
  179. builder.WriteString("label_id=")
  180. builder.WriteString(fmt.Sprintf("%v", lr.LabelID))
  181. builder.WriteString(", ")
  182. builder.WriteString("contact_id=")
  183. builder.WriteString(fmt.Sprintf("%v", lr.ContactID))
  184. builder.WriteString(", ")
  185. builder.WriteString("organization_id=")
  186. builder.WriteString(fmt.Sprintf("%v", lr.OrganizationID))
  187. builder.WriteByte(')')
  188. return builder.String()
  189. }
  190. // LabelRelationships is a parsable slice of LabelRelationship.
  191. type LabelRelationships []*LabelRelationship