sopnode_update.go 31 KB

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