userattributevalue_create.go 23 KB

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