123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719 |
- // Code generated by entc, DO NOT EDIT.
- package ent
- import (
- "context"
- "errors"
- "fmt"
- "todo/ent/predicate"
- "todo/ent/todo"
- "entgo.io/ent/dialect/sql"
- "entgo.io/ent/dialect/sql/sqlgraph"
- "entgo.io/ent/schema/field"
- )
- // TodoUpdate is the builder for updating Todo entities.
- type TodoUpdate struct {
- config
- hooks []Hook
- mutation *TodoMutation
- }
- // Where appends a list predicates to the TodoUpdate builder.
- func (tu *TodoUpdate) Where(ps ...predicate.Todo) *TodoUpdate {
- tu.mutation.Where(ps...)
- return tu
- }
- // SetText sets the "text" field.
- func (tu *TodoUpdate) SetText(s string) *TodoUpdate {
- tu.mutation.SetText(s)
- return tu
- }
- // SetStatus sets the "status" field.
- func (tu *TodoUpdate) SetStatus(t todo.Status) *TodoUpdate {
- tu.mutation.SetStatus(t)
- return tu
- }
- // SetNillableStatus sets the "status" field if the given value is not nil.
- func (tu *TodoUpdate) SetNillableStatus(t *todo.Status) *TodoUpdate {
- if t != nil {
- tu.SetStatus(*t)
- }
- return tu
- }
- // SetPriority sets the "priority" field.
- func (tu *TodoUpdate) SetPriority(i int) *TodoUpdate {
- tu.mutation.ResetPriority()
- tu.mutation.SetPriority(i)
- return tu
- }
- // SetNillablePriority sets the "priority" field if the given value is not nil.
- func (tu *TodoUpdate) SetNillablePriority(i *int) *TodoUpdate {
- if i != nil {
- tu.SetPriority(*i)
- }
- return tu
- }
- // AddPriority adds i to the "priority" field.
- func (tu *TodoUpdate) AddPriority(i int) *TodoUpdate {
- tu.mutation.AddPriority(i)
- return tu
- }
- // AddChildIDs adds the "children" edge to the Todo entity by IDs.
- func (tu *TodoUpdate) AddChildIDs(ids ...int) *TodoUpdate {
- tu.mutation.AddChildIDs(ids...)
- return tu
- }
- // AddChildren adds the "children" edges to the Todo entity.
- func (tu *TodoUpdate) AddChildren(t ...*Todo) *TodoUpdate {
- ids := make([]int, len(t))
- for i := range t {
- ids[i] = t[i].ID
- }
- return tu.AddChildIDs(ids...)
- }
- // SetParentID sets the "parent" edge to the Todo entity by ID.
- func (tu *TodoUpdate) SetParentID(id int) *TodoUpdate {
- tu.mutation.SetParentID(id)
- return tu
- }
- // SetNillableParentID sets the "parent" edge to the Todo entity by ID if the given value is not nil.
- func (tu *TodoUpdate) SetNillableParentID(id *int) *TodoUpdate {
- if id != nil {
- tu = tu.SetParentID(*id)
- }
- return tu
- }
- // SetParent sets the "parent" edge to the Todo entity.
- func (tu *TodoUpdate) SetParent(t *Todo) *TodoUpdate {
- return tu.SetParentID(t.ID)
- }
- // Mutation returns the TodoMutation object of the builder.
- func (tu *TodoUpdate) Mutation() *TodoMutation {
- return tu.mutation
- }
- // ClearChildren clears all "children" edges to the Todo entity.
- func (tu *TodoUpdate) ClearChildren() *TodoUpdate {
- tu.mutation.ClearChildren()
- return tu
- }
- // RemoveChildIDs removes the "children" edge to Todo entities by IDs.
- func (tu *TodoUpdate) RemoveChildIDs(ids ...int) *TodoUpdate {
- tu.mutation.RemoveChildIDs(ids...)
- return tu
- }
- // RemoveChildren removes "children" edges to Todo entities.
- func (tu *TodoUpdate) RemoveChildren(t ...*Todo) *TodoUpdate {
- ids := make([]int, len(t))
- for i := range t {
- ids[i] = t[i].ID
- }
- return tu.RemoveChildIDs(ids...)
- }
- // ClearParent clears the "parent" edge to the Todo entity.
- func (tu *TodoUpdate) ClearParent() *TodoUpdate {
- tu.mutation.ClearParent()
- return tu
- }
- // Save executes the query and returns the number of nodes affected by the update operation.
- func (tu *TodoUpdate) Save(ctx context.Context) (int, error) {
- var (
- err error
- affected int
- )
- if len(tu.hooks) == 0 {
- if err = tu.check(); err != nil {
- return 0, err
- }
- affected, err = tu.sqlSave(ctx)
- } else {
- var mut Mutator = MutateFunc(func(ctx context.Context, m Mutation) (Value, error) {
- mutation, ok := m.(*TodoMutation)
- if !ok {
- return nil, fmt.Errorf("unexpected mutation type %T", m)
- }
- if err = tu.check(); err != nil {
- return 0, err
- }
- tu.mutation = mutation
- affected, err = tu.sqlSave(ctx)
- mutation.done = true
- return affected, err
- })
- for i := len(tu.hooks) - 1; i >= 0; i-- {
- if tu.hooks[i] == nil {
- return 0, fmt.Errorf("ent: uninitialized hook (forgotten import ent/runtime?)")
- }
- mut = tu.hooks[i](mut)
- }
- if _, err := mut.Mutate(ctx, tu.mutation); err != nil {
- return 0, err
- }
- }
- return affected, err
- }
- // SaveX is like Save, but panics if an error occurs.
- func (tu *TodoUpdate) SaveX(ctx context.Context) int {
- affected, err := tu.Save(ctx)
- if err != nil {
- panic(err)
- }
- return affected
- }
- // Exec executes the query.
- func (tu *TodoUpdate) Exec(ctx context.Context) error {
- _, err := tu.Save(ctx)
- return err
- }
- // ExecX is like Exec, but panics if an error occurs.
- func (tu *TodoUpdate) ExecX(ctx context.Context) {
- if err := tu.Exec(ctx); err != nil {
- panic(err)
- }
- }
- // check runs all checks and user-defined validators on the builder.
- func (tu *TodoUpdate) check() error {
- if v, ok := tu.mutation.Text(); ok {
- if err := todo.TextValidator(v); err != nil {
- return &ValidationError{Name: "text", err: fmt.Errorf(`ent: validator failed for field "Todo.text": %w`, err)}
- }
- }
- if v, ok := tu.mutation.Status(); ok {
- if err := todo.StatusValidator(v); err != nil {
- return &ValidationError{Name: "status", err: fmt.Errorf(`ent: validator failed for field "Todo.status": %w`, err)}
- }
- }
- return nil
- }
- func (tu *TodoUpdate) sqlSave(ctx context.Context) (n int, err error) {
- _spec := &sqlgraph.UpdateSpec{
- Node: &sqlgraph.NodeSpec{
- Table: todo.Table,
- Columns: todo.Columns,
- ID: &sqlgraph.FieldSpec{
- Type: field.TypeInt,
- Column: todo.FieldID,
- },
- },
- }
- if ps := tu.mutation.predicates; len(ps) > 0 {
- _spec.Predicate = func(selector *sql.Selector) {
- for i := range ps {
- ps[i](selector)
- }
- }
- }
- if value, ok := tu.mutation.Text(); ok {
- _spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{
- Type: field.TypeString,
- Value: value,
- Column: todo.FieldText,
- })
- }
- if value, ok := tu.mutation.Status(); ok {
- _spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{
- Type: field.TypeEnum,
- Value: value,
- Column: todo.FieldStatus,
- })
- }
- if value, ok := tu.mutation.Priority(); ok {
- _spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{
- Type: field.TypeInt,
- Value: value,
- Column: todo.FieldPriority,
- })
- }
- if value, ok := tu.mutation.AddedPriority(); ok {
- _spec.Fields.Add = append(_spec.Fields.Add, &sqlgraph.FieldSpec{
- Type: field.TypeInt,
- Value: value,
- Column: todo.FieldPriority,
- })
- }
- if tu.mutation.ChildrenCleared() {
- edge := &sqlgraph.EdgeSpec{
- Rel: sqlgraph.O2M,
- Inverse: true,
- Table: todo.ChildrenTable,
- Columns: []string{todo.ChildrenColumn},
- Bidi: false,
- Target: &sqlgraph.EdgeTarget{
- IDSpec: &sqlgraph.FieldSpec{
- Type: field.TypeInt,
- Column: todo.FieldID,
- },
- },
- }
- _spec.Edges.Clear = append(_spec.Edges.Clear, edge)
- }
- if nodes := tu.mutation.RemovedChildrenIDs(); len(nodes) > 0 && !tu.mutation.ChildrenCleared() {
- edge := &sqlgraph.EdgeSpec{
- Rel: sqlgraph.O2M,
- Inverse: true,
- Table: todo.ChildrenTable,
- Columns: []string{todo.ChildrenColumn},
- Bidi: false,
- Target: &sqlgraph.EdgeTarget{
- IDSpec: &sqlgraph.FieldSpec{
- Type: field.TypeInt,
- Column: todo.FieldID,
- },
- },
- }
- for _, k := range nodes {
- edge.Target.Nodes = append(edge.Target.Nodes, k)
- }
- _spec.Edges.Clear = append(_spec.Edges.Clear, edge)
- }
- if nodes := tu.mutation.ChildrenIDs(); len(nodes) > 0 {
- edge := &sqlgraph.EdgeSpec{
- Rel: sqlgraph.O2M,
- Inverse: true,
- Table: todo.ChildrenTable,
- Columns: []string{todo.ChildrenColumn},
- Bidi: false,
- Target: &sqlgraph.EdgeTarget{
- IDSpec: &sqlgraph.FieldSpec{
- Type: field.TypeInt,
- Column: todo.FieldID,
- },
- },
- }
- for _, k := range nodes {
- edge.Target.Nodes = append(edge.Target.Nodes, k)
- }
- _spec.Edges.Add = append(_spec.Edges.Add, edge)
- }
- if tu.mutation.ParentCleared() {
- edge := &sqlgraph.EdgeSpec{
- Rel: sqlgraph.M2O,
- Inverse: false,
- Table: todo.ParentTable,
- Columns: []string{todo.ParentColumn},
- Bidi: false,
- Target: &sqlgraph.EdgeTarget{
- IDSpec: &sqlgraph.FieldSpec{
- Type: field.TypeInt,
- Column: todo.FieldID,
- },
- },
- }
- _spec.Edges.Clear = append(_spec.Edges.Clear, edge)
- }
- if nodes := tu.mutation.ParentIDs(); len(nodes) > 0 {
- edge := &sqlgraph.EdgeSpec{
- Rel: sqlgraph.M2O,
- Inverse: false,
- Table: todo.ParentTable,
- Columns: []string{todo.ParentColumn},
- Bidi: false,
- Target: &sqlgraph.EdgeTarget{
- IDSpec: &sqlgraph.FieldSpec{
- Type: field.TypeInt,
- Column: todo.FieldID,
- },
- },
- }
- for _, k := range nodes {
- edge.Target.Nodes = append(edge.Target.Nodes, k)
- }
- _spec.Edges.Add = append(_spec.Edges.Add, edge)
- }
- if n, err = sqlgraph.UpdateNodes(ctx, tu.driver, _spec); err != nil {
- if _, ok := err.(*sqlgraph.NotFoundError); ok {
- err = &NotFoundError{todo.Label}
- } else if sqlgraph.IsConstraintError(err) {
- err = &ConstraintError{err.Error(), err}
- }
- return 0, err
- }
- return n, nil
- }
- // TodoUpdateOne is the builder for updating a single Todo entity.
- type TodoUpdateOne struct {
- config
- fields []string
- hooks []Hook
- mutation *TodoMutation
- }
- // SetText sets the "text" field.
- func (tuo *TodoUpdateOne) SetText(s string) *TodoUpdateOne {
- tuo.mutation.SetText(s)
- return tuo
- }
- // SetStatus sets the "status" field.
- func (tuo *TodoUpdateOne) SetStatus(t todo.Status) *TodoUpdateOne {
- tuo.mutation.SetStatus(t)
- return tuo
- }
- // SetNillableStatus sets the "status" field if the given value is not nil.
- func (tuo *TodoUpdateOne) SetNillableStatus(t *todo.Status) *TodoUpdateOne {
- if t != nil {
- tuo.SetStatus(*t)
- }
- return tuo
- }
- // SetPriority sets the "priority" field.
- func (tuo *TodoUpdateOne) SetPriority(i int) *TodoUpdateOne {
- tuo.mutation.ResetPriority()
- tuo.mutation.SetPriority(i)
- return tuo
- }
- // SetNillablePriority sets the "priority" field if the given value is not nil.
- func (tuo *TodoUpdateOne) SetNillablePriority(i *int) *TodoUpdateOne {
- if i != nil {
- tuo.SetPriority(*i)
- }
- return tuo
- }
- // AddPriority adds i to the "priority" field.
- func (tuo *TodoUpdateOne) AddPriority(i int) *TodoUpdateOne {
- tuo.mutation.AddPriority(i)
- return tuo
- }
- // AddChildIDs adds the "children" edge to the Todo entity by IDs.
- func (tuo *TodoUpdateOne) AddChildIDs(ids ...int) *TodoUpdateOne {
- tuo.mutation.AddChildIDs(ids...)
- return tuo
- }
- // AddChildren adds the "children" edges to the Todo entity.
- func (tuo *TodoUpdateOne) AddChildren(t ...*Todo) *TodoUpdateOne {
- ids := make([]int, len(t))
- for i := range t {
- ids[i] = t[i].ID
- }
- return tuo.AddChildIDs(ids...)
- }
- // SetParentID sets the "parent" edge to the Todo entity by ID.
- func (tuo *TodoUpdateOne) SetParentID(id int) *TodoUpdateOne {
- tuo.mutation.SetParentID(id)
- return tuo
- }
- // SetNillableParentID sets the "parent" edge to the Todo entity by ID if the given value is not nil.
- func (tuo *TodoUpdateOne) SetNillableParentID(id *int) *TodoUpdateOne {
- if id != nil {
- tuo = tuo.SetParentID(*id)
- }
- return tuo
- }
- // SetParent sets the "parent" edge to the Todo entity.
- func (tuo *TodoUpdateOne) SetParent(t *Todo) *TodoUpdateOne {
- return tuo.SetParentID(t.ID)
- }
- // Mutation returns the TodoMutation object of the builder.
- func (tuo *TodoUpdateOne) Mutation() *TodoMutation {
- return tuo.mutation
- }
- // ClearChildren clears all "children" edges to the Todo entity.
- func (tuo *TodoUpdateOne) ClearChildren() *TodoUpdateOne {
- tuo.mutation.ClearChildren()
- return tuo
- }
- // RemoveChildIDs removes the "children" edge to Todo entities by IDs.
- func (tuo *TodoUpdateOne) RemoveChildIDs(ids ...int) *TodoUpdateOne {
- tuo.mutation.RemoveChildIDs(ids...)
- return tuo
- }
- // RemoveChildren removes "children" edges to Todo entities.
- func (tuo *TodoUpdateOne) RemoveChildren(t ...*Todo) *TodoUpdateOne {
- ids := make([]int, len(t))
- for i := range t {
- ids[i] = t[i].ID
- }
- return tuo.RemoveChildIDs(ids...)
- }
- // ClearParent clears the "parent" edge to the Todo entity.
- func (tuo *TodoUpdateOne) ClearParent() *TodoUpdateOne {
- tuo.mutation.ClearParent()
- return tuo
- }
- // Select allows selecting one or more fields (columns) of the returned entity.
- // The default is selecting all fields defined in the entity schema.
- func (tuo *TodoUpdateOne) Select(field string, fields ...string) *TodoUpdateOne {
- tuo.fields = append([]string{field}, fields...)
- return tuo
- }
- // Save executes the query and returns the updated Todo entity.
- func (tuo *TodoUpdateOne) Save(ctx context.Context) (*Todo, error) {
- var (
- err error
- node *Todo
- )
- if len(tuo.hooks) == 0 {
- if err = tuo.check(); err != nil {
- return nil, err
- }
- node, err = tuo.sqlSave(ctx)
- } else {
- var mut Mutator = MutateFunc(func(ctx context.Context, m Mutation) (Value, error) {
- mutation, ok := m.(*TodoMutation)
- if !ok {
- return nil, fmt.Errorf("unexpected mutation type %T", m)
- }
- if err = tuo.check(); err != nil {
- return nil, err
- }
- tuo.mutation = mutation
- node, err = tuo.sqlSave(ctx)
- mutation.done = true
- return node, err
- })
- for i := len(tuo.hooks) - 1; i >= 0; i-- {
- if tuo.hooks[i] == nil {
- return nil, fmt.Errorf("ent: uninitialized hook (forgotten import ent/runtime?)")
- }
- mut = tuo.hooks[i](mut)
- }
- if _, err := mut.Mutate(ctx, tuo.mutation); err != nil {
- return nil, err
- }
- }
- return node, err
- }
- // SaveX is like Save, but panics if an error occurs.
- func (tuo *TodoUpdateOne) SaveX(ctx context.Context) *Todo {
- node, err := tuo.Save(ctx)
- if err != nil {
- panic(err)
- }
- return node
- }
- // Exec executes the query on the entity.
- func (tuo *TodoUpdateOne) Exec(ctx context.Context) error {
- _, err := tuo.Save(ctx)
- return err
- }
- // ExecX is like Exec, but panics if an error occurs.
- func (tuo *TodoUpdateOne) ExecX(ctx context.Context) {
- if err := tuo.Exec(ctx); err != nil {
- panic(err)
- }
- }
- // check runs all checks and user-defined validators on the builder.
- func (tuo *TodoUpdateOne) check() error {
- if v, ok := tuo.mutation.Text(); ok {
- if err := todo.TextValidator(v); err != nil {
- return &ValidationError{Name: "text", err: fmt.Errorf(`ent: validator failed for field "Todo.text": %w`, err)}
- }
- }
- if v, ok := tuo.mutation.Status(); ok {
- if err := todo.StatusValidator(v); err != nil {
- return &ValidationError{Name: "status", err: fmt.Errorf(`ent: validator failed for field "Todo.status": %w`, err)}
- }
- }
- return nil
- }
- func (tuo *TodoUpdateOne) sqlSave(ctx context.Context) (_node *Todo, err error) {
- _spec := &sqlgraph.UpdateSpec{
- Node: &sqlgraph.NodeSpec{
- Table: todo.Table,
- Columns: todo.Columns,
- ID: &sqlgraph.FieldSpec{
- Type: field.TypeInt,
- Column: todo.FieldID,
- },
- },
- }
- id, ok := tuo.mutation.ID()
- if !ok {
- return nil, &ValidationError{Name: "id", err: errors.New(`ent: missing "Todo.id" for update`)}
- }
- _spec.Node.ID.Value = id
- if fields := tuo.fields; len(fields) > 0 {
- _spec.Node.Columns = make([]string, 0, len(fields))
- _spec.Node.Columns = append(_spec.Node.Columns, todo.FieldID)
- for _, f := range fields {
- if !todo.ValidColumn(f) {
- return nil, &ValidationError{Name: f, err: fmt.Errorf("ent: invalid field %q for query", f)}
- }
- if f != todo.FieldID {
- _spec.Node.Columns = append(_spec.Node.Columns, f)
- }
- }
- }
- if ps := tuo.mutation.predicates; len(ps) > 0 {
- _spec.Predicate = func(selector *sql.Selector) {
- for i := range ps {
- ps[i](selector)
- }
- }
- }
- if value, ok := tuo.mutation.Text(); ok {
- _spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{
- Type: field.TypeString,
- Value: value,
- Column: todo.FieldText,
- })
- }
- if value, ok := tuo.mutation.Status(); ok {
- _spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{
- Type: field.TypeEnum,
- Value: value,
- Column: todo.FieldStatus,
- })
- }
- if value, ok := tuo.mutation.Priority(); ok {
- _spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{
- Type: field.TypeInt,
- Value: value,
- Column: todo.FieldPriority,
- })
- }
- if value, ok := tuo.mutation.AddedPriority(); ok {
- _spec.Fields.Add = append(_spec.Fields.Add, &sqlgraph.FieldSpec{
- Type: field.TypeInt,
- Value: value,
- Column: todo.FieldPriority,
- })
- }
- if tuo.mutation.ChildrenCleared() {
- edge := &sqlgraph.EdgeSpec{
- Rel: sqlgraph.O2M,
- Inverse: true,
- Table: todo.ChildrenTable,
- Columns: []string{todo.ChildrenColumn},
- Bidi: false,
- Target: &sqlgraph.EdgeTarget{
- IDSpec: &sqlgraph.FieldSpec{
- Type: field.TypeInt,
- Column: todo.FieldID,
- },
- },
- }
- _spec.Edges.Clear = append(_spec.Edges.Clear, edge)
- }
- if nodes := tuo.mutation.RemovedChildrenIDs(); len(nodes) > 0 && !tuo.mutation.ChildrenCleared() {
- edge := &sqlgraph.EdgeSpec{
- Rel: sqlgraph.O2M,
- Inverse: true,
- Table: todo.ChildrenTable,
- Columns: []string{todo.ChildrenColumn},
- Bidi: false,
- Target: &sqlgraph.EdgeTarget{
- IDSpec: &sqlgraph.FieldSpec{
- Type: field.TypeInt,
- Column: todo.FieldID,
- },
- },
- }
- for _, k := range nodes {
- edge.Target.Nodes = append(edge.Target.Nodes, k)
- }
- _spec.Edges.Clear = append(_spec.Edges.Clear, edge)
- }
- if nodes := tuo.mutation.ChildrenIDs(); len(nodes) > 0 {
- edge := &sqlgraph.EdgeSpec{
- Rel: sqlgraph.O2M,
- Inverse: true,
- Table: todo.ChildrenTable,
- Columns: []string{todo.ChildrenColumn},
- Bidi: false,
- Target: &sqlgraph.EdgeTarget{
- IDSpec: &sqlgraph.FieldSpec{
- Type: field.TypeInt,
- Column: todo.FieldID,
- },
- },
- }
- for _, k := range nodes {
- edge.Target.Nodes = append(edge.Target.Nodes, k)
- }
- _spec.Edges.Add = append(_spec.Edges.Add, edge)
- }
- if tuo.mutation.ParentCleared() {
- edge := &sqlgraph.EdgeSpec{
- Rel: sqlgraph.M2O,
- Inverse: false,
- Table: todo.ParentTable,
- Columns: []string{todo.ParentColumn},
- Bidi: false,
- Target: &sqlgraph.EdgeTarget{
- IDSpec: &sqlgraph.FieldSpec{
- Type: field.TypeInt,
- Column: todo.FieldID,
- },
- },
- }
- _spec.Edges.Clear = append(_spec.Edges.Clear, edge)
- }
- if nodes := tuo.mutation.ParentIDs(); len(nodes) > 0 {
- edge := &sqlgraph.EdgeSpec{
- Rel: sqlgraph.M2O,
- Inverse: false,
- Table: todo.ParentTable,
- Columns: []string{todo.ParentColumn},
- Bidi: false,
- Target: &sqlgraph.EdgeTarget{
- IDSpec: &sqlgraph.FieldSpec{
- Type: field.TypeInt,
- Column: todo.FieldID,
- },
- },
- }
- for _, k := range nodes {
- edge.Target.Nodes = append(edge.Target.Nodes, k)
- }
- _spec.Edges.Add = append(_spec.Edges.Add, edge)
- }
- _node = &Todo{config: tuo.config}
- _spec.Assign = _node.assignValues
- _spec.ScanValues = _node.scanValues
- if err = sqlgraph.UpdateNode(ctx, tuo.driver, _spec); err != nil {
- if _, ok := err.(*sqlgraph.NotFoundError); ok {
- err = &NotFoundError{todo.Label}
- } else if sqlgraph.IsConstraintError(err) {
- err = &ConstraintError{err.Error(), err}
- }
- return nil, err
- }
- return _node, nil
- }
|