tutorial.go 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212
  1. // Code generated by ent, DO NOT EDIT.
  2. package ent
  3. import (
  4. "fmt"
  5. "strings"
  6. "time"
  7. "wechat-api/ent/employee"
  8. "wechat-api/ent/tutorial"
  9. "entgo.io/ent"
  10. "entgo.io/ent/dialect/sql"
  11. )
  12. // Tutorial is the model entity for the Tutorial schema.
  13. type Tutorial struct {
  14. config `json:"-"`
  15. // ID of the ent.
  16. ID uint64 `json:"id,omitempty"`
  17. // Create Time | 创建日期
  18. CreatedAt time.Time `json:"created_at,omitempty"`
  19. // Update Time | 修改日期
  20. UpdatedAt time.Time `json:"updated_at,omitempty"`
  21. // Delete Time | 删除日期
  22. DeletedAt time.Time `json:"deleted_at,omitempty"`
  23. // employee_id | 员工ID
  24. EmployeeID uint64 `json:"employee_id,omitempty"`
  25. // index | 序号
  26. Index int `json:"index,omitempty"`
  27. // title | 标题
  28. Title string `json:"title,omitempty"`
  29. // content | 内容
  30. Content string `json:"content,omitempty"`
  31. // organization_id | 租户ID
  32. OrganizationID uint64 `json:"organization_id,omitempty"`
  33. // Edges holds the relations/edges for other nodes in the graph.
  34. // The values are being populated by the TutorialQuery when eager-loading is set.
  35. Edges TutorialEdges `json:"edges"`
  36. selectValues sql.SelectValues
  37. }
  38. // TutorialEdges holds the relations/edges for other nodes in the graph.
  39. type TutorialEdges struct {
  40. // Employee holds the value of the employee edge.
  41. Employee *Employee `json:"employee,omitempty"`
  42. // loadedTypes holds the information for reporting if a
  43. // type was loaded (or requested) in eager-loading or not.
  44. loadedTypes [1]bool
  45. }
  46. // EmployeeOrErr returns the Employee value or an error if the edge
  47. // was not loaded in eager-loading, or loaded but was not found.
  48. func (e TutorialEdges) EmployeeOrErr() (*Employee, error) {
  49. if e.Employee != nil {
  50. return e.Employee, nil
  51. } else if e.loadedTypes[0] {
  52. return nil, &NotFoundError{label: employee.Label}
  53. }
  54. return nil, &NotLoadedError{edge: "employee"}
  55. }
  56. // scanValues returns the types for scanning values from sql.Rows.
  57. func (*Tutorial) scanValues(columns []string) ([]any, error) {
  58. values := make([]any, len(columns))
  59. for i := range columns {
  60. switch columns[i] {
  61. case tutorial.FieldID, tutorial.FieldEmployeeID, tutorial.FieldIndex, tutorial.FieldOrganizationID:
  62. values[i] = new(sql.NullInt64)
  63. case tutorial.FieldTitle, tutorial.FieldContent:
  64. values[i] = new(sql.NullString)
  65. case tutorial.FieldCreatedAt, tutorial.FieldUpdatedAt, tutorial.FieldDeletedAt:
  66. values[i] = new(sql.NullTime)
  67. default:
  68. values[i] = new(sql.UnknownType)
  69. }
  70. }
  71. return values, nil
  72. }
  73. // assignValues assigns the values that were returned from sql.Rows (after scanning)
  74. // to the Tutorial fields.
  75. func (t *Tutorial) assignValues(columns []string, values []any) error {
  76. if m, n := len(values), len(columns); m < n {
  77. return fmt.Errorf("mismatch number of scan values: %d != %d", m, n)
  78. }
  79. for i := range columns {
  80. switch columns[i] {
  81. case tutorial.FieldID:
  82. value, ok := values[i].(*sql.NullInt64)
  83. if !ok {
  84. return fmt.Errorf("unexpected type %T for field id", value)
  85. }
  86. t.ID = uint64(value.Int64)
  87. case tutorial.FieldCreatedAt:
  88. if value, ok := values[i].(*sql.NullTime); !ok {
  89. return fmt.Errorf("unexpected type %T for field created_at", values[i])
  90. } else if value.Valid {
  91. t.CreatedAt = value.Time
  92. }
  93. case tutorial.FieldUpdatedAt:
  94. if value, ok := values[i].(*sql.NullTime); !ok {
  95. return fmt.Errorf("unexpected type %T for field updated_at", values[i])
  96. } else if value.Valid {
  97. t.UpdatedAt = value.Time
  98. }
  99. case tutorial.FieldDeletedAt:
  100. if value, ok := values[i].(*sql.NullTime); !ok {
  101. return fmt.Errorf("unexpected type %T for field deleted_at", values[i])
  102. } else if value.Valid {
  103. t.DeletedAt = value.Time
  104. }
  105. case tutorial.FieldEmployeeID:
  106. if value, ok := values[i].(*sql.NullInt64); !ok {
  107. return fmt.Errorf("unexpected type %T for field employee_id", values[i])
  108. } else if value.Valid {
  109. t.EmployeeID = uint64(value.Int64)
  110. }
  111. case tutorial.FieldIndex:
  112. if value, ok := values[i].(*sql.NullInt64); !ok {
  113. return fmt.Errorf("unexpected type %T for field index", values[i])
  114. } else if value.Valid {
  115. t.Index = int(value.Int64)
  116. }
  117. case tutorial.FieldTitle:
  118. if value, ok := values[i].(*sql.NullString); !ok {
  119. return fmt.Errorf("unexpected type %T for field title", values[i])
  120. } else if value.Valid {
  121. t.Title = value.String
  122. }
  123. case tutorial.FieldContent:
  124. if value, ok := values[i].(*sql.NullString); !ok {
  125. return fmt.Errorf("unexpected type %T for field content", values[i])
  126. } else if value.Valid {
  127. t.Content = value.String
  128. }
  129. case tutorial.FieldOrganizationID:
  130. if value, ok := values[i].(*sql.NullInt64); !ok {
  131. return fmt.Errorf("unexpected type %T for field organization_id", values[i])
  132. } else if value.Valid {
  133. t.OrganizationID = uint64(value.Int64)
  134. }
  135. default:
  136. t.selectValues.Set(columns[i], values[i])
  137. }
  138. }
  139. return nil
  140. }
  141. // Value returns the ent.Value that was dynamically selected and assigned to the Tutorial.
  142. // This includes values selected through modifiers, order, etc.
  143. func (t *Tutorial) Value(name string) (ent.Value, error) {
  144. return t.selectValues.Get(name)
  145. }
  146. // QueryEmployee queries the "employee" edge of the Tutorial entity.
  147. func (t *Tutorial) QueryEmployee() *EmployeeQuery {
  148. return NewTutorialClient(t.config).QueryEmployee(t)
  149. }
  150. // Update returns a builder for updating this Tutorial.
  151. // Note that you need to call Tutorial.Unwrap() before calling this method if this Tutorial
  152. // was returned from a transaction, and the transaction was committed or rolled back.
  153. func (t *Tutorial) Update() *TutorialUpdateOne {
  154. return NewTutorialClient(t.config).UpdateOne(t)
  155. }
  156. // Unwrap unwraps the Tutorial entity that was returned from a transaction after it was closed,
  157. // so that all future queries will be executed through the driver which created the transaction.
  158. func (t *Tutorial) Unwrap() *Tutorial {
  159. _tx, ok := t.config.driver.(*txDriver)
  160. if !ok {
  161. panic("ent: Tutorial is not a transactional entity")
  162. }
  163. t.config.driver = _tx.drv
  164. return t
  165. }
  166. // String implements the fmt.Stringer.
  167. func (t *Tutorial) String() string {
  168. var builder strings.Builder
  169. builder.WriteString("Tutorial(")
  170. builder.WriteString(fmt.Sprintf("id=%v, ", t.ID))
  171. builder.WriteString("created_at=")
  172. builder.WriteString(t.CreatedAt.Format(time.ANSIC))
  173. builder.WriteString(", ")
  174. builder.WriteString("updated_at=")
  175. builder.WriteString(t.UpdatedAt.Format(time.ANSIC))
  176. builder.WriteString(", ")
  177. builder.WriteString("deleted_at=")
  178. builder.WriteString(t.DeletedAt.Format(time.ANSIC))
  179. builder.WriteString(", ")
  180. builder.WriteString("employee_id=")
  181. builder.WriteString(fmt.Sprintf("%v", t.EmployeeID))
  182. builder.WriteString(", ")
  183. builder.WriteString("index=")
  184. builder.WriteString(fmt.Sprintf("%v", t.Index))
  185. builder.WriteString(", ")
  186. builder.WriteString("title=")
  187. builder.WriteString(t.Title)
  188. builder.WriteString(", ")
  189. builder.WriteString("content=")
  190. builder.WriteString(t.Content)
  191. builder.WriteString(", ")
  192. builder.WriteString("organization_id=")
  193. builder.WriteString(fmt.Sprintf("%v", t.OrganizationID))
  194. builder.WriteByte(')')
  195. return builder.String()
  196. }
  197. // Tutorials is a parsable slice of Tutorial.
  198. type Tutorials []*Tutorial