sopstage_create.go 41 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399
  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/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/schema/field"
  16. )
  17. // SopStageCreate is the builder for creating a SopStage entity.
  18. type SopStageCreate struct {
  19. config
  20. mutation *SopStageMutation
  21. hooks []Hook
  22. conflict []sql.ConflictOption
  23. }
  24. // SetCreatedAt sets the "created_at" field.
  25. func (ssc *SopStageCreate) SetCreatedAt(t time.Time) *SopStageCreate {
  26. ssc.mutation.SetCreatedAt(t)
  27. return ssc
  28. }
  29. // SetNillableCreatedAt sets the "created_at" field if the given value is not nil.
  30. func (ssc *SopStageCreate) SetNillableCreatedAt(t *time.Time) *SopStageCreate {
  31. if t != nil {
  32. ssc.SetCreatedAt(*t)
  33. }
  34. return ssc
  35. }
  36. // SetUpdatedAt sets the "updated_at" field.
  37. func (ssc *SopStageCreate) SetUpdatedAt(t time.Time) *SopStageCreate {
  38. ssc.mutation.SetUpdatedAt(t)
  39. return ssc
  40. }
  41. // SetNillableUpdatedAt sets the "updated_at" field if the given value is not nil.
  42. func (ssc *SopStageCreate) SetNillableUpdatedAt(t *time.Time) *SopStageCreate {
  43. if t != nil {
  44. ssc.SetUpdatedAt(*t)
  45. }
  46. return ssc
  47. }
  48. // SetStatus sets the "status" field.
  49. func (ssc *SopStageCreate) SetStatus(u uint8) *SopStageCreate {
  50. ssc.mutation.SetStatus(u)
  51. return ssc
  52. }
  53. // SetNillableStatus sets the "status" field if the given value is not nil.
  54. func (ssc *SopStageCreate) SetNillableStatus(u *uint8) *SopStageCreate {
  55. if u != nil {
  56. ssc.SetStatus(*u)
  57. }
  58. return ssc
  59. }
  60. // SetDeletedAt sets the "deleted_at" field.
  61. func (ssc *SopStageCreate) SetDeletedAt(t time.Time) *SopStageCreate {
  62. ssc.mutation.SetDeletedAt(t)
  63. return ssc
  64. }
  65. // SetNillableDeletedAt sets the "deleted_at" field if the given value is not nil.
  66. func (ssc *SopStageCreate) SetNillableDeletedAt(t *time.Time) *SopStageCreate {
  67. if t != nil {
  68. ssc.SetDeletedAt(*t)
  69. }
  70. return ssc
  71. }
  72. // SetTaskID sets the "task_id" field.
  73. func (ssc *SopStageCreate) SetTaskID(u uint64) *SopStageCreate {
  74. ssc.mutation.SetTaskID(u)
  75. return ssc
  76. }
  77. // SetName sets the "name" field.
  78. func (ssc *SopStageCreate) SetName(s string) *SopStageCreate {
  79. ssc.mutation.SetName(s)
  80. return ssc
  81. }
  82. // SetNillableName sets the "name" field if the given value is not nil.
  83. func (ssc *SopStageCreate) SetNillableName(s *string) *SopStageCreate {
  84. if s != nil {
  85. ssc.SetName(*s)
  86. }
  87. return ssc
  88. }
  89. // SetConditionType sets the "condition_type" field.
  90. func (ssc *SopStageCreate) SetConditionType(i int) *SopStageCreate {
  91. ssc.mutation.SetConditionType(i)
  92. return ssc
  93. }
  94. // SetNillableConditionType sets the "condition_type" field if the given value is not nil.
  95. func (ssc *SopStageCreate) SetNillableConditionType(i *int) *SopStageCreate {
  96. if i != nil {
  97. ssc.SetConditionType(*i)
  98. }
  99. return ssc
  100. }
  101. // SetConditionOperator sets the "condition_operator" field.
  102. func (ssc *SopStageCreate) SetConditionOperator(i int) *SopStageCreate {
  103. ssc.mutation.SetConditionOperator(i)
  104. return ssc
  105. }
  106. // SetNillableConditionOperator sets the "condition_operator" field if the given value is not nil.
  107. func (ssc *SopStageCreate) SetNillableConditionOperator(i *int) *SopStageCreate {
  108. if i != nil {
  109. ssc.SetConditionOperator(*i)
  110. }
  111. return ssc
  112. }
  113. // SetConditionList sets the "condition_list" field.
  114. func (ssc *SopStageCreate) SetConditionList(ct []custom_types.Condition) *SopStageCreate {
  115. ssc.mutation.SetConditionList(ct)
  116. return ssc
  117. }
  118. // SetActionMessage sets the "action_message" field.
  119. func (ssc *SopStageCreate) SetActionMessage(ct []custom_types.Action) *SopStageCreate {
  120. ssc.mutation.SetActionMessage(ct)
  121. return ssc
  122. }
  123. // SetActionLabel sets the "action_label" field.
  124. func (ssc *SopStageCreate) SetActionLabel(u []uint64) *SopStageCreate {
  125. ssc.mutation.SetActionLabel(u)
  126. return ssc
  127. }
  128. // SetIndexSort sets the "index_sort" field.
  129. func (ssc *SopStageCreate) SetIndexSort(i int) *SopStageCreate {
  130. ssc.mutation.SetIndexSort(i)
  131. return ssc
  132. }
  133. // SetNillableIndexSort sets the "index_sort" field if the given value is not nil.
  134. func (ssc *SopStageCreate) SetNillableIndexSort(i *int) *SopStageCreate {
  135. if i != nil {
  136. ssc.SetIndexSort(*i)
  137. }
  138. return ssc
  139. }
  140. // SetID sets the "id" field.
  141. func (ssc *SopStageCreate) SetID(u uint64) *SopStageCreate {
  142. ssc.mutation.SetID(u)
  143. return ssc
  144. }
  145. // SetSopTaskID sets the "sop_task" edge to the SopTask entity by ID.
  146. func (ssc *SopStageCreate) SetSopTaskID(id uint64) *SopStageCreate {
  147. ssc.mutation.SetSopTaskID(id)
  148. return ssc
  149. }
  150. // SetSopTask sets the "sop_task" edge to the SopTask entity.
  151. func (ssc *SopStageCreate) SetSopTask(s *SopTask) *SopStageCreate {
  152. return ssc.SetSopTaskID(s.ID)
  153. }
  154. // AddStageNodeIDs adds the "stage_nodes" edge to the SopNode entity by IDs.
  155. func (ssc *SopStageCreate) AddStageNodeIDs(ids ...uint64) *SopStageCreate {
  156. ssc.mutation.AddStageNodeIDs(ids...)
  157. return ssc
  158. }
  159. // AddStageNodes adds the "stage_nodes" edges to the SopNode entity.
  160. func (ssc *SopStageCreate) AddStageNodes(s ...*SopNode) *SopStageCreate {
  161. ids := make([]uint64, len(s))
  162. for i := range s {
  163. ids[i] = s[i].ID
  164. }
  165. return ssc.AddStageNodeIDs(ids...)
  166. }
  167. // AddStageMessageIDs adds the "stage_messages" edge to the MessageRecords entity by IDs.
  168. func (ssc *SopStageCreate) AddStageMessageIDs(ids ...uint64) *SopStageCreate {
  169. ssc.mutation.AddStageMessageIDs(ids...)
  170. return ssc
  171. }
  172. // AddStageMessages adds the "stage_messages" edges to the MessageRecords entity.
  173. func (ssc *SopStageCreate) AddStageMessages(m ...*MessageRecords) *SopStageCreate {
  174. ids := make([]uint64, len(m))
  175. for i := range m {
  176. ids[i] = m[i].ID
  177. }
  178. return ssc.AddStageMessageIDs(ids...)
  179. }
  180. // Mutation returns the SopStageMutation object of the builder.
  181. func (ssc *SopStageCreate) Mutation() *SopStageMutation {
  182. return ssc.mutation
  183. }
  184. // Save creates the SopStage in the database.
  185. func (ssc *SopStageCreate) Save(ctx context.Context) (*SopStage, error) {
  186. if err := ssc.defaults(); err != nil {
  187. return nil, err
  188. }
  189. return withHooks(ctx, ssc.sqlSave, ssc.mutation, ssc.hooks)
  190. }
  191. // SaveX calls Save and panics if Save returns an error.
  192. func (ssc *SopStageCreate) SaveX(ctx context.Context) *SopStage {
  193. v, err := ssc.Save(ctx)
  194. if err != nil {
  195. panic(err)
  196. }
  197. return v
  198. }
  199. // Exec executes the query.
  200. func (ssc *SopStageCreate) Exec(ctx context.Context) error {
  201. _, err := ssc.Save(ctx)
  202. return err
  203. }
  204. // ExecX is like Exec, but panics if an error occurs.
  205. func (ssc *SopStageCreate) ExecX(ctx context.Context) {
  206. if err := ssc.Exec(ctx); err != nil {
  207. panic(err)
  208. }
  209. }
  210. // defaults sets the default values of the builder before save.
  211. func (ssc *SopStageCreate) defaults() error {
  212. if _, ok := ssc.mutation.CreatedAt(); !ok {
  213. if sopstage.DefaultCreatedAt == nil {
  214. return fmt.Errorf("ent: uninitialized sopstage.DefaultCreatedAt (forgotten import ent/runtime?)")
  215. }
  216. v := sopstage.DefaultCreatedAt()
  217. ssc.mutation.SetCreatedAt(v)
  218. }
  219. if _, ok := ssc.mutation.UpdatedAt(); !ok {
  220. if sopstage.DefaultUpdatedAt == nil {
  221. return fmt.Errorf("ent: uninitialized sopstage.DefaultUpdatedAt (forgotten import ent/runtime?)")
  222. }
  223. v := sopstage.DefaultUpdatedAt()
  224. ssc.mutation.SetUpdatedAt(v)
  225. }
  226. if _, ok := ssc.mutation.Status(); !ok {
  227. v := sopstage.DefaultStatus
  228. ssc.mutation.SetStatus(v)
  229. }
  230. if _, ok := ssc.mutation.Name(); !ok {
  231. v := sopstage.DefaultName
  232. ssc.mutation.SetName(v)
  233. }
  234. if _, ok := ssc.mutation.ConditionType(); !ok {
  235. v := sopstage.DefaultConditionType
  236. ssc.mutation.SetConditionType(v)
  237. }
  238. if _, ok := ssc.mutation.ConditionOperator(); !ok {
  239. v := sopstage.DefaultConditionOperator
  240. ssc.mutation.SetConditionOperator(v)
  241. }
  242. if _, ok := ssc.mutation.IndexSort(); !ok {
  243. v := sopstage.DefaultIndexSort
  244. ssc.mutation.SetIndexSort(v)
  245. }
  246. return nil
  247. }
  248. // check runs all checks and user-defined validators on the builder.
  249. func (ssc *SopStageCreate) check() error {
  250. if _, ok := ssc.mutation.CreatedAt(); !ok {
  251. return &ValidationError{Name: "created_at", err: errors.New(`ent: missing required field "SopStage.created_at"`)}
  252. }
  253. if _, ok := ssc.mutation.UpdatedAt(); !ok {
  254. return &ValidationError{Name: "updated_at", err: errors.New(`ent: missing required field "SopStage.updated_at"`)}
  255. }
  256. if _, ok := ssc.mutation.TaskID(); !ok {
  257. return &ValidationError{Name: "task_id", err: errors.New(`ent: missing required field "SopStage.task_id"`)}
  258. }
  259. if _, ok := ssc.mutation.Name(); !ok {
  260. return &ValidationError{Name: "name", err: errors.New(`ent: missing required field "SopStage.name"`)}
  261. }
  262. if _, ok := ssc.mutation.ConditionType(); !ok {
  263. return &ValidationError{Name: "condition_type", err: errors.New(`ent: missing required field "SopStage.condition_type"`)}
  264. }
  265. if _, ok := ssc.mutation.ConditionOperator(); !ok {
  266. return &ValidationError{Name: "condition_operator", err: errors.New(`ent: missing required field "SopStage.condition_operator"`)}
  267. }
  268. if _, ok := ssc.mutation.ConditionList(); !ok {
  269. return &ValidationError{Name: "condition_list", err: errors.New(`ent: missing required field "SopStage.condition_list"`)}
  270. }
  271. if _, ok := ssc.mutation.SopTaskID(); !ok {
  272. return &ValidationError{Name: "sop_task", err: errors.New(`ent: missing required edge "SopStage.sop_task"`)}
  273. }
  274. return nil
  275. }
  276. func (ssc *SopStageCreate) sqlSave(ctx context.Context) (*SopStage, error) {
  277. if err := ssc.check(); err != nil {
  278. return nil, err
  279. }
  280. _node, _spec := ssc.createSpec()
  281. if err := sqlgraph.CreateNode(ctx, ssc.driver, _spec); err != nil {
  282. if sqlgraph.IsConstraintError(err) {
  283. err = &ConstraintError{msg: err.Error(), wrap: err}
  284. }
  285. return nil, err
  286. }
  287. if _spec.ID.Value != _node.ID {
  288. id := _spec.ID.Value.(int64)
  289. _node.ID = uint64(id)
  290. }
  291. ssc.mutation.id = &_node.ID
  292. ssc.mutation.done = true
  293. return _node, nil
  294. }
  295. func (ssc *SopStageCreate) createSpec() (*SopStage, *sqlgraph.CreateSpec) {
  296. var (
  297. _node = &SopStage{config: ssc.config}
  298. _spec = sqlgraph.NewCreateSpec(sopstage.Table, sqlgraph.NewFieldSpec(sopstage.FieldID, field.TypeUint64))
  299. )
  300. _spec.OnConflict = ssc.conflict
  301. if id, ok := ssc.mutation.ID(); ok {
  302. _node.ID = id
  303. _spec.ID.Value = id
  304. }
  305. if value, ok := ssc.mutation.CreatedAt(); ok {
  306. _spec.SetField(sopstage.FieldCreatedAt, field.TypeTime, value)
  307. _node.CreatedAt = value
  308. }
  309. if value, ok := ssc.mutation.UpdatedAt(); ok {
  310. _spec.SetField(sopstage.FieldUpdatedAt, field.TypeTime, value)
  311. _node.UpdatedAt = value
  312. }
  313. if value, ok := ssc.mutation.Status(); ok {
  314. _spec.SetField(sopstage.FieldStatus, field.TypeUint8, value)
  315. _node.Status = value
  316. }
  317. if value, ok := ssc.mutation.DeletedAt(); ok {
  318. _spec.SetField(sopstage.FieldDeletedAt, field.TypeTime, value)
  319. _node.DeletedAt = value
  320. }
  321. if value, ok := ssc.mutation.Name(); ok {
  322. _spec.SetField(sopstage.FieldName, field.TypeString, value)
  323. _node.Name = value
  324. }
  325. if value, ok := ssc.mutation.ConditionType(); ok {
  326. _spec.SetField(sopstage.FieldConditionType, field.TypeInt, value)
  327. _node.ConditionType = value
  328. }
  329. if value, ok := ssc.mutation.ConditionOperator(); ok {
  330. _spec.SetField(sopstage.FieldConditionOperator, field.TypeInt, value)
  331. _node.ConditionOperator = value
  332. }
  333. if value, ok := ssc.mutation.ConditionList(); ok {
  334. _spec.SetField(sopstage.FieldConditionList, field.TypeJSON, value)
  335. _node.ConditionList = value
  336. }
  337. if value, ok := ssc.mutation.ActionMessage(); ok {
  338. _spec.SetField(sopstage.FieldActionMessage, field.TypeJSON, value)
  339. _node.ActionMessage = value
  340. }
  341. if value, ok := ssc.mutation.ActionLabel(); ok {
  342. _spec.SetField(sopstage.FieldActionLabel, field.TypeJSON, value)
  343. _node.ActionLabel = value
  344. }
  345. if value, ok := ssc.mutation.IndexSort(); ok {
  346. _spec.SetField(sopstage.FieldIndexSort, field.TypeInt, value)
  347. _node.IndexSort = value
  348. }
  349. if nodes := ssc.mutation.SopTaskIDs(); len(nodes) > 0 {
  350. edge := &sqlgraph.EdgeSpec{
  351. Rel: sqlgraph.M2O,
  352. Inverse: true,
  353. Table: sopstage.SopTaskTable,
  354. Columns: []string{sopstage.SopTaskColumn},
  355. Bidi: false,
  356. Target: &sqlgraph.EdgeTarget{
  357. IDSpec: sqlgraph.NewFieldSpec(soptask.FieldID, field.TypeUint64),
  358. },
  359. }
  360. for _, k := range nodes {
  361. edge.Target.Nodes = append(edge.Target.Nodes, k)
  362. }
  363. _node.TaskID = nodes[0]
  364. _spec.Edges = append(_spec.Edges, edge)
  365. }
  366. if nodes := ssc.mutation.StageNodesIDs(); len(nodes) > 0 {
  367. edge := &sqlgraph.EdgeSpec{
  368. Rel: sqlgraph.O2M,
  369. Inverse: false,
  370. Table: sopstage.StageNodesTable,
  371. Columns: []string{sopstage.StageNodesColumn},
  372. Bidi: false,
  373. Target: &sqlgraph.EdgeTarget{
  374. IDSpec: sqlgraph.NewFieldSpec(sopnode.FieldID, field.TypeUint64),
  375. },
  376. }
  377. for _, k := range nodes {
  378. edge.Target.Nodes = append(edge.Target.Nodes, k)
  379. }
  380. _spec.Edges = append(_spec.Edges, edge)
  381. }
  382. if nodes := ssc.mutation.StageMessagesIDs(); len(nodes) > 0 {
  383. edge := &sqlgraph.EdgeSpec{
  384. Rel: sqlgraph.O2M,
  385. Inverse: false,
  386. Table: sopstage.StageMessagesTable,
  387. Columns: []string{sopstage.StageMessagesColumn},
  388. Bidi: false,
  389. Target: &sqlgraph.EdgeTarget{
  390. IDSpec: sqlgraph.NewFieldSpec(messagerecords.FieldID, field.TypeUint64),
  391. },
  392. }
  393. for _, k := range nodes {
  394. edge.Target.Nodes = append(edge.Target.Nodes, k)
  395. }
  396. _spec.Edges = append(_spec.Edges, edge)
  397. }
  398. return _node, _spec
  399. }
  400. // OnConflict allows configuring the `ON CONFLICT` / `ON DUPLICATE KEY` clause
  401. // of the `INSERT` statement. For example:
  402. //
  403. // client.SopStage.Create().
  404. // SetCreatedAt(v).
  405. // OnConflict(
  406. // // Update the row with the new values
  407. // // the was proposed for insertion.
  408. // sql.ResolveWithNewValues(),
  409. // ).
  410. // // Override some of the fields with custom
  411. // // update values.
  412. // Update(func(u *ent.SopStageUpsert) {
  413. // SetCreatedAt(v+v).
  414. // }).
  415. // Exec(ctx)
  416. func (ssc *SopStageCreate) OnConflict(opts ...sql.ConflictOption) *SopStageUpsertOne {
  417. ssc.conflict = opts
  418. return &SopStageUpsertOne{
  419. create: ssc,
  420. }
  421. }
  422. // OnConflictColumns calls `OnConflict` and configures the columns
  423. // as conflict target. Using this option is equivalent to using:
  424. //
  425. // client.SopStage.Create().
  426. // OnConflict(sql.ConflictColumns(columns...)).
  427. // Exec(ctx)
  428. func (ssc *SopStageCreate) OnConflictColumns(columns ...string) *SopStageUpsertOne {
  429. ssc.conflict = append(ssc.conflict, sql.ConflictColumns(columns...))
  430. return &SopStageUpsertOne{
  431. create: ssc,
  432. }
  433. }
  434. type (
  435. // SopStageUpsertOne is the builder for "upsert"-ing
  436. // one SopStage node.
  437. SopStageUpsertOne struct {
  438. create *SopStageCreate
  439. }
  440. // SopStageUpsert is the "OnConflict" setter.
  441. SopStageUpsert struct {
  442. *sql.UpdateSet
  443. }
  444. )
  445. // SetUpdatedAt sets the "updated_at" field.
  446. func (u *SopStageUpsert) SetUpdatedAt(v time.Time) *SopStageUpsert {
  447. u.Set(sopstage.FieldUpdatedAt, v)
  448. return u
  449. }
  450. // UpdateUpdatedAt sets the "updated_at" field to the value that was provided on create.
  451. func (u *SopStageUpsert) UpdateUpdatedAt() *SopStageUpsert {
  452. u.SetExcluded(sopstage.FieldUpdatedAt)
  453. return u
  454. }
  455. // SetStatus sets the "status" field.
  456. func (u *SopStageUpsert) SetStatus(v uint8) *SopStageUpsert {
  457. u.Set(sopstage.FieldStatus, v)
  458. return u
  459. }
  460. // UpdateStatus sets the "status" field to the value that was provided on create.
  461. func (u *SopStageUpsert) UpdateStatus() *SopStageUpsert {
  462. u.SetExcluded(sopstage.FieldStatus)
  463. return u
  464. }
  465. // AddStatus adds v to the "status" field.
  466. func (u *SopStageUpsert) AddStatus(v uint8) *SopStageUpsert {
  467. u.Add(sopstage.FieldStatus, v)
  468. return u
  469. }
  470. // ClearStatus clears the value of the "status" field.
  471. func (u *SopStageUpsert) ClearStatus() *SopStageUpsert {
  472. u.SetNull(sopstage.FieldStatus)
  473. return u
  474. }
  475. // SetDeletedAt sets the "deleted_at" field.
  476. func (u *SopStageUpsert) SetDeletedAt(v time.Time) *SopStageUpsert {
  477. u.Set(sopstage.FieldDeletedAt, v)
  478. return u
  479. }
  480. // UpdateDeletedAt sets the "deleted_at" field to the value that was provided on create.
  481. func (u *SopStageUpsert) UpdateDeletedAt() *SopStageUpsert {
  482. u.SetExcluded(sopstage.FieldDeletedAt)
  483. return u
  484. }
  485. // ClearDeletedAt clears the value of the "deleted_at" field.
  486. func (u *SopStageUpsert) ClearDeletedAt() *SopStageUpsert {
  487. u.SetNull(sopstage.FieldDeletedAt)
  488. return u
  489. }
  490. // SetTaskID sets the "task_id" field.
  491. func (u *SopStageUpsert) SetTaskID(v uint64) *SopStageUpsert {
  492. u.Set(sopstage.FieldTaskID, v)
  493. return u
  494. }
  495. // UpdateTaskID sets the "task_id" field to the value that was provided on create.
  496. func (u *SopStageUpsert) UpdateTaskID() *SopStageUpsert {
  497. u.SetExcluded(sopstage.FieldTaskID)
  498. return u
  499. }
  500. // SetName sets the "name" field.
  501. func (u *SopStageUpsert) SetName(v string) *SopStageUpsert {
  502. u.Set(sopstage.FieldName, v)
  503. return u
  504. }
  505. // UpdateName sets the "name" field to the value that was provided on create.
  506. func (u *SopStageUpsert) UpdateName() *SopStageUpsert {
  507. u.SetExcluded(sopstage.FieldName)
  508. return u
  509. }
  510. // SetConditionType sets the "condition_type" field.
  511. func (u *SopStageUpsert) SetConditionType(v int) *SopStageUpsert {
  512. u.Set(sopstage.FieldConditionType, v)
  513. return u
  514. }
  515. // UpdateConditionType sets the "condition_type" field to the value that was provided on create.
  516. func (u *SopStageUpsert) UpdateConditionType() *SopStageUpsert {
  517. u.SetExcluded(sopstage.FieldConditionType)
  518. return u
  519. }
  520. // AddConditionType adds v to the "condition_type" field.
  521. func (u *SopStageUpsert) AddConditionType(v int) *SopStageUpsert {
  522. u.Add(sopstage.FieldConditionType, v)
  523. return u
  524. }
  525. // SetConditionOperator sets the "condition_operator" field.
  526. func (u *SopStageUpsert) SetConditionOperator(v int) *SopStageUpsert {
  527. u.Set(sopstage.FieldConditionOperator, v)
  528. return u
  529. }
  530. // UpdateConditionOperator sets the "condition_operator" field to the value that was provided on create.
  531. func (u *SopStageUpsert) UpdateConditionOperator() *SopStageUpsert {
  532. u.SetExcluded(sopstage.FieldConditionOperator)
  533. return u
  534. }
  535. // AddConditionOperator adds v to the "condition_operator" field.
  536. func (u *SopStageUpsert) AddConditionOperator(v int) *SopStageUpsert {
  537. u.Add(sopstage.FieldConditionOperator, v)
  538. return u
  539. }
  540. // SetConditionList sets the "condition_list" field.
  541. func (u *SopStageUpsert) SetConditionList(v []custom_types.Condition) *SopStageUpsert {
  542. u.Set(sopstage.FieldConditionList, v)
  543. return u
  544. }
  545. // UpdateConditionList sets the "condition_list" field to the value that was provided on create.
  546. func (u *SopStageUpsert) UpdateConditionList() *SopStageUpsert {
  547. u.SetExcluded(sopstage.FieldConditionList)
  548. return u
  549. }
  550. // SetActionMessage sets the "action_message" field.
  551. func (u *SopStageUpsert) SetActionMessage(v []custom_types.Action) *SopStageUpsert {
  552. u.Set(sopstage.FieldActionMessage, v)
  553. return u
  554. }
  555. // UpdateActionMessage sets the "action_message" field to the value that was provided on create.
  556. func (u *SopStageUpsert) UpdateActionMessage() *SopStageUpsert {
  557. u.SetExcluded(sopstage.FieldActionMessage)
  558. return u
  559. }
  560. // ClearActionMessage clears the value of the "action_message" field.
  561. func (u *SopStageUpsert) ClearActionMessage() *SopStageUpsert {
  562. u.SetNull(sopstage.FieldActionMessage)
  563. return u
  564. }
  565. // SetActionLabel sets the "action_label" field.
  566. func (u *SopStageUpsert) SetActionLabel(v []uint64) *SopStageUpsert {
  567. u.Set(sopstage.FieldActionLabel, v)
  568. return u
  569. }
  570. // UpdateActionLabel sets the "action_label" field to the value that was provided on create.
  571. func (u *SopStageUpsert) UpdateActionLabel() *SopStageUpsert {
  572. u.SetExcluded(sopstage.FieldActionLabel)
  573. return u
  574. }
  575. // ClearActionLabel clears the value of the "action_label" field.
  576. func (u *SopStageUpsert) ClearActionLabel() *SopStageUpsert {
  577. u.SetNull(sopstage.FieldActionLabel)
  578. return u
  579. }
  580. // SetIndexSort sets the "index_sort" field.
  581. func (u *SopStageUpsert) SetIndexSort(v int) *SopStageUpsert {
  582. u.Set(sopstage.FieldIndexSort, v)
  583. return u
  584. }
  585. // UpdateIndexSort sets the "index_sort" field to the value that was provided on create.
  586. func (u *SopStageUpsert) UpdateIndexSort() *SopStageUpsert {
  587. u.SetExcluded(sopstage.FieldIndexSort)
  588. return u
  589. }
  590. // AddIndexSort adds v to the "index_sort" field.
  591. func (u *SopStageUpsert) AddIndexSort(v int) *SopStageUpsert {
  592. u.Add(sopstage.FieldIndexSort, v)
  593. return u
  594. }
  595. // ClearIndexSort clears the value of the "index_sort" field.
  596. func (u *SopStageUpsert) ClearIndexSort() *SopStageUpsert {
  597. u.SetNull(sopstage.FieldIndexSort)
  598. return u
  599. }
  600. // UpdateNewValues updates the mutable fields using the new values that were set on create except the ID field.
  601. // Using this option is equivalent to using:
  602. //
  603. // client.SopStage.Create().
  604. // OnConflict(
  605. // sql.ResolveWithNewValues(),
  606. // sql.ResolveWith(func(u *sql.UpdateSet) {
  607. // u.SetIgnore(sopstage.FieldID)
  608. // }),
  609. // ).
  610. // Exec(ctx)
  611. func (u *SopStageUpsertOne) UpdateNewValues() *SopStageUpsertOne {
  612. u.create.conflict = append(u.create.conflict, sql.ResolveWithNewValues())
  613. u.create.conflict = append(u.create.conflict, sql.ResolveWith(func(s *sql.UpdateSet) {
  614. if _, exists := u.create.mutation.ID(); exists {
  615. s.SetIgnore(sopstage.FieldID)
  616. }
  617. if _, exists := u.create.mutation.CreatedAt(); exists {
  618. s.SetIgnore(sopstage.FieldCreatedAt)
  619. }
  620. }))
  621. return u
  622. }
  623. // Ignore sets each column to itself in case of conflict.
  624. // Using this option is equivalent to using:
  625. //
  626. // client.SopStage.Create().
  627. // OnConflict(sql.ResolveWithIgnore()).
  628. // Exec(ctx)
  629. func (u *SopStageUpsertOne) Ignore() *SopStageUpsertOne {
  630. u.create.conflict = append(u.create.conflict, sql.ResolveWithIgnore())
  631. return u
  632. }
  633. // DoNothing configures the conflict_action to `DO NOTHING`.
  634. // Supported only by SQLite and PostgreSQL.
  635. func (u *SopStageUpsertOne) DoNothing() *SopStageUpsertOne {
  636. u.create.conflict = append(u.create.conflict, sql.DoNothing())
  637. return u
  638. }
  639. // Update allows overriding fields `UPDATE` values. See the SopStageCreate.OnConflict
  640. // documentation for more info.
  641. func (u *SopStageUpsertOne) Update(set func(*SopStageUpsert)) *SopStageUpsertOne {
  642. u.create.conflict = append(u.create.conflict, sql.ResolveWith(func(update *sql.UpdateSet) {
  643. set(&SopStageUpsert{UpdateSet: update})
  644. }))
  645. return u
  646. }
  647. // SetUpdatedAt sets the "updated_at" field.
  648. func (u *SopStageUpsertOne) SetUpdatedAt(v time.Time) *SopStageUpsertOne {
  649. return u.Update(func(s *SopStageUpsert) {
  650. s.SetUpdatedAt(v)
  651. })
  652. }
  653. // UpdateUpdatedAt sets the "updated_at" field to the value that was provided on create.
  654. func (u *SopStageUpsertOne) UpdateUpdatedAt() *SopStageUpsertOne {
  655. return u.Update(func(s *SopStageUpsert) {
  656. s.UpdateUpdatedAt()
  657. })
  658. }
  659. // SetStatus sets the "status" field.
  660. func (u *SopStageUpsertOne) SetStatus(v uint8) *SopStageUpsertOne {
  661. return u.Update(func(s *SopStageUpsert) {
  662. s.SetStatus(v)
  663. })
  664. }
  665. // AddStatus adds v to the "status" field.
  666. func (u *SopStageUpsertOne) AddStatus(v uint8) *SopStageUpsertOne {
  667. return u.Update(func(s *SopStageUpsert) {
  668. s.AddStatus(v)
  669. })
  670. }
  671. // UpdateStatus sets the "status" field to the value that was provided on create.
  672. func (u *SopStageUpsertOne) UpdateStatus() *SopStageUpsertOne {
  673. return u.Update(func(s *SopStageUpsert) {
  674. s.UpdateStatus()
  675. })
  676. }
  677. // ClearStatus clears the value of the "status" field.
  678. func (u *SopStageUpsertOne) ClearStatus() *SopStageUpsertOne {
  679. return u.Update(func(s *SopStageUpsert) {
  680. s.ClearStatus()
  681. })
  682. }
  683. // SetDeletedAt sets the "deleted_at" field.
  684. func (u *SopStageUpsertOne) SetDeletedAt(v time.Time) *SopStageUpsertOne {
  685. return u.Update(func(s *SopStageUpsert) {
  686. s.SetDeletedAt(v)
  687. })
  688. }
  689. // UpdateDeletedAt sets the "deleted_at" field to the value that was provided on create.
  690. func (u *SopStageUpsertOne) UpdateDeletedAt() *SopStageUpsertOne {
  691. return u.Update(func(s *SopStageUpsert) {
  692. s.UpdateDeletedAt()
  693. })
  694. }
  695. // ClearDeletedAt clears the value of the "deleted_at" field.
  696. func (u *SopStageUpsertOne) ClearDeletedAt() *SopStageUpsertOne {
  697. return u.Update(func(s *SopStageUpsert) {
  698. s.ClearDeletedAt()
  699. })
  700. }
  701. // SetTaskID sets the "task_id" field.
  702. func (u *SopStageUpsertOne) SetTaskID(v uint64) *SopStageUpsertOne {
  703. return u.Update(func(s *SopStageUpsert) {
  704. s.SetTaskID(v)
  705. })
  706. }
  707. // UpdateTaskID sets the "task_id" field to the value that was provided on create.
  708. func (u *SopStageUpsertOne) UpdateTaskID() *SopStageUpsertOne {
  709. return u.Update(func(s *SopStageUpsert) {
  710. s.UpdateTaskID()
  711. })
  712. }
  713. // SetName sets the "name" field.
  714. func (u *SopStageUpsertOne) SetName(v string) *SopStageUpsertOne {
  715. return u.Update(func(s *SopStageUpsert) {
  716. s.SetName(v)
  717. })
  718. }
  719. // UpdateName sets the "name" field to the value that was provided on create.
  720. func (u *SopStageUpsertOne) UpdateName() *SopStageUpsertOne {
  721. return u.Update(func(s *SopStageUpsert) {
  722. s.UpdateName()
  723. })
  724. }
  725. // SetConditionType sets the "condition_type" field.
  726. func (u *SopStageUpsertOne) SetConditionType(v int) *SopStageUpsertOne {
  727. return u.Update(func(s *SopStageUpsert) {
  728. s.SetConditionType(v)
  729. })
  730. }
  731. // AddConditionType adds v to the "condition_type" field.
  732. func (u *SopStageUpsertOne) AddConditionType(v int) *SopStageUpsertOne {
  733. return u.Update(func(s *SopStageUpsert) {
  734. s.AddConditionType(v)
  735. })
  736. }
  737. // UpdateConditionType sets the "condition_type" field to the value that was provided on create.
  738. func (u *SopStageUpsertOne) UpdateConditionType() *SopStageUpsertOne {
  739. return u.Update(func(s *SopStageUpsert) {
  740. s.UpdateConditionType()
  741. })
  742. }
  743. // SetConditionOperator sets the "condition_operator" field.
  744. func (u *SopStageUpsertOne) SetConditionOperator(v int) *SopStageUpsertOne {
  745. return u.Update(func(s *SopStageUpsert) {
  746. s.SetConditionOperator(v)
  747. })
  748. }
  749. // AddConditionOperator adds v to the "condition_operator" field.
  750. func (u *SopStageUpsertOne) AddConditionOperator(v int) *SopStageUpsertOne {
  751. return u.Update(func(s *SopStageUpsert) {
  752. s.AddConditionOperator(v)
  753. })
  754. }
  755. // UpdateConditionOperator sets the "condition_operator" field to the value that was provided on create.
  756. func (u *SopStageUpsertOne) UpdateConditionOperator() *SopStageUpsertOne {
  757. return u.Update(func(s *SopStageUpsert) {
  758. s.UpdateConditionOperator()
  759. })
  760. }
  761. // SetConditionList sets the "condition_list" field.
  762. func (u *SopStageUpsertOne) SetConditionList(v []custom_types.Condition) *SopStageUpsertOne {
  763. return u.Update(func(s *SopStageUpsert) {
  764. s.SetConditionList(v)
  765. })
  766. }
  767. // UpdateConditionList sets the "condition_list" field to the value that was provided on create.
  768. func (u *SopStageUpsertOne) UpdateConditionList() *SopStageUpsertOne {
  769. return u.Update(func(s *SopStageUpsert) {
  770. s.UpdateConditionList()
  771. })
  772. }
  773. // SetActionMessage sets the "action_message" field.
  774. func (u *SopStageUpsertOne) SetActionMessage(v []custom_types.Action) *SopStageUpsertOne {
  775. return u.Update(func(s *SopStageUpsert) {
  776. s.SetActionMessage(v)
  777. })
  778. }
  779. // UpdateActionMessage sets the "action_message" field to the value that was provided on create.
  780. func (u *SopStageUpsertOne) UpdateActionMessage() *SopStageUpsertOne {
  781. return u.Update(func(s *SopStageUpsert) {
  782. s.UpdateActionMessage()
  783. })
  784. }
  785. // ClearActionMessage clears the value of the "action_message" field.
  786. func (u *SopStageUpsertOne) ClearActionMessage() *SopStageUpsertOne {
  787. return u.Update(func(s *SopStageUpsert) {
  788. s.ClearActionMessage()
  789. })
  790. }
  791. // SetActionLabel sets the "action_label" field.
  792. func (u *SopStageUpsertOne) SetActionLabel(v []uint64) *SopStageUpsertOne {
  793. return u.Update(func(s *SopStageUpsert) {
  794. s.SetActionLabel(v)
  795. })
  796. }
  797. // UpdateActionLabel sets the "action_label" field to the value that was provided on create.
  798. func (u *SopStageUpsertOne) UpdateActionLabel() *SopStageUpsertOne {
  799. return u.Update(func(s *SopStageUpsert) {
  800. s.UpdateActionLabel()
  801. })
  802. }
  803. // ClearActionLabel clears the value of the "action_label" field.
  804. func (u *SopStageUpsertOne) ClearActionLabel() *SopStageUpsertOne {
  805. return u.Update(func(s *SopStageUpsert) {
  806. s.ClearActionLabel()
  807. })
  808. }
  809. // SetIndexSort sets the "index_sort" field.
  810. func (u *SopStageUpsertOne) SetIndexSort(v int) *SopStageUpsertOne {
  811. return u.Update(func(s *SopStageUpsert) {
  812. s.SetIndexSort(v)
  813. })
  814. }
  815. // AddIndexSort adds v to the "index_sort" field.
  816. func (u *SopStageUpsertOne) AddIndexSort(v int) *SopStageUpsertOne {
  817. return u.Update(func(s *SopStageUpsert) {
  818. s.AddIndexSort(v)
  819. })
  820. }
  821. // UpdateIndexSort sets the "index_sort" field to the value that was provided on create.
  822. func (u *SopStageUpsertOne) UpdateIndexSort() *SopStageUpsertOne {
  823. return u.Update(func(s *SopStageUpsert) {
  824. s.UpdateIndexSort()
  825. })
  826. }
  827. // ClearIndexSort clears the value of the "index_sort" field.
  828. func (u *SopStageUpsertOne) ClearIndexSort() *SopStageUpsertOne {
  829. return u.Update(func(s *SopStageUpsert) {
  830. s.ClearIndexSort()
  831. })
  832. }
  833. // Exec executes the query.
  834. func (u *SopStageUpsertOne) Exec(ctx context.Context) error {
  835. if len(u.create.conflict) == 0 {
  836. return errors.New("ent: missing options for SopStageCreate.OnConflict")
  837. }
  838. return u.create.Exec(ctx)
  839. }
  840. // ExecX is like Exec, but panics if an error occurs.
  841. func (u *SopStageUpsertOne) ExecX(ctx context.Context) {
  842. if err := u.create.Exec(ctx); err != nil {
  843. panic(err)
  844. }
  845. }
  846. // Exec executes the UPSERT query and returns the inserted/updated ID.
  847. func (u *SopStageUpsertOne) ID(ctx context.Context) (id uint64, err error) {
  848. node, err := u.create.Save(ctx)
  849. if err != nil {
  850. return id, err
  851. }
  852. return node.ID, nil
  853. }
  854. // IDX is like ID, but panics if an error occurs.
  855. func (u *SopStageUpsertOne) IDX(ctx context.Context) uint64 {
  856. id, err := u.ID(ctx)
  857. if err != nil {
  858. panic(err)
  859. }
  860. return id
  861. }
  862. // SopStageCreateBulk is the builder for creating many SopStage entities in bulk.
  863. type SopStageCreateBulk struct {
  864. config
  865. err error
  866. builders []*SopStageCreate
  867. conflict []sql.ConflictOption
  868. }
  869. // Save creates the SopStage entities in the database.
  870. func (sscb *SopStageCreateBulk) Save(ctx context.Context) ([]*SopStage, error) {
  871. if sscb.err != nil {
  872. return nil, sscb.err
  873. }
  874. specs := make([]*sqlgraph.CreateSpec, len(sscb.builders))
  875. nodes := make([]*SopStage, len(sscb.builders))
  876. mutators := make([]Mutator, len(sscb.builders))
  877. for i := range sscb.builders {
  878. func(i int, root context.Context) {
  879. builder := sscb.builders[i]
  880. builder.defaults()
  881. var mut Mutator = MutateFunc(func(ctx context.Context, m Mutation) (Value, error) {
  882. mutation, ok := m.(*SopStageMutation)
  883. if !ok {
  884. return nil, fmt.Errorf("unexpected mutation type %T", m)
  885. }
  886. if err := builder.check(); err != nil {
  887. return nil, err
  888. }
  889. builder.mutation = mutation
  890. var err error
  891. nodes[i], specs[i] = builder.createSpec()
  892. if i < len(mutators)-1 {
  893. _, err = mutators[i+1].Mutate(root, sscb.builders[i+1].mutation)
  894. } else {
  895. spec := &sqlgraph.BatchCreateSpec{Nodes: specs}
  896. spec.OnConflict = sscb.conflict
  897. // Invoke the actual operation on the latest mutation in the chain.
  898. if err = sqlgraph.BatchCreate(ctx, sscb.driver, spec); err != nil {
  899. if sqlgraph.IsConstraintError(err) {
  900. err = &ConstraintError{msg: err.Error(), wrap: err}
  901. }
  902. }
  903. }
  904. if err != nil {
  905. return nil, err
  906. }
  907. mutation.id = &nodes[i].ID
  908. if specs[i].ID.Value != nil && nodes[i].ID == 0 {
  909. id := specs[i].ID.Value.(int64)
  910. nodes[i].ID = uint64(id)
  911. }
  912. mutation.done = true
  913. return nodes[i], nil
  914. })
  915. for i := len(builder.hooks) - 1; i >= 0; i-- {
  916. mut = builder.hooks[i](mut)
  917. }
  918. mutators[i] = mut
  919. }(i, ctx)
  920. }
  921. if len(mutators) > 0 {
  922. if _, err := mutators[0].Mutate(ctx, sscb.builders[0].mutation); err != nil {
  923. return nil, err
  924. }
  925. }
  926. return nodes, nil
  927. }
  928. // SaveX is like Save, but panics if an error occurs.
  929. func (sscb *SopStageCreateBulk) SaveX(ctx context.Context) []*SopStage {
  930. v, err := sscb.Save(ctx)
  931. if err != nil {
  932. panic(err)
  933. }
  934. return v
  935. }
  936. // Exec executes the query.
  937. func (sscb *SopStageCreateBulk) Exec(ctx context.Context) error {
  938. _, err := sscb.Save(ctx)
  939. return err
  940. }
  941. // ExecX is like Exec, but panics if an error occurs.
  942. func (sscb *SopStageCreateBulk) ExecX(ctx context.Context) {
  943. if err := sscb.Exec(ctx); err != nil {
  944. panic(err)
  945. }
  946. }
  947. // OnConflict allows configuring the `ON CONFLICT` / `ON DUPLICATE KEY` clause
  948. // of the `INSERT` statement. For example:
  949. //
  950. // client.SopStage.CreateBulk(builders...).
  951. // OnConflict(
  952. // // Update the row with the new values
  953. // // the was proposed for insertion.
  954. // sql.ResolveWithNewValues(),
  955. // ).
  956. // // Override some of the fields with custom
  957. // // update values.
  958. // Update(func(u *ent.SopStageUpsert) {
  959. // SetCreatedAt(v+v).
  960. // }).
  961. // Exec(ctx)
  962. func (sscb *SopStageCreateBulk) OnConflict(opts ...sql.ConflictOption) *SopStageUpsertBulk {
  963. sscb.conflict = opts
  964. return &SopStageUpsertBulk{
  965. create: sscb,
  966. }
  967. }
  968. // OnConflictColumns calls `OnConflict` and configures the columns
  969. // as conflict target. Using this option is equivalent to using:
  970. //
  971. // client.SopStage.Create().
  972. // OnConflict(sql.ConflictColumns(columns...)).
  973. // Exec(ctx)
  974. func (sscb *SopStageCreateBulk) OnConflictColumns(columns ...string) *SopStageUpsertBulk {
  975. sscb.conflict = append(sscb.conflict, sql.ConflictColumns(columns...))
  976. return &SopStageUpsertBulk{
  977. create: sscb,
  978. }
  979. }
  980. // SopStageUpsertBulk is the builder for "upsert"-ing
  981. // a bulk of SopStage nodes.
  982. type SopStageUpsertBulk struct {
  983. create *SopStageCreateBulk
  984. }
  985. // UpdateNewValues updates the mutable fields using the new values that
  986. // were set on create. Using this option is equivalent to using:
  987. //
  988. // client.SopStage.Create().
  989. // OnConflict(
  990. // sql.ResolveWithNewValues(),
  991. // sql.ResolveWith(func(u *sql.UpdateSet) {
  992. // u.SetIgnore(sopstage.FieldID)
  993. // }),
  994. // ).
  995. // Exec(ctx)
  996. func (u *SopStageUpsertBulk) UpdateNewValues() *SopStageUpsertBulk {
  997. u.create.conflict = append(u.create.conflict, sql.ResolveWithNewValues())
  998. u.create.conflict = append(u.create.conflict, sql.ResolveWith(func(s *sql.UpdateSet) {
  999. for _, b := range u.create.builders {
  1000. if _, exists := b.mutation.ID(); exists {
  1001. s.SetIgnore(sopstage.FieldID)
  1002. }
  1003. if _, exists := b.mutation.CreatedAt(); exists {
  1004. s.SetIgnore(sopstage.FieldCreatedAt)
  1005. }
  1006. }
  1007. }))
  1008. return u
  1009. }
  1010. // Ignore sets each column to itself in case of conflict.
  1011. // Using this option is equivalent to using:
  1012. //
  1013. // client.SopStage.Create().
  1014. // OnConflict(sql.ResolveWithIgnore()).
  1015. // Exec(ctx)
  1016. func (u *SopStageUpsertBulk) Ignore() *SopStageUpsertBulk {
  1017. u.create.conflict = append(u.create.conflict, sql.ResolveWithIgnore())
  1018. return u
  1019. }
  1020. // DoNothing configures the conflict_action to `DO NOTHING`.
  1021. // Supported only by SQLite and PostgreSQL.
  1022. func (u *SopStageUpsertBulk) DoNothing() *SopStageUpsertBulk {
  1023. u.create.conflict = append(u.create.conflict, sql.DoNothing())
  1024. return u
  1025. }
  1026. // Update allows overriding fields `UPDATE` values. See the SopStageCreateBulk.OnConflict
  1027. // documentation for more info.
  1028. func (u *SopStageUpsertBulk) Update(set func(*SopStageUpsert)) *SopStageUpsertBulk {
  1029. u.create.conflict = append(u.create.conflict, sql.ResolveWith(func(update *sql.UpdateSet) {
  1030. set(&SopStageUpsert{UpdateSet: update})
  1031. }))
  1032. return u
  1033. }
  1034. // SetUpdatedAt sets the "updated_at" field.
  1035. func (u *SopStageUpsertBulk) SetUpdatedAt(v time.Time) *SopStageUpsertBulk {
  1036. return u.Update(func(s *SopStageUpsert) {
  1037. s.SetUpdatedAt(v)
  1038. })
  1039. }
  1040. // UpdateUpdatedAt sets the "updated_at" field to the value that was provided on create.
  1041. func (u *SopStageUpsertBulk) UpdateUpdatedAt() *SopStageUpsertBulk {
  1042. return u.Update(func(s *SopStageUpsert) {
  1043. s.UpdateUpdatedAt()
  1044. })
  1045. }
  1046. // SetStatus sets the "status" field.
  1047. func (u *SopStageUpsertBulk) SetStatus(v uint8) *SopStageUpsertBulk {
  1048. return u.Update(func(s *SopStageUpsert) {
  1049. s.SetStatus(v)
  1050. })
  1051. }
  1052. // AddStatus adds v to the "status" field.
  1053. func (u *SopStageUpsertBulk) AddStatus(v uint8) *SopStageUpsertBulk {
  1054. return u.Update(func(s *SopStageUpsert) {
  1055. s.AddStatus(v)
  1056. })
  1057. }
  1058. // UpdateStatus sets the "status" field to the value that was provided on create.
  1059. func (u *SopStageUpsertBulk) UpdateStatus() *SopStageUpsertBulk {
  1060. return u.Update(func(s *SopStageUpsert) {
  1061. s.UpdateStatus()
  1062. })
  1063. }
  1064. // ClearStatus clears the value of the "status" field.
  1065. func (u *SopStageUpsertBulk) ClearStatus() *SopStageUpsertBulk {
  1066. return u.Update(func(s *SopStageUpsert) {
  1067. s.ClearStatus()
  1068. })
  1069. }
  1070. // SetDeletedAt sets the "deleted_at" field.
  1071. func (u *SopStageUpsertBulk) SetDeletedAt(v time.Time) *SopStageUpsertBulk {
  1072. return u.Update(func(s *SopStageUpsert) {
  1073. s.SetDeletedAt(v)
  1074. })
  1075. }
  1076. // UpdateDeletedAt sets the "deleted_at" field to the value that was provided on create.
  1077. func (u *SopStageUpsertBulk) UpdateDeletedAt() *SopStageUpsertBulk {
  1078. return u.Update(func(s *SopStageUpsert) {
  1079. s.UpdateDeletedAt()
  1080. })
  1081. }
  1082. // ClearDeletedAt clears the value of the "deleted_at" field.
  1083. func (u *SopStageUpsertBulk) ClearDeletedAt() *SopStageUpsertBulk {
  1084. return u.Update(func(s *SopStageUpsert) {
  1085. s.ClearDeletedAt()
  1086. })
  1087. }
  1088. // SetTaskID sets the "task_id" field.
  1089. func (u *SopStageUpsertBulk) SetTaskID(v uint64) *SopStageUpsertBulk {
  1090. return u.Update(func(s *SopStageUpsert) {
  1091. s.SetTaskID(v)
  1092. })
  1093. }
  1094. // UpdateTaskID sets the "task_id" field to the value that was provided on create.
  1095. func (u *SopStageUpsertBulk) UpdateTaskID() *SopStageUpsertBulk {
  1096. return u.Update(func(s *SopStageUpsert) {
  1097. s.UpdateTaskID()
  1098. })
  1099. }
  1100. // SetName sets the "name" field.
  1101. func (u *SopStageUpsertBulk) SetName(v string) *SopStageUpsertBulk {
  1102. return u.Update(func(s *SopStageUpsert) {
  1103. s.SetName(v)
  1104. })
  1105. }
  1106. // UpdateName sets the "name" field to the value that was provided on create.
  1107. func (u *SopStageUpsertBulk) UpdateName() *SopStageUpsertBulk {
  1108. return u.Update(func(s *SopStageUpsert) {
  1109. s.UpdateName()
  1110. })
  1111. }
  1112. // SetConditionType sets the "condition_type" field.
  1113. func (u *SopStageUpsertBulk) SetConditionType(v int) *SopStageUpsertBulk {
  1114. return u.Update(func(s *SopStageUpsert) {
  1115. s.SetConditionType(v)
  1116. })
  1117. }
  1118. // AddConditionType adds v to the "condition_type" field.
  1119. func (u *SopStageUpsertBulk) AddConditionType(v int) *SopStageUpsertBulk {
  1120. return u.Update(func(s *SopStageUpsert) {
  1121. s.AddConditionType(v)
  1122. })
  1123. }
  1124. // UpdateConditionType sets the "condition_type" field to the value that was provided on create.
  1125. func (u *SopStageUpsertBulk) UpdateConditionType() *SopStageUpsertBulk {
  1126. return u.Update(func(s *SopStageUpsert) {
  1127. s.UpdateConditionType()
  1128. })
  1129. }
  1130. // SetConditionOperator sets the "condition_operator" field.
  1131. func (u *SopStageUpsertBulk) SetConditionOperator(v int) *SopStageUpsertBulk {
  1132. return u.Update(func(s *SopStageUpsert) {
  1133. s.SetConditionOperator(v)
  1134. })
  1135. }
  1136. // AddConditionOperator adds v to the "condition_operator" field.
  1137. func (u *SopStageUpsertBulk) AddConditionOperator(v int) *SopStageUpsertBulk {
  1138. return u.Update(func(s *SopStageUpsert) {
  1139. s.AddConditionOperator(v)
  1140. })
  1141. }
  1142. // UpdateConditionOperator sets the "condition_operator" field to the value that was provided on create.
  1143. func (u *SopStageUpsertBulk) UpdateConditionOperator() *SopStageUpsertBulk {
  1144. return u.Update(func(s *SopStageUpsert) {
  1145. s.UpdateConditionOperator()
  1146. })
  1147. }
  1148. // SetConditionList sets the "condition_list" field.
  1149. func (u *SopStageUpsertBulk) SetConditionList(v []custom_types.Condition) *SopStageUpsertBulk {
  1150. return u.Update(func(s *SopStageUpsert) {
  1151. s.SetConditionList(v)
  1152. })
  1153. }
  1154. // UpdateConditionList sets the "condition_list" field to the value that was provided on create.
  1155. func (u *SopStageUpsertBulk) UpdateConditionList() *SopStageUpsertBulk {
  1156. return u.Update(func(s *SopStageUpsert) {
  1157. s.UpdateConditionList()
  1158. })
  1159. }
  1160. // SetActionMessage sets the "action_message" field.
  1161. func (u *SopStageUpsertBulk) SetActionMessage(v []custom_types.Action) *SopStageUpsertBulk {
  1162. return u.Update(func(s *SopStageUpsert) {
  1163. s.SetActionMessage(v)
  1164. })
  1165. }
  1166. // UpdateActionMessage sets the "action_message" field to the value that was provided on create.
  1167. func (u *SopStageUpsertBulk) UpdateActionMessage() *SopStageUpsertBulk {
  1168. return u.Update(func(s *SopStageUpsert) {
  1169. s.UpdateActionMessage()
  1170. })
  1171. }
  1172. // ClearActionMessage clears the value of the "action_message" field.
  1173. func (u *SopStageUpsertBulk) ClearActionMessage() *SopStageUpsertBulk {
  1174. return u.Update(func(s *SopStageUpsert) {
  1175. s.ClearActionMessage()
  1176. })
  1177. }
  1178. // SetActionLabel sets the "action_label" field.
  1179. func (u *SopStageUpsertBulk) SetActionLabel(v []uint64) *SopStageUpsertBulk {
  1180. return u.Update(func(s *SopStageUpsert) {
  1181. s.SetActionLabel(v)
  1182. })
  1183. }
  1184. // UpdateActionLabel sets the "action_label" field to the value that was provided on create.
  1185. func (u *SopStageUpsertBulk) UpdateActionLabel() *SopStageUpsertBulk {
  1186. return u.Update(func(s *SopStageUpsert) {
  1187. s.UpdateActionLabel()
  1188. })
  1189. }
  1190. // ClearActionLabel clears the value of the "action_label" field.
  1191. func (u *SopStageUpsertBulk) ClearActionLabel() *SopStageUpsertBulk {
  1192. return u.Update(func(s *SopStageUpsert) {
  1193. s.ClearActionLabel()
  1194. })
  1195. }
  1196. // SetIndexSort sets the "index_sort" field.
  1197. func (u *SopStageUpsertBulk) SetIndexSort(v int) *SopStageUpsertBulk {
  1198. return u.Update(func(s *SopStageUpsert) {
  1199. s.SetIndexSort(v)
  1200. })
  1201. }
  1202. // AddIndexSort adds v to the "index_sort" field.
  1203. func (u *SopStageUpsertBulk) AddIndexSort(v int) *SopStageUpsertBulk {
  1204. return u.Update(func(s *SopStageUpsert) {
  1205. s.AddIndexSort(v)
  1206. })
  1207. }
  1208. // UpdateIndexSort sets the "index_sort" field to the value that was provided on create.
  1209. func (u *SopStageUpsertBulk) UpdateIndexSort() *SopStageUpsertBulk {
  1210. return u.Update(func(s *SopStageUpsert) {
  1211. s.UpdateIndexSort()
  1212. })
  1213. }
  1214. // ClearIndexSort clears the value of the "index_sort" field.
  1215. func (u *SopStageUpsertBulk) ClearIndexSort() *SopStageUpsertBulk {
  1216. return u.Update(func(s *SopStageUpsert) {
  1217. s.ClearIndexSort()
  1218. })
  1219. }
  1220. // Exec executes the query.
  1221. func (u *SopStageUpsertBulk) Exec(ctx context.Context) error {
  1222. if u.create.err != nil {
  1223. return u.create.err
  1224. }
  1225. for i, b := range u.create.builders {
  1226. if len(b.conflict) != 0 {
  1227. return fmt.Errorf("ent: OnConflict was set for builder %d. Set it on the SopStageCreateBulk instead", i)
  1228. }
  1229. }
  1230. if len(u.create.conflict) == 0 {
  1231. return errors.New("ent: missing options for SopStageCreateBulk.OnConflict")
  1232. }
  1233. return u.create.Exec(ctx)
  1234. }
  1235. // ExecX is like Exec, but panics if an error occurs.
  1236. func (u *SopStageUpsertBulk) ExecX(ctx context.Context) {
  1237. if err := u.create.Exec(ctx); err != nil {
  1238. panic(err)
  1239. }
  1240. }