// Code generated by ent, DO NOT EDIT. package ent import ( "fmt" "strings" "time" "entgo.io/ent" "entgo.io/ent/dialect/sql" "git.gorlug.de/code/ersteller/starter/ent/todo" "git.gorlug.de/code/ersteller/starter/ent/user" ) // Todo is the model entity for the Todo schema. type Todo struct { config `json:"-"` // ID of the ent. ID int `json:"id,omitempty"` // CreatedAt holds the value of the "created_at" field. CreatedAt time.Time `json:"created_at,omitempty"` // UpdatedAt holds the value of the "updated_at" field. UpdatedAt time.Time `json:"updated_at,omitempty"` // Title holds the value of the "title" field. Title string `json:"title,omitempty"` // Completed holds the value of the "completed" field. Completed bool `json:"completed,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_user *int selectValues sql.SelectValues } // TodoEdges holds the relations/edges for other nodes in the graph. type TodoEdges struct { // User holds the value of the user edge. User *User `json:"user,omitempty"` // loadedTypes holds the information for reporting if a // type was loaded (or requested) in eager-loading or not. loadedTypes [1]bool } // UserOrErr returns the User value or an error if the edge // was not loaded in eager-loading, or loaded but was not found. func (e TodoEdges) UserOrErr() (*User, error) { if e.User != nil { return e.User, nil } else if e.loadedTypes[0] { return nil, &NotFoundError{label: user.Label} } return nil, &NotLoadedError{edge: "user"} } // scanValues returns the types for scanning values from sql.Rows. func (*Todo) scanValues(columns []string) ([]any, error) { values := make([]any, len(columns)) for i := range columns { switch columns[i] { case todo.FieldCompleted: values[i] = new(sql.NullBool) case todo.FieldID: values[i] = new(sql.NullInt64) case todo.FieldTitle: values[i] = new(sql.NullString) case todo.FieldCreatedAt, todo.FieldUpdatedAt: values[i] = new(sql.NullTime) case todo.ForeignKeys[0]: // todo_user values[i] = new(sql.NullInt64) default: values[i] = new(sql.UnknownType) } } return values, nil } // assignValues assigns the values that were returned from sql.Rows (after scanning) // to the Todo fields. func (_m *Todo) assignValues(columns []string, values []any) 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) } _m.ID = int(value.Int64) 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 { _m.CreatedAt = value.Time } case todo.FieldUpdatedAt: if value, ok := values[i].(*sql.NullTime); !ok { return fmt.Errorf("unexpected type %T for field updated_at", values[i]) } else if value.Valid { _m.UpdatedAt = value.Time } case todo.FieldTitle: if value, ok := values[i].(*sql.NullString); !ok { return fmt.Errorf("unexpected type %T for field title", values[i]) } else if value.Valid { _m.Title = value.String } case todo.FieldCompleted: if value, ok := values[i].(*sql.NullBool); !ok { return fmt.Errorf("unexpected type %T for field completed", values[i]) } else if value.Valid { _m.Completed = value.Bool } case todo.ForeignKeys[0]: if value, ok := values[i].(*sql.NullInt64); !ok { return fmt.Errorf("unexpected type %T for edge-field todo_user", value) } else if value.Valid { _m.todo_user = new(int) *_m.todo_user = int(value.Int64) } default: _m.selectValues.Set(columns[i], values[i]) } } return nil } // Value returns the ent.Value that was dynamically selected and assigned to the Todo. // This includes values selected through modifiers, order, etc. func (_m *Todo) Value(name string) (ent.Value, error) { return _m.selectValues.Get(name) } // QueryUser queries the "user" edge of the Todo entity. func (_m *Todo) QueryUser() *UserQuery { return NewTodoClient(_m.config).QueryUser(_m) } // 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 (_m *Todo) Update() *TodoUpdateOne { return NewTodoClient(_m.config).UpdateOne(_m) } // 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 (_m *Todo) Unwrap() *Todo { _tx, ok := _m.config.driver.(*txDriver) if !ok { panic("ent: Todo is not a transactional entity") } _m.config.driver = _tx.drv return _m } // String implements the fmt.Stringer. func (_m *Todo) String() string { var builder strings.Builder builder.WriteString("Todo(") builder.WriteString(fmt.Sprintf("id=%v, ", _m.ID)) builder.WriteString("created_at=") builder.WriteString(_m.CreatedAt.Format(time.ANSIC)) builder.WriteString(", ") builder.WriteString("updated_at=") builder.WriteString(_m.UpdatedAt.Format(time.ANSIC)) builder.WriteString(", ") builder.WriteString("title=") builder.WriteString(_m.Title) builder.WriteString(", ") builder.WriteString("completed=") builder.WriteString(fmt.Sprintf("%v", _m.Completed)) builder.WriteByte(')') return builder.String() } // Todos is a parsable slice of Todo. type Todos []*Todo