todo_update.go 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719
  1. // Code generated by entc, DO NOT EDIT.
  2. package ent
  3. import (
  4. "context"
  5. "errors"
  6. "fmt"
  7. "todo/ent/predicate"
  8. "todo/ent/todo"
  9. "entgo.io/ent/dialect/sql"
  10. "entgo.io/ent/dialect/sql/sqlgraph"
  11. "entgo.io/ent/schema/field"
  12. )
  13. // TodoUpdate is the builder for updating Todo entities.
  14. type TodoUpdate struct {
  15. config
  16. hooks []Hook
  17. mutation *TodoMutation
  18. }
  19. // Where appends a list predicates to the TodoUpdate builder.
  20. func (tu *TodoUpdate) Where(ps ...predicate.Todo) *TodoUpdate {
  21. tu.mutation.Where(ps...)
  22. return tu
  23. }
  24. // SetText sets the "text" field.
  25. func (tu *TodoUpdate) SetText(s string) *TodoUpdate {
  26. tu.mutation.SetText(s)
  27. return tu
  28. }
  29. // SetStatus sets the "status" field.
  30. func (tu *TodoUpdate) SetStatus(t todo.Status) *TodoUpdate {
  31. tu.mutation.SetStatus(t)
  32. return tu
  33. }
  34. // SetNillableStatus sets the "status" field if the given value is not nil.
  35. func (tu *TodoUpdate) SetNillableStatus(t *todo.Status) *TodoUpdate {
  36. if t != nil {
  37. tu.SetStatus(*t)
  38. }
  39. return tu
  40. }
  41. // SetPriority sets the "priority" field.
  42. func (tu *TodoUpdate) SetPriority(i int) *TodoUpdate {
  43. tu.mutation.ResetPriority()
  44. tu.mutation.SetPriority(i)
  45. return tu
  46. }
  47. // SetNillablePriority sets the "priority" field if the given value is not nil.
  48. func (tu *TodoUpdate) SetNillablePriority(i *int) *TodoUpdate {
  49. if i != nil {
  50. tu.SetPriority(*i)
  51. }
  52. return tu
  53. }
  54. // AddPriority adds i to the "priority" field.
  55. func (tu *TodoUpdate) AddPriority(i int) *TodoUpdate {
  56. tu.mutation.AddPriority(i)
  57. return tu
  58. }
  59. // AddChildIDs adds the "children" edge to the Todo entity by IDs.
  60. func (tu *TodoUpdate) AddChildIDs(ids ...int) *TodoUpdate {
  61. tu.mutation.AddChildIDs(ids...)
  62. return tu
  63. }
  64. // AddChildren adds the "children" edges to the Todo entity.
  65. func (tu *TodoUpdate) AddChildren(t ...*Todo) *TodoUpdate {
  66. ids := make([]int, len(t))
  67. for i := range t {
  68. ids[i] = t[i].ID
  69. }
  70. return tu.AddChildIDs(ids...)
  71. }
  72. // SetParentID sets the "parent" edge to the Todo entity by ID.
  73. func (tu *TodoUpdate) SetParentID(id int) *TodoUpdate {
  74. tu.mutation.SetParentID(id)
  75. return tu
  76. }
  77. // SetNillableParentID sets the "parent" edge to the Todo entity by ID if the given value is not nil.
  78. func (tu *TodoUpdate) SetNillableParentID(id *int) *TodoUpdate {
  79. if id != nil {
  80. tu = tu.SetParentID(*id)
  81. }
  82. return tu
  83. }
  84. // SetParent sets the "parent" edge to the Todo entity.
  85. func (tu *TodoUpdate) SetParent(t *Todo) *TodoUpdate {
  86. return tu.SetParentID(t.ID)
  87. }
  88. // Mutation returns the TodoMutation object of the builder.
  89. func (tu *TodoUpdate) Mutation() *TodoMutation {
  90. return tu.mutation
  91. }
  92. // ClearChildren clears all "children" edges to the Todo entity.
  93. func (tu *TodoUpdate) ClearChildren() *TodoUpdate {
  94. tu.mutation.ClearChildren()
  95. return tu
  96. }
  97. // RemoveChildIDs removes the "children" edge to Todo entities by IDs.
  98. func (tu *TodoUpdate) RemoveChildIDs(ids ...int) *TodoUpdate {
  99. tu.mutation.RemoveChildIDs(ids...)
  100. return tu
  101. }
  102. // RemoveChildren removes "children" edges to Todo entities.
  103. func (tu *TodoUpdate) RemoveChildren(t ...*Todo) *TodoUpdate {
  104. ids := make([]int, len(t))
  105. for i := range t {
  106. ids[i] = t[i].ID
  107. }
  108. return tu.RemoveChildIDs(ids...)
  109. }
  110. // ClearParent clears the "parent" edge to the Todo entity.
  111. func (tu *TodoUpdate) ClearParent() *TodoUpdate {
  112. tu.mutation.ClearParent()
  113. return tu
  114. }
  115. // Save executes the query and returns the number of nodes affected by the update operation.
  116. func (tu *TodoUpdate) Save(ctx context.Context) (int, error) {
  117. var (
  118. err error
  119. affected int
  120. )
  121. if len(tu.hooks) == 0 {
  122. if err = tu.check(); err != nil {
  123. return 0, err
  124. }
  125. affected, err = tu.sqlSave(ctx)
  126. } else {
  127. var mut Mutator = MutateFunc(func(ctx context.Context, m Mutation) (Value, error) {
  128. mutation, ok := m.(*TodoMutation)
  129. if !ok {
  130. return nil, fmt.Errorf("unexpected mutation type %T", m)
  131. }
  132. if err = tu.check(); err != nil {
  133. return 0, err
  134. }
  135. tu.mutation = mutation
  136. affected, err = tu.sqlSave(ctx)
  137. mutation.done = true
  138. return affected, err
  139. })
  140. for i := len(tu.hooks) - 1; i >= 0; i-- {
  141. if tu.hooks[i] == nil {
  142. return 0, fmt.Errorf("ent: uninitialized hook (forgotten import ent/runtime?)")
  143. }
  144. mut = tu.hooks[i](mut)
  145. }
  146. if _, err := mut.Mutate(ctx, tu.mutation); err != nil {
  147. return 0, err
  148. }
  149. }
  150. return affected, err
  151. }
  152. // SaveX is like Save, but panics if an error occurs.
  153. func (tu *TodoUpdate) SaveX(ctx context.Context) int {
  154. affected, err := tu.Save(ctx)
  155. if err != nil {
  156. panic(err)
  157. }
  158. return affected
  159. }
  160. // Exec executes the query.
  161. func (tu *TodoUpdate) Exec(ctx context.Context) error {
  162. _, err := tu.Save(ctx)
  163. return err
  164. }
  165. // ExecX is like Exec, but panics if an error occurs.
  166. func (tu *TodoUpdate) ExecX(ctx context.Context) {
  167. if err := tu.Exec(ctx); err != nil {
  168. panic(err)
  169. }
  170. }
  171. // check runs all checks and user-defined validators on the builder.
  172. func (tu *TodoUpdate) check() error {
  173. if v, ok := tu.mutation.Text(); ok {
  174. if err := todo.TextValidator(v); err != nil {
  175. return &ValidationError{Name: "text", err: fmt.Errorf(`ent: validator failed for field "Todo.text": %w`, err)}
  176. }
  177. }
  178. if v, ok := tu.mutation.Status(); ok {
  179. if err := todo.StatusValidator(v); err != nil {
  180. return &ValidationError{Name: "status", err: fmt.Errorf(`ent: validator failed for field "Todo.status": %w`, err)}
  181. }
  182. }
  183. return nil
  184. }
  185. func (tu *TodoUpdate) sqlSave(ctx context.Context) (n int, err error) {
  186. _spec := &sqlgraph.UpdateSpec{
  187. Node: &sqlgraph.NodeSpec{
  188. Table: todo.Table,
  189. Columns: todo.Columns,
  190. ID: &sqlgraph.FieldSpec{
  191. Type: field.TypeInt,
  192. Column: todo.FieldID,
  193. },
  194. },
  195. }
  196. if ps := tu.mutation.predicates; len(ps) > 0 {
  197. _spec.Predicate = func(selector *sql.Selector) {
  198. for i := range ps {
  199. ps[i](selector)
  200. }
  201. }
  202. }
  203. if value, ok := tu.mutation.Text(); ok {
  204. _spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{
  205. Type: field.TypeString,
  206. Value: value,
  207. Column: todo.FieldText,
  208. })
  209. }
  210. if value, ok := tu.mutation.Status(); ok {
  211. _spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{
  212. Type: field.TypeEnum,
  213. Value: value,
  214. Column: todo.FieldStatus,
  215. })
  216. }
  217. if value, ok := tu.mutation.Priority(); ok {
  218. _spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{
  219. Type: field.TypeInt,
  220. Value: value,
  221. Column: todo.FieldPriority,
  222. })
  223. }
  224. if value, ok := tu.mutation.AddedPriority(); ok {
  225. _spec.Fields.Add = append(_spec.Fields.Add, &sqlgraph.FieldSpec{
  226. Type: field.TypeInt,
  227. Value: value,
  228. Column: todo.FieldPriority,
  229. })
  230. }
  231. if tu.mutation.ChildrenCleared() {
  232. edge := &sqlgraph.EdgeSpec{
  233. Rel: sqlgraph.O2M,
  234. Inverse: true,
  235. Table: todo.ChildrenTable,
  236. Columns: []string{todo.ChildrenColumn},
  237. Bidi: false,
  238. Target: &sqlgraph.EdgeTarget{
  239. IDSpec: &sqlgraph.FieldSpec{
  240. Type: field.TypeInt,
  241. Column: todo.FieldID,
  242. },
  243. },
  244. }
  245. _spec.Edges.Clear = append(_spec.Edges.Clear, edge)
  246. }
  247. if nodes := tu.mutation.RemovedChildrenIDs(); len(nodes) > 0 && !tu.mutation.ChildrenCleared() {
  248. edge := &sqlgraph.EdgeSpec{
  249. Rel: sqlgraph.O2M,
  250. Inverse: true,
  251. Table: todo.ChildrenTable,
  252. Columns: []string{todo.ChildrenColumn},
  253. Bidi: false,
  254. Target: &sqlgraph.EdgeTarget{
  255. IDSpec: &sqlgraph.FieldSpec{
  256. Type: field.TypeInt,
  257. Column: todo.FieldID,
  258. },
  259. },
  260. }
  261. for _, k := range nodes {
  262. edge.Target.Nodes = append(edge.Target.Nodes, k)
  263. }
  264. _spec.Edges.Clear = append(_spec.Edges.Clear, edge)
  265. }
  266. if nodes := tu.mutation.ChildrenIDs(); len(nodes) > 0 {
  267. edge := &sqlgraph.EdgeSpec{
  268. Rel: sqlgraph.O2M,
  269. Inverse: true,
  270. Table: todo.ChildrenTable,
  271. Columns: []string{todo.ChildrenColumn},
  272. Bidi: false,
  273. Target: &sqlgraph.EdgeTarget{
  274. IDSpec: &sqlgraph.FieldSpec{
  275. Type: field.TypeInt,
  276. Column: todo.FieldID,
  277. },
  278. },
  279. }
  280. for _, k := range nodes {
  281. edge.Target.Nodes = append(edge.Target.Nodes, k)
  282. }
  283. _spec.Edges.Add = append(_spec.Edges.Add, edge)
  284. }
  285. if tu.mutation.ParentCleared() {
  286. edge := &sqlgraph.EdgeSpec{
  287. Rel: sqlgraph.M2O,
  288. Inverse: false,
  289. Table: todo.ParentTable,
  290. Columns: []string{todo.ParentColumn},
  291. Bidi: false,
  292. Target: &sqlgraph.EdgeTarget{
  293. IDSpec: &sqlgraph.FieldSpec{
  294. Type: field.TypeInt,
  295. Column: todo.FieldID,
  296. },
  297. },
  298. }
  299. _spec.Edges.Clear = append(_spec.Edges.Clear, edge)
  300. }
  301. if nodes := tu.mutation.ParentIDs(); len(nodes) > 0 {
  302. edge := &sqlgraph.EdgeSpec{
  303. Rel: sqlgraph.M2O,
  304. Inverse: false,
  305. Table: todo.ParentTable,
  306. Columns: []string{todo.ParentColumn},
  307. Bidi: false,
  308. Target: &sqlgraph.EdgeTarget{
  309. IDSpec: &sqlgraph.FieldSpec{
  310. Type: field.TypeInt,
  311. Column: todo.FieldID,
  312. },
  313. },
  314. }
  315. for _, k := range nodes {
  316. edge.Target.Nodes = append(edge.Target.Nodes, k)
  317. }
  318. _spec.Edges.Add = append(_spec.Edges.Add, edge)
  319. }
  320. if n, err = sqlgraph.UpdateNodes(ctx, tu.driver, _spec); err != nil {
  321. if _, ok := err.(*sqlgraph.NotFoundError); ok {
  322. err = &NotFoundError{todo.Label}
  323. } else if sqlgraph.IsConstraintError(err) {
  324. err = &ConstraintError{err.Error(), err}
  325. }
  326. return 0, err
  327. }
  328. return n, nil
  329. }
  330. // TodoUpdateOne is the builder for updating a single Todo entity.
  331. type TodoUpdateOne struct {
  332. config
  333. fields []string
  334. hooks []Hook
  335. mutation *TodoMutation
  336. }
  337. // SetText sets the "text" field.
  338. func (tuo *TodoUpdateOne) SetText(s string) *TodoUpdateOne {
  339. tuo.mutation.SetText(s)
  340. return tuo
  341. }
  342. // SetStatus sets the "status" field.
  343. func (tuo *TodoUpdateOne) SetStatus(t todo.Status) *TodoUpdateOne {
  344. tuo.mutation.SetStatus(t)
  345. return tuo
  346. }
  347. // SetNillableStatus sets the "status" field if the given value is not nil.
  348. func (tuo *TodoUpdateOne) SetNillableStatus(t *todo.Status) *TodoUpdateOne {
  349. if t != nil {
  350. tuo.SetStatus(*t)
  351. }
  352. return tuo
  353. }
  354. // SetPriority sets the "priority" field.
  355. func (tuo *TodoUpdateOne) SetPriority(i int) *TodoUpdateOne {
  356. tuo.mutation.ResetPriority()
  357. tuo.mutation.SetPriority(i)
  358. return tuo
  359. }
  360. // SetNillablePriority sets the "priority" field if the given value is not nil.
  361. func (tuo *TodoUpdateOne) SetNillablePriority(i *int) *TodoUpdateOne {
  362. if i != nil {
  363. tuo.SetPriority(*i)
  364. }
  365. return tuo
  366. }
  367. // AddPriority adds i to the "priority" field.
  368. func (tuo *TodoUpdateOne) AddPriority(i int) *TodoUpdateOne {
  369. tuo.mutation.AddPriority(i)
  370. return tuo
  371. }
  372. // AddChildIDs adds the "children" edge to the Todo entity by IDs.
  373. func (tuo *TodoUpdateOne) AddChildIDs(ids ...int) *TodoUpdateOne {
  374. tuo.mutation.AddChildIDs(ids...)
  375. return tuo
  376. }
  377. // AddChildren adds the "children" edges to the Todo entity.
  378. func (tuo *TodoUpdateOne) AddChildren(t ...*Todo) *TodoUpdateOne {
  379. ids := make([]int, len(t))
  380. for i := range t {
  381. ids[i] = t[i].ID
  382. }
  383. return tuo.AddChildIDs(ids...)
  384. }
  385. // SetParentID sets the "parent" edge to the Todo entity by ID.
  386. func (tuo *TodoUpdateOne) SetParentID(id int) *TodoUpdateOne {
  387. tuo.mutation.SetParentID(id)
  388. return tuo
  389. }
  390. // SetNillableParentID sets the "parent" edge to the Todo entity by ID if the given value is not nil.
  391. func (tuo *TodoUpdateOne) SetNillableParentID(id *int) *TodoUpdateOne {
  392. if id != nil {
  393. tuo = tuo.SetParentID(*id)
  394. }
  395. return tuo
  396. }
  397. // SetParent sets the "parent" edge to the Todo entity.
  398. func (tuo *TodoUpdateOne) SetParent(t *Todo) *TodoUpdateOne {
  399. return tuo.SetParentID(t.ID)
  400. }
  401. // Mutation returns the TodoMutation object of the builder.
  402. func (tuo *TodoUpdateOne) Mutation() *TodoMutation {
  403. return tuo.mutation
  404. }
  405. // ClearChildren clears all "children" edges to the Todo entity.
  406. func (tuo *TodoUpdateOne) ClearChildren() *TodoUpdateOne {
  407. tuo.mutation.ClearChildren()
  408. return tuo
  409. }
  410. // RemoveChildIDs removes the "children" edge to Todo entities by IDs.
  411. func (tuo *TodoUpdateOne) RemoveChildIDs(ids ...int) *TodoUpdateOne {
  412. tuo.mutation.RemoveChildIDs(ids...)
  413. return tuo
  414. }
  415. // RemoveChildren removes "children" edges to Todo entities.
  416. func (tuo *TodoUpdateOne) RemoveChildren(t ...*Todo) *TodoUpdateOne {
  417. ids := make([]int, len(t))
  418. for i := range t {
  419. ids[i] = t[i].ID
  420. }
  421. return tuo.RemoveChildIDs(ids...)
  422. }
  423. // ClearParent clears the "parent" edge to the Todo entity.
  424. func (tuo *TodoUpdateOne) ClearParent() *TodoUpdateOne {
  425. tuo.mutation.ClearParent()
  426. return tuo
  427. }
  428. // Select allows selecting one or more fields (columns) of the returned entity.
  429. // The default is selecting all fields defined in the entity schema.
  430. func (tuo *TodoUpdateOne) Select(field string, fields ...string) *TodoUpdateOne {
  431. tuo.fields = append([]string{field}, fields...)
  432. return tuo
  433. }
  434. // Save executes the query and returns the updated Todo entity.
  435. func (tuo *TodoUpdateOne) Save(ctx context.Context) (*Todo, error) {
  436. var (
  437. err error
  438. node *Todo
  439. )
  440. if len(tuo.hooks) == 0 {
  441. if err = tuo.check(); err != nil {
  442. return nil, err
  443. }
  444. node, err = tuo.sqlSave(ctx)
  445. } else {
  446. var mut Mutator = MutateFunc(func(ctx context.Context, m Mutation) (Value, error) {
  447. mutation, ok := m.(*TodoMutation)
  448. if !ok {
  449. return nil, fmt.Errorf("unexpected mutation type %T", m)
  450. }
  451. if err = tuo.check(); err != nil {
  452. return nil, err
  453. }
  454. tuo.mutation = mutation
  455. node, err = tuo.sqlSave(ctx)
  456. mutation.done = true
  457. return node, err
  458. })
  459. for i := len(tuo.hooks) - 1; i >= 0; i-- {
  460. if tuo.hooks[i] == nil {
  461. return nil, fmt.Errorf("ent: uninitialized hook (forgotten import ent/runtime?)")
  462. }
  463. mut = tuo.hooks[i](mut)
  464. }
  465. if _, err := mut.Mutate(ctx, tuo.mutation); err != nil {
  466. return nil, err
  467. }
  468. }
  469. return node, err
  470. }
  471. // SaveX is like Save, but panics if an error occurs.
  472. func (tuo *TodoUpdateOne) SaveX(ctx context.Context) *Todo {
  473. node, err := tuo.Save(ctx)
  474. if err != nil {
  475. panic(err)
  476. }
  477. return node
  478. }
  479. // Exec executes the query on the entity.
  480. func (tuo *TodoUpdateOne) Exec(ctx context.Context) error {
  481. _, err := tuo.Save(ctx)
  482. return err
  483. }
  484. // ExecX is like Exec, but panics if an error occurs.
  485. func (tuo *TodoUpdateOne) ExecX(ctx context.Context) {
  486. if err := tuo.Exec(ctx); err != nil {
  487. panic(err)
  488. }
  489. }
  490. // check runs all checks and user-defined validators on the builder.
  491. func (tuo *TodoUpdateOne) check() error {
  492. if v, ok := tuo.mutation.Text(); ok {
  493. if err := todo.TextValidator(v); err != nil {
  494. return &ValidationError{Name: "text", err: fmt.Errorf(`ent: validator failed for field "Todo.text": %w`, err)}
  495. }
  496. }
  497. if v, ok := tuo.mutation.Status(); ok {
  498. if err := todo.StatusValidator(v); err != nil {
  499. return &ValidationError{Name: "status", err: fmt.Errorf(`ent: validator failed for field "Todo.status": %w`, err)}
  500. }
  501. }
  502. return nil
  503. }
  504. func (tuo *TodoUpdateOne) sqlSave(ctx context.Context) (_node *Todo, err error) {
  505. _spec := &sqlgraph.UpdateSpec{
  506. Node: &sqlgraph.NodeSpec{
  507. Table: todo.Table,
  508. Columns: todo.Columns,
  509. ID: &sqlgraph.FieldSpec{
  510. Type: field.TypeInt,
  511. Column: todo.FieldID,
  512. },
  513. },
  514. }
  515. id, ok := tuo.mutation.ID()
  516. if !ok {
  517. return nil, &ValidationError{Name: "id", err: errors.New(`ent: missing "Todo.id" for update`)}
  518. }
  519. _spec.Node.ID.Value = id
  520. if fields := tuo.fields; len(fields) > 0 {
  521. _spec.Node.Columns = make([]string, 0, len(fields))
  522. _spec.Node.Columns = append(_spec.Node.Columns, todo.FieldID)
  523. for _, f := range fields {
  524. if !todo.ValidColumn(f) {
  525. return nil, &ValidationError{Name: f, err: fmt.Errorf("ent: invalid field %q for query", f)}
  526. }
  527. if f != todo.FieldID {
  528. _spec.Node.Columns = append(_spec.Node.Columns, f)
  529. }
  530. }
  531. }
  532. if ps := tuo.mutation.predicates; len(ps) > 0 {
  533. _spec.Predicate = func(selector *sql.Selector) {
  534. for i := range ps {
  535. ps[i](selector)
  536. }
  537. }
  538. }
  539. if value, ok := tuo.mutation.Text(); ok {
  540. _spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{
  541. Type: field.TypeString,
  542. Value: value,
  543. Column: todo.FieldText,
  544. })
  545. }
  546. if value, ok := tuo.mutation.Status(); ok {
  547. _spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{
  548. Type: field.TypeEnum,
  549. Value: value,
  550. Column: todo.FieldStatus,
  551. })
  552. }
  553. if value, ok := tuo.mutation.Priority(); ok {
  554. _spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{
  555. Type: field.TypeInt,
  556. Value: value,
  557. Column: todo.FieldPriority,
  558. })
  559. }
  560. if value, ok := tuo.mutation.AddedPriority(); ok {
  561. _spec.Fields.Add = append(_spec.Fields.Add, &sqlgraph.FieldSpec{
  562. Type: field.TypeInt,
  563. Value: value,
  564. Column: todo.FieldPriority,
  565. })
  566. }
  567. if tuo.mutation.ChildrenCleared() {
  568. edge := &sqlgraph.EdgeSpec{
  569. Rel: sqlgraph.O2M,
  570. Inverse: true,
  571. Table: todo.ChildrenTable,
  572. Columns: []string{todo.ChildrenColumn},
  573. Bidi: false,
  574. Target: &sqlgraph.EdgeTarget{
  575. IDSpec: &sqlgraph.FieldSpec{
  576. Type: field.TypeInt,
  577. Column: todo.FieldID,
  578. },
  579. },
  580. }
  581. _spec.Edges.Clear = append(_spec.Edges.Clear, edge)
  582. }
  583. if nodes := tuo.mutation.RemovedChildrenIDs(); len(nodes) > 0 && !tuo.mutation.ChildrenCleared() {
  584. edge := &sqlgraph.EdgeSpec{
  585. Rel: sqlgraph.O2M,
  586. Inverse: true,
  587. Table: todo.ChildrenTable,
  588. Columns: []string{todo.ChildrenColumn},
  589. Bidi: false,
  590. Target: &sqlgraph.EdgeTarget{
  591. IDSpec: &sqlgraph.FieldSpec{
  592. Type: field.TypeInt,
  593. Column: todo.FieldID,
  594. },
  595. },
  596. }
  597. for _, k := range nodes {
  598. edge.Target.Nodes = append(edge.Target.Nodes, k)
  599. }
  600. _spec.Edges.Clear = append(_spec.Edges.Clear, edge)
  601. }
  602. if nodes := tuo.mutation.ChildrenIDs(); len(nodes) > 0 {
  603. edge := &sqlgraph.EdgeSpec{
  604. Rel: sqlgraph.O2M,
  605. Inverse: true,
  606. Table: todo.ChildrenTable,
  607. Columns: []string{todo.ChildrenColumn},
  608. Bidi: false,
  609. Target: &sqlgraph.EdgeTarget{
  610. IDSpec: &sqlgraph.FieldSpec{
  611. Type: field.TypeInt,
  612. Column: todo.FieldID,
  613. },
  614. },
  615. }
  616. for _, k := range nodes {
  617. edge.Target.Nodes = append(edge.Target.Nodes, k)
  618. }
  619. _spec.Edges.Add = append(_spec.Edges.Add, edge)
  620. }
  621. if tuo.mutation.ParentCleared() {
  622. edge := &sqlgraph.EdgeSpec{
  623. Rel: sqlgraph.M2O,
  624. Inverse: false,
  625. Table: todo.ParentTable,
  626. Columns: []string{todo.ParentColumn},
  627. Bidi: false,
  628. Target: &sqlgraph.EdgeTarget{
  629. IDSpec: &sqlgraph.FieldSpec{
  630. Type: field.TypeInt,
  631. Column: todo.FieldID,
  632. },
  633. },
  634. }
  635. _spec.Edges.Clear = append(_spec.Edges.Clear, edge)
  636. }
  637. if nodes := tuo.mutation.ParentIDs(); len(nodes) > 0 {
  638. edge := &sqlgraph.EdgeSpec{
  639. Rel: sqlgraph.M2O,
  640. Inverse: false,
  641. Table: todo.ParentTable,
  642. Columns: []string{todo.ParentColumn},
  643. Bidi: false,
  644. Target: &sqlgraph.EdgeTarget{
  645. IDSpec: &sqlgraph.FieldSpec{
  646. Type: field.TypeInt,
  647. Column: todo.FieldID,
  648. },
  649. },
  650. }
  651. for _, k := range nodes {
  652. edge.Target.Nodes = append(edge.Target.Nodes, k)
  653. }
  654. _spec.Edges.Add = append(_spec.Edges.Add, edge)
  655. }
  656. _node = &Todo{config: tuo.config}
  657. _spec.Assign = _node.assignValues
  658. _spec.ScanValues = _node.scanValues
  659. if err = sqlgraph.UpdateNode(ctx, tuo.driver, _spec); err != nil {
  660. if _, ok := err.(*sqlgraph.NotFoundError); ok {
  661. err = &NotFoundError{todo.Label}
  662. } else if sqlgraph.IsConstraintError(err) {
  663. err = &ConstraintError{err.Error(), err}
  664. }
  665. return nil, err
  666. }
  667. return _node, nil
  668. }