sopnode_update.go 35 KB

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