accountgroup_create.go 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653
  1. // Code generated by ent, DO NOT EDIT.
  2. package ent
  3. import (
  4. "context"
  5. "errors"
  6. "fmt"
  7. "time"
  8. "entgo.io/ent/dialect/sql"
  9. "entgo.io/ent/dialect/sql/sqlgraph"
  10. "entgo.io/ent/schema/field"
  11. "github.com/Wei-Shaw/sub2api/ent/account"
  12. "github.com/Wei-Shaw/sub2api/ent/accountgroup"
  13. "github.com/Wei-Shaw/sub2api/ent/group"
  14. )
  15. // AccountGroupCreate is the builder for creating a AccountGroup entity.
  16. type AccountGroupCreate struct {
  17. config
  18. mutation *AccountGroupMutation
  19. hooks []Hook
  20. conflict []sql.ConflictOption
  21. }
  22. // SetAccountID sets the "account_id" field.
  23. func (_c *AccountGroupCreate) SetAccountID(v int64) *AccountGroupCreate {
  24. _c.mutation.SetAccountID(v)
  25. return _c
  26. }
  27. // SetGroupID sets the "group_id" field.
  28. func (_c *AccountGroupCreate) SetGroupID(v int64) *AccountGroupCreate {
  29. _c.mutation.SetGroupID(v)
  30. return _c
  31. }
  32. // SetPriority sets the "priority" field.
  33. func (_c *AccountGroupCreate) SetPriority(v int) *AccountGroupCreate {
  34. _c.mutation.SetPriority(v)
  35. return _c
  36. }
  37. // SetNillablePriority sets the "priority" field if the given value is not nil.
  38. func (_c *AccountGroupCreate) SetNillablePriority(v *int) *AccountGroupCreate {
  39. if v != nil {
  40. _c.SetPriority(*v)
  41. }
  42. return _c
  43. }
  44. // SetCreatedAt sets the "created_at" field.
  45. func (_c *AccountGroupCreate) SetCreatedAt(v time.Time) *AccountGroupCreate {
  46. _c.mutation.SetCreatedAt(v)
  47. return _c
  48. }
  49. // SetNillableCreatedAt sets the "created_at" field if the given value is not nil.
  50. func (_c *AccountGroupCreate) SetNillableCreatedAt(v *time.Time) *AccountGroupCreate {
  51. if v != nil {
  52. _c.SetCreatedAt(*v)
  53. }
  54. return _c
  55. }
  56. // SetAccount sets the "account" edge to the Account entity.
  57. func (_c *AccountGroupCreate) SetAccount(v *Account) *AccountGroupCreate {
  58. return _c.SetAccountID(v.ID)
  59. }
  60. // SetGroup sets the "group" edge to the Group entity.
  61. func (_c *AccountGroupCreate) SetGroup(v *Group) *AccountGroupCreate {
  62. return _c.SetGroupID(v.ID)
  63. }
  64. // Mutation returns the AccountGroupMutation object of the builder.
  65. func (_c *AccountGroupCreate) Mutation() *AccountGroupMutation {
  66. return _c.mutation
  67. }
  68. // Save creates the AccountGroup in the database.
  69. func (_c *AccountGroupCreate) Save(ctx context.Context) (*AccountGroup, error) {
  70. _c.defaults()
  71. return withHooks(ctx, _c.sqlSave, _c.mutation, _c.hooks)
  72. }
  73. // SaveX calls Save and panics if Save returns an error.
  74. func (_c *AccountGroupCreate) SaveX(ctx context.Context) *AccountGroup {
  75. v, err := _c.Save(ctx)
  76. if err != nil {
  77. panic(err)
  78. }
  79. return v
  80. }
  81. // Exec executes the query.
  82. func (_c *AccountGroupCreate) Exec(ctx context.Context) error {
  83. _, err := _c.Save(ctx)
  84. return err
  85. }
  86. // ExecX is like Exec, but panics if an error occurs.
  87. func (_c *AccountGroupCreate) ExecX(ctx context.Context) {
  88. if err := _c.Exec(ctx); err != nil {
  89. panic(err)
  90. }
  91. }
  92. // defaults sets the default values of the builder before save.
  93. func (_c *AccountGroupCreate) defaults() {
  94. if _, ok := _c.mutation.Priority(); !ok {
  95. v := accountgroup.DefaultPriority
  96. _c.mutation.SetPriority(v)
  97. }
  98. if _, ok := _c.mutation.CreatedAt(); !ok {
  99. v := accountgroup.DefaultCreatedAt()
  100. _c.mutation.SetCreatedAt(v)
  101. }
  102. }
  103. // check runs all checks and user-defined validators on the builder.
  104. func (_c *AccountGroupCreate) check() error {
  105. if _, ok := _c.mutation.AccountID(); !ok {
  106. return &ValidationError{Name: "account_id", err: errors.New(`ent: missing required field "AccountGroup.account_id"`)}
  107. }
  108. if _, ok := _c.mutation.GroupID(); !ok {
  109. return &ValidationError{Name: "group_id", err: errors.New(`ent: missing required field "AccountGroup.group_id"`)}
  110. }
  111. if _, ok := _c.mutation.Priority(); !ok {
  112. return &ValidationError{Name: "priority", err: errors.New(`ent: missing required field "AccountGroup.priority"`)}
  113. }
  114. if _, ok := _c.mutation.CreatedAt(); !ok {
  115. return &ValidationError{Name: "created_at", err: errors.New(`ent: missing required field "AccountGroup.created_at"`)}
  116. }
  117. if len(_c.mutation.AccountIDs()) == 0 {
  118. return &ValidationError{Name: "account", err: errors.New(`ent: missing required edge "AccountGroup.account"`)}
  119. }
  120. if len(_c.mutation.GroupIDs()) == 0 {
  121. return &ValidationError{Name: "group", err: errors.New(`ent: missing required edge "AccountGroup.group"`)}
  122. }
  123. return nil
  124. }
  125. func (_c *AccountGroupCreate) sqlSave(ctx context.Context) (*AccountGroup, error) {
  126. if err := _c.check(); err != nil {
  127. return nil, err
  128. }
  129. _node, _spec := _c.createSpec()
  130. if err := sqlgraph.CreateNode(ctx, _c.driver, _spec); err != nil {
  131. if sqlgraph.IsConstraintError(err) {
  132. err = &ConstraintError{msg: err.Error(), wrap: err}
  133. }
  134. return nil, err
  135. }
  136. return _node, nil
  137. }
  138. func (_c *AccountGroupCreate) createSpec() (*AccountGroup, *sqlgraph.CreateSpec) {
  139. var (
  140. _node = &AccountGroup{config: _c.config}
  141. _spec = sqlgraph.NewCreateSpec(accountgroup.Table, nil)
  142. )
  143. _spec.OnConflict = _c.conflict
  144. if value, ok := _c.mutation.Priority(); ok {
  145. _spec.SetField(accountgroup.FieldPriority, field.TypeInt, value)
  146. _node.Priority = value
  147. }
  148. if value, ok := _c.mutation.CreatedAt(); ok {
  149. _spec.SetField(accountgroup.FieldCreatedAt, field.TypeTime, value)
  150. _node.CreatedAt = value
  151. }
  152. if nodes := _c.mutation.AccountIDs(); len(nodes) > 0 {
  153. edge := &sqlgraph.EdgeSpec{
  154. Rel: sqlgraph.M2O,
  155. Inverse: false,
  156. Table: accountgroup.AccountTable,
  157. Columns: []string{accountgroup.AccountColumn},
  158. Bidi: false,
  159. Target: &sqlgraph.EdgeTarget{
  160. IDSpec: sqlgraph.NewFieldSpec(account.FieldID, field.TypeInt64),
  161. },
  162. }
  163. for _, k := range nodes {
  164. edge.Target.Nodes = append(edge.Target.Nodes, k)
  165. }
  166. _node.AccountID = nodes[0]
  167. _spec.Edges = append(_spec.Edges, edge)
  168. }
  169. if nodes := _c.mutation.GroupIDs(); len(nodes) > 0 {
  170. edge := &sqlgraph.EdgeSpec{
  171. Rel: sqlgraph.M2O,
  172. Inverse: false,
  173. Table: accountgroup.GroupTable,
  174. Columns: []string{accountgroup.GroupColumn},
  175. Bidi: false,
  176. Target: &sqlgraph.EdgeTarget{
  177. IDSpec: sqlgraph.NewFieldSpec(group.FieldID, field.TypeInt64),
  178. },
  179. }
  180. for _, k := range nodes {
  181. edge.Target.Nodes = append(edge.Target.Nodes, k)
  182. }
  183. _node.GroupID = nodes[0]
  184. _spec.Edges = append(_spec.Edges, edge)
  185. }
  186. return _node, _spec
  187. }
  188. // OnConflict allows configuring the `ON CONFLICT` / `ON DUPLICATE KEY` clause
  189. // of the `INSERT` statement. For example:
  190. //
  191. // client.AccountGroup.Create().
  192. // SetAccountID(v).
  193. // OnConflict(
  194. // // Update the row with the new values
  195. // // the was proposed for insertion.
  196. // sql.ResolveWithNewValues(),
  197. // ).
  198. // // Override some of the fields with custom
  199. // // update values.
  200. // Update(func(u *ent.AccountGroupUpsert) {
  201. // SetAccountID(v+v).
  202. // }).
  203. // Exec(ctx)
  204. func (_c *AccountGroupCreate) OnConflict(opts ...sql.ConflictOption) *AccountGroupUpsertOne {
  205. _c.conflict = opts
  206. return &AccountGroupUpsertOne{
  207. create: _c,
  208. }
  209. }
  210. // OnConflictColumns calls `OnConflict` and configures the columns
  211. // as conflict target. Using this option is equivalent to using:
  212. //
  213. // client.AccountGroup.Create().
  214. // OnConflict(sql.ConflictColumns(columns...)).
  215. // Exec(ctx)
  216. func (_c *AccountGroupCreate) OnConflictColumns(columns ...string) *AccountGroupUpsertOne {
  217. _c.conflict = append(_c.conflict, sql.ConflictColumns(columns...))
  218. return &AccountGroupUpsertOne{
  219. create: _c,
  220. }
  221. }
  222. type (
  223. // AccountGroupUpsertOne is the builder for "upsert"-ing
  224. // one AccountGroup node.
  225. AccountGroupUpsertOne struct {
  226. create *AccountGroupCreate
  227. }
  228. // AccountGroupUpsert is the "OnConflict" setter.
  229. AccountGroupUpsert struct {
  230. *sql.UpdateSet
  231. }
  232. )
  233. // SetAccountID sets the "account_id" field.
  234. func (u *AccountGroupUpsert) SetAccountID(v int64) *AccountGroupUpsert {
  235. u.Set(accountgroup.FieldAccountID, v)
  236. return u
  237. }
  238. // UpdateAccountID sets the "account_id" field to the value that was provided on create.
  239. func (u *AccountGroupUpsert) UpdateAccountID() *AccountGroupUpsert {
  240. u.SetExcluded(accountgroup.FieldAccountID)
  241. return u
  242. }
  243. // SetGroupID sets the "group_id" field.
  244. func (u *AccountGroupUpsert) SetGroupID(v int64) *AccountGroupUpsert {
  245. u.Set(accountgroup.FieldGroupID, v)
  246. return u
  247. }
  248. // UpdateGroupID sets the "group_id" field to the value that was provided on create.
  249. func (u *AccountGroupUpsert) UpdateGroupID() *AccountGroupUpsert {
  250. u.SetExcluded(accountgroup.FieldGroupID)
  251. return u
  252. }
  253. // SetPriority sets the "priority" field.
  254. func (u *AccountGroupUpsert) SetPriority(v int) *AccountGroupUpsert {
  255. u.Set(accountgroup.FieldPriority, v)
  256. return u
  257. }
  258. // UpdatePriority sets the "priority" field to the value that was provided on create.
  259. func (u *AccountGroupUpsert) UpdatePriority() *AccountGroupUpsert {
  260. u.SetExcluded(accountgroup.FieldPriority)
  261. return u
  262. }
  263. // AddPriority adds v to the "priority" field.
  264. func (u *AccountGroupUpsert) AddPriority(v int) *AccountGroupUpsert {
  265. u.Add(accountgroup.FieldPriority, v)
  266. return u
  267. }
  268. // UpdateNewValues updates the mutable fields using the new values that were set on create.
  269. // Using this option is equivalent to using:
  270. //
  271. // client.AccountGroup.Create().
  272. // OnConflict(
  273. // sql.ResolveWithNewValues(),
  274. // ).
  275. // Exec(ctx)
  276. func (u *AccountGroupUpsertOne) UpdateNewValues() *AccountGroupUpsertOne {
  277. u.create.conflict = append(u.create.conflict, sql.ResolveWithNewValues())
  278. u.create.conflict = append(u.create.conflict, sql.ResolveWith(func(s *sql.UpdateSet) {
  279. if _, exists := u.create.mutation.CreatedAt(); exists {
  280. s.SetIgnore(accountgroup.FieldCreatedAt)
  281. }
  282. }))
  283. return u
  284. }
  285. // Ignore sets each column to itself in case of conflict.
  286. // Using this option is equivalent to using:
  287. //
  288. // client.AccountGroup.Create().
  289. // OnConflict(sql.ResolveWithIgnore()).
  290. // Exec(ctx)
  291. func (u *AccountGroupUpsertOne) Ignore() *AccountGroupUpsertOne {
  292. u.create.conflict = append(u.create.conflict, sql.ResolveWithIgnore())
  293. return u
  294. }
  295. // DoNothing configures the conflict_action to `DO NOTHING`.
  296. // Supported only by SQLite and PostgreSQL.
  297. func (u *AccountGroupUpsertOne) DoNothing() *AccountGroupUpsertOne {
  298. u.create.conflict = append(u.create.conflict, sql.DoNothing())
  299. return u
  300. }
  301. // Update allows overriding fields `UPDATE` values. See the AccountGroupCreate.OnConflict
  302. // documentation for more info.
  303. func (u *AccountGroupUpsertOne) Update(set func(*AccountGroupUpsert)) *AccountGroupUpsertOne {
  304. u.create.conflict = append(u.create.conflict, sql.ResolveWith(func(update *sql.UpdateSet) {
  305. set(&AccountGroupUpsert{UpdateSet: update})
  306. }))
  307. return u
  308. }
  309. // SetAccountID sets the "account_id" field.
  310. func (u *AccountGroupUpsertOne) SetAccountID(v int64) *AccountGroupUpsertOne {
  311. return u.Update(func(s *AccountGroupUpsert) {
  312. s.SetAccountID(v)
  313. })
  314. }
  315. // UpdateAccountID sets the "account_id" field to the value that was provided on create.
  316. func (u *AccountGroupUpsertOne) UpdateAccountID() *AccountGroupUpsertOne {
  317. return u.Update(func(s *AccountGroupUpsert) {
  318. s.UpdateAccountID()
  319. })
  320. }
  321. // SetGroupID sets the "group_id" field.
  322. func (u *AccountGroupUpsertOne) SetGroupID(v int64) *AccountGroupUpsertOne {
  323. return u.Update(func(s *AccountGroupUpsert) {
  324. s.SetGroupID(v)
  325. })
  326. }
  327. // UpdateGroupID sets the "group_id" field to the value that was provided on create.
  328. func (u *AccountGroupUpsertOne) UpdateGroupID() *AccountGroupUpsertOne {
  329. return u.Update(func(s *AccountGroupUpsert) {
  330. s.UpdateGroupID()
  331. })
  332. }
  333. // SetPriority sets the "priority" field.
  334. func (u *AccountGroupUpsertOne) SetPriority(v int) *AccountGroupUpsertOne {
  335. return u.Update(func(s *AccountGroupUpsert) {
  336. s.SetPriority(v)
  337. })
  338. }
  339. // AddPriority adds v to the "priority" field.
  340. func (u *AccountGroupUpsertOne) AddPriority(v int) *AccountGroupUpsertOne {
  341. return u.Update(func(s *AccountGroupUpsert) {
  342. s.AddPriority(v)
  343. })
  344. }
  345. // UpdatePriority sets the "priority" field to the value that was provided on create.
  346. func (u *AccountGroupUpsertOne) UpdatePriority() *AccountGroupUpsertOne {
  347. return u.Update(func(s *AccountGroupUpsert) {
  348. s.UpdatePriority()
  349. })
  350. }
  351. // Exec executes the query.
  352. func (u *AccountGroupUpsertOne) Exec(ctx context.Context) error {
  353. if len(u.create.conflict) == 0 {
  354. return errors.New("ent: missing options for AccountGroupCreate.OnConflict")
  355. }
  356. return u.create.Exec(ctx)
  357. }
  358. // ExecX is like Exec, but panics if an error occurs.
  359. func (u *AccountGroupUpsertOne) ExecX(ctx context.Context) {
  360. if err := u.create.Exec(ctx); err != nil {
  361. panic(err)
  362. }
  363. }
  364. // AccountGroupCreateBulk is the builder for creating many AccountGroup entities in bulk.
  365. type AccountGroupCreateBulk struct {
  366. config
  367. err error
  368. builders []*AccountGroupCreate
  369. conflict []sql.ConflictOption
  370. }
  371. // Save creates the AccountGroup entities in the database.
  372. func (_c *AccountGroupCreateBulk) Save(ctx context.Context) ([]*AccountGroup, error) {
  373. if _c.err != nil {
  374. return nil, _c.err
  375. }
  376. specs := make([]*sqlgraph.CreateSpec, len(_c.builders))
  377. nodes := make([]*AccountGroup, len(_c.builders))
  378. mutators := make([]Mutator, len(_c.builders))
  379. for i := range _c.builders {
  380. func(i int, root context.Context) {
  381. builder := _c.builders[i]
  382. builder.defaults()
  383. var mut Mutator = MutateFunc(func(ctx context.Context, m Mutation) (Value, error) {
  384. mutation, ok := m.(*AccountGroupMutation)
  385. if !ok {
  386. return nil, fmt.Errorf("unexpected mutation type %T", m)
  387. }
  388. if err := builder.check(); err != nil {
  389. return nil, err
  390. }
  391. builder.mutation = mutation
  392. var err error
  393. nodes[i], specs[i] = builder.createSpec()
  394. if i < len(mutators)-1 {
  395. _, err = mutators[i+1].Mutate(root, _c.builders[i+1].mutation)
  396. } else {
  397. spec := &sqlgraph.BatchCreateSpec{Nodes: specs}
  398. spec.OnConflict = _c.conflict
  399. // Invoke the actual operation on the latest mutation in the chain.
  400. if err = sqlgraph.BatchCreate(ctx, _c.driver, spec); err != nil {
  401. if sqlgraph.IsConstraintError(err) {
  402. err = &ConstraintError{msg: err.Error(), wrap: err}
  403. }
  404. }
  405. }
  406. if err != nil {
  407. return nil, err
  408. }
  409. mutation.done = true
  410. return nodes[i], nil
  411. })
  412. for i := len(builder.hooks) - 1; i >= 0; i-- {
  413. mut = builder.hooks[i](mut)
  414. }
  415. mutators[i] = mut
  416. }(i, ctx)
  417. }
  418. if len(mutators) > 0 {
  419. if _, err := mutators[0].Mutate(ctx, _c.builders[0].mutation); err != nil {
  420. return nil, err
  421. }
  422. }
  423. return nodes, nil
  424. }
  425. // SaveX is like Save, but panics if an error occurs.
  426. func (_c *AccountGroupCreateBulk) SaveX(ctx context.Context) []*AccountGroup {
  427. v, err := _c.Save(ctx)
  428. if err != nil {
  429. panic(err)
  430. }
  431. return v
  432. }
  433. // Exec executes the query.
  434. func (_c *AccountGroupCreateBulk) Exec(ctx context.Context) error {
  435. _, err := _c.Save(ctx)
  436. return err
  437. }
  438. // ExecX is like Exec, but panics if an error occurs.
  439. func (_c *AccountGroupCreateBulk) ExecX(ctx context.Context) {
  440. if err := _c.Exec(ctx); err != nil {
  441. panic(err)
  442. }
  443. }
  444. // OnConflict allows configuring the `ON CONFLICT` / `ON DUPLICATE KEY` clause
  445. // of the `INSERT` statement. For example:
  446. //
  447. // client.AccountGroup.CreateBulk(builders...).
  448. // OnConflict(
  449. // // Update the row with the new values
  450. // // the was proposed for insertion.
  451. // sql.ResolveWithNewValues(),
  452. // ).
  453. // // Override some of the fields with custom
  454. // // update values.
  455. // Update(func(u *ent.AccountGroupUpsert) {
  456. // SetAccountID(v+v).
  457. // }).
  458. // Exec(ctx)
  459. func (_c *AccountGroupCreateBulk) OnConflict(opts ...sql.ConflictOption) *AccountGroupUpsertBulk {
  460. _c.conflict = opts
  461. return &AccountGroupUpsertBulk{
  462. create: _c,
  463. }
  464. }
  465. // OnConflictColumns calls `OnConflict` and configures the columns
  466. // as conflict target. Using this option is equivalent to using:
  467. //
  468. // client.AccountGroup.Create().
  469. // OnConflict(sql.ConflictColumns(columns...)).
  470. // Exec(ctx)
  471. func (_c *AccountGroupCreateBulk) OnConflictColumns(columns ...string) *AccountGroupUpsertBulk {
  472. _c.conflict = append(_c.conflict, sql.ConflictColumns(columns...))
  473. return &AccountGroupUpsertBulk{
  474. create: _c,
  475. }
  476. }
  477. // AccountGroupUpsertBulk is the builder for "upsert"-ing
  478. // a bulk of AccountGroup nodes.
  479. type AccountGroupUpsertBulk struct {
  480. create *AccountGroupCreateBulk
  481. }
  482. // UpdateNewValues updates the mutable fields using the new values that
  483. // were set on create. Using this option is equivalent to using:
  484. //
  485. // client.AccountGroup.Create().
  486. // OnConflict(
  487. // sql.ResolveWithNewValues(),
  488. // ).
  489. // Exec(ctx)
  490. func (u *AccountGroupUpsertBulk) UpdateNewValues() *AccountGroupUpsertBulk {
  491. u.create.conflict = append(u.create.conflict, sql.ResolveWithNewValues())
  492. u.create.conflict = append(u.create.conflict, sql.ResolveWith(func(s *sql.UpdateSet) {
  493. for _, b := range u.create.builders {
  494. if _, exists := b.mutation.CreatedAt(); exists {
  495. s.SetIgnore(accountgroup.FieldCreatedAt)
  496. }
  497. }
  498. }))
  499. return u
  500. }
  501. // Ignore sets each column to itself in case of conflict.
  502. // Using this option is equivalent to using:
  503. //
  504. // client.AccountGroup.Create().
  505. // OnConflict(sql.ResolveWithIgnore()).
  506. // Exec(ctx)
  507. func (u *AccountGroupUpsertBulk) Ignore() *AccountGroupUpsertBulk {
  508. u.create.conflict = append(u.create.conflict, sql.ResolveWithIgnore())
  509. return u
  510. }
  511. // DoNothing configures the conflict_action to `DO NOTHING`.
  512. // Supported only by SQLite and PostgreSQL.
  513. func (u *AccountGroupUpsertBulk) DoNothing() *AccountGroupUpsertBulk {
  514. u.create.conflict = append(u.create.conflict, sql.DoNothing())
  515. return u
  516. }
  517. // Update allows overriding fields `UPDATE` values. See the AccountGroupCreateBulk.OnConflict
  518. // documentation for more info.
  519. func (u *AccountGroupUpsertBulk) Update(set func(*AccountGroupUpsert)) *AccountGroupUpsertBulk {
  520. u.create.conflict = append(u.create.conflict, sql.ResolveWith(func(update *sql.UpdateSet) {
  521. set(&AccountGroupUpsert{UpdateSet: update})
  522. }))
  523. return u
  524. }
  525. // SetAccountID sets the "account_id" field.
  526. func (u *AccountGroupUpsertBulk) SetAccountID(v int64) *AccountGroupUpsertBulk {
  527. return u.Update(func(s *AccountGroupUpsert) {
  528. s.SetAccountID(v)
  529. })
  530. }
  531. // UpdateAccountID sets the "account_id" field to the value that was provided on create.
  532. func (u *AccountGroupUpsertBulk) UpdateAccountID() *AccountGroupUpsertBulk {
  533. return u.Update(func(s *AccountGroupUpsert) {
  534. s.UpdateAccountID()
  535. })
  536. }
  537. // SetGroupID sets the "group_id" field.
  538. func (u *AccountGroupUpsertBulk) SetGroupID(v int64) *AccountGroupUpsertBulk {
  539. return u.Update(func(s *AccountGroupUpsert) {
  540. s.SetGroupID(v)
  541. })
  542. }
  543. // UpdateGroupID sets the "group_id" field to the value that was provided on create.
  544. func (u *AccountGroupUpsertBulk) UpdateGroupID() *AccountGroupUpsertBulk {
  545. return u.Update(func(s *AccountGroupUpsert) {
  546. s.UpdateGroupID()
  547. })
  548. }
  549. // SetPriority sets the "priority" field.
  550. func (u *AccountGroupUpsertBulk) SetPriority(v int) *AccountGroupUpsertBulk {
  551. return u.Update(func(s *AccountGroupUpsert) {
  552. s.SetPriority(v)
  553. })
  554. }
  555. // AddPriority adds v to the "priority" field.
  556. func (u *AccountGroupUpsertBulk) AddPriority(v int) *AccountGroupUpsertBulk {
  557. return u.Update(func(s *AccountGroupUpsert) {
  558. s.AddPriority(v)
  559. })
  560. }
  561. // UpdatePriority sets the "priority" field to the value that was provided on create.
  562. func (u *AccountGroupUpsertBulk) UpdatePriority() *AccountGroupUpsertBulk {
  563. return u.Update(func(s *AccountGroupUpsert) {
  564. s.UpdatePriority()
  565. })
  566. }
  567. // Exec executes the query.
  568. func (u *AccountGroupUpsertBulk) Exec(ctx context.Context) error {
  569. if u.create.err != nil {
  570. return u.create.err
  571. }
  572. for i, b := range u.create.builders {
  573. if len(b.conflict) != 0 {
  574. return fmt.Errorf("ent: OnConflict was set for builder %d. Set it on the AccountGroupCreateBulk instead", i)
  575. }
  576. }
  577. if len(u.create.conflict) == 0 {
  578. return errors.New("ent: missing options for AccountGroupCreateBulk.OnConflict")
  579. }
  580. return u.create.Exec(ctx)
  581. }
  582. // ExecX is like Exec, but panics if an error occurs.
  583. func (u *AccountGroupUpsertBulk) ExecX(ctx context.Context) {
  584. if err := u.create.Exec(ctx); err != nil {
  585. panic(err)
  586. }
  587. }