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