sopstage_create.go 46 KB

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