sopnode_update.go 31 KB

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