announcementread_create.go 20 KB

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