todo.go 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189
  1. // Code generated by entc, DO NOT EDIT.
  2. package ent
  3. import (
  4. "fmt"
  5. "strings"
  6. "time"
  7. "todo/ent/todo"
  8. "entgo.io/ent/dialect/sql"
  9. )
  10. // Todo is the model entity for the Todo schema.
  11. type Todo struct {
  12. config `json:"-"`
  13. // ID of the ent.
  14. ID int `json:"id,omitempty"`
  15. // Text holds the value of the "text" field.
  16. Text string `json:"text,omitempty"`
  17. // CreatedAt holds the value of the "created_at" field.
  18. CreatedAt time.Time `json:"created_at,omitempty"`
  19. // Status holds the value of the "status" field.
  20. Status todo.Status `json:"status,omitempty"`
  21. // Priority holds the value of the "priority" field.
  22. Priority int `json:"priority,omitempty"`
  23. // Edges holds the relations/edges for other nodes in the graph.
  24. // The values are being populated by the TodoQuery when eager-loading is set.
  25. Edges TodoEdges `json:"edges"`
  26. todo_parent *int
  27. }
  28. // TodoEdges holds the relations/edges for other nodes in the graph.
  29. type TodoEdges struct {
  30. // Children holds the value of the children edge.
  31. Children []*Todo `json:"children,omitempty"`
  32. // Parent holds the value of the parent edge.
  33. Parent *Todo `json:"parent,omitempty"`
  34. // loadedTypes holds the information for reporting if a
  35. // type was loaded (or requested) in eager-loading or not.
  36. loadedTypes [2]bool
  37. }
  38. // ChildrenOrErr returns the Children value or an error if the edge
  39. // was not loaded in eager-loading.
  40. func (e TodoEdges) ChildrenOrErr() ([]*Todo, error) {
  41. if e.loadedTypes[0] {
  42. return e.Children, nil
  43. }
  44. return nil, &NotLoadedError{edge: "children"}
  45. }
  46. // ParentOrErr returns the Parent value or an error if the edge
  47. // was not loaded in eager-loading, or loaded but was not found.
  48. func (e TodoEdges) ParentOrErr() (*Todo, error) {
  49. if e.loadedTypes[1] {
  50. if e.Parent == nil {
  51. // The edge parent was loaded in eager-loading,
  52. // but was not found.
  53. return nil, &NotFoundError{label: todo.Label}
  54. }
  55. return e.Parent, nil
  56. }
  57. return nil, &NotLoadedError{edge: "parent"}
  58. }
  59. // scanValues returns the types for scanning values from sql.Rows.
  60. func (*Todo) scanValues(columns []string) ([]interface{}, error) {
  61. values := make([]interface{}, len(columns))
  62. for i := range columns {
  63. switch columns[i] {
  64. case todo.FieldID, todo.FieldPriority:
  65. values[i] = new(sql.NullInt64)
  66. case todo.FieldText, todo.FieldStatus:
  67. values[i] = new(sql.NullString)
  68. case todo.FieldCreatedAt:
  69. values[i] = new(sql.NullTime)
  70. case todo.ForeignKeys[0]: // todo_parent
  71. values[i] = new(sql.NullInt64)
  72. default:
  73. return nil, fmt.Errorf("unexpected column %q for type Todo", columns[i])
  74. }
  75. }
  76. return values, nil
  77. }
  78. // assignValues assigns the values that were returned from sql.Rows (after scanning)
  79. // to the Todo fields.
  80. func (t *Todo) assignValues(columns []string, values []interface{}) error {
  81. if m, n := len(values), len(columns); m < n {
  82. return fmt.Errorf("mismatch number of scan values: %d != %d", m, n)
  83. }
  84. for i := range columns {
  85. switch columns[i] {
  86. case todo.FieldID:
  87. value, ok := values[i].(*sql.NullInt64)
  88. if !ok {
  89. return fmt.Errorf("unexpected type %T for field id", value)
  90. }
  91. t.ID = int(value.Int64)
  92. case todo.FieldText:
  93. if value, ok := values[i].(*sql.NullString); !ok {
  94. return fmt.Errorf("unexpected type %T for field text", values[i])
  95. } else if value.Valid {
  96. t.Text = value.String
  97. }
  98. case todo.FieldCreatedAt:
  99. if value, ok := values[i].(*sql.NullTime); !ok {
  100. return fmt.Errorf("unexpected type %T for field created_at", values[i])
  101. } else if value.Valid {
  102. t.CreatedAt = value.Time
  103. }
  104. case todo.FieldStatus:
  105. if value, ok := values[i].(*sql.NullString); !ok {
  106. return fmt.Errorf("unexpected type %T for field status", values[i])
  107. } else if value.Valid {
  108. t.Status = todo.Status(value.String)
  109. }
  110. case todo.FieldPriority:
  111. if value, ok := values[i].(*sql.NullInt64); !ok {
  112. return fmt.Errorf("unexpected type %T for field priority", values[i])
  113. } else if value.Valid {
  114. t.Priority = int(value.Int64)
  115. }
  116. case todo.ForeignKeys[0]:
  117. if value, ok := values[i].(*sql.NullInt64); !ok {
  118. return fmt.Errorf("unexpected type %T for edge-field todo_parent", value)
  119. } else if value.Valid {
  120. t.todo_parent = new(int)
  121. *t.todo_parent = int(value.Int64)
  122. }
  123. }
  124. }
  125. return nil
  126. }
  127. // QueryChildren queries the "children" edge of the Todo entity.
  128. func (t *Todo) QueryChildren() *TodoQuery {
  129. return (&TodoClient{config: t.config}).QueryChildren(t)
  130. }
  131. // QueryParent queries the "parent" edge of the Todo entity.
  132. func (t *Todo) QueryParent() *TodoQuery {
  133. return (&TodoClient{config: t.config}).QueryParent(t)
  134. }
  135. // Update returns a builder for updating this Todo.
  136. // Note that you need to call Todo.Unwrap() before calling this method if this Todo
  137. // was returned from a transaction, and the transaction was committed or rolled back.
  138. func (t *Todo) Update() *TodoUpdateOne {
  139. return (&TodoClient{config: t.config}).UpdateOne(t)
  140. }
  141. // Unwrap unwraps the Todo entity that was returned from a transaction after it was closed,
  142. // so that all future queries will be executed through the driver which created the transaction.
  143. func (t *Todo) Unwrap() *Todo {
  144. tx, ok := t.config.driver.(*txDriver)
  145. if !ok {
  146. panic("ent: Todo is not a transactional entity")
  147. }
  148. t.config.driver = tx.drv
  149. return t
  150. }
  151. // String implements the fmt.Stringer.
  152. func (t *Todo) String() string {
  153. var builder strings.Builder
  154. builder.WriteString("Todo(")
  155. builder.WriteString(fmt.Sprintf("id=%v", t.ID))
  156. builder.WriteString(", text=")
  157. builder.WriteString(t.Text)
  158. builder.WriteString(", created_at=")
  159. builder.WriteString(t.CreatedAt.Format(time.ANSIC))
  160. builder.WriteString(", status=")
  161. builder.WriteString(fmt.Sprintf("%v", t.Status))
  162. builder.WriteString(", priority=")
  163. builder.WriteString(fmt.Sprintf("%v", t.Priority))
  164. builder.WriteByte(')')
  165. return builder.String()
  166. }
  167. // Todos is a parsable slice of Todo.
  168. type Todos []*Todo
  169. func (t Todos) config(cfg config) {
  170. for _i := range t {
  171. t[_i].config = cfg
  172. }
  173. }