sopnode_update.go 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809
  1. // Code generated by ent, DO NOT EDIT.
  2. package ent
  3. import (
  4. "context"
  5. "errors"
  6. "fmt"
  7. "time"
  8. "wechat-api/ent/custom_types"
  9. "wechat-api/ent/predicate"
  10. "wechat-api/ent/sopnode"
  11. "wechat-api/ent/sopstage"
  12. "entgo.io/ent/dialect/sql"
  13. "entgo.io/ent/dialect/sql/sqlgraph"
  14. "entgo.io/ent/dialect/sql/sqljson"
  15. "entgo.io/ent/schema/field"
  16. )
  17. // SopNodeUpdate is the builder for updating SopNode entities.
  18. type SopNodeUpdate struct {
  19. config
  20. hooks []Hook
  21. mutation *SopNodeMutation
  22. }
  23. // Where appends a list predicates to the SopNodeUpdate builder.
  24. func (snu *SopNodeUpdate) Where(ps ...predicate.SopNode) *SopNodeUpdate {
  25. snu.mutation.Where(ps...)
  26. return snu
  27. }
  28. // SetUpdatedAt sets the "updated_at" field.
  29. func (snu *SopNodeUpdate) SetUpdatedAt(t time.Time) *SopNodeUpdate {
  30. snu.mutation.SetUpdatedAt(t)
  31. return snu
  32. }
  33. // SetStatus sets the "status" field.
  34. func (snu *SopNodeUpdate) SetStatus(u uint8) *SopNodeUpdate {
  35. snu.mutation.ResetStatus()
  36. snu.mutation.SetStatus(u)
  37. return snu
  38. }
  39. // SetNillableStatus sets the "status" field if the given value is not nil.
  40. func (snu *SopNodeUpdate) SetNillableStatus(u *uint8) *SopNodeUpdate {
  41. if u != nil {
  42. snu.SetStatus(*u)
  43. }
  44. return snu
  45. }
  46. // AddStatus adds u to the "status" field.
  47. func (snu *SopNodeUpdate) AddStatus(u int8) *SopNodeUpdate {
  48. snu.mutation.AddStatus(u)
  49. return snu
  50. }
  51. // ClearStatus clears the value of the "status" field.
  52. func (snu *SopNodeUpdate) ClearStatus() *SopNodeUpdate {
  53. snu.mutation.ClearStatus()
  54. return snu
  55. }
  56. // SetDeletedAt sets the "deleted_at" field.
  57. func (snu *SopNodeUpdate) SetDeletedAt(t time.Time) *SopNodeUpdate {
  58. snu.mutation.SetDeletedAt(t)
  59. return snu
  60. }
  61. // SetNillableDeletedAt sets the "deleted_at" field if the given value is not nil.
  62. func (snu *SopNodeUpdate) SetNillableDeletedAt(t *time.Time) *SopNodeUpdate {
  63. if t != nil {
  64. snu.SetDeletedAt(*t)
  65. }
  66. return snu
  67. }
  68. // ClearDeletedAt clears the value of the "deleted_at" field.
  69. func (snu *SopNodeUpdate) ClearDeletedAt() *SopNodeUpdate {
  70. snu.mutation.ClearDeletedAt()
  71. return snu
  72. }
  73. // SetStageID sets the "stage_id" field.
  74. func (snu *SopNodeUpdate) SetStageID(u uint64) *SopNodeUpdate {
  75. snu.mutation.SetStageID(u)
  76. return snu
  77. }
  78. // SetNillableStageID sets the "stage_id" field if the given value is not nil.
  79. func (snu *SopNodeUpdate) SetNillableStageID(u *uint64) *SopNodeUpdate {
  80. if u != nil {
  81. snu.SetStageID(*u)
  82. }
  83. return snu
  84. }
  85. // SetParentID sets the "parent_id" field.
  86. func (snu *SopNodeUpdate) SetParentID(u uint64) *SopNodeUpdate {
  87. snu.mutation.ResetParentID()
  88. snu.mutation.SetParentID(u)
  89. return snu
  90. }
  91. // SetNillableParentID sets the "parent_id" field if the given value is not nil.
  92. func (snu *SopNodeUpdate) SetNillableParentID(u *uint64) *SopNodeUpdate {
  93. if u != nil {
  94. snu.SetParentID(*u)
  95. }
  96. return snu
  97. }
  98. // AddParentID adds u to the "parent_id" field.
  99. func (snu *SopNodeUpdate) AddParentID(u int64) *SopNodeUpdate {
  100. snu.mutation.AddParentID(u)
  101. return snu
  102. }
  103. // SetName sets the "name" field.
  104. func (snu *SopNodeUpdate) SetName(s string) *SopNodeUpdate {
  105. snu.mutation.SetName(s)
  106. return snu
  107. }
  108. // SetNillableName sets the "name" field if the given value is not nil.
  109. func (snu *SopNodeUpdate) SetNillableName(s *string) *SopNodeUpdate {
  110. if s != nil {
  111. snu.SetName(*s)
  112. }
  113. return snu
  114. }
  115. // SetConditionType sets the "condition_type" field.
  116. func (snu *SopNodeUpdate) SetConditionType(i int) *SopNodeUpdate {
  117. snu.mutation.ResetConditionType()
  118. snu.mutation.SetConditionType(i)
  119. return snu
  120. }
  121. // SetNillableConditionType sets the "condition_type" field if the given value is not nil.
  122. func (snu *SopNodeUpdate) SetNillableConditionType(i *int) *SopNodeUpdate {
  123. if i != nil {
  124. snu.SetConditionType(*i)
  125. }
  126. return snu
  127. }
  128. // AddConditionType adds i to the "condition_type" field.
  129. func (snu *SopNodeUpdate) AddConditionType(i int) *SopNodeUpdate {
  130. snu.mutation.AddConditionType(i)
  131. return snu
  132. }
  133. // SetConditionList sets the "condition_list" field.
  134. func (snu *SopNodeUpdate) SetConditionList(s []string) *SopNodeUpdate {
  135. snu.mutation.SetConditionList(s)
  136. return snu
  137. }
  138. // AppendConditionList appends s to the "condition_list" field.
  139. func (snu *SopNodeUpdate) AppendConditionList(s []string) *SopNodeUpdate {
  140. snu.mutation.AppendConditionList(s)
  141. return snu
  142. }
  143. // ClearConditionList clears the value of the "condition_list" field.
  144. func (snu *SopNodeUpdate) ClearConditionList() *SopNodeUpdate {
  145. snu.mutation.ClearConditionList()
  146. return snu
  147. }
  148. // SetActionMessage sets the "action_message" field.
  149. func (snu *SopNodeUpdate) SetActionMessage(ct []custom_types.Action) *SopNodeUpdate {
  150. snu.mutation.SetActionMessage(ct)
  151. return snu
  152. }
  153. // AppendActionMessage appends ct to the "action_message" field.
  154. func (snu *SopNodeUpdate) AppendActionMessage(ct []custom_types.Action) *SopNodeUpdate {
  155. snu.mutation.AppendActionMessage(ct)
  156. return snu
  157. }
  158. // ClearActionMessage clears the value of the "action_message" field.
  159. func (snu *SopNodeUpdate) ClearActionMessage() *SopNodeUpdate {
  160. snu.mutation.ClearActionMessage()
  161. return snu
  162. }
  163. // SetActionLabel sets the "action_label" field.
  164. func (snu *SopNodeUpdate) SetActionLabel(i []int) *SopNodeUpdate {
  165. snu.mutation.SetActionLabel(i)
  166. return snu
  167. }
  168. // AppendActionLabel appends i to the "action_label" field.
  169. func (snu *SopNodeUpdate) AppendActionLabel(i []int) *SopNodeUpdate {
  170. snu.mutation.AppendActionLabel(i)
  171. return snu
  172. }
  173. // ClearActionLabel clears the value of the "action_label" field.
  174. func (snu *SopNodeUpdate) ClearActionLabel() *SopNodeUpdate {
  175. snu.mutation.ClearActionLabel()
  176. return snu
  177. }
  178. // SetSopStageID sets the "sop_stage" edge to the SopStage entity by ID.
  179. func (snu *SopNodeUpdate) SetSopStageID(id uint64) *SopNodeUpdate {
  180. snu.mutation.SetSopStageID(id)
  181. return snu
  182. }
  183. // SetSopStage sets the "sop_stage" edge to the SopStage entity.
  184. func (snu *SopNodeUpdate) SetSopStage(s *SopStage) *SopNodeUpdate {
  185. return snu.SetSopStageID(s.ID)
  186. }
  187. // Mutation returns the SopNodeMutation object of the builder.
  188. func (snu *SopNodeUpdate) Mutation() *SopNodeMutation {
  189. return snu.mutation
  190. }
  191. // ClearSopStage clears the "sop_stage" edge to the SopStage entity.
  192. func (snu *SopNodeUpdate) ClearSopStage() *SopNodeUpdate {
  193. snu.mutation.ClearSopStage()
  194. return snu
  195. }
  196. // Save executes the query and returns the number of nodes affected by the update operation.
  197. func (snu *SopNodeUpdate) Save(ctx context.Context) (int, error) {
  198. if err := snu.defaults(); err != nil {
  199. return 0, err
  200. }
  201. return withHooks(ctx, snu.sqlSave, snu.mutation, snu.hooks)
  202. }
  203. // SaveX is like Save, but panics if an error occurs.
  204. func (snu *SopNodeUpdate) SaveX(ctx context.Context) int {
  205. affected, err := snu.Save(ctx)
  206. if err != nil {
  207. panic(err)
  208. }
  209. return affected
  210. }
  211. // Exec executes the query.
  212. func (snu *SopNodeUpdate) Exec(ctx context.Context) error {
  213. _, err := snu.Save(ctx)
  214. return err
  215. }
  216. // ExecX is like Exec, but panics if an error occurs.
  217. func (snu *SopNodeUpdate) ExecX(ctx context.Context) {
  218. if err := snu.Exec(ctx); err != nil {
  219. panic(err)
  220. }
  221. }
  222. // defaults sets the default values of the builder before save.
  223. func (snu *SopNodeUpdate) defaults() error {
  224. if _, ok := snu.mutation.UpdatedAt(); !ok {
  225. if sopnode.UpdateDefaultUpdatedAt == nil {
  226. return fmt.Errorf("ent: uninitialized sopnode.UpdateDefaultUpdatedAt (forgotten import ent/runtime?)")
  227. }
  228. v := sopnode.UpdateDefaultUpdatedAt()
  229. snu.mutation.SetUpdatedAt(v)
  230. }
  231. return nil
  232. }
  233. // check runs all checks and user-defined validators on the builder.
  234. func (snu *SopNodeUpdate) check() error {
  235. if _, ok := snu.mutation.SopStageID(); snu.mutation.SopStageCleared() && !ok {
  236. return errors.New(`ent: clearing a required unique edge "SopNode.sop_stage"`)
  237. }
  238. return nil
  239. }
  240. func (snu *SopNodeUpdate) sqlSave(ctx context.Context) (n int, err error) {
  241. if err := snu.check(); err != nil {
  242. return n, err
  243. }
  244. _spec := sqlgraph.NewUpdateSpec(sopnode.Table, sopnode.Columns, sqlgraph.NewFieldSpec(sopnode.FieldID, field.TypeUint64))
  245. if ps := snu.mutation.predicates; len(ps) > 0 {
  246. _spec.Predicate = func(selector *sql.Selector) {
  247. for i := range ps {
  248. ps[i](selector)
  249. }
  250. }
  251. }
  252. if value, ok := snu.mutation.UpdatedAt(); ok {
  253. _spec.SetField(sopnode.FieldUpdatedAt, field.TypeTime, value)
  254. }
  255. if value, ok := snu.mutation.Status(); ok {
  256. _spec.SetField(sopnode.FieldStatus, field.TypeUint8, value)
  257. }
  258. if value, ok := snu.mutation.AddedStatus(); ok {
  259. _spec.AddField(sopnode.FieldStatus, field.TypeUint8, value)
  260. }
  261. if snu.mutation.StatusCleared() {
  262. _spec.ClearField(sopnode.FieldStatus, field.TypeUint8)
  263. }
  264. if value, ok := snu.mutation.DeletedAt(); ok {
  265. _spec.SetField(sopnode.FieldDeletedAt, field.TypeTime, value)
  266. }
  267. if snu.mutation.DeletedAtCleared() {
  268. _spec.ClearField(sopnode.FieldDeletedAt, field.TypeTime)
  269. }
  270. if value, ok := snu.mutation.ParentID(); ok {
  271. _spec.SetField(sopnode.FieldParentID, field.TypeUint64, value)
  272. }
  273. if value, ok := snu.mutation.AddedParentID(); ok {
  274. _spec.AddField(sopnode.FieldParentID, field.TypeUint64, value)
  275. }
  276. if value, ok := snu.mutation.Name(); ok {
  277. _spec.SetField(sopnode.FieldName, field.TypeString, value)
  278. }
  279. if value, ok := snu.mutation.ConditionType(); ok {
  280. _spec.SetField(sopnode.FieldConditionType, field.TypeInt, value)
  281. }
  282. if value, ok := snu.mutation.AddedConditionType(); ok {
  283. _spec.AddField(sopnode.FieldConditionType, field.TypeInt, value)
  284. }
  285. if value, ok := snu.mutation.ConditionList(); ok {
  286. _spec.SetField(sopnode.FieldConditionList, field.TypeJSON, value)
  287. }
  288. if value, ok := snu.mutation.AppendedConditionList(); ok {
  289. _spec.AddModifier(func(u *sql.UpdateBuilder) {
  290. sqljson.Append(u, sopnode.FieldConditionList, value)
  291. })
  292. }
  293. if snu.mutation.ConditionListCleared() {
  294. _spec.ClearField(sopnode.FieldConditionList, field.TypeJSON)
  295. }
  296. if value, ok := snu.mutation.ActionMessage(); ok {
  297. _spec.SetField(sopnode.FieldActionMessage, field.TypeJSON, value)
  298. }
  299. if value, ok := snu.mutation.AppendedActionMessage(); ok {
  300. _spec.AddModifier(func(u *sql.UpdateBuilder) {
  301. sqljson.Append(u, sopnode.FieldActionMessage, value)
  302. })
  303. }
  304. if snu.mutation.ActionMessageCleared() {
  305. _spec.ClearField(sopnode.FieldActionMessage, field.TypeJSON)
  306. }
  307. if value, ok := snu.mutation.ActionLabel(); ok {
  308. _spec.SetField(sopnode.FieldActionLabel, field.TypeJSON, value)
  309. }
  310. if value, ok := snu.mutation.AppendedActionLabel(); ok {
  311. _spec.AddModifier(func(u *sql.UpdateBuilder) {
  312. sqljson.Append(u, sopnode.FieldActionLabel, value)
  313. })
  314. }
  315. if snu.mutation.ActionLabelCleared() {
  316. _spec.ClearField(sopnode.FieldActionLabel, field.TypeJSON)
  317. }
  318. if snu.mutation.SopStageCleared() {
  319. edge := &sqlgraph.EdgeSpec{
  320. Rel: sqlgraph.M2O,
  321. Inverse: true,
  322. Table: sopnode.SopStageTable,
  323. Columns: []string{sopnode.SopStageColumn},
  324. Bidi: false,
  325. Target: &sqlgraph.EdgeTarget{
  326. IDSpec: sqlgraph.NewFieldSpec(sopstage.FieldID, field.TypeUint64),
  327. },
  328. }
  329. _spec.Edges.Clear = append(_spec.Edges.Clear, edge)
  330. }
  331. if nodes := snu.mutation.SopStageIDs(); len(nodes) > 0 {
  332. edge := &sqlgraph.EdgeSpec{
  333. Rel: sqlgraph.M2O,
  334. Inverse: true,
  335. Table: sopnode.SopStageTable,
  336. Columns: []string{sopnode.SopStageColumn},
  337. Bidi: false,
  338. Target: &sqlgraph.EdgeTarget{
  339. IDSpec: sqlgraph.NewFieldSpec(sopstage.FieldID, field.TypeUint64),
  340. },
  341. }
  342. for _, k := range nodes {
  343. edge.Target.Nodes = append(edge.Target.Nodes, k)
  344. }
  345. _spec.Edges.Add = append(_spec.Edges.Add, edge)
  346. }
  347. if n, err = sqlgraph.UpdateNodes(ctx, snu.driver, _spec); err != nil {
  348. if _, ok := err.(*sqlgraph.NotFoundError); ok {
  349. err = &NotFoundError{sopnode.Label}
  350. } else if sqlgraph.IsConstraintError(err) {
  351. err = &ConstraintError{msg: err.Error(), wrap: err}
  352. }
  353. return 0, err
  354. }
  355. snu.mutation.done = true
  356. return n, nil
  357. }
  358. // SopNodeUpdateOne is the builder for updating a single SopNode entity.
  359. type SopNodeUpdateOne struct {
  360. config
  361. fields []string
  362. hooks []Hook
  363. mutation *SopNodeMutation
  364. }
  365. // SetUpdatedAt sets the "updated_at" field.
  366. func (snuo *SopNodeUpdateOne) SetUpdatedAt(t time.Time) *SopNodeUpdateOne {
  367. snuo.mutation.SetUpdatedAt(t)
  368. return snuo
  369. }
  370. // SetStatus sets the "status" field.
  371. func (snuo *SopNodeUpdateOne) SetStatus(u uint8) *SopNodeUpdateOne {
  372. snuo.mutation.ResetStatus()
  373. snuo.mutation.SetStatus(u)
  374. return snuo
  375. }
  376. // SetNillableStatus sets the "status" field if the given value is not nil.
  377. func (snuo *SopNodeUpdateOne) SetNillableStatus(u *uint8) *SopNodeUpdateOne {
  378. if u != nil {
  379. snuo.SetStatus(*u)
  380. }
  381. return snuo
  382. }
  383. // AddStatus adds u to the "status" field.
  384. func (snuo *SopNodeUpdateOne) AddStatus(u int8) *SopNodeUpdateOne {
  385. snuo.mutation.AddStatus(u)
  386. return snuo
  387. }
  388. // ClearStatus clears the value of the "status" field.
  389. func (snuo *SopNodeUpdateOne) ClearStatus() *SopNodeUpdateOne {
  390. snuo.mutation.ClearStatus()
  391. return snuo
  392. }
  393. // SetDeletedAt sets the "deleted_at" field.
  394. func (snuo *SopNodeUpdateOne) SetDeletedAt(t time.Time) *SopNodeUpdateOne {
  395. snuo.mutation.SetDeletedAt(t)
  396. return snuo
  397. }
  398. // SetNillableDeletedAt sets the "deleted_at" field if the given value is not nil.
  399. func (snuo *SopNodeUpdateOne) SetNillableDeletedAt(t *time.Time) *SopNodeUpdateOne {
  400. if t != nil {
  401. snuo.SetDeletedAt(*t)
  402. }
  403. return snuo
  404. }
  405. // ClearDeletedAt clears the value of the "deleted_at" field.
  406. func (snuo *SopNodeUpdateOne) ClearDeletedAt() *SopNodeUpdateOne {
  407. snuo.mutation.ClearDeletedAt()
  408. return snuo
  409. }
  410. // SetStageID sets the "stage_id" field.
  411. func (snuo *SopNodeUpdateOne) SetStageID(u uint64) *SopNodeUpdateOne {
  412. snuo.mutation.SetStageID(u)
  413. return snuo
  414. }
  415. // SetNillableStageID sets the "stage_id" field if the given value is not nil.
  416. func (snuo *SopNodeUpdateOne) SetNillableStageID(u *uint64) *SopNodeUpdateOne {
  417. if u != nil {
  418. snuo.SetStageID(*u)
  419. }
  420. return snuo
  421. }
  422. // SetParentID sets the "parent_id" field.
  423. func (snuo *SopNodeUpdateOne) SetParentID(u uint64) *SopNodeUpdateOne {
  424. snuo.mutation.ResetParentID()
  425. snuo.mutation.SetParentID(u)
  426. return snuo
  427. }
  428. // SetNillableParentID sets the "parent_id" field if the given value is not nil.
  429. func (snuo *SopNodeUpdateOne) SetNillableParentID(u *uint64) *SopNodeUpdateOne {
  430. if u != nil {
  431. snuo.SetParentID(*u)
  432. }
  433. return snuo
  434. }
  435. // AddParentID adds u to the "parent_id" field.
  436. func (snuo *SopNodeUpdateOne) AddParentID(u int64) *SopNodeUpdateOne {
  437. snuo.mutation.AddParentID(u)
  438. return snuo
  439. }
  440. // SetName sets the "name" field.
  441. func (snuo *SopNodeUpdateOne) SetName(s string) *SopNodeUpdateOne {
  442. snuo.mutation.SetName(s)
  443. return snuo
  444. }
  445. // SetNillableName sets the "name" field if the given value is not nil.
  446. func (snuo *SopNodeUpdateOne) SetNillableName(s *string) *SopNodeUpdateOne {
  447. if s != nil {
  448. snuo.SetName(*s)
  449. }
  450. return snuo
  451. }
  452. // SetConditionType sets the "condition_type" field.
  453. func (snuo *SopNodeUpdateOne) SetConditionType(i int) *SopNodeUpdateOne {
  454. snuo.mutation.ResetConditionType()
  455. snuo.mutation.SetConditionType(i)
  456. return snuo
  457. }
  458. // SetNillableConditionType sets the "condition_type" field if the given value is not nil.
  459. func (snuo *SopNodeUpdateOne) SetNillableConditionType(i *int) *SopNodeUpdateOne {
  460. if i != nil {
  461. snuo.SetConditionType(*i)
  462. }
  463. return snuo
  464. }
  465. // AddConditionType adds i to the "condition_type" field.
  466. func (snuo *SopNodeUpdateOne) AddConditionType(i int) *SopNodeUpdateOne {
  467. snuo.mutation.AddConditionType(i)
  468. return snuo
  469. }
  470. // SetConditionList sets the "condition_list" field.
  471. func (snuo *SopNodeUpdateOne) SetConditionList(s []string) *SopNodeUpdateOne {
  472. snuo.mutation.SetConditionList(s)
  473. return snuo
  474. }
  475. // AppendConditionList appends s to the "condition_list" field.
  476. func (snuo *SopNodeUpdateOne) AppendConditionList(s []string) *SopNodeUpdateOne {
  477. snuo.mutation.AppendConditionList(s)
  478. return snuo
  479. }
  480. // ClearConditionList clears the value of the "condition_list" field.
  481. func (snuo *SopNodeUpdateOne) ClearConditionList() *SopNodeUpdateOne {
  482. snuo.mutation.ClearConditionList()
  483. return snuo
  484. }
  485. // SetActionMessage sets the "action_message" field.
  486. func (snuo *SopNodeUpdateOne) SetActionMessage(ct []custom_types.Action) *SopNodeUpdateOne {
  487. snuo.mutation.SetActionMessage(ct)
  488. return snuo
  489. }
  490. // AppendActionMessage appends ct to the "action_message" field.
  491. func (snuo *SopNodeUpdateOne) AppendActionMessage(ct []custom_types.Action) *SopNodeUpdateOne {
  492. snuo.mutation.AppendActionMessage(ct)
  493. return snuo
  494. }
  495. // ClearActionMessage clears the value of the "action_message" field.
  496. func (snuo *SopNodeUpdateOne) ClearActionMessage() *SopNodeUpdateOne {
  497. snuo.mutation.ClearActionMessage()
  498. return snuo
  499. }
  500. // SetActionLabel sets the "action_label" field.
  501. func (snuo *SopNodeUpdateOne) SetActionLabel(i []int) *SopNodeUpdateOne {
  502. snuo.mutation.SetActionLabel(i)
  503. return snuo
  504. }
  505. // AppendActionLabel appends i to the "action_label" field.
  506. func (snuo *SopNodeUpdateOne) AppendActionLabel(i []int) *SopNodeUpdateOne {
  507. snuo.mutation.AppendActionLabel(i)
  508. return snuo
  509. }
  510. // ClearActionLabel clears the value of the "action_label" field.
  511. func (snuo *SopNodeUpdateOne) ClearActionLabel() *SopNodeUpdateOne {
  512. snuo.mutation.ClearActionLabel()
  513. return snuo
  514. }
  515. // SetSopStageID sets the "sop_stage" edge to the SopStage entity by ID.
  516. func (snuo *SopNodeUpdateOne) SetSopStageID(id uint64) *SopNodeUpdateOne {
  517. snuo.mutation.SetSopStageID(id)
  518. return snuo
  519. }
  520. // SetSopStage sets the "sop_stage" edge to the SopStage entity.
  521. func (snuo *SopNodeUpdateOne) SetSopStage(s *SopStage) *SopNodeUpdateOne {
  522. return snuo.SetSopStageID(s.ID)
  523. }
  524. // Mutation returns the SopNodeMutation object of the builder.
  525. func (snuo *SopNodeUpdateOne) Mutation() *SopNodeMutation {
  526. return snuo.mutation
  527. }
  528. // ClearSopStage clears the "sop_stage" edge to the SopStage entity.
  529. func (snuo *SopNodeUpdateOne) ClearSopStage() *SopNodeUpdateOne {
  530. snuo.mutation.ClearSopStage()
  531. return snuo
  532. }
  533. // Where appends a list predicates to the SopNodeUpdate builder.
  534. func (snuo *SopNodeUpdateOne) Where(ps ...predicate.SopNode) *SopNodeUpdateOne {
  535. snuo.mutation.Where(ps...)
  536. return snuo
  537. }
  538. // Select allows selecting one or more fields (columns) of the returned entity.
  539. // The default is selecting all fields defined in the entity schema.
  540. func (snuo *SopNodeUpdateOne) Select(field string, fields ...string) *SopNodeUpdateOne {
  541. snuo.fields = append([]string{field}, fields...)
  542. return snuo
  543. }
  544. // Save executes the query and returns the updated SopNode entity.
  545. func (snuo *SopNodeUpdateOne) Save(ctx context.Context) (*SopNode, error) {
  546. if err := snuo.defaults(); err != nil {
  547. return nil, err
  548. }
  549. return withHooks(ctx, snuo.sqlSave, snuo.mutation, snuo.hooks)
  550. }
  551. // SaveX is like Save, but panics if an error occurs.
  552. func (snuo *SopNodeUpdateOne) SaveX(ctx context.Context) *SopNode {
  553. node, err := snuo.Save(ctx)
  554. if err != nil {
  555. panic(err)
  556. }
  557. return node
  558. }
  559. // Exec executes the query on the entity.
  560. func (snuo *SopNodeUpdateOne) Exec(ctx context.Context) error {
  561. _, err := snuo.Save(ctx)
  562. return err
  563. }
  564. // ExecX is like Exec, but panics if an error occurs.
  565. func (snuo *SopNodeUpdateOne) ExecX(ctx context.Context) {
  566. if err := snuo.Exec(ctx); err != nil {
  567. panic(err)
  568. }
  569. }
  570. // defaults sets the default values of the builder before save.
  571. func (snuo *SopNodeUpdateOne) defaults() error {
  572. if _, ok := snuo.mutation.UpdatedAt(); !ok {
  573. if sopnode.UpdateDefaultUpdatedAt == nil {
  574. return fmt.Errorf("ent: uninitialized sopnode.UpdateDefaultUpdatedAt (forgotten import ent/runtime?)")
  575. }
  576. v := sopnode.UpdateDefaultUpdatedAt()
  577. snuo.mutation.SetUpdatedAt(v)
  578. }
  579. return nil
  580. }
  581. // check runs all checks and user-defined validators on the builder.
  582. func (snuo *SopNodeUpdateOne) check() error {
  583. if _, ok := snuo.mutation.SopStageID(); snuo.mutation.SopStageCleared() && !ok {
  584. return errors.New(`ent: clearing a required unique edge "SopNode.sop_stage"`)
  585. }
  586. return nil
  587. }
  588. func (snuo *SopNodeUpdateOne) sqlSave(ctx context.Context) (_node *SopNode, err error) {
  589. if err := snuo.check(); err != nil {
  590. return _node, err
  591. }
  592. _spec := sqlgraph.NewUpdateSpec(sopnode.Table, sopnode.Columns, sqlgraph.NewFieldSpec(sopnode.FieldID, field.TypeUint64))
  593. id, ok := snuo.mutation.ID()
  594. if !ok {
  595. return nil, &ValidationError{Name: "id", err: errors.New(`ent: missing "SopNode.id" for update`)}
  596. }
  597. _spec.Node.ID.Value = id
  598. if fields := snuo.fields; len(fields) > 0 {
  599. _spec.Node.Columns = make([]string, 0, len(fields))
  600. _spec.Node.Columns = append(_spec.Node.Columns, sopnode.FieldID)
  601. for _, f := range fields {
  602. if !sopnode.ValidColumn(f) {
  603. return nil, &ValidationError{Name: f, err: fmt.Errorf("ent: invalid field %q for query", f)}
  604. }
  605. if f != sopnode.FieldID {
  606. _spec.Node.Columns = append(_spec.Node.Columns, f)
  607. }
  608. }
  609. }
  610. if ps := snuo.mutation.predicates; len(ps) > 0 {
  611. _spec.Predicate = func(selector *sql.Selector) {
  612. for i := range ps {
  613. ps[i](selector)
  614. }
  615. }
  616. }
  617. if value, ok := snuo.mutation.UpdatedAt(); ok {
  618. _spec.SetField(sopnode.FieldUpdatedAt, field.TypeTime, value)
  619. }
  620. if value, ok := snuo.mutation.Status(); ok {
  621. _spec.SetField(sopnode.FieldStatus, field.TypeUint8, value)
  622. }
  623. if value, ok := snuo.mutation.AddedStatus(); ok {
  624. _spec.AddField(sopnode.FieldStatus, field.TypeUint8, value)
  625. }
  626. if snuo.mutation.StatusCleared() {
  627. _spec.ClearField(sopnode.FieldStatus, field.TypeUint8)
  628. }
  629. if value, ok := snuo.mutation.DeletedAt(); ok {
  630. _spec.SetField(sopnode.FieldDeletedAt, field.TypeTime, value)
  631. }
  632. if snuo.mutation.DeletedAtCleared() {
  633. _spec.ClearField(sopnode.FieldDeletedAt, field.TypeTime)
  634. }
  635. if value, ok := snuo.mutation.ParentID(); ok {
  636. _spec.SetField(sopnode.FieldParentID, field.TypeUint64, value)
  637. }
  638. if value, ok := snuo.mutation.AddedParentID(); ok {
  639. _spec.AddField(sopnode.FieldParentID, field.TypeUint64, value)
  640. }
  641. if value, ok := snuo.mutation.Name(); ok {
  642. _spec.SetField(sopnode.FieldName, field.TypeString, value)
  643. }
  644. if value, ok := snuo.mutation.ConditionType(); ok {
  645. _spec.SetField(sopnode.FieldConditionType, field.TypeInt, value)
  646. }
  647. if value, ok := snuo.mutation.AddedConditionType(); ok {
  648. _spec.AddField(sopnode.FieldConditionType, field.TypeInt, value)
  649. }
  650. if value, ok := snuo.mutation.ConditionList(); ok {
  651. _spec.SetField(sopnode.FieldConditionList, field.TypeJSON, value)
  652. }
  653. if value, ok := snuo.mutation.AppendedConditionList(); ok {
  654. _spec.AddModifier(func(u *sql.UpdateBuilder) {
  655. sqljson.Append(u, sopnode.FieldConditionList, value)
  656. })
  657. }
  658. if snuo.mutation.ConditionListCleared() {
  659. _spec.ClearField(sopnode.FieldConditionList, field.TypeJSON)
  660. }
  661. if value, ok := snuo.mutation.ActionMessage(); ok {
  662. _spec.SetField(sopnode.FieldActionMessage, field.TypeJSON, value)
  663. }
  664. if value, ok := snuo.mutation.AppendedActionMessage(); ok {
  665. _spec.AddModifier(func(u *sql.UpdateBuilder) {
  666. sqljson.Append(u, sopnode.FieldActionMessage, value)
  667. })
  668. }
  669. if snuo.mutation.ActionMessageCleared() {
  670. _spec.ClearField(sopnode.FieldActionMessage, field.TypeJSON)
  671. }
  672. if value, ok := snuo.mutation.ActionLabel(); ok {
  673. _spec.SetField(sopnode.FieldActionLabel, field.TypeJSON, value)
  674. }
  675. if value, ok := snuo.mutation.AppendedActionLabel(); ok {
  676. _spec.AddModifier(func(u *sql.UpdateBuilder) {
  677. sqljson.Append(u, sopnode.FieldActionLabel, value)
  678. })
  679. }
  680. if snuo.mutation.ActionLabelCleared() {
  681. _spec.ClearField(sopnode.FieldActionLabel, field.TypeJSON)
  682. }
  683. if snuo.mutation.SopStageCleared() {
  684. edge := &sqlgraph.EdgeSpec{
  685. Rel: sqlgraph.M2O,
  686. Inverse: true,
  687. Table: sopnode.SopStageTable,
  688. Columns: []string{sopnode.SopStageColumn},
  689. Bidi: false,
  690. Target: &sqlgraph.EdgeTarget{
  691. IDSpec: sqlgraph.NewFieldSpec(sopstage.FieldID, field.TypeUint64),
  692. },
  693. }
  694. _spec.Edges.Clear = append(_spec.Edges.Clear, edge)
  695. }
  696. if nodes := snuo.mutation.SopStageIDs(); len(nodes) > 0 {
  697. edge := &sqlgraph.EdgeSpec{
  698. Rel: sqlgraph.M2O,
  699. Inverse: true,
  700. Table: sopnode.SopStageTable,
  701. Columns: []string{sopnode.SopStageColumn},
  702. Bidi: false,
  703. Target: &sqlgraph.EdgeTarget{
  704. IDSpec: sqlgraph.NewFieldSpec(sopstage.FieldID, field.TypeUint64),
  705. },
  706. }
  707. for _, k := range nodes {
  708. edge.Target.Nodes = append(edge.Target.Nodes, k)
  709. }
  710. _spec.Edges.Add = append(_spec.Edges.Add, edge)
  711. }
  712. _node = &SopNode{config: snuo.config}
  713. _spec.Assign = _node.assignValues
  714. _spec.ScanValues = _node.scanValues
  715. if err = sqlgraph.UpdateNode(ctx, snuo.driver, _spec); err != nil {
  716. if _, ok := err.(*sqlgraph.NotFoundError); ok {
  717. err = &NotFoundError{sopnode.Label}
  718. } else if sqlgraph.IsConstraintError(err) {
  719. err = &ConstraintError{msg: err.Error(), wrap: err}
  720. }
  721. return nil, err
  722. }
  723. snuo.mutation.done = true
  724. return _node, nil
  725. }