whatsappchannel_create.go 42 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371
  1. // Code generated by ent, DO NOT EDIT.
  2. package ent
  3. import (
  4. "context"
  5. "errors"
  6. "fmt"
  7. "time"
  8. "wechat-api/ent/whatsappchannel"
  9. "entgo.io/ent/dialect/sql"
  10. "entgo.io/ent/dialect/sql/sqlgraph"
  11. "entgo.io/ent/schema/field"
  12. )
  13. // WhatsappChannelCreate is the builder for creating a WhatsappChannel entity.
  14. type WhatsappChannelCreate struct {
  15. config
  16. mutation *WhatsappChannelMutation
  17. hooks []Hook
  18. conflict []sql.ConflictOption
  19. }
  20. // SetCreatedAt sets the "created_at" field.
  21. func (wcc *WhatsappChannelCreate) SetCreatedAt(t time.Time) *WhatsappChannelCreate {
  22. wcc.mutation.SetCreatedAt(t)
  23. return wcc
  24. }
  25. // SetNillableCreatedAt sets the "created_at" field if the given value is not nil.
  26. func (wcc *WhatsappChannelCreate) SetNillableCreatedAt(t *time.Time) *WhatsappChannelCreate {
  27. if t != nil {
  28. wcc.SetCreatedAt(*t)
  29. }
  30. return wcc
  31. }
  32. // SetUpdatedAt sets the "updated_at" field.
  33. func (wcc *WhatsappChannelCreate) SetUpdatedAt(t time.Time) *WhatsappChannelCreate {
  34. wcc.mutation.SetUpdatedAt(t)
  35. return wcc
  36. }
  37. // SetNillableUpdatedAt sets the "updated_at" field if the given value is not nil.
  38. func (wcc *WhatsappChannelCreate) SetNillableUpdatedAt(t *time.Time) *WhatsappChannelCreate {
  39. if t != nil {
  40. wcc.SetUpdatedAt(*t)
  41. }
  42. return wcc
  43. }
  44. // SetStatus sets the "status" field.
  45. func (wcc *WhatsappChannelCreate) SetStatus(u uint8) *WhatsappChannelCreate {
  46. wcc.mutation.SetStatus(u)
  47. return wcc
  48. }
  49. // SetNillableStatus sets the "status" field if the given value is not nil.
  50. func (wcc *WhatsappChannelCreate) SetNillableStatus(u *uint8) *WhatsappChannelCreate {
  51. if u != nil {
  52. wcc.SetStatus(*u)
  53. }
  54. return wcc
  55. }
  56. // SetDeletedAt sets the "deleted_at" field.
  57. func (wcc *WhatsappChannelCreate) SetDeletedAt(t time.Time) *WhatsappChannelCreate {
  58. wcc.mutation.SetDeletedAt(t)
  59. return wcc
  60. }
  61. // SetNillableDeletedAt sets the "deleted_at" field if the given value is not nil.
  62. func (wcc *WhatsappChannelCreate) SetNillableDeletedAt(t *time.Time) *WhatsappChannelCreate {
  63. if t != nil {
  64. wcc.SetDeletedAt(*t)
  65. }
  66. return wcc
  67. }
  68. // SetAk sets the "ak" field.
  69. func (wcc *WhatsappChannelCreate) SetAk(s string) *WhatsappChannelCreate {
  70. wcc.mutation.SetAk(s)
  71. return wcc
  72. }
  73. // SetNillableAk sets the "ak" field if the given value is not nil.
  74. func (wcc *WhatsappChannelCreate) SetNillableAk(s *string) *WhatsappChannelCreate {
  75. if s != nil {
  76. wcc.SetAk(*s)
  77. }
  78. return wcc
  79. }
  80. // SetSk sets the "sk" field.
  81. func (wcc *WhatsappChannelCreate) SetSk(s string) *WhatsappChannelCreate {
  82. wcc.mutation.SetSk(s)
  83. return wcc
  84. }
  85. // SetNillableSk sets the "sk" field if the given value is not nil.
  86. func (wcc *WhatsappChannelCreate) SetNillableSk(s *string) *WhatsappChannelCreate {
  87. if s != nil {
  88. wcc.SetSk(*s)
  89. }
  90. return wcc
  91. }
  92. // SetWaID sets the "wa_id" field.
  93. func (wcc *WhatsappChannelCreate) SetWaID(s string) *WhatsappChannelCreate {
  94. wcc.mutation.SetWaID(s)
  95. return wcc
  96. }
  97. // SetNillableWaID sets the "wa_id" field if the given value is not nil.
  98. func (wcc *WhatsappChannelCreate) SetNillableWaID(s *string) *WhatsappChannelCreate {
  99. if s != nil {
  100. wcc.SetWaID(*s)
  101. }
  102. return wcc
  103. }
  104. // SetWaName sets the "wa_name" field.
  105. func (wcc *WhatsappChannelCreate) SetWaName(s string) *WhatsappChannelCreate {
  106. wcc.mutation.SetWaName(s)
  107. return wcc
  108. }
  109. // SetNillableWaName sets the "wa_name" field if the given value is not nil.
  110. func (wcc *WhatsappChannelCreate) SetNillableWaName(s *string) *WhatsappChannelCreate {
  111. if s != nil {
  112. wcc.SetWaName(*s)
  113. }
  114. return wcc
  115. }
  116. // SetWabaID sets the "waba_id" field.
  117. func (wcc *WhatsappChannelCreate) SetWabaID(u uint64) *WhatsappChannelCreate {
  118. wcc.mutation.SetWabaID(u)
  119. return wcc
  120. }
  121. // SetNillableWabaID sets the "waba_id" field if the given value is not nil.
  122. func (wcc *WhatsappChannelCreate) SetNillableWabaID(u *uint64) *WhatsappChannelCreate {
  123. if u != nil {
  124. wcc.SetWabaID(*u)
  125. }
  126. return wcc
  127. }
  128. // SetBusinessID sets the "business_id" field.
  129. func (wcc *WhatsappChannelCreate) SetBusinessID(u uint64) *WhatsappChannelCreate {
  130. wcc.mutation.SetBusinessID(u)
  131. return wcc
  132. }
  133. // SetNillableBusinessID sets the "business_id" field if the given value is not nil.
  134. func (wcc *WhatsappChannelCreate) SetNillableBusinessID(u *uint64) *WhatsappChannelCreate {
  135. if u != nil {
  136. wcc.SetBusinessID(*u)
  137. }
  138. return wcc
  139. }
  140. // SetOrganizationID sets the "organization_id" field.
  141. func (wcc *WhatsappChannelCreate) SetOrganizationID(u uint64) *WhatsappChannelCreate {
  142. wcc.mutation.SetOrganizationID(u)
  143. return wcc
  144. }
  145. // SetNillableOrganizationID sets the "organization_id" field if the given value is not nil.
  146. func (wcc *WhatsappChannelCreate) SetNillableOrganizationID(u *uint64) *WhatsappChannelCreate {
  147. if u != nil {
  148. wcc.SetOrganizationID(*u)
  149. }
  150. return wcc
  151. }
  152. // SetVerifyAccount sets the "verify_account" field.
  153. func (wcc *WhatsappChannelCreate) SetVerifyAccount(s string) *WhatsappChannelCreate {
  154. wcc.mutation.SetVerifyAccount(s)
  155. return wcc
  156. }
  157. // SetNillableVerifyAccount sets the "verify_account" field if the given value is not nil.
  158. func (wcc *WhatsappChannelCreate) SetNillableVerifyAccount(s *string) *WhatsappChannelCreate {
  159. if s != nil {
  160. wcc.SetVerifyAccount(*s)
  161. }
  162. return wcc
  163. }
  164. // SetID sets the "id" field.
  165. func (wcc *WhatsappChannelCreate) SetID(u uint64) *WhatsappChannelCreate {
  166. wcc.mutation.SetID(u)
  167. return wcc
  168. }
  169. // Mutation returns the WhatsappChannelMutation object of the builder.
  170. func (wcc *WhatsappChannelCreate) Mutation() *WhatsappChannelMutation {
  171. return wcc.mutation
  172. }
  173. // Save creates the WhatsappChannel in the database.
  174. func (wcc *WhatsappChannelCreate) Save(ctx context.Context) (*WhatsappChannel, error) {
  175. if err := wcc.defaults(); err != nil {
  176. return nil, err
  177. }
  178. return withHooks(ctx, wcc.sqlSave, wcc.mutation, wcc.hooks)
  179. }
  180. // SaveX calls Save and panics if Save returns an error.
  181. func (wcc *WhatsappChannelCreate) SaveX(ctx context.Context) *WhatsappChannel {
  182. v, err := wcc.Save(ctx)
  183. if err != nil {
  184. panic(err)
  185. }
  186. return v
  187. }
  188. // Exec executes the query.
  189. func (wcc *WhatsappChannelCreate) Exec(ctx context.Context) error {
  190. _, err := wcc.Save(ctx)
  191. return err
  192. }
  193. // ExecX is like Exec, but panics if an error occurs.
  194. func (wcc *WhatsappChannelCreate) ExecX(ctx context.Context) {
  195. if err := wcc.Exec(ctx); err != nil {
  196. panic(err)
  197. }
  198. }
  199. // defaults sets the default values of the builder before save.
  200. func (wcc *WhatsappChannelCreate) defaults() error {
  201. if _, ok := wcc.mutation.CreatedAt(); !ok {
  202. if whatsappchannel.DefaultCreatedAt == nil {
  203. return fmt.Errorf("ent: uninitialized whatsappchannel.DefaultCreatedAt (forgotten import ent/runtime?)")
  204. }
  205. v := whatsappchannel.DefaultCreatedAt()
  206. wcc.mutation.SetCreatedAt(v)
  207. }
  208. if _, ok := wcc.mutation.UpdatedAt(); !ok {
  209. if whatsappchannel.DefaultUpdatedAt == nil {
  210. return fmt.Errorf("ent: uninitialized whatsappchannel.DefaultUpdatedAt (forgotten import ent/runtime?)")
  211. }
  212. v := whatsappchannel.DefaultUpdatedAt()
  213. wcc.mutation.SetUpdatedAt(v)
  214. }
  215. if _, ok := wcc.mutation.Status(); !ok {
  216. v := whatsappchannel.DefaultStatus
  217. wcc.mutation.SetStatus(v)
  218. }
  219. if _, ok := wcc.mutation.Ak(); !ok {
  220. v := whatsappchannel.DefaultAk
  221. wcc.mutation.SetAk(v)
  222. }
  223. if _, ok := wcc.mutation.Sk(); !ok {
  224. v := whatsappchannel.DefaultSk
  225. wcc.mutation.SetSk(v)
  226. }
  227. if _, ok := wcc.mutation.WaID(); !ok {
  228. v := whatsappchannel.DefaultWaID
  229. wcc.mutation.SetWaID(v)
  230. }
  231. if _, ok := wcc.mutation.WaName(); !ok {
  232. v := whatsappchannel.DefaultWaName
  233. wcc.mutation.SetWaName(v)
  234. }
  235. if _, ok := wcc.mutation.WabaID(); !ok {
  236. v := whatsappchannel.DefaultWabaID
  237. wcc.mutation.SetWabaID(v)
  238. }
  239. if _, ok := wcc.mutation.BusinessID(); !ok {
  240. v := whatsappchannel.DefaultBusinessID
  241. wcc.mutation.SetBusinessID(v)
  242. }
  243. if _, ok := wcc.mutation.OrganizationID(); !ok {
  244. v := whatsappchannel.DefaultOrganizationID
  245. wcc.mutation.SetOrganizationID(v)
  246. }
  247. if _, ok := wcc.mutation.VerifyAccount(); !ok {
  248. v := whatsappchannel.DefaultVerifyAccount
  249. wcc.mutation.SetVerifyAccount(v)
  250. }
  251. return nil
  252. }
  253. // check runs all checks and user-defined validators on the builder.
  254. func (wcc *WhatsappChannelCreate) check() error {
  255. if _, ok := wcc.mutation.CreatedAt(); !ok {
  256. return &ValidationError{Name: "created_at", err: errors.New(`ent: missing required field "WhatsappChannel.created_at"`)}
  257. }
  258. if _, ok := wcc.mutation.UpdatedAt(); !ok {
  259. return &ValidationError{Name: "updated_at", err: errors.New(`ent: missing required field "WhatsappChannel.updated_at"`)}
  260. }
  261. if _, ok := wcc.mutation.Sk(); !ok {
  262. return &ValidationError{Name: "sk", err: errors.New(`ent: missing required field "WhatsappChannel.sk"`)}
  263. }
  264. if _, ok := wcc.mutation.WabaID(); !ok {
  265. return &ValidationError{Name: "waba_id", err: errors.New(`ent: missing required field "WhatsappChannel.waba_id"`)}
  266. }
  267. if _, ok := wcc.mutation.BusinessID(); !ok {
  268. return &ValidationError{Name: "business_id", err: errors.New(`ent: missing required field "WhatsappChannel.business_id"`)}
  269. }
  270. if _, ok := wcc.mutation.VerifyAccount(); !ok {
  271. return &ValidationError{Name: "verify_account", err: errors.New(`ent: missing required field "WhatsappChannel.verify_account"`)}
  272. }
  273. return nil
  274. }
  275. func (wcc *WhatsappChannelCreate) sqlSave(ctx context.Context) (*WhatsappChannel, error) {
  276. if err := wcc.check(); err != nil {
  277. return nil, err
  278. }
  279. _node, _spec := wcc.createSpec()
  280. if err := sqlgraph.CreateNode(ctx, wcc.driver, _spec); err != nil {
  281. if sqlgraph.IsConstraintError(err) {
  282. err = &ConstraintError{msg: err.Error(), wrap: err}
  283. }
  284. return nil, err
  285. }
  286. if _spec.ID.Value != _node.ID {
  287. id := _spec.ID.Value.(int64)
  288. _node.ID = uint64(id)
  289. }
  290. wcc.mutation.id = &_node.ID
  291. wcc.mutation.done = true
  292. return _node, nil
  293. }
  294. func (wcc *WhatsappChannelCreate) createSpec() (*WhatsappChannel, *sqlgraph.CreateSpec) {
  295. var (
  296. _node = &WhatsappChannel{config: wcc.config}
  297. _spec = sqlgraph.NewCreateSpec(whatsappchannel.Table, sqlgraph.NewFieldSpec(whatsappchannel.FieldID, field.TypeUint64))
  298. )
  299. _spec.OnConflict = wcc.conflict
  300. if id, ok := wcc.mutation.ID(); ok {
  301. _node.ID = id
  302. _spec.ID.Value = id
  303. }
  304. if value, ok := wcc.mutation.CreatedAt(); ok {
  305. _spec.SetField(whatsappchannel.FieldCreatedAt, field.TypeTime, value)
  306. _node.CreatedAt = value
  307. }
  308. if value, ok := wcc.mutation.UpdatedAt(); ok {
  309. _spec.SetField(whatsappchannel.FieldUpdatedAt, field.TypeTime, value)
  310. _node.UpdatedAt = value
  311. }
  312. if value, ok := wcc.mutation.Status(); ok {
  313. _spec.SetField(whatsappchannel.FieldStatus, field.TypeUint8, value)
  314. _node.Status = value
  315. }
  316. if value, ok := wcc.mutation.DeletedAt(); ok {
  317. _spec.SetField(whatsappchannel.FieldDeletedAt, field.TypeTime, value)
  318. _node.DeletedAt = value
  319. }
  320. if value, ok := wcc.mutation.Ak(); ok {
  321. _spec.SetField(whatsappchannel.FieldAk, field.TypeString, value)
  322. _node.Ak = value
  323. }
  324. if value, ok := wcc.mutation.Sk(); ok {
  325. _spec.SetField(whatsappchannel.FieldSk, field.TypeString, value)
  326. _node.Sk = value
  327. }
  328. if value, ok := wcc.mutation.WaID(); ok {
  329. _spec.SetField(whatsappchannel.FieldWaID, field.TypeString, value)
  330. _node.WaID = value
  331. }
  332. if value, ok := wcc.mutation.WaName(); ok {
  333. _spec.SetField(whatsappchannel.FieldWaName, field.TypeString, value)
  334. _node.WaName = value
  335. }
  336. if value, ok := wcc.mutation.WabaID(); ok {
  337. _spec.SetField(whatsappchannel.FieldWabaID, field.TypeUint64, value)
  338. _node.WabaID = value
  339. }
  340. if value, ok := wcc.mutation.BusinessID(); ok {
  341. _spec.SetField(whatsappchannel.FieldBusinessID, field.TypeUint64, value)
  342. _node.BusinessID = value
  343. }
  344. if value, ok := wcc.mutation.OrganizationID(); ok {
  345. _spec.SetField(whatsappchannel.FieldOrganizationID, field.TypeUint64, value)
  346. _node.OrganizationID = value
  347. }
  348. if value, ok := wcc.mutation.VerifyAccount(); ok {
  349. _spec.SetField(whatsappchannel.FieldVerifyAccount, field.TypeString, value)
  350. _node.VerifyAccount = value
  351. }
  352. return _node, _spec
  353. }
  354. // OnConflict allows configuring the `ON CONFLICT` / `ON DUPLICATE KEY` clause
  355. // of the `INSERT` statement. For example:
  356. //
  357. // client.WhatsappChannel.Create().
  358. // SetCreatedAt(v).
  359. // OnConflict(
  360. // // Update the row with the new values
  361. // // the was proposed for insertion.
  362. // sql.ResolveWithNewValues(),
  363. // ).
  364. // // Override some of the fields with custom
  365. // // update values.
  366. // Update(func(u *ent.WhatsappChannelUpsert) {
  367. // SetCreatedAt(v+v).
  368. // }).
  369. // Exec(ctx)
  370. func (wcc *WhatsappChannelCreate) OnConflict(opts ...sql.ConflictOption) *WhatsappChannelUpsertOne {
  371. wcc.conflict = opts
  372. return &WhatsappChannelUpsertOne{
  373. create: wcc,
  374. }
  375. }
  376. // OnConflictColumns calls `OnConflict` and configures the columns
  377. // as conflict target. Using this option is equivalent to using:
  378. //
  379. // client.WhatsappChannel.Create().
  380. // OnConflict(sql.ConflictColumns(columns...)).
  381. // Exec(ctx)
  382. func (wcc *WhatsappChannelCreate) OnConflictColumns(columns ...string) *WhatsappChannelUpsertOne {
  383. wcc.conflict = append(wcc.conflict, sql.ConflictColumns(columns...))
  384. return &WhatsappChannelUpsertOne{
  385. create: wcc,
  386. }
  387. }
  388. type (
  389. // WhatsappChannelUpsertOne is the builder for "upsert"-ing
  390. // one WhatsappChannel node.
  391. WhatsappChannelUpsertOne struct {
  392. create *WhatsappChannelCreate
  393. }
  394. // WhatsappChannelUpsert is the "OnConflict" setter.
  395. WhatsappChannelUpsert struct {
  396. *sql.UpdateSet
  397. }
  398. )
  399. // SetUpdatedAt sets the "updated_at" field.
  400. func (u *WhatsappChannelUpsert) SetUpdatedAt(v time.Time) *WhatsappChannelUpsert {
  401. u.Set(whatsappchannel.FieldUpdatedAt, v)
  402. return u
  403. }
  404. // UpdateUpdatedAt sets the "updated_at" field to the value that was provided on create.
  405. func (u *WhatsappChannelUpsert) UpdateUpdatedAt() *WhatsappChannelUpsert {
  406. u.SetExcluded(whatsappchannel.FieldUpdatedAt)
  407. return u
  408. }
  409. // SetStatus sets the "status" field.
  410. func (u *WhatsappChannelUpsert) SetStatus(v uint8) *WhatsappChannelUpsert {
  411. u.Set(whatsappchannel.FieldStatus, v)
  412. return u
  413. }
  414. // UpdateStatus sets the "status" field to the value that was provided on create.
  415. func (u *WhatsappChannelUpsert) UpdateStatus() *WhatsappChannelUpsert {
  416. u.SetExcluded(whatsappchannel.FieldStatus)
  417. return u
  418. }
  419. // AddStatus adds v to the "status" field.
  420. func (u *WhatsappChannelUpsert) AddStatus(v uint8) *WhatsappChannelUpsert {
  421. u.Add(whatsappchannel.FieldStatus, v)
  422. return u
  423. }
  424. // ClearStatus clears the value of the "status" field.
  425. func (u *WhatsappChannelUpsert) ClearStatus() *WhatsappChannelUpsert {
  426. u.SetNull(whatsappchannel.FieldStatus)
  427. return u
  428. }
  429. // SetDeletedAt sets the "deleted_at" field.
  430. func (u *WhatsappChannelUpsert) SetDeletedAt(v time.Time) *WhatsappChannelUpsert {
  431. u.Set(whatsappchannel.FieldDeletedAt, v)
  432. return u
  433. }
  434. // UpdateDeletedAt sets the "deleted_at" field to the value that was provided on create.
  435. func (u *WhatsappChannelUpsert) UpdateDeletedAt() *WhatsappChannelUpsert {
  436. u.SetExcluded(whatsappchannel.FieldDeletedAt)
  437. return u
  438. }
  439. // ClearDeletedAt clears the value of the "deleted_at" field.
  440. func (u *WhatsappChannelUpsert) ClearDeletedAt() *WhatsappChannelUpsert {
  441. u.SetNull(whatsappchannel.FieldDeletedAt)
  442. return u
  443. }
  444. // SetAk sets the "ak" field.
  445. func (u *WhatsappChannelUpsert) SetAk(v string) *WhatsappChannelUpsert {
  446. u.Set(whatsappchannel.FieldAk, v)
  447. return u
  448. }
  449. // UpdateAk sets the "ak" field to the value that was provided on create.
  450. func (u *WhatsappChannelUpsert) UpdateAk() *WhatsappChannelUpsert {
  451. u.SetExcluded(whatsappchannel.FieldAk)
  452. return u
  453. }
  454. // ClearAk clears the value of the "ak" field.
  455. func (u *WhatsappChannelUpsert) ClearAk() *WhatsappChannelUpsert {
  456. u.SetNull(whatsappchannel.FieldAk)
  457. return u
  458. }
  459. // SetSk sets the "sk" field.
  460. func (u *WhatsappChannelUpsert) SetSk(v string) *WhatsappChannelUpsert {
  461. u.Set(whatsappchannel.FieldSk, v)
  462. return u
  463. }
  464. // UpdateSk sets the "sk" field to the value that was provided on create.
  465. func (u *WhatsappChannelUpsert) UpdateSk() *WhatsappChannelUpsert {
  466. u.SetExcluded(whatsappchannel.FieldSk)
  467. return u
  468. }
  469. // SetWaID sets the "wa_id" field.
  470. func (u *WhatsappChannelUpsert) SetWaID(v string) *WhatsappChannelUpsert {
  471. u.Set(whatsappchannel.FieldWaID, v)
  472. return u
  473. }
  474. // UpdateWaID sets the "wa_id" field to the value that was provided on create.
  475. func (u *WhatsappChannelUpsert) UpdateWaID() *WhatsappChannelUpsert {
  476. u.SetExcluded(whatsappchannel.FieldWaID)
  477. return u
  478. }
  479. // ClearWaID clears the value of the "wa_id" field.
  480. func (u *WhatsappChannelUpsert) ClearWaID() *WhatsappChannelUpsert {
  481. u.SetNull(whatsappchannel.FieldWaID)
  482. return u
  483. }
  484. // SetWaName sets the "wa_name" field.
  485. func (u *WhatsappChannelUpsert) SetWaName(v string) *WhatsappChannelUpsert {
  486. u.Set(whatsappchannel.FieldWaName, v)
  487. return u
  488. }
  489. // UpdateWaName sets the "wa_name" field to the value that was provided on create.
  490. func (u *WhatsappChannelUpsert) UpdateWaName() *WhatsappChannelUpsert {
  491. u.SetExcluded(whatsappchannel.FieldWaName)
  492. return u
  493. }
  494. // ClearWaName clears the value of the "wa_name" field.
  495. func (u *WhatsappChannelUpsert) ClearWaName() *WhatsappChannelUpsert {
  496. u.SetNull(whatsappchannel.FieldWaName)
  497. return u
  498. }
  499. // SetWabaID sets the "waba_id" field.
  500. func (u *WhatsappChannelUpsert) SetWabaID(v uint64) *WhatsappChannelUpsert {
  501. u.Set(whatsappchannel.FieldWabaID, v)
  502. return u
  503. }
  504. // UpdateWabaID sets the "waba_id" field to the value that was provided on create.
  505. func (u *WhatsappChannelUpsert) UpdateWabaID() *WhatsappChannelUpsert {
  506. u.SetExcluded(whatsappchannel.FieldWabaID)
  507. return u
  508. }
  509. // AddWabaID adds v to the "waba_id" field.
  510. func (u *WhatsappChannelUpsert) AddWabaID(v uint64) *WhatsappChannelUpsert {
  511. u.Add(whatsappchannel.FieldWabaID, v)
  512. return u
  513. }
  514. // SetBusinessID sets the "business_id" field.
  515. func (u *WhatsappChannelUpsert) SetBusinessID(v uint64) *WhatsappChannelUpsert {
  516. u.Set(whatsappchannel.FieldBusinessID, v)
  517. return u
  518. }
  519. // UpdateBusinessID sets the "business_id" field to the value that was provided on create.
  520. func (u *WhatsappChannelUpsert) UpdateBusinessID() *WhatsappChannelUpsert {
  521. u.SetExcluded(whatsappchannel.FieldBusinessID)
  522. return u
  523. }
  524. // AddBusinessID adds v to the "business_id" field.
  525. func (u *WhatsappChannelUpsert) AddBusinessID(v uint64) *WhatsappChannelUpsert {
  526. u.Add(whatsappchannel.FieldBusinessID, v)
  527. return u
  528. }
  529. // SetOrganizationID sets the "organization_id" field.
  530. func (u *WhatsappChannelUpsert) SetOrganizationID(v uint64) *WhatsappChannelUpsert {
  531. u.Set(whatsappchannel.FieldOrganizationID, v)
  532. return u
  533. }
  534. // UpdateOrganizationID sets the "organization_id" field to the value that was provided on create.
  535. func (u *WhatsappChannelUpsert) UpdateOrganizationID() *WhatsappChannelUpsert {
  536. u.SetExcluded(whatsappchannel.FieldOrganizationID)
  537. return u
  538. }
  539. // AddOrganizationID adds v to the "organization_id" field.
  540. func (u *WhatsappChannelUpsert) AddOrganizationID(v uint64) *WhatsappChannelUpsert {
  541. u.Add(whatsappchannel.FieldOrganizationID, v)
  542. return u
  543. }
  544. // ClearOrganizationID clears the value of the "organization_id" field.
  545. func (u *WhatsappChannelUpsert) ClearOrganizationID() *WhatsappChannelUpsert {
  546. u.SetNull(whatsappchannel.FieldOrganizationID)
  547. return u
  548. }
  549. // SetVerifyAccount sets the "verify_account" field.
  550. func (u *WhatsappChannelUpsert) SetVerifyAccount(v string) *WhatsappChannelUpsert {
  551. u.Set(whatsappchannel.FieldVerifyAccount, v)
  552. return u
  553. }
  554. // UpdateVerifyAccount sets the "verify_account" field to the value that was provided on create.
  555. func (u *WhatsappChannelUpsert) UpdateVerifyAccount() *WhatsappChannelUpsert {
  556. u.SetExcluded(whatsappchannel.FieldVerifyAccount)
  557. return u
  558. }
  559. // UpdateNewValues updates the mutable fields using the new values that were set on create except the ID field.
  560. // Using this option is equivalent to using:
  561. //
  562. // client.WhatsappChannel.Create().
  563. // OnConflict(
  564. // sql.ResolveWithNewValues(),
  565. // sql.ResolveWith(func(u *sql.UpdateSet) {
  566. // u.SetIgnore(whatsappchannel.FieldID)
  567. // }),
  568. // ).
  569. // Exec(ctx)
  570. func (u *WhatsappChannelUpsertOne) UpdateNewValues() *WhatsappChannelUpsertOne {
  571. u.create.conflict = append(u.create.conflict, sql.ResolveWithNewValues())
  572. u.create.conflict = append(u.create.conflict, sql.ResolveWith(func(s *sql.UpdateSet) {
  573. if _, exists := u.create.mutation.ID(); exists {
  574. s.SetIgnore(whatsappchannel.FieldID)
  575. }
  576. if _, exists := u.create.mutation.CreatedAt(); exists {
  577. s.SetIgnore(whatsappchannel.FieldCreatedAt)
  578. }
  579. }))
  580. return u
  581. }
  582. // Ignore sets each column to itself in case of conflict.
  583. // Using this option is equivalent to using:
  584. //
  585. // client.WhatsappChannel.Create().
  586. // OnConflict(sql.ResolveWithIgnore()).
  587. // Exec(ctx)
  588. func (u *WhatsappChannelUpsertOne) Ignore() *WhatsappChannelUpsertOne {
  589. u.create.conflict = append(u.create.conflict, sql.ResolveWithIgnore())
  590. return u
  591. }
  592. // DoNothing configures the conflict_action to `DO NOTHING`.
  593. // Supported only by SQLite and PostgreSQL.
  594. func (u *WhatsappChannelUpsertOne) DoNothing() *WhatsappChannelUpsertOne {
  595. u.create.conflict = append(u.create.conflict, sql.DoNothing())
  596. return u
  597. }
  598. // Update allows overriding fields `UPDATE` values. See the WhatsappChannelCreate.OnConflict
  599. // documentation for more info.
  600. func (u *WhatsappChannelUpsertOne) Update(set func(*WhatsappChannelUpsert)) *WhatsappChannelUpsertOne {
  601. u.create.conflict = append(u.create.conflict, sql.ResolveWith(func(update *sql.UpdateSet) {
  602. set(&WhatsappChannelUpsert{UpdateSet: update})
  603. }))
  604. return u
  605. }
  606. // SetUpdatedAt sets the "updated_at" field.
  607. func (u *WhatsappChannelUpsertOne) SetUpdatedAt(v time.Time) *WhatsappChannelUpsertOne {
  608. return u.Update(func(s *WhatsappChannelUpsert) {
  609. s.SetUpdatedAt(v)
  610. })
  611. }
  612. // UpdateUpdatedAt sets the "updated_at" field to the value that was provided on create.
  613. func (u *WhatsappChannelUpsertOne) UpdateUpdatedAt() *WhatsappChannelUpsertOne {
  614. return u.Update(func(s *WhatsappChannelUpsert) {
  615. s.UpdateUpdatedAt()
  616. })
  617. }
  618. // SetStatus sets the "status" field.
  619. func (u *WhatsappChannelUpsertOne) SetStatus(v uint8) *WhatsappChannelUpsertOne {
  620. return u.Update(func(s *WhatsappChannelUpsert) {
  621. s.SetStatus(v)
  622. })
  623. }
  624. // AddStatus adds v to the "status" field.
  625. func (u *WhatsappChannelUpsertOne) AddStatus(v uint8) *WhatsappChannelUpsertOne {
  626. return u.Update(func(s *WhatsappChannelUpsert) {
  627. s.AddStatus(v)
  628. })
  629. }
  630. // UpdateStatus sets the "status" field to the value that was provided on create.
  631. func (u *WhatsappChannelUpsertOne) UpdateStatus() *WhatsappChannelUpsertOne {
  632. return u.Update(func(s *WhatsappChannelUpsert) {
  633. s.UpdateStatus()
  634. })
  635. }
  636. // ClearStatus clears the value of the "status" field.
  637. func (u *WhatsappChannelUpsertOne) ClearStatus() *WhatsappChannelUpsertOne {
  638. return u.Update(func(s *WhatsappChannelUpsert) {
  639. s.ClearStatus()
  640. })
  641. }
  642. // SetDeletedAt sets the "deleted_at" field.
  643. func (u *WhatsappChannelUpsertOne) SetDeletedAt(v time.Time) *WhatsappChannelUpsertOne {
  644. return u.Update(func(s *WhatsappChannelUpsert) {
  645. s.SetDeletedAt(v)
  646. })
  647. }
  648. // UpdateDeletedAt sets the "deleted_at" field to the value that was provided on create.
  649. func (u *WhatsappChannelUpsertOne) UpdateDeletedAt() *WhatsappChannelUpsertOne {
  650. return u.Update(func(s *WhatsappChannelUpsert) {
  651. s.UpdateDeletedAt()
  652. })
  653. }
  654. // ClearDeletedAt clears the value of the "deleted_at" field.
  655. func (u *WhatsappChannelUpsertOne) ClearDeletedAt() *WhatsappChannelUpsertOne {
  656. return u.Update(func(s *WhatsappChannelUpsert) {
  657. s.ClearDeletedAt()
  658. })
  659. }
  660. // SetAk sets the "ak" field.
  661. func (u *WhatsappChannelUpsertOne) SetAk(v string) *WhatsappChannelUpsertOne {
  662. return u.Update(func(s *WhatsappChannelUpsert) {
  663. s.SetAk(v)
  664. })
  665. }
  666. // UpdateAk sets the "ak" field to the value that was provided on create.
  667. func (u *WhatsappChannelUpsertOne) UpdateAk() *WhatsappChannelUpsertOne {
  668. return u.Update(func(s *WhatsappChannelUpsert) {
  669. s.UpdateAk()
  670. })
  671. }
  672. // ClearAk clears the value of the "ak" field.
  673. func (u *WhatsappChannelUpsertOne) ClearAk() *WhatsappChannelUpsertOne {
  674. return u.Update(func(s *WhatsappChannelUpsert) {
  675. s.ClearAk()
  676. })
  677. }
  678. // SetSk sets the "sk" field.
  679. func (u *WhatsappChannelUpsertOne) SetSk(v string) *WhatsappChannelUpsertOne {
  680. return u.Update(func(s *WhatsappChannelUpsert) {
  681. s.SetSk(v)
  682. })
  683. }
  684. // UpdateSk sets the "sk" field to the value that was provided on create.
  685. func (u *WhatsappChannelUpsertOne) UpdateSk() *WhatsappChannelUpsertOne {
  686. return u.Update(func(s *WhatsappChannelUpsert) {
  687. s.UpdateSk()
  688. })
  689. }
  690. // SetWaID sets the "wa_id" field.
  691. func (u *WhatsappChannelUpsertOne) SetWaID(v string) *WhatsappChannelUpsertOne {
  692. return u.Update(func(s *WhatsappChannelUpsert) {
  693. s.SetWaID(v)
  694. })
  695. }
  696. // UpdateWaID sets the "wa_id" field to the value that was provided on create.
  697. func (u *WhatsappChannelUpsertOne) UpdateWaID() *WhatsappChannelUpsertOne {
  698. return u.Update(func(s *WhatsappChannelUpsert) {
  699. s.UpdateWaID()
  700. })
  701. }
  702. // ClearWaID clears the value of the "wa_id" field.
  703. func (u *WhatsappChannelUpsertOne) ClearWaID() *WhatsappChannelUpsertOne {
  704. return u.Update(func(s *WhatsappChannelUpsert) {
  705. s.ClearWaID()
  706. })
  707. }
  708. // SetWaName sets the "wa_name" field.
  709. func (u *WhatsappChannelUpsertOne) SetWaName(v string) *WhatsappChannelUpsertOne {
  710. return u.Update(func(s *WhatsappChannelUpsert) {
  711. s.SetWaName(v)
  712. })
  713. }
  714. // UpdateWaName sets the "wa_name" field to the value that was provided on create.
  715. func (u *WhatsappChannelUpsertOne) UpdateWaName() *WhatsappChannelUpsertOne {
  716. return u.Update(func(s *WhatsappChannelUpsert) {
  717. s.UpdateWaName()
  718. })
  719. }
  720. // ClearWaName clears the value of the "wa_name" field.
  721. func (u *WhatsappChannelUpsertOne) ClearWaName() *WhatsappChannelUpsertOne {
  722. return u.Update(func(s *WhatsappChannelUpsert) {
  723. s.ClearWaName()
  724. })
  725. }
  726. // SetWabaID sets the "waba_id" field.
  727. func (u *WhatsappChannelUpsertOne) SetWabaID(v uint64) *WhatsappChannelUpsertOne {
  728. return u.Update(func(s *WhatsappChannelUpsert) {
  729. s.SetWabaID(v)
  730. })
  731. }
  732. // AddWabaID adds v to the "waba_id" field.
  733. func (u *WhatsappChannelUpsertOne) AddWabaID(v uint64) *WhatsappChannelUpsertOne {
  734. return u.Update(func(s *WhatsappChannelUpsert) {
  735. s.AddWabaID(v)
  736. })
  737. }
  738. // UpdateWabaID sets the "waba_id" field to the value that was provided on create.
  739. func (u *WhatsappChannelUpsertOne) UpdateWabaID() *WhatsappChannelUpsertOne {
  740. return u.Update(func(s *WhatsappChannelUpsert) {
  741. s.UpdateWabaID()
  742. })
  743. }
  744. // SetBusinessID sets the "business_id" field.
  745. func (u *WhatsappChannelUpsertOne) SetBusinessID(v uint64) *WhatsappChannelUpsertOne {
  746. return u.Update(func(s *WhatsappChannelUpsert) {
  747. s.SetBusinessID(v)
  748. })
  749. }
  750. // AddBusinessID adds v to the "business_id" field.
  751. func (u *WhatsappChannelUpsertOne) AddBusinessID(v uint64) *WhatsappChannelUpsertOne {
  752. return u.Update(func(s *WhatsappChannelUpsert) {
  753. s.AddBusinessID(v)
  754. })
  755. }
  756. // UpdateBusinessID sets the "business_id" field to the value that was provided on create.
  757. func (u *WhatsappChannelUpsertOne) UpdateBusinessID() *WhatsappChannelUpsertOne {
  758. return u.Update(func(s *WhatsappChannelUpsert) {
  759. s.UpdateBusinessID()
  760. })
  761. }
  762. // SetOrganizationID sets the "organization_id" field.
  763. func (u *WhatsappChannelUpsertOne) SetOrganizationID(v uint64) *WhatsappChannelUpsertOne {
  764. return u.Update(func(s *WhatsappChannelUpsert) {
  765. s.SetOrganizationID(v)
  766. })
  767. }
  768. // AddOrganizationID adds v to the "organization_id" field.
  769. func (u *WhatsappChannelUpsertOne) AddOrganizationID(v uint64) *WhatsappChannelUpsertOne {
  770. return u.Update(func(s *WhatsappChannelUpsert) {
  771. s.AddOrganizationID(v)
  772. })
  773. }
  774. // UpdateOrganizationID sets the "organization_id" field to the value that was provided on create.
  775. func (u *WhatsappChannelUpsertOne) UpdateOrganizationID() *WhatsappChannelUpsertOne {
  776. return u.Update(func(s *WhatsappChannelUpsert) {
  777. s.UpdateOrganizationID()
  778. })
  779. }
  780. // ClearOrganizationID clears the value of the "organization_id" field.
  781. func (u *WhatsappChannelUpsertOne) ClearOrganizationID() *WhatsappChannelUpsertOne {
  782. return u.Update(func(s *WhatsappChannelUpsert) {
  783. s.ClearOrganizationID()
  784. })
  785. }
  786. // SetVerifyAccount sets the "verify_account" field.
  787. func (u *WhatsappChannelUpsertOne) SetVerifyAccount(v string) *WhatsappChannelUpsertOne {
  788. return u.Update(func(s *WhatsappChannelUpsert) {
  789. s.SetVerifyAccount(v)
  790. })
  791. }
  792. // UpdateVerifyAccount sets the "verify_account" field to the value that was provided on create.
  793. func (u *WhatsappChannelUpsertOne) UpdateVerifyAccount() *WhatsappChannelUpsertOne {
  794. return u.Update(func(s *WhatsappChannelUpsert) {
  795. s.UpdateVerifyAccount()
  796. })
  797. }
  798. // Exec executes the query.
  799. func (u *WhatsappChannelUpsertOne) Exec(ctx context.Context) error {
  800. if len(u.create.conflict) == 0 {
  801. return errors.New("ent: missing options for WhatsappChannelCreate.OnConflict")
  802. }
  803. return u.create.Exec(ctx)
  804. }
  805. // ExecX is like Exec, but panics if an error occurs.
  806. func (u *WhatsappChannelUpsertOne) ExecX(ctx context.Context) {
  807. if err := u.create.Exec(ctx); err != nil {
  808. panic(err)
  809. }
  810. }
  811. // Exec executes the UPSERT query and returns the inserted/updated ID.
  812. func (u *WhatsappChannelUpsertOne) ID(ctx context.Context) (id uint64, err error) {
  813. node, err := u.create.Save(ctx)
  814. if err != nil {
  815. return id, err
  816. }
  817. return node.ID, nil
  818. }
  819. // IDX is like ID, but panics if an error occurs.
  820. func (u *WhatsappChannelUpsertOne) IDX(ctx context.Context) uint64 {
  821. id, err := u.ID(ctx)
  822. if err != nil {
  823. panic(err)
  824. }
  825. return id
  826. }
  827. // WhatsappChannelCreateBulk is the builder for creating many WhatsappChannel entities in bulk.
  828. type WhatsappChannelCreateBulk struct {
  829. config
  830. err error
  831. builders []*WhatsappChannelCreate
  832. conflict []sql.ConflictOption
  833. }
  834. // Save creates the WhatsappChannel entities in the database.
  835. func (wccb *WhatsappChannelCreateBulk) Save(ctx context.Context) ([]*WhatsappChannel, error) {
  836. if wccb.err != nil {
  837. return nil, wccb.err
  838. }
  839. specs := make([]*sqlgraph.CreateSpec, len(wccb.builders))
  840. nodes := make([]*WhatsappChannel, len(wccb.builders))
  841. mutators := make([]Mutator, len(wccb.builders))
  842. for i := range wccb.builders {
  843. func(i int, root context.Context) {
  844. builder := wccb.builders[i]
  845. builder.defaults()
  846. var mut Mutator = MutateFunc(func(ctx context.Context, m Mutation) (Value, error) {
  847. mutation, ok := m.(*WhatsappChannelMutation)
  848. if !ok {
  849. return nil, fmt.Errorf("unexpected mutation type %T", m)
  850. }
  851. if err := builder.check(); err != nil {
  852. return nil, err
  853. }
  854. builder.mutation = mutation
  855. var err error
  856. nodes[i], specs[i] = builder.createSpec()
  857. if i < len(mutators)-1 {
  858. _, err = mutators[i+1].Mutate(root, wccb.builders[i+1].mutation)
  859. } else {
  860. spec := &sqlgraph.BatchCreateSpec{Nodes: specs}
  861. spec.OnConflict = wccb.conflict
  862. // Invoke the actual operation on the latest mutation in the chain.
  863. if err = sqlgraph.BatchCreate(ctx, wccb.driver, spec); err != nil {
  864. if sqlgraph.IsConstraintError(err) {
  865. err = &ConstraintError{msg: err.Error(), wrap: err}
  866. }
  867. }
  868. }
  869. if err != nil {
  870. return nil, err
  871. }
  872. mutation.id = &nodes[i].ID
  873. if specs[i].ID.Value != nil && nodes[i].ID == 0 {
  874. id := specs[i].ID.Value.(int64)
  875. nodes[i].ID = uint64(id)
  876. }
  877. mutation.done = true
  878. return nodes[i], nil
  879. })
  880. for i := len(builder.hooks) - 1; i >= 0; i-- {
  881. mut = builder.hooks[i](mut)
  882. }
  883. mutators[i] = mut
  884. }(i, ctx)
  885. }
  886. if len(mutators) > 0 {
  887. if _, err := mutators[0].Mutate(ctx, wccb.builders[0].mutation); err != nil {
  888. return nil, err
  889. }
  890. }
  891. return nodes, nil
  892. }
  893. // SaveX is like Save, but panics if an error occurs.
  894. func (wccb *WhatsappChannelCreateBulk) SaveX(ctx context.Context) []*WhatsappChannel {
  895. v, err := wccb.Save(ctx)
  896. if err != nil {
  897. panic(err)
  898. }
  899. return v
  900. }
  901. // Exec executes the query.
  902. func (wccb *WhatsappChannelCreateBulk) Exec(ctx context.Context) error {
  903. _, err := wccb.Save(ctx)
  904. return err
  905. }
  906. // ExecX is like Exec, but panics if an error occurs.
  907. func (wccb *WhatsappChannelCreateBulk) ExecX(ctx context.Context) {
  908. if err := wccb.Exec(ctx); err != nil {
  909. panic(err)
  910. }
  911. }
  912. // OnConflict allows configuring the `ON CONFLICT` / `ON DUPLICATE KEY` clause
  913. // of the `INSERT` statement. For example:
  914. //
  915. // client.WhatsappChannel.CreateBulk(builders...).
  916. // OnConflict(
  917. // // Update the row with the new values
  918. // // the was proposed for insertion.
  919. // sql.ResolveWithNewValues(),
  920. // ).
  921. // // Override some of the fields with custom
  922. // // update values.
  923. // Update(func(u *ent.WhatsappChannelUpsert) {
  924. // SetCreatedAt(v+v).
  925. // }).
  926. // Exec(ctx)
  927. func (wccb *WhatsappChannelCreateBulk) OnConflict(opts ...sql.ConflictOption) *WhatsappChannelUpsertBulk {
  928. wccb.conflict = opts
  929. return &WhatsappChannelUpsertBulk{
  930. create: wccb,
  931. }
  932. }
  933. // OnConflictColumns calls `OnConflict` and configures the columns
  934. // as conflict target. Using this option is equivalent to using:
  935. //
  936. // client.WhatsappChannel.Create().
  937. // OnConflict(sql.ConflictColumns(columns...)).
  938. // Exec(ctx)
  939. func (wccb *WhatsappChannelCreateBulk) OnConflictColumns(columns ...string) *WhatsappChannelUpsertBulk {
  940. wccb.conflict = append(wccb.conflict, sql.ConflictColumns(columns...))
  941. return &WhatsappChannelUpsertBulk{
  942. create: wccb,
  943. }
  944. }
  945. // WhatsappChannelUpsertBulk is the builder for "upsert"-ing
  946. // a bulk of WhatsappChannel nodes.
  947. type WhatsappChannelUpsertBulk struct {
  948. create *WhatsappChannelCreateBulk
  949. }
  950. // UpdateNewValues updates the mutable fields using the new values that
  951. // were set on create. Using this option is equivalent to using:
  952. //
  953. // client.WhatsappChannel.Create().
  954. // OnConflict(
  955. // sql.ResolveWithNewValues(),
  956. // sql.ResolveWith(func(u *sql.UpdateSet) {
  957. // u.SetIgnore(whatsappchannel.FieldID)
  958. // }),
  959. // ).
  960. // Exec(ctx)
  961. func (u *WhatsappChannelUpsertBulk) UpdateNewValues() *WhatsappChannelUpsertBulk {
  962. u.create.conflict = append(u.create.conflict, sql.ResolveWithNewValues())
  963. u.create.conflict = append(u.create.conflict, sql.ResolveWith(func(s *sql.UpdateSet) {
  964. for _, b := range u.create.builders {
  965. if _, exists := b.mutation.ID(); exists {
  966. s.SetIgnore(whatsappchannel.FieldID)
  967. }
  968. if _, exists := b.mutation.CreatedAt(); exists {
  969. s.SetIgnore(whatsappchannel.FieldCreatedAt)
  970. }
  971. }
  972. }))
  973. return u
  974. }
  975. // Ignore sets each column to itself in case of conflict.
  976. // Using this option is equivalent to using:
  977. //
  978. // client.WhatsappChannel.Create().
  979. // OnConflict(sql.ResolveWithIgnore()).
  980. // Exec(ctx)
  981. func (u *WhatsappChannelUpsertBulk) Ignore() *WhatsappChannelUpsertBulk {
  982. u.create.conflict = append(u.create.conflict, sql.ResolveWithIgnore())
  983. return u
  984. }
  985. // DoNothing configures the conflict_action to `DO NOTHING`.
  986. // Supported only by SQLite and PostgreSQL.
  987. func (u *WhatsappChannelUpsertBulk) DoNothing() *WhatsappChannelUpsertBulk {
  988. u.create.conflict = append(u.create.conflict, sql.DoNothing())
  989. return u
  990. }
  991. // Update allows overriding fields `UPDATE` values. See the WhatsappChannelCreateBulk.OnConflict
  992. // documentation for more info.
  993. func (u *WhatsappChannelUpsertBulk) Update(set func(*WhatsappChannelUpsert)) *WhatsappChannelUpsertBulk {
  994. u.create.conflict = append(u.create.conflict, sql.ResolveWith(func(update *sql.UpdateSet) {
  995. set(&WhatsappChannelUpsert{UpdateSet: update})
  996. }))
  997. return u
  998. }
  999. // SetUpdatedAt sets the "updated_at" field.
  1000. func (u *WhatsappChannelUpsertBulk) SetUpdatedAt(v time.Time) *WhatsappChannelUpsertBulk {
  1001. return u.Update(func(s *WhatsappChannelUpsert) {
  1002. s.SetUpdatedAt(v)
  1003. })
  1004. }
  1005. // UpdateUpdatedAt sets the "updated_at" field to the value that was provided on create.
  1006. func (u *WhatsappChannelUpsertBulk) UpdateUpdatedAt() *WhatsappChannelUpsertBulk {
  1007. return u.Update(func(s *WhatsappChannelUpsert) {
  1008. s.UpdateUpdatedAt()
  1009. })
  1010. }
  1011. // SetStatus sets the "status" field.
  1012. func (u *WhatsappChannelUpsertBulk) SetStatus(v uint8) *WhatsappChannelUpsertBulk {
  1013. return u.Update(func(s *WhatsappChannelUpsert) {
  1014. s.SetStatus(v)
  1015. })
  1016. }
  1017. // AddStatus adds v to the "status" field.
  1018. func (u *WhatsappChannelUpsertBulk) AddStatus(v uint8) *WhatsappChannelUpsertBulk {
  1019. return u.Update(func(s *WhatsappChannelUpsert) {
  1020. s.AddStatus(v)
  1021. })
  1022. }
  1023. // UpdateStatus sets the "status" field to the value that was provided on create.
  1024. func (u *WhatsappChannelUpsertBulk) UpdateStatus() *WhatsappChannelUpsertBulk {
  1025. return u.Update(func(s *WhatsappChannelUpsert) {
  1026. s.UpdateStatus()
  1027. })
  1028. }
  1029. // ClearStatus clears the value of the "status" field.
  1030. func (u *WhatsappChannelUpsertBulk) ClearStatus() *WhatsappChannelUpsertBulk {
  1031. return u.Update(func(s *WhatsappChannelUpsert) {
  1032. s.ClearStatus()
  1033. })
  1034. }
  1035. // SetDeletedAt sets the "deleted_at" field.
  1036. func (u *WhatsappChannelUpsertBulk) SetDeletedAt(v time.Time) *WhatsappChannelUpsertBulk {
  1037. return u.Update(func(s *WhatsappChannelUpsert) {
  1038. s.SetDeletedAt(v)
  1039. })
  1040. }
  1041. // UpdateDeletedAt sets the "deleted_at" field to the value that was provided on create.
  1042. func (u *WhatsappChannelUpsertBulk) UpdateDeletedAt() *WhatsappChannelUpsertBulk {
  1043. return u.Update(func(s *WhatsappChannelUpsert) {
  1044. s.UpdateDeletedAt()
  1045. })
  1046. }
  1047. // ClearDeletedAt clears the value of the "deleted_at" field.
  1048. func (u *WhatsappChannelUpsertBulk) ClearDeletedAt() *WhatsappChannelUpsertBulk {
  1049. return u.Update(func(s *WhatsappChannelUpsert) {
  1050. s.ClearDeletedAt()
  1051. })
  1052. }
  1053. // SetAk sets the "ak" field.
  1054. func (u *WhatsappChannelUpsertBulk) SetAk(v string) *WhatsappChannelUpsertBulk {
  1055. return u.Update(func(s *WhatsappChannelUpsert) {
  1056. s.SetAk(v)
  1057. })
  1058. }
  1059. // UpdateAk sets the "ak" field to the value that was provided on create.
  1060. func (u *WhatsappChannelUpsertBulk) UpdateAk() *WhatsappChannelUpsertBulk {
  1061. return u.Update(func(s *WhatsappChannelUpsert) {
  1062. s.UpdateAk()
  1063. })
  1064. }
  1065. // ClearAk clears the value of the "ak" field.
  1066. func (u *WhatsappChannelUpsertBulk) ClearAk() *WhatsappChannelUpsertBulk {
  1067. return u.Update(func(s *WhatsappChannelUpsert) {
  1068. s.ClearAk()
  1069. })
  1070. }
  1071. // SetSk sets the "sk" field.
  1072. func (u *WhatsappChannelUpsertBulk) SetSk(v string) *WhatsappChannelUpsertBulk {
  1073. return u.Update(func(s *WhatsappChannelUpsert) {
  1074. s.SetSk(v)
  1075. })
  1076. }
  1077. // UpdateSk sets the "sk" field to the value that was provided on create.
  1078. func (u *WhatsappChannelUpsertBulk) UpdateSk() *WhatsappChannelUpsertBulk {
  1079. return u.Update(func(s *WhatsappChannelUpsert) {
  1080. s.UpdateSk()
  1081. })
  1082. }
  1083. // SetWaID sets the "wa_id" field.
  1084. func (u *WhatsappChannelUpsertBulk) SetWaID(v string) *WhatsappChannelUpsertBulk {
  1085. return u.Update(func(s *WhatsappChannelUpsert) {
  1086. s.SetWaID(v)
  1087. })
  1088. }
  1089. // UpdateWaID sets the "wa_id" field to the value that was provided on create.
  1090. func (u *WhatsappChannelUpsertBulk) UpdateWaID() *WhatsappChannelUpsertBulk {
  1091. return u.Update(func(s *WhatsappChannelUpsert) {
  1092. s.UpdateWaID()
  1093. })
  1094. }
  1095. // ClearWaID clears the value of the "wa_id" field.
  1096. func (u *WhatsappChannelUpsertBulk) ClearWaID() *WhatsappChannelUpsertBulk {
  1097. return u.Update(func(s *WhatsappChannelUpsert) {
  1098. s.ClearWaID()
  1099. })
  1100. }
  1101. // SetWaName sets the "wa_name" field.
  1102. func (u *WhatsappChannelUpsertBulk) SetWaName(v string) *WhatsappChannelUpsertBulk {
  1103. return u.Update(func(s *WhatsappChannelUpsert) {
  1104. s.SetWaName(v)
  1105. })
  1106. }
  1107. // UpdateWaName sets the "wa_name" field to the value that was provided on create.
  1108. func (u *WhatsappChannelUpsertBulk) UpdateWaName() *WhatsappChannelUpsertBulk {
  1109. return u.Update(func(s *WhatsappChannelUpsert) {
  1110. s.UpdateWaName()
  1111. })
  1112. }
  1113. // ClearWaName clears the value of the "wa_name" field.
  1114. func (u *WhatsappChannelUpsertBulk) ClearWaName() *WhatsappChannelUpsertBulk {
  1115. return u.Update(func(s *WhatsappChannelUpsert) {
  1116. s.ClearWaName()
  1117. })
  1118. }
  1119. // SetWabaID sets the "waba_id" field.
  1120. func (u *WhatsappChannelUpsertBulk) SetWabaID(v uint64) *WhatsappChannelUpsertBulk {
  1121. return u.Update(func(s *WhatsappChannelUpsert) {
  1122. s.SetWabaID(v)
  1123. })
  1124. }
  1125. // AddWabaID adds v to the "waba_id" field.
  1126. func (u *WhatsappChannelUpsertBulk) AddWabaID(v uint64) *WhatsappChannelUpsertBulk {
  1127. return u.Update(func(s *WhatsappChannelUpsert) {
  1128. s.AddWabaID(v)
  1129. })
  1130. }
  1131. // UpdateWabaID sets the "waba_id" field to the value that was provided on create.
  1132. func (u *WhatsappChannelUpsertBulk) UpdateWabaID() *WhatsappChannelUpsertBulk {
  1133. return u.Update(func(s *WhatsappChannelUpsert) {
  1134. s.UpdateWabaID()
  1135. })
  1136. }
  1137. // SetBusinessID sets the "business_id" field.
  1138. func (u *WhatsappChannelUpsertBulk) SetBusinessID(v uint64) *WhatsappChannelUpsertBulk {
  1139. return u.Update(func(s *WhatsappChannelUpsert) {
  1140. s.SetBusinessID(v)
  1141. })
  1142. }
  1143. // AddBusinessID adds v to the "business_id" field.
  1144. func (u *WhatsappChannelUpsertBulk) AddBusinessID(v uint64) *WhatsappChannelUpsertBulk {
  1145. return u.Update(func(s *WhatsappChannelUpsert) {
  1146. s.AddBusinessID(v)
  1147. })
  1148. }
  1149. // UpdateBusinessID sets the "business_id" field to the value that was provided on create.
  1150. func (u *WhatsappChannelUpsertBulk) UpdateBusinessID() *WhatsappChannelUpsertBulk {
  1151. return u.Update(func(s *WhatsappChannelUpsert) {
  1152. s.UpdateBusinessID()
  1153. })
  1154. }
  1155. // SetOrganizationID sets the "organization_id" field.
  1156. func (u *WhatsappChannelUpsertBulk) SetOrganizationID(v uint64) *WhatsappChannelUpsertBulk {
  1157. return u.Update(func(s *WhatsappChannelUpsert) {
  1158. s.SetOrganizationID(v)
  1159. })
  1160. }
  1161. // AddOrganizationID adds v to the "organization_id" field.
  1162. func (u *WhatsappChannelUpsertBulk) AddOrganizationID(v uint64) *WhatsappChannelUpsertBulk {
  1163. return u.Update(func(s *WhatsappChannelUpsert) {
  1164. s.AddOrganizationID(v)
  1165. })
  1166. }
  1167. // UpdateOrganizationID sets the "organization_id" field to the value that was provided on create.
  1168. func (u *WhatsappChannelUpsertBulk) UpdateOrganizationID() *WhatsappChannelUpsertBulk {
  1169. return u.Update(func(s *WhatsappChannelUpsert) {
  1170. s.UpdateOrganizationID()
  1171. })
  1172. }
  1173. // ClearOrganizationID clears the value of the "organization_id" field.
  1174. func (u *WhatsappChannelUpsertBulk) ClearOrganizationID() *WhatsappChannelUpsertBulk {
  1175. return u.Update(func(s *WhatsappChannelUpsert) {
  1176. s.ClearOrganizationID()
  1177. })
  1178. }
  1179. // SetVerifyAccount sets the "verify_account" field.
  1180. func (u *WhatsappChannelUpsertBulk) SetVerifyAccount(v string) *WhatsappChannelUpsertBulk {
  1181. return u.Update(func(s *WhatsappChannelUpsert) {
  1182. s.SetVerifyAccount(v)
  1183. })
  1184. }
  1185. // UpdateVerifyAccount sets the "verify_account" field to the value that was provided on create.
  1186. func (u *WhatsappChannelUpsertBulk) UpdateVerifyAccount() *WhatsappChannelUpsertBulk {
  1187. return u.Update(func(s *WhatsappChannelUpsert) {
  1188. s.UpdateVerifyAccount()
  1189. })
  1190. }
  1191. // Exec executes the query.
  1192. func (u *WhatsappChannelUpsertBulk) Exec(ctx context.Context) error {
  1193. if u.create.err != nil {
  1194. return u.create.err
  1195. }
  1196. for i, b := range u.create.builders {
  1197. if len(b.conflict) != 0 {
  1198. return fmt.Errorf("ent: OnConflict was set for builder %d. Set it on the WhatsappChannelCreateBulk instead", i)
  1199. }
  1200. }
  1201. if len(u.create.conflict) == 0 {
  1202. return errors.New("ent: missing options for WhatsappChannelCreateBulk.OnConflict")
  1203. }
  1204. return u.create.Exec(ctx)
  1205. }
  1206. // ExecX is like Exec, but panics if an error occurs.
  1207. func (u *WhatsappChannelUpsertBulk) ExecX(ctx context.Context) {
  1208. if err := u.create.Exec(ctx); err != nil {
  1209. panic(err)
  1210. }
  1211. }