category.go 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  1. // Code generated by ent, DO NOT EDIT.
  2. package ent
  3. import (
  4. "fmt"
  5. "strings"
  6. "time"
  7. "wechat-api/ent/category"
  8. "entgo.io/ent"
  9. "entgo.io/ent/dialect/sql"
  10. )
  11. // Category is the model entity for the Category schema.
  12. type Category 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. // Delete Time | 删除日期
  21. DeletedAt time.Time `json:"deleted_at,omitempty"`
  22. // name | 角色名称
  23. Name string `json:"name,omitempty"`
  24. // organization_id | 租户ID
  25. OrganizationID uint64 `json:"organization_id,omitempty"`
  26. selectValues sql.SelectValues
  27. }
  28. // scanValues returns the types for scanning values from sql.Rows.
  29. func (*Category) scanValues(columns []string) ([]any, error) {
  30. values := make([]any, len(columns))
  31. for i := range columns {
  32. switch columns[i] {
  33. case category.FieldID, category.FieldOrganizationID:
  34. values[i] = new(sql.NullInt64)
  35. case category.FieldName:
  36. values[i] = new(sql.NullString)
  37. case category.FieldCreatedAt, category.FieldUpdatedAt, category.FieldDeletedAt:
  38. values[i] = new(sql.NullTime)
  39. default:
  40. values[i] = new(sql.UnknownType)
  41. }
  42. }
  43. return values, nil
  44. }
  45. // assignValues assigns the values that were returned from sql.Rows (after scanning)
  46. // to the Category fields.
  47. func (c *Category) assignValues(columns []string, values []any) error {
  48. if m, n := len(values), len(columns); m < n {
  49. return fmt.Errorf("mismatch number of scan values: %d != %d", m, n)
  50. }
  51. for i := range columns {
  52. switch columns[i] {
  53. case category.FieldID:
  54. value, ok := values[i].(*sql.NullInt64)
  55. if !ok {
  56. return fmt.Errorf("unexpected type %T for field id", value)
  57. }
  58. c.ID = uint64(value.Int64)
  59. case category.FieldCreatedAt:
  60. if value, ok := values[i].(*sql.NullTime); !ok {
  61. return fmt.Errorf("unexpected type %T for field created_at", values[i])
  62. } else if value.Valid {
  63. c.CreatedAt = value.Time
  64. }
  65. case category.FieldUpdatedAt:
  66. if value, ok := values[i].(*sql.NullTime); !ok {
  67. return fmt.Errorf("unexpected type %T for field updated_at", values[i])
  68. } else if value.Valid {
  69. c.UpdatedAt = value.Time
  70. }
  71. case category.FieldDeletedAt:
  72. if value, ok := values[i].(*sql.NullTime); !ok {
  73. return fmt.Errorf("unexpected type %T for field deleted_at", values[i])
  74. } else if value.Valid {
  75. c.DeletedAt = value.Time
  76. }
  77. case category.FieldName:
  78. if value, ok := values[i].(*sql.NullString); !ok {
  79. return fmt.Errorf("unexpected type %T for field name", values[i])
  80. } else if value.Valid {
  81. c.Name = value.String
  82. }
  83. case category.FieldOrganizationID:
  84. if value, ok := values[i].(*sql.NullInt64); !ok {
  85. return fmt.Errorf("unexpected type %T for field organization_id", values[i])
  86. } else if value.Valid {
  87. c.OrganizationID = uint64(value.Int64)
  88. }
  89. default:
  90. c.selectValues.Set(columns[i], values[i])
  91. }
  92. }
  93. return nil
  94. }
  95. // Value returns the ent.Value that was dynamically selected and assigned to the Category.
  96. // This includes values selected through modifiers, order, etc.
  97. func (c *Category) Value(name string) (ent.Value, error) {
  98. return c.selectValues.Get(name)
  99. }
  100. // Update returns a builder for updating this Category.
  101. // Note that you need to call Category.Unwrap() before calling this method if this Category
  102. // was returned from a transaction, and the transaction was committed or rolled back.
  103. func (c *Category) Update() *CategoryUpdateOne {
  104. return NewCategoryClient(c.config).UpdateOne(c)
  105. }
  106. // Unwrap unwraps the Category entity that was returned from a transaction after it was closed,
  107. // so that all future queries will be executed through the driver which created the transaction.
  108. func (c *Category) Unwrap() *Category {
  109. _tx, ok := c.config.driver.(*txDriver)
  110. if !ok {
  111. panic("ent: Category is not a transactional entity")
  112. }
  113. c.config.driver = _tx.drv
  114. return c
  115. }
  116. // String implements the fmt.Stringer.
  117. func (c *Category) String() string {
  118. var builder strings.Builder
  119. builder.WriteString("Category(")
  120. builder.WriteString(fmt.Sprintf("id=%v, ", c.ID))
  121. builder.WriteString("created_at=")
  122. builder.WriteString(c.CreatedAt.Format(time.ANSIC))
  123. builder.WriteString(", ")
  124. builder.WriteString("updated_at=")
  125. builder.WriteString(c.UpdatedAt.Format(time.ANSIC))
  126. builder.WriteString(", ")
  127. builder.WriteString("deleted_at=")
  128. builder.WriteString(c.DeletedAt.Format(time.ANSIC))
  129. builder.WriteString(", ")
  130. builder.WriteString("name=")
  131. builder.WriteString(c.Name)
  132. builder.WriteString(", ")
  133. builder.WriteString("organization_id=")
  134. builder.WriteString(fmt.Sprintf("%v", c.OrganizationID))
  135. builder.WriteByte(')')
  136. return builder.String()
  137. }
  138. // Categories is a parsable slice of Category.
  139. type Categories []*Category