123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189 |
- // Code generated by entc, DO NOT EDIT.
- package ent
- import (
- "fmt"
- "strings"
- "time"
- "todo/ent/todo"
- "entgo.io/ent/dialect/sql"
- )
- // Todo is the model entity for the Todo schema.
- type Todo struct {
- config `json:"-"`
- // ID of the ent.
- ID int `json:"id,omitempty"`
- // Text holds the value of the "text" field.
- Text string `json:"text,omitempty"`
- // CreatedAt holds the value of the "created_at" field.
- CreatedAt time.Time `json:"created_at,omitempty"`
- // Status holds the value of the "status" field.
- Status todo.Status `json:"status,omitempty"`
- // Priority holds the value of the "priority" field.
- Priority int `json:"priority,omitempty"`
- // Edges holds the relations/edges for other nodes in the graph.
- // The values are being populated by the TodoQuery when eager-loading is set.
- Edges TodoEdges `json:"edges"`
- todo_parent *int
- }
- // TodoEdges holds the relations/edges for other nodes in the graph.
- type TodoEdges struct {
- // Children holds the value of the children edge.
- Children []*Todo `json:"children,omitempty"`
- // Parent holds the value of the parent edge.
- Parent *Todo `json:"parent,omitempty"`
- // loadedTypes holds the information for reporting if a
- // type was loaded (or requested) in eager-loading or not.
- loadedTypes [2]bool
- }
- // ChildrenOrErr returns the Children value or an error if the edge
- // was not loaded in eager-loading.
- func (e TodoEdges) ChildrenOrErr() ([]*Todo, error) {
- if e.loadedTypes[0] {
- return e.Children, nil
- }
- return nil, &NotLoadedError{edge: "children"}
- }
- // ParentOrErr returns the Parent value or an error if the edge
- // was not loaded in eager-loading, or loaded but was not found.
- func (e TodoEdges) ParentOrErr() (*Todo, error) {
- if e.loadedTypes[1] {
- if e.Parent == nil {
- // The edge parent was loaded in eager-loading,
- // but was not found.
- return nil, &NotFoundError{label: todo.Label}
- }
- return e.Parent, nil
- }
- return nil, &NotLoadedError{edge: "parent"}
- }
- // scanValues returns the types for scanning values from sql.Rows.
- func (*Todo) scanValues(columns []string) ([]interface{}, error) {
- values := make([]interface{}, len(columns))
- for i := range columns {
- switch columns[i] {
- case todo.FieldID, todo.FieldPriority:
- values[i] = new(sql.NullInt64)
- case todo.FieldText, todo.FieldStatus:
- values[i] = new(sql.NullString)
- case todo.FieldCreatedAt:
- values[i] = new(sql.NullTime)
- case todo.ForeignKeys[0]: // todo_parent
- values[i] = new(sql.NullInt64)
- default:
- return nil, fmt.Errorf("unexpected column %q for type Todo", columns[i])
- }
- }
- return values, nil
- }
- // assignValues assigns the values that were returned from sql.Rows (after scanning)
- // to the Todo fields.
- func (t *Todo) assignValues(columns []string, values []interface{}) error {
- if m, n := len(values), len(columns); m < n {
- return fmt.Errorf("mismatch number of scan values: %d != %d", m, n)
- }
- for i := range columns {
- switch columns[i] {
- case todo.FieldID:
- value, ok := values[i].(*sql.NullInt64)
- if !ok {
- return fmt.Errorf("unexpected type %T for field id", value)
- }
- t.ID = int(value.Int64)
- case todo.FieldText:
- if value, ok := values[i].(*sql.NullString); !ok {
- return fmt.Errorf("unexpected type %T for field text", values[i])
- } else if value.Valid {
- t.Text = value.String
- }
- case todo.FieldCreatedAt:
- if value, ok := values[i].(*sql.NullTime); !ok {
- return fmt.Errorf("unexpected type %T for field created_at", values[i])
- } else if value.Valid {
- t.CreatedAt = value.Time
- }
- case todo.FieldStatus:
- if value, ok := values[i].(*sql.NullString); !ok {
- return fmt.Errorf("unexpected type %T for field status", values[i])
- } else if value.Valid {
- t.Status = todo.Status(value.String)
- }
- case todo.FieldPriority:
- if value, ok := values[i].(*sql.NullInt64); !ok {
- return fmt.Errorf("unexpected type %T for field priority", values[i])
- } else if value.Valid {
- t.Priority = int(value.Int64)
- }
- case todo.ForeignKeys[0]:
- if value, ok := values[i].(*sql.NullInt64); !ok {
- return fmt.Errorf("unexpected type %T for edge-field todo_parent", value)
- } else if value.Valid {
- t.todo_parent = new(int)
- *t.todo_parent = int(value.Int64)
- }
- }
- }
- return nil
- }
- // QueryChildren queries the "children" edge of the Todo entity.
- func (t *Todo) QueryChildren() *TodoQuery {
- return (&TodoClient{config: t.config}).QueryChildren(t)
- }
- // QueryParent queries the "parent" edge of the Todo entity.
- func (t *Todo) QueryParent() *TodoQuery {
- return (&TodoClient{config: t.config}).QueryParent(t)
- }
- // Update returns a builder for updating this Todo.
- // Note that you need to call Todo.Unwrap() before calling this method if this Todo
- // was returned from a transaction, and the transaction was committed or rolled back.
- func (t *Todo) Update() *TodoUpdateOne {
- return (&TodoClient{config: t.config}).UpdateOne(t)
- }
- // Unwrap unwraps the Todo entity that was returned from a transaction after it was closed,
- // so that all future queries will be executed through the driver which created the transaction.
- func (t *Todo) Unwrap() *Todo {
- tx, ok := t.config.driver.(*txDriver)
- if !ok {
- panic("ent: Todo is not a transactional entity")
- }
- t.config.driver = tx.drv
- return t
- }
- // String implements the fmt.Stringer.
- func (t *Todo) String() string {
- var builder strings.Builder
- builder.WriteString("Todo(")
- builder.WriteString(fmt.Sprintf("id=%v", t.ID))
- builder.WriteString(", text=")
- builder.WriteString(t.Text)
- builder.WriteString(", created_at=")
- builder.WriteString(t.CreatedAt.Format(time.ANSIC))
- builder.WriteString(", status=")
- builder.WriteString(fmt.Sprintf("%v", t.Status))
- builder.WriteString(", priority=")
- builder.WriteString(fmt.Sprintf("%v", t.Priority))
- builder.WriteByte(')')
- return builder.String()
- }
- // Todos is a parsable slice of Todo.
- type Todos []*Todo
- func (t Todos) config(cfg config) {
- for _i := range t {
- t[_i].config = cfg
- }
- }
|