announcement_create.go 37 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229
  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/internal/domain"
  14. )
  15. // AnnouncementCreate is the builder for creating a Announcement entity.
  16. type AnnouncementCreate struct {
  17. config
  18. mutation *AnnouncementMutation
  19. hooks []Hook
  20. conflict []sql.ConflictOption
  21. }
  22. // SetTitle sets the "title" field.
  23. func (_c *AnnouncementCreate) SetTitle(v string) *AnnouncementCreate {
  24. _c.mutation.SetTitle(v)
  25. return _c
  26. }
  27. // SetContent sets the "content" field.
  28. func (_c *AnnouncementCreate) SetContent(v string) *AnnouncementCreate {
  29. _c.mutation.SetContent(v)
  30. return _c
  31. }
  32. // SetStatus sets the "status" field.
  33. func (_c *AnnouncementCreate) SetStatus(v string) *AnnouncementCreate {
  34. _c.mutation.SetStatus(v)
  35. return _c
  36. }
  37. // SetNillableStatus sets the "status" field if the given value is not nil.
  38. func (_c *AnnouncementCreate) SetNillableStatus(v *string) *AnnouncementCreate {
  39. if v != nil {
  40. _c.SetStatus(*v)
  41. }
  42. return _c
  43. }
  44. // SetNotifyMode sets the "notify_mode" field.
  45. func (_c *AnnouncementCreate) SetNotifyMode(v string) *AnnouncementCreate {
  46. _c.mutation.SetNotifyMode(v)
  47. return _c
  48. }
  49. // SetNillableNotifyMode sets the "notify_mode" field if the given value is not nil.
  50. func (_c *AnnouncementCreate) SetNillableNotifyMode(v *string) *AnnouncementCreate {
  51. if v != nil {
  52. _c.SetNotifyMode(*v)
  53. }
  54. return _c
  55. }
  56. // SetTargeting sets the "targeting" field.
  57. func (_c *AnnouncementCreate) SetTargeting(v domain.AnnouncementTargeting) *AnnouncementCreate {
  58. _c.mutation.SetTargeting(v)
  59. return _c
  60. }
  61. // SetNillableTargeting sets the "targeting" field if the given value is not nil.
  62. func (_c *AnnouncementCreate) SetNillableTargeting(v *domain.AnnouncementTargeting) *AnnouncementCreate {
  63. if v != nil {
  64. _c.SetTargeting(*v)
  65. }
  66. return _c
  67. }
  68. // SetStartsAt sets the "starts_at" field.
  69. func (_c *AnnouncementCreate) SetStartsAt(v time.Time) *AnnouncementCreate {
  70. _c.mutation.SetStartsAt(v)
  71. return _c
  72. }
  73. // SetNillableStartsAt sets the "starts_at" field if the given value is not nil.
  74. func (_c *AnnouncementCreate) SetNillableStartsAt(v *time.Time) *AnnouncementCreate {
  75. if v != nil {
  76. _c.SetStartsAt(*v)
  77. }
  78. return _c
  79. }
  80. // SetEndsAt sets the "ends_at" field.
  81. func (_c *AnnouncementCreate) SetEndsAt(v time.Time) *AnnouncementCreate {
  82. _c.mutation.SetEndsAt(v)
  83. return _c
  84. }
  85. // SetNillableEndsAt sets the "ends_at" field if the given value is not nil.
  86. func (_c *AnnouncementCreate) SetNillableEndsAt(v *time.Time) *AnnouncementCreate {
  87. if v != nil {
  88. _c.SetEndsAt(*v)
  89. }
  90. return _c
  91. }
  92. // SetCreatedBy sets the "created_by" field.
  93. func (_c *AnnouncementCreate) SetCreatedBy(v int64) *AnnouncementCreate {
  94. _c.mutation.SetCreatedBy(v)
  95. return _c
  96. }
  97. // SetNillableCreatedBy sets the "created_by" field if the given value is not nil.
  98. func (_c *AnnouncementCreate) SetNillableCreatedBy(v *int64) *AnnouncementCreate {
  99. if v != nil {
  100. _c.SetCreatedBy(*v)
  101. }
  102. return _c
  103. }
  104. // SetUpdatedBy sets the "updated_by" field.
  105. func (_c *AnnouncementCreate) SetUpdatedBy(v int64) *AnnouncementCreate {
  106. _c.mutation.SetUpdatedBy(v)
  107. return _c
  108. }
  109. // SetNillableUpdatedBy sets the "updated_by" field if the given value is not nil.
  110. func (_c *AnnouncementCreate) SetNillableUpdatedBy(v *int64) *AnnouncementCreate {
  111. if v != nil {
  112. _c.SetUpdatedBy(*v)
  113. }
  114. return _c
  115. }
  116. // SetCreatedAt sets the "created_at" field.
  117. func (_c *AnnouncementCreate) SetCreatedAt(v time.Time) *AnnouncementCreate {
  118. _c.mutation.SetCreatedAt(v)
  119. return _c
  120. }
  121. // SetNillableCreatedAt sets the "created_at" field if the given value is not nil.
  122. func (_c *AnnouncementCreate) SetNillableCreatedAt(v *time.Time) *AnnouncementCreate {
  123. if v != nil {
  124. _c.SetCreatedAt(*v)
  125. }
  126. return _c
  127. }
  128. // SetUpdatedAt sets the "updated_at" field.
  129. func (_c *AnnouncementCreate) SetUpdatedAt(v time.Time) *AnnouncementCreate {
  130. _c.mutation.SetUpdatedAt(v)
  131. return _c
  132. }
  133. // SetNillableUpdatedAt sets the "updated_at" field if the given value is not nil.
  134. func (_c *AnnouncementCreate) SetNillableUpdatedAt(v *time.Time) *AnnouncementCreate {
  135. if v != nil {
  136. _c.SetUpdatedAt(*v)
  137. }
  138. return _c
  139. }
  140. // AddReadIDs adds the "reads" edge to the AnnouncementRead entity by IDs.
  141. func (_c *AnnouncementCreate) AddReadIDs(ids ...int64) *AnnouncementCreate {
  142. _c.mutation.AddReadIDs(ids...)
  143. return _c
  144. }
  145. // AddReads adds the "reads" edges to the AnnouncementRead entity.
  146. func (_c *AnnouncementCreate) AddReads(v ...*AnnouncementRead) *AnnouncementCreate {
  147. ids := make([]int64, len(v))
  148. for i := range v {
  149. ids[i] = v[i].ID
  150. }
  151. return _c.AddReadIDs(ids...)
  152. }
  153. // Mutation returns the AnnouncementMutation object of the builder.
  154. func (_c *AnnouncementCreate) Mutation() *AnnouncementMutation {
  155. return _c.mutation
  156. }
  157. // Save creates the Announcement in the database.
  158. func (_c *AnnouncementCreate) Save(ctx context.Context) (*Announcement, error) {
  159. _c.defaults()
  160. return withHooks(ctx, _c.sqlSave, _c.mutation, _c.hooks)
  161. }
  162. // SaveX calls Save and panics if Save returns an error.
  163. func (_c *AnnouncementCreate) SaveX(ctx context.Context) *Announcement {
  164. v, err := _c.Save(ctx)
  165. if err != nil {
  166. panic(err)
  167. }
  168. return v
  169. }
  170. // Exec executes the query.
  171. func (_c *AnnouncementCreate) Exec(ctx context.Context) error {
  172. _, err := _c.Save(ctx)
  173. return err
  174. }
  175. // ExecX is like Exec, but panics if an error occurs.
  176. func (_c *AnnouncementCreate) ExecX(ctx context.Context) {
  177. if err := _c.Exec(ctx); err != nil {
  178. panic(err)
  179. }
  180. }
  181. // defaults sets the default values of the builder before save.
  182. func (_c *AnnouncementCreate) defaults() {
  183. if _, ok := _c.mutation.Status(); !ok {
  184. v := announcement.DefaultStatus
  185. _c.mutation.SetStatus(v)
  186. }
  187. if _, ok := _c.mutation.NotifyMode(); !ok {
  188. v := announcement.DefaultNotifyMode
  189. _c.mutation.SetNotifyMode(v)
  190. }
  191. if _, ok := _c.mutation.CreatedAt(); !ok {
  192. v := announcement.DefaultCreatedAt()
  193. _c.mutation.SetCreatedAt(v)
  194. }
  195. if _, ok := _c.mutation.UpdatedAt(); !ok {
  196. v := announcement.DefaultUpdatedAt()
  197. _c.mutation.SetUpdatedAt(v)
  198. }
  199. }
  200. // check runs all checks and user-defined validators on the builder.
  201. func (_c *AnnouncementCreate) check() error {
  202. if _, ok := _c.mutation.Title(); !ok {
  203. return &ValidationError{Name: "title", err: errors.New(`ent: missing required field "Announcement.title"`)}
  204. }
  205. if v, ok := _c.mutation.Title(); ok {
  206. if err := announcement.TitleValidator(v); err != nil {
  207. return &ValidationError{Name: "title", err: fmt.Errorf(`ent: validator failed for field "Announcement.title": %w`, err)}
  208. }
  209. }
  210. if _, ok := _c.mutation.Content(); !ok {
  211. return &ValidationError{Name: "content", err: errors.New(`ent: missing required field "Announcement.content"`)}
  212. }
  213. if v, ok := _c.mutation.Content(); ok {
  214. if err := announcement.ContentValidator(v); err != nil {
  215. return &ValidationError{Name: "content", err: fmt.Errorf(`ent: validator failed for field "Announcement.content": %w`, err)}
  216. }
  217. }
  218. if _, ok := _c.mutation.Status(); !ok {
  219. return &ValidationError{Name: "status", err: errors.New(`ent: missing required field "Announcement.status"`)}
  220. }
  221. if v, ok := _c.mutation.Status(); ok {
  222. if err := announcement.StatusValidator(v); err != nil {
  223. return &ValidationError{Name: "status", err: fmt.Errorf(`ent: validator failed for field "Announcement.status": %w`, err)}
  224. }
  225. }
  226. if _, ok := _c.mutation.NotifyMode(); !ok {
  227. return &ValidationError{Name: "notify_mode", err: errors.New(`ent: missing required field "Announcement.notify_mode"`)}
  228. }
  229. if v, ok := _c.mutation.NotifyMode(); ok {
  230. if err := announcement.NotifyModeValidator(v); err != nil {
  231. return &ValidationError{Name: "notify_mode", err: fmt.Errorf(`ent: validator failed for field "Announcement.notify_mode": %w`, err)}
  232. }
  233. }
  234. if _, ok := _c.mutation.CreatedAt(); !ok {
  235. return &ValidationError{Name: "created_at", err: errors.New(`ent: missing required field "Announcement.created_at"`)}
  236. }
  237. if _, ok := _c.mutation.UpdatedAt(); !ok {
  238. return &ValidationError{Name: "updated_at", err: errors.New(`ent: missing required field "Announcement.updated_at"`)}
  239. }
  240. return nil
  241. }
  242. func (_c *AnnouncementCreate) sqlSave(ctx context.Context) (*Announcement, error) {
  243. if err := _c.check(); err != nil {
  244. return nil, err
  245. }
  246. _node, _spec := _c.createSpec()
  247. if err := sqlgraph.CreateNode(ctx, _c.driver, _spec); err != nil {
  248. if sqlgraph.IsConstraintError(err) {
  249. err = &ConstraintError{msg: err.Error(), wrap: err}
  250. }
  251. return nil, err
  252. }
  253. id := _spec.ID.Value.(int64)
  254. _node.ID = int64(id)
  255. _c.mutation.id = &_node.ID
  256. _c.mutation.done = true
  257. return _node, nil
  258. }
  259. func (_c *AnnouncementCreate) createSpec() (*Announcement, *sqlgraph.CreateSpec) {
  260. var (
  261. _node = &Announcement{config: _c.config}
  262. _spec = sqlgraph.NewCreateSpec(announcement.Table, sqlgraph.NewFieldSpec(announcement.FieldID, field.TypeInt64))
  263. )
  264. _spec.OnConflict = _c.conflict
  265. if value, ok := _c.mutation.Title(); ok {
  266. _spec.SetField(announcement.FieldTitle, field.TypeString, value)
  267. _node.Title = value
  268. }
  269. if value, ok := _c.mutation.Content(); ok {
  270. _spec.SetField(announcement.FieldContent, field.TypeString, value)
  271. _node.Content = value
  272. }
  273. if value, ok := _c.mutation.Status(); ok {
  274. _spec.SetField(announcement.FieldStatus, field.TypeString, value)
  275. _node.Status = value
  276. }
  277. if value, ok := _c.mutation.NotifyMode(); ok {
  278. _spec.SetField(announcement.FieldNotifyMode, field.TypeString, value)
  279. _node.NotifyMode = value
  280. }
  281. if value, ok := _c.mutation.Targeting(); ok {
  282. _spec.SetField(announcement.FieldTargeting, field.TypeJSON, value)
  283. _node.Targeting = value
  284. }
  285. if value, ok := _c.mutation.StartsAt(); ok {
  286. _spec.SetField(announcement.FieldStartsAt, field.TypeTime, value)
  287. _node.StartsAt = &value
  288. }
  289. if value, ok := _c.mutation.EndsAt(); ok {
  290. _spec.SetField(announcement.FieldEndsAt, field.TypeTime, value)
  291. _node.EndsAt = &value
  292. }
  293. if value, ok := _c.mutation.CreatedBy(); ok {
  294. _spec.SetField(announcement.FieldCreatedBy, field.TypeInt64, value)
  295. _node.CreatedBy = &value
  296. }
  297. if value, ok := _c.mutation.UpdatedBy(); ok {
  298. _spec.SetField(announcement.FieldUpdatedBy, field.TypeInt64, value)
  299. _node.UpdatedBy = &value
  300. }
  301. if value, ok := _c.mutation.CreatedAt(); ok {
  302. _spec.SetField(announcement.FieldCreatedAt, field.TypeTime, value)
  303. _node.CreatedAt = value
  304. }
  305. if value, ok := _c.mutation.UpdatedAt(); ok {
  306. _spec.SetField(announcement.FieldUpdatedAt, field.TypeTime, value)
  307. _node.UpdatedAt = value
  308. }
  309. if nodes := _c.mutation.ReadsIDs(); len(nodes) > 0 {
  310. edge := &sqlgraph.EdgeSpec{
  311. Rel: sqlgraph.O2M,
  312. Inverse: false,
  313. Table: announcement.ReadsTable,
  314. Columns: []string{announcement.ReadsColumn},
  315. Bidi: false,
  316. Target: &sqlgraph.EdgeTarget{
  317. IDSpec: sqlgraph.NewFieldSpec(announcementread.FieldID, field.TypeInt64),
  318. },
  319. }
  320. for _, k := range nodes {
  321. edge.Target.Nodes = append(edge.Target.Nodes, k)
  322. }
  323. _spec.Edges = append(_spec.Edges, edge)
  324. }
  325. return _node, _spec
  326. }
  327. // OnConflict allows configuring the `ON CONFLICT` / `ON DUPLICATE KEY` clause
  328. // of the `INSERT` statement. For example:
  329. //
  330. // client.Announcement.Create().
  331. // SetTitle(v).
  332. // OnConflict(
  333. // // Update the row with the new values
  334. // // the was proposed for insertion.
  335. // sql.ResolveWithNewValues(),
  336. // ).
  337. // // Override some of the fields with custom
  338. // // update values.
  339. // Update(func(u *ent.AnnouncementUpsert) {
  340. // SetTitle(v+v).
  341. // }).
  342. // Exec(ctx)
  343. func (_c *AnnouncementCreate) OnConflict(opts ...sql.ConflictOption) *AnnouncementUpsertOne {
  344. _c.conflict = opts
  345. return &AnnouncementUpsertOne{
  346. create: _c,
  347. }
  348. }
  349. // OnConflictColumns calls `OnConflict` and configures the columns
  350. // as conflict target. Using this option is equivalent to using:
  351. //
  352. // client.Announcement.Create().
  353. // OnConflict(sql.ConflictColumns(columns...)).
  354. // Exec(ctx)
  355. func (_c *AnnouncementCreate) OnConflictColumns(columns ...string) *AnnouncementUpsertOne {
  356. _c.conflict = append(_c.conflict, sql.ConflictColumns(columns...))
  357. return &AnnouncementUpsertOne{
  358. create: _c,
  359. }
  360. }
  361. type (
  362. // AnnouncementUpsertOne is the builder for "upsert"-ing
  363. // one Announcement node.
  364. AnnouncementUpsertOne struct {
  365. create *AnnouncementCreate
  366. }
  367. // AnnouncementUpsert is the "OnConflict" setter.
  368. AnnouncementUpsert struct {
  369. *sql.UpdateSet
  370. }
  371. )
  372. // SetTitle sets the "title" field.
  373. func (u *AnnouncementUpsert) SetTitle(v string) *AnnouncementUpsert {
  374. u.Set(announcement.FieldTitle, v)
  375. return u
  376. }
  377. // UpdateTitle sets the "title" field to the value that was provided on create.
  378. func (u *AnnouncementUpsert) UpdateTitle() *AnnouncementUpsert {
  379. u.SetExcluded(announcement.FieldTitle)
  380. return u
  381. }
  382. // SetContent sets the "content" field.
  383. func (u *AnnouncementUpsert) SetContent(v string) *AnnouncementUpsert {
  384. u.Set(announcement.FieldContent, v)
  385. return u
  386. }
  387. // UpdateContent sets the "content" field to the value that was provided on create.
  388. func (u *AnnouncementUpsert) UpdateContent() *AnnouncementUpsert {
  389. u.SetExcluded(announcement.FieldContent)
  390. return u
  391. }
  392. // SetStatus sets the "status" field.
  393. func (u *AnnouncementUpsert) SetStatus(v string) *AnnouncementUpsert {
  394. u.Set(announcement.FieldStatus, v)
  395. return u
  396. }
  397. // UpdateStatus sets the "status" field to the value that was provided on create.
  398. func (u *AnnouncementUpsert) UpdateStatus() *AnnouncementUpsert {
  399. u.SetExcluded(announcement.FieldStatus)
  400. return u
  401. }
  402. // SetNotifyMode sets the "notify_mode" field.
  403. func (u *AnnouncementUpsert) SetNotifyMode(v string) *AnnouncementUpsert {
  404. u.Set(announcement.FieldNotifyMode, v)
  405. return u
  406. }
  407. // UpdateNotifyMode sets the "notify_mode" field to the value that was provided on create.
  408. func (u *AnnouncementUpsert) UpdateNotifyMode() *AnnouncementUpsert {
  409. u.SetExcluded(announcement.FieldNotifyMode)
  410. return u
  411. }
  412. // SetTargeting sets the "targeting" field.
  413. func (u *AnnouncementUpsert) SetTargeting(v domain.AnnouncementTargeting) *AnnouncementUpsert {
  414. u.Set(announcement.FieldTargeting, v)
  415. return u
  416. }
  417. // UpdateTargeting sets the "targeting" field to the value that was provided on create.
  418. func (u *AnnouncementUpsert) UpdateTargeting() *AnnouncementUpsert {
  419. u.SetExcluded(announcement.FieldTargeting)
  420. return u
  421. }
  422. // ClearTargeting clears the value of the "targeting" field.
  423. func (u *AnnouncementUpsert) ClearTargeting() *AnnouncementUpsert {
  424. u.SetNull(announcement.FieldTargeting)
  425. return u
  426. }
  427. // SetStartsAt sets the "starts_at" field.
  428. func (u *AnnouncementUpsert) SetStartsAt(v time.Time) *AnnouncementUpsert {
  429. u.Set(announcement.FieldStartsAt, v)
  430. return u
  431. }
  432. // UpdateStartsAt sets the "starts_at" field to the value that was provided on create.
  433. func (u *AnnouncementUpsert) UpdateStartsAt() *AnnouncementUpsert {
  434. u.SetExcluded(announcement.FieldStartsAt)
  435. return u
  436. }
  437. // ClearStartsAt clears the value of the "starts_at" field.
  438. func (u *AnnouncementUpsert) ClearStartsAt() *AnnouncementUpsert {
  439. u.SetNull(announcement.FieldStartsAt)
  440. return u
  441. }
  442. // SetEndsAt sets the "ends_at" field.
  443. func (u *AnnouncementUpsert) SetEndsAt(v time.Time) *AnnouncementUpsert {
  444. u.Set(announcement.FieldEndsAt, v)
  445. return u
  446. }
  447. // UpdateEndsAt sets the "ends_at" field to the value that was provided on create.
  448. func (u *AnnouncementUpsert) UpdateEndsAt() *AnnouncementUpsert {
  449. u.SetExcluded(announcement.FieldEndsAt)
  450. return u
  451. }
  452. // ClearEndsAt clears the value of the "ends_at" field.
  453. func (u *AnnouncementUpsert) ClearEndsAt() *AnnouncementUpsert {
  454. u.SetNull(announcement.FieldEndsAt)
  455. return u
  456. }
  457. // SetCreatedBy sets the "created_by" field.
  458. func (u *AnnouncementUpsert) SetCreatedBy(v int64) *AnnouncementUpsert {
  459. u.Set(announcement.FieldCreatedBy, v)
  460. return u
  461. }
  462. // UpdateCreatedBy sets the "created_by" field to the value that was provided on create.
  463. func (u *AnnouncementUpsert) UpdateCreatedBy() *AnnouncementUpsert {
  464. u.SetExcluded(announcement.FieldCreatedBy)
  465. return u
  466. }
  467. // AddCreatedBy adds v to the "created_by" field.
  468. func (u *AnnouncementUpsert) AddCreatedBy(v int64) *AnnouncementUpsert {
  469. u.Add(announcement.FieldCreatedBy, v)
  470. return u
  471. }
  472. // ClearCreatedBy clears the value of the "created_by" field.
  473. func (u *AnnouncementUpsert) ClearCreatedBy() *AnnouncementUpsert {
  474. u.SetNull(announcement.FieldCreatedBy)
  475. return u
  476. }
  477. // SetUpdatedBy sets the "updated_by" field.
  478. func (u *AnnouncementUpsert) SetUpdatedBy(v int64) *AnnouncementUpsert {
  479. u.Set(announcement.FieldUpdatedBy, v)
  480. return u
  481. }
  482. // UpdateUpdatedBy sets the "updated_by" field to the value that was provided on create.
  483. func (u *AnnouncementUpsert) UpdateUpdatedBy() *AnnouncementUpsert {
  484. u.SetExcluded(announcement.FieldUpdatedBy)
  485. return u
  486. }
  487. // AddUpdatedBy adds v to the "updated_by" field.
  488. func (u *AnnouncementUpsert) AddUpdatedBy(v int64) *AnnouncementUpsert {
  489. u.Add(announcement.FieldUpdatedBy, v)
  490. return u
  491. }
  492. // ClearUpdatedBy clears the value of the "updated_by" field.
  493. func (u *AnnouncementUpsert) ClearUpdatedBy() *AnnouncementUpsert {
  494. u.SetNull(announcement.FieldUpdatedBy)
  495. return u
  496. }
  497. // SetUpdatedAt sets the "updated_at" field.
  498. func (u *AnnouncementUpsert) SetUpdatedAt(v time.Time) *AnnouncementUpsert {
  499. u.Set(announcement.FieldUpdatedAt, v)
  500. return u
  501. }
  502. // UpdateUpdatedAt sets the "updated_at" field to the value that was provided on create.
  503. func (u *AnnouncementUpsert) UpdateUpdatedAt() *AnnouncementUpsert {
  504. u.SetExcluded(announcement.FieldUpdatedAt)
  505. return u
  506. }
  507. // UpdateNewValues updates the mutable fields using the new values that were set on create.
  508. // Using this option is equivalent to using:
  509. //
  510. // client.Announcement.Create().
  511. // OnConflict(
  512. // sql.ResolveWithNewValues(),
  513. // ).
  514. // Exec(ctx)
  515. func (u *AnnouncementUpsertOne) UpdateNewValues() *AnnouncementUpsertOne {
  516. u.create.conflict = append(u.create.conflict, sql.ResolveWithNewValues())
  517. u.create.conflict = append(u.create.conflict, sql.ResolveWith(func(s *sql.UpdateSet) {
  518. if _, exists := u.create.mutation.CreatedAt(); exists {
  519. s.SetIgnore(announcement.FieldCreatedAt)
  520. }
  521. }))
  522. return u
  523. }
  524. // Ignore sets each column to itself in case of conflict.
  525. // Using this option is equivalent to using:
  526. //
  527. // client.Announcement.Create().
  528. // OnConflict(sql.ResolveWithIgnore()).
  529. // Exec(ctx)
  530. func (u *AnnouncementUpsertOne) Ignore() *AnnouncementUpsertOne {
  531. u.create.conflict = append(u.create.conflict, sql.ResolveWithIgnore())
  532. return u
  533. }
  534. // DoNothing configures the conflict_action to `DO NOTHING`.
  535. // Supported only by SQLite and PostgreSQL.
  536. func (u *AnnouncementUpsertOne) DoNothing() *AnnouncementUpsertOne {
  537. u.create.conflict = append(u.create.conflict, sql.DoNothing())
  538. return u
  539. }
  540. // Update allows overriding fields `UPDATE` values. See the AnnouncementCreate.OnConflict
  541. // documentation for more info.
  542. func (u *AnnouncementUpsertOne) Update(set func(*AnnouncementUpsert)) *AnnouncementUpsertOne {
  543. u.create.conflict = append(u.create.conflict, sql.ResolveWith(func(update *sql.UpdateSet) {
  544. set(&AnnouncementUpsert{UpdateSet: update})
  545. }))
  546. return u
  547. }
  548. // SetTitle sets the "title" field.
  549. func (u *AnnouncementUpsertOne) SetTitle(v string) *AnnouncementUpsertOne {
  550. return u.Update(func(s *AnnouncementUpsert) {
  551. s.SetTitle(v)
  552. })
  553. }
  554. // UpdateTitle sets the "title" field to the value that was provided on create.
  555. func (u *AnnouncementUpsertOne) UpdateTitle() *AnnouncementUpsertOne {
  556. return u.Update(func(s *AnnouncementUpsert) {
  557. s.UpdateTitle()
  558. })
  559. }
  560. // SetContent sets the "content" field.
  561. func (u *AnnouncementUpsertOne) SetContent(v string) *AnnouncementUpsertOne {
  562. return u.Update(func(s *AnnouncementUpsert) {
  563. s.SetContent(v)
  564. })
  565. }
  566. // UpdateContent sets the "content" field to the value that was provided on create.
  567. func (u *AnnouncementUpsertOne) UpdateContent() *AnnouncementUpsertOne {
  568. return u.Update(func(s *AnnouncementUpsert) {
  569. s.UpdateContent()
  570. })
  571. }
  572. // SetStatus sets the "status" field.
  573. func (u *AnnouncementUpsertOne) SetStatus(v string) *AnnouncementUpsertOne {
  574. return u.Update(func(s *AnnouncementUpsert) {
  575. s.SetStatus(v)
  576. })
  577. }
  578. // UpdateStatus sets the "status" field to the value that was provided on create.
  579. func (u *AnnouncementUpsertOne) UpdateStatus() *AnnouncementUpsertOne {
  580. return u.Update(func(s *AnnouncementUpsert) {
  581. s.UpdateStatus()
  582. })
  583. }
  584. // SetNotifyMode sets the "notify_mode" field.
  585. func (u *AnnouncementUpsertOne) SetNotifyMode(v string) *AnnouncementUpsertOne {
  586. return u.Update(func(s *AnnouncementUpsert) {
  587. s.SetNotifyMode(v)
  588. })
  589. }
  590. // UpdateNotifyMode sets the "notify_mode" field to the value that was provided on create.
  591. func (u *AnnouncementUpsertOne) UpdateNotifyMode() *AnnouncementUpsertOne {
  592. return u.Update(func(s *AnnouncementUpsert) {
  593. s.UpdateNotifyMode()
  594. })
  595. }
  596. // SetTargeting sets the "targeting" field.
  597. func (u *AnnouncementUpsertOne) SetTargeting(v domain.AnnouncementTargeting) *AnnouncementUpsertOne {
  598. return u.Update(func(s *AnnouncementUpsert) {
  599. s.SetTargeting(v)
  600. })
  601. }
  602. // UpdateTargeting sets the "targeting" field to the value that was provided on create.
  603. func (u *AnnouncementUpsertOne) UpdateTargeting() *AnnouncementUpsertOne {
  604. return u.Update(func(s *AnnouncementUpsert) {
  605. s.UpdateTargeting()
  606. })
  607. }
  608. // ClearTargeting clears the value of the "targeting" field.
  609. func (u *AnnouncementUpsertOne) ClearTargeting() *AnnouncementUpsertOne {
  610. return u.Update(func(s *AnnouncementUpsert) {
  611. s.ClearTargeting()
  612. })
  613. }
  614. // SetStartsAt sets the "starts_at" field.
  615. func (u *AnnouncementUpsertOne) SetStartsAt(v time.Time) *AnnouncementUpsertOne {
  616. return u.Update(func(s *AnnouncementUpsert) {
  617. s.SetStartsAt(v)
  618. })
  619. }
  620. // UpdateStartsAt sets the "starts_at" field to the value that was provided on create.
  621. func (u *AnnouncementUpsertOne) UpdateStartsAt() *AnnouncementUpsertOne {
  622. return u.Update(func(s *AnnouncementUpsert) {
  623. s.UpdateStartsAt()
  624. })
  625. }
  626. // ClearStartsAt clears the value of the "starts_at" field.
  627. func (u *AnnouncementUpsertOne) ClearStartsAt() *AnnouncementUpsertOne {
  628. return u.Update(func(s *AnnouncementUpsert) {
  629. s.ClearStartsAt()
  630. })
  631. }
  632. // SetEndsAt sets the "ends_at" field.
  633. func (u *AnnouncementUpsertOne) SetEndsAt(v time.Time) *AnnouncementUpsertOne {
  634. return u.Update(func(s *AnnouncementUpsert) {
  635. s.SetEndsAt(v)
  636. })
  637. }
  638. // UpdateEndsAt sets the "ends_at" field to the value that was provided on create.
  639. func (u *AnnouncementUpsertOne) UpdateEndsAt() *AnnouncementUpsertOne {
  640. return u.Update(func(s *AnnouncementUpsert) {
  641. s.UpdateEndsAt()
  642. })
  643. }
  644. // ClearEndsAt clears the value of the "ends_at" field.
  645. func (u *AnnouncementUpsertOne) ClearEndsAt() *AnnouncementUpsertOne {
  646. return u.Update(func(s *AnnouncementUpsert) {
  647. s.ClearEndsAt()
  648. })
  649. }
  650. // SetCreatedBy sets the "created_by" field.
  651. func (u *AnnouncementUpsertOne) SetCreatedBy(v int64) *AnnouncementUpsertOne {
  652. return u.Update(func(s *AnnouncementUpsert) {
  653. s.SetCreatedBy(v)
  654. })
  655. }
  656. // AddCreatedBy adds v to the "created_by" field.
  657. func (u *AnnouncementUpsertOne) AddCreatedBy(v int64) *AnnouncementUpsertOne {
  658. return u.Update(func(s *AnnouncementUpsert) {
  659. s.AddCreatedBy(v)
  660. })
  661. }
  662. // UpdateCreatedBy sets the "created_by" field to the value that was provided on create.
  663. func (u *AnnouncementUpsertOne) UpdateCreatedBy() *AnnouncementUpsertOne {
  664. return u.Update(func(s *AnnouncementUpsert) {
  665. s.UpdateCreatedBy()
  666. })
  667. }
  668. // ClearCreatedBy clears the value of the "created_by" field.
  669. func (u *AnnouncementUpsertOne) ClearCreatedBy() *AnnouncementUpsertOne {
  670. return u.Update(func(s *AnnouncementUpsert) {
  671. s.ClearCreatedBy()
  672. })
  673. }
  674. // SetUpdatedBy sets the "updated_by" field.
  675. func (u *AnnouncementUpsertOne) SetUpdatedBy(v int64) *AnnouncementUpsertOne {
  676. return u.Update(func(s *AnnouncementUpsert) {
  677. s.SetUpdatedBy(v)
  678. })
  679. }
  680. // AddUpdatedBy adds v to the "updated_by" field.
  681. func (u *AnnouncementUpsertOne) AddUpdatedBy(v int64) *AnnouncementUpsertOne {
  682. return u.Update(func(s *AnnouncementUpsert) {
  683. s.AddUpdatedBy(v)
  684. })
  685. }
  686. // UpdateUpdatedBy sets the "updated_by" field to the value that was provided on create.
  687. func (u *AnnouncementUpsertOne) UpdateUpdatedBy() *AnnouncementUpsertOne {
  688. return u.Update(func(s *AnnouncementUpsert) {
  689. s.UpdateUpdatedBy()
  690. })
  691. }
  692. // ClearUpdatedBy clears the value of the "updated_by" field.
  693. func (u *AnnouncementUpsertOne) ClearUpdatedBy() *AnnouncementUpsertOne {
  694. return u.Update(func(s *AnnouncementUpsert) {
  695. s.ClearUpdatedBy()
  696. })
  697. }
  698. // SetUpdatedAt sets the "updated_at" field.
  699. func (u *AnnouncementUpsertOne) SetUpdatedAt(v time.Time) *AnnouncementUpsertOne {
  700. return u.Update(func(s *AnnouncementUpsert) {
  701. s.SetUpdatedAt(v)
  702. })
  703. }
  704. // UpdateUpdatedAt sets the "updated_at" field to the value that was provided on create.
  705. func (u *AnnouncementUpsertOne) UpdateUpdatedAt() *AnnouncementUpsertOne {
  706. return u.Update(func(s *AnnouncementUpsert) {
  707. s.UpdateUpdatedAt()
  708. })
  709. }
  710. // Exec executes the query.
  711. func (u *AnnouncementUpsertOne) Exec(ctx context.Context) error {
  712. if len(u.create.conflict) == 0 {
  713. return errors.New("ent: missing options for AnnouncementCreate.OnConflict")
  714. }
  715. return u.create.Exec(ctx)
  716. }
  717. // ExecX is like Exec, but panics if an error occurs.
  718. func (u *AnnouncementUpsertOne) ExecX(ctx context.Context) {
  719. if err := u.create.Exec(ctx); err != nil {
  720. panic(err)
  721. }
  722. }
  723. // Exec executes the UPSERT query and returns the inserted/updated ID.
  724. func (u *AnnouncementUpsertOne) ID(ctx context.Context) (id int64, err error) {
  725. node, err := u.create.Save(ctx)
  726. if err != nil {
  727. return id, err
  728. }
  729. return node.ID, nil
  730. }
  731. // IDX is like ID, but panics if an error occurs.
  732. func (u *AnnouncementUpsertOne) IDX(ctx context.Context) int64 {
  733. id, err := u.ID(ctx)
  734. if err != nil {
  735. panic(err)
  736. }
  737. return id
  738. }
  739. // AnnouncementCreateBulk is the builder for creating many Announcement entities in bulk.
  740. type AnnouncementCreateBulk struct {
  741. config
  742. err error
  743. builders []*AnnouncementCreate
  744. conflict []sql.ConflictOption
  745. }
  746. // Save creates the Announcement entities in the database.
  747. func (_c *AnnouncementCreateBulk) Save(ctx context.Context) ([]*Announcement, error) {
  748. if _c.err != nil {
  749. return nil, _c.err
  750. }
  751. specs := make([]*sqlgraph.CreateSpec, len(_c.builders))
  752. nodes := make([]*Announcement, len(_c.builders))
  753. mutators := make([]Mutator, len(_c.builders))
  754. for i := range _c.builders {
  755. func(i int, root context.Context) {
  756. builder := _c.builders[i]
  757. builder.defaults()
  758. var mut Mutator = MutateFunc(func(ctx context.Context, m Mutation) (Value, error) {
  759. mutation, ok := m.(*AnnouncementMutation)
  760. if !ok {
  761. return nil, fmt.Errorf("unexpected mutation type %T", m)
  762. }
  763. if err := builder.check(); err != nil {
  764. return nil, err
  765. }
  766. builder.mutation = mutation
  767. var err error
  768. nodes[i], specs[i] = builder.createSpec()
  769. if i < len(mutators)-1 {
  770. _, err = mutators[i+1].Mutate(root, _c.builders[i+1].mutation)
  771. } else {
  772. spec := &sqlgraph.BatchCreateSpec{Nodes: specs}
  773. spec.OnConflict = _c.conflict
  774. // Invoke the actual operation on the latest mutation in the chain.
  775. if err = sqlgraph.BatchCreate(ctx, _c.driver, spec); err != nil {
  776. if sqlgraph.IsConstraintError(err) {
  777. err = &ConstraintError{msg: err.Error(), wrap: err}
  778. }
  779. }
  780. }
  781. if err != nil {
  782. return nil, err
  783. }
  784. mutation.id = &nodes[i].ID
  785. if specs[i].ID.Value != nil {
  786. id := specs[i].ID.Value.(int64)
  787. nodes[i].ID = int64(id)
  788. }
  789. mutation.done = true
  790. return nodes[i], nil
  791. })
  792. for i := len(builder.hooks) - 1; i >= 0; i-- {
  793. mut = builder.hooks[i](mut)
  794. }
  795. mutators[i] = mut
  796. }(i, ctx)
  797. }
  798. if len(mutators) > 0 {
  799. if _, err := mutators[0].Mutate(ctx, _c.builders[0].mutation); err != nil {
  800. return nil, err
  801. }
  802. }
  803. return nodes, nil
  804. }
  805. // SaveX is like Save, but panics if an error occurs.
  806. func (_c *AnnouncementCreateBulk) SaveX(ctx context.Context) []*Announcement {
  807. v, err := _c.Save(ctx)
  808. if err != nil {
  809. panic(err)
  810. }
  811. return v
  812. }
  813. // Exec executes the query.
  814. func (_c *AnnouncementCreateBulk) Exec(ctx context.Context) error {
  815. _, err := _c.Save(ctx)
  816. return err
  817. }
  818. // ExecX is like Exec, but panics if an error occurs.
  819. func (_c *AnnouncementCreateBulk) ExecX(ctx context.Context) {
  820. if err := _c.Exec(ctx); err != nil {
  821. panic(err)
  822. }
  823. }
  824. // OnConflict allows configuring the `ON CONFLICT` / `ON DUPLICATE KEY` clause
  825. // of the `INSERT` statement. For example:
  826. //
  827. // client.Announcement.CreateBulk(builders...).
  828. // OnConflict(
  829. // // Update the row with the new values
  830. // // the was proposed for insertion.
  831. // sql.ResolveWithNewValues(),
  832. // ).
  833. // // Override some of the fields with custom
  834. // // update values.
  835. // Update(func(u *ent.AnnouncementUpsert) {
  836. // SetTitle(v+v).
  837. // }).
  838. // Exec(ctx)
  839. func (_c *AnnouncementCreateBulk) OnConflict(opts ...sql.ConflictOption) *AnnouncementUpsertBulk {
  840. _c.conflict = opts
  841. return &AnnouncementUpsertBulk{
  842. create: _c,
  843. }
  844. }
  845. // OnConflictColumns calls `OnConflict` and configures the columns
  846. // as conflict target. Using this option is equivalent to using:
  847. //
  848. // client.Announcement.Create().
  849. // OnConflict(sql.ConflictColumns(columns...)).
  850. // Exec(ctx)
  851. func (_c *AnnouncementCreateBulk) OnConflictColumns(columns ...string) *AnnouncementUpsertBulk {
  852. _c.conflict = append(_c.conflict, sql.ConflictColumns(columns...))
  853. return &AnnouncementUpsertBulk{
  854. create: _c,
  855. }
  856. }
  857. // AnnouncementUpsertBulk is the builder for "upsert"-ing
  858. // a bulk of Announcement nodes.
  859. type AnnouncementUpsertBulk struct {
  860. create *AnnouncementCreateBulk
  861. }
  862. // UpdateNewValues updates the mutable fields using the new values that
  863. // were set on create. Using this option is equivalent to using:
  864. //
  865. // client.Announcement.Create().
  866. // OnConflict(
  867. // sql.ResolveWithNewValues(),
  868. // ).
  869. // Exec(ctx)
  870. func (u *AnnouncementUpsertBulk) UpdateNewValues() *AnnouncementUpsertBulk {
  871. u.create.conflict = append(u.create.conflict, sql.ResolveWithNewValues())
  872. u.create.conflict = append(u.create.conflict, sql.ResolveWith(func(s *sql.UpdateSet) {
  873. for _, b := range u.create.builders {
  874. if _, exists := b.mutation.CreatedAt(); exists {
  875. s.SetIgnore(announcement.FieldCreatedAt)
  876. }
  877. }
  878. }))
  879. return u
  880. }
  881. // Ignore sets each column to itself in case of conflict.
  882. // Using this option is equivalent to using:
  883. //
  884. // client.Announcement.Create().
  885. // OnConflict(sql.ResolveWithIgnore()).
  886. // Exec(ctx)
  887. func (u *AnnouncementUpsertBulk) Ignore() *AnnouncementUpsertBulk {
  888. u.create.conflict = append(u.create.conflict, sql.ResolveWithIgnore())
  889. return u
  890. }
  891. // DoNothing configures the conflict_action to `DO NOTHING`.
  892. // Supported only by SQLite and PostgreSQL.
  893. func (u *AnnouncementUpsertBulk) DoNothing() *AnnouncementUpsertBulk {
  894. u.create.conflict = append(u.create.conflict, sql.DoNothing())
  895. return u
  896. }
  897. // Update allows overriding fields `UPDATE` values. See the AnnouncementCreateBulk.OnConflict
  898. // documentation for more info.
  899. func (u *AnnouncementUpsertBulk) Update(set func(*AnnouncementUpsert)) *AnnouncementUpsertBulk {
  900. u.create.conflict = append(u.create.conflict, sql.ResolveWith(func(update *sql.UpdateSet) {
  901. set(&AnnouncementUpsert{UpdateSet: update})
  902. }))
  903. return u
  904. }
  905. // SetTitle sets the "title" field.
  906. func (u *AnnouncementUpsertBulk) SetTitle(v string) *AnnouncementUpsertBulk {
  907. return u.Update(func(s *AnnouncementUpsert) {
  908. s.SetTitle(v)
  909. })
  910. }
  911. // UpdateTitle sets the "title" field to the value that was provided on create.
  912. func (u *AnnouncementUpsertBulk) UpdateTitle() *AnnouncementUpsertBulk {
  913. return u.Update(func(s *AnnouncementUpsert) {
  914. s.UpdateTitle()
  915. })
  916. }
  917. // SetContent sets the "content" field.
  918. func (u *AnnouncementUpsertBulk) SetContent(v string) *AnnouncementUpsertBulk {
  919. return u.Update(func(s *AnnouncementUpsert) {
  920. s.SetContent(v)
  921. })
  922. }
  923. // UpdateContent sets the "content" field to the value that was provided on create.
  924. func (u *AnnouncementUpsertBulk) UpdateContent() *AnnouncementUpsertBulk {
  925. return u.Update(func(s *AnnouncementUpsert) {
  926. s.UpdateContent()
  927. })
  928. }
  929. // SetStatus sets the "status" field.
  930. func (u *AnnouncementUpsertBulk) SetStatus(v string) *AnnouncementUpsertBulk {
  931. return u.Update(func(s *AnnouncementUpsert) {
  932. s.SetStatus(v)
  933. })
  934. }
  935. // UpdateStatus sets the "status" field to the value that was provided on create.
  936. func (u *AnnouncementUpsertBulk) UpdateStatus() *AnnouncementUpsertBulk {
  937. return u.Update(func(s *AnnouncementUpsert) {
  938. s.UpdateStatus()
  939. })
  940. }
  941. // SetNotifyMode sets the "notify_mode" field.
  942. func (u *AnnouncementUpsertBulk) SetNotifyMode(v string) *AnnouncementUpsertBulk {
  943. return u.Update(func(s *AnnouncementUpsert) {
  944. s.SetNotifyMode(v)
  945. })
  946. }
  947. // UpdateNotifyMode sets the "notify_mode" field to the value that was provided on create.
  948. func (u *AnnouncementUpsertBulk) UpdateNotifyMode() *AnnouncementUpsertBulk {
  949. return u.Update(func(s *AnnouncementUpsert) {
  950. s.UpdateNotifyMode()
  951. })
  952. }
  953. // SetTargeting sets the "targeting" field.
  954. func (u *AnnouncementUpsertBulk) SetTargeting(v domain.AnnouncementTargeting) *AnnouncementUpsertBulk {
  955. return u.Update(func(s *AnnouncementUpsert) {
  956. s.SetTargeting(v)
  957. })
  958. }
  959. // UpdateTargeting sets the "targeting" field to the value that was provided on create.
  960. func (u *AnnouncementUpsertBulk) UpdateTargeting() *AnnouncementUpsertBulk {
  961. return u.Update(func(s *AnnouncementUpsert) {
  962. s.UpdateTargeting()
  963. })
  964. }
  965. // ClearTargeting clears the value of the "targeting" field.
  966. func (u *AnnouncementUpsertBulk) ClearTargeting() *AnnouncementUpsertBulk {
  967. return u.Update(func(s *AnnouncementUpsert) {
  968. s.ClearTargeting()
  969. })
  970. }
  971. // SetStartsAt sets the "starts_at" field.
  972. func (u *AnnouncementUpsertBulk) SetStartsAt(v time.Time) *AnnouncementUpsertBulk {
  973. return u.Update(func(s *AnnouncementUpsert) {
  974. s.SetStartsAt(v)
  975. })
  976. }
  977. // UpdateStartsAt sets the "starts_at" field to the value that was provided on create.
  978. func (u *AnnouncementUpsertBulk) UpdateStartsAt() *AnnouncementUpsertBulk {
  979. return u.Update(func(s *AnnouncementUpsert) {
  980. s.UpdateStartsAt()
  981. })
  982. }
  983. // ClearStartsAt clears the value of the "starts_at" field.
  984. func (u *AnnouncementUpsertBulk) ClearStartsAt() *AnnouncementUpsertBulk {
  985. return u.Update(func(s *AnnouncementUpsert) {
  986. s.ClearStartsAt()
  987. })
  988. }
  989. // SetEndsAt sets the "ends_at" field.
  990. func (u *AnnouncementUpsertBulk) SetEndsAt(v time.Time) *AnnouncementUpsertBulk {
  991. return u.Update(func(s *AnnouncementUpsert) {
  992. s.SetEndsAt(v)
  993. })
  994. }
  995. // UpdateEndsAt sets the "ends_at" field to the value that was provided on create.
  996. func (u *AnnouncementUpsertBulk) UpdateEndsAt() *AnnouncementUpsertBulk {
  997. return u.Update(func(s *AnnouncementUpsert) {
  998. s.UpdateEndsAt()
  999. })
  1000. }
  1001. // ClearEndsAt clears the value of the "ends_at" field.
  1002. func (u *AnnouncementUpsertBulk) ClearEndsAt() *AnnouncementUpsertBulk {
  1003. return u.Update(func(s *AnnouncementUpsert) {
  1004. s.ClearEndsAt()
  1005. })
  1006. }
  1007. // SetCreatedBy sets the "created_by" field.
  1008. func (u *AnnouncementUpsertBulk) SetCreatedBy(v int64) *AnnouncementUpsertBulk {
  1009. return u.Update(func(s *AnnouncementUpsert) {
  1010. s.SetCreatedBy(v)
  1011. })
  1012. }
  1013. // AddCreatedBy adds v to the "created_by" field.
  1014. func (u *AnnouncementUpsertBulk) AddCreatedBy(v int64) *AnnouncementUpsertBulk {
  1015. return u.Update(func(s *AnnouncementUpsert) {
  1016. s.AddCreatedBy(v)
  1017. })
  1018. }
  1019. // UpdateCreatedBy sets the "created_by" field to the value that was provided on create.
  1020. func (u *AnnouncementUpsertBulk) UpdateCreatedBy() *AnnouncementUpsertBulk {
  1021. return u.Update(func(s *AnnouncementUpsert) {
  1022. s.UpdateCreatedBy()
  1023. })
  1024. }
  1025. // ClearCreatedBy clears the value of the "created_by" field.
  1026. func (u *AnnouncementUpsertBulk) ClearCreatedBy() *AnnouncementUpsertBulk {
  1027. return u.Update(func(s *AnnouncementUpsert) {
  1028. s.ClearCreatedBy()
  1029. })
  1030. }
  1031. // SetUpdatedBy sets the "updated_by" field.
  1032. func (u *AnnouncementUpsertBulk) SetUpdatedBy(v int64) *AnnouncementUpsertBulk {
  1033. return u.Update(func(s *AnnouncementUpsert) {
  1034. s.SetUpdatedBy(v)
  1035. })
  1036. }
  1037. // AddUpdatedBy adds v to the "updated_by" field.
  1038. func (u *AnnouncementUpsertBulk) AddUpdatedBy(v int64) *AnnouncementUpsertBulk {
  1039. return u.Update(func(s *AnnouncementUpsert) {
  1040. s.AddUpdatedBy(v)
  1041. })
  1042. }
  1043. // UpdateUpdatedBy sets the "updated_by" field to the value that was provided on create.
  1044. func (u *AnnouncementUpsertBulk) UpdateUpdatedBy() *AnnouncementUpsertBulk {
  1045. return u.Update(func(s *AnnouncementUpsert) {
  1046. s.UpdateUpdatedBy()
  1047. })
  1048. }
  1049. // ClearUpdatedBy clears the value of the "updated_by" field.
  1050. func (u *AnnouncementUpsertBulk) ClearUpdatedBy() *AnnouncementUpsertBulk {
  1051. return u.Update(func(s *AnnouncementUpsert) {
  1052. s.ClearUpdatedBy()
  1053. })
  1054. }
  1055. // SetUpdatedAt sets the "updated_at" field.
  1056. func (u *AnnouncementUpsertBulk) SetUpdatedAt(v time.Time) *AnnouncementUpsertBulk {
  1057. return u.Update(func(s *AnnouncementUpsert) {
  1058. s.SetUpdatedAt(v)
  1059. })
  1060. }
  1061. // UpdateUpdatedAt sets the "updated_at" field to the value that was provided on create.
  1062. func (u *AnnouncementUpsertBulk) UpdateUpdatedAt() *AnnouncementUpsertBulk {
  1063. return u.Update(func(s *AnnouncementUpsert) {
  1064. s.UpdateUpdatedAt()
  1065. })
  1066. }
  1067. // Exec executes the query.
  1068. func (u *AnnouncementUpsertBulk) Exec(ctx context.Context) error {
  1069. if u.create.err != nil {
  1070. return u.create.err
  1071. }
  1072. for i, b := range u.create.builders {
  1073. if len(b.conflict) != 0 {
  1074. return fmt.Errorf("ent: OnConflict was set for builder %d. Set it on the AnnouncementCreateBulk instead", i)
  1075. }
  1076. }
  1077. if len(u.create.conflict) == 0 {
  1078. return errors.New("ent: missing options for AnnouncementCreateBulk.OnConflict")
  1079. }
  1080. return u.create.Exec(ctx)
  1081. }
  1082. // ExecX is like Exec, but panics if an error occurs.
  1083. func (u *AnnouncementUpsertBulk) ExecX(ctx context.Context) {
  1084. if err := u.create.Exec(ctx); err != nil {
  1085. panic(err)
  1086. }
  1087. }