sopnode_create.go 46 KB

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