sopnode_update.go 29 KB

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