labelrelationship.go 7.8 KB

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