whatsappchannel_create.go 42 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391
  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(u uint64) *WhatsappChannelCreate {
  94. wcc.mutation.SetWaID(u)
  95. return wcc
  96. }
  97. // SetNillableWaID sets the "wa_id" field if the given value is not nil.
  98. func (wcc *WhatsappChannelCreate) SetNillableWaID(u *uint64) *WhatsappChannelCreate {
  99. if u != nil {
  100. wcc.SetWaID(*u)
  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.TypeUint64, 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 uint64) *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. // AddWaID adds v to the "wa_id" field.
  480. func (u *WhatsappChannelUpsert) AddWaID(v uint64) *WhatsappChannelUpsert {
  481. u.Add(whatsappchannel.FieldWaID, v)
  482. return u
  483. }
  484. // ClearWaID clears the value of the "wa_id" field.
  485. func (u *WhatsappChannelUpsert) ClearWaID() *WhatsappChannelUpsert {
  486. u.SetNull(whatsappchannel.FieldWaID)
  487. return u
  488. }
  489. // SetWaName sets the "wa_name" field.
  490. func (u *WhatsappChannelUpsert) SetWaName(v string) *WhatsappChannelUpsert {
  491. u.Set(whatsappchannel.FieldWaName, v)
  492. return u
  493. }
  494. // UpdateWaName sets the "wa_name" field to the value that was provided on create.
  495. func (u *WhatsappChannelUpsert) UpdateWaName() *WhatsappChannelUpsert {
  496. u.SetExcluded(whatsappchannel.FieldWaName)
  497. return u
  498. }
  499. // ClearWaName clears the value of the "wa_name" field.
  500. func (u *WhatsappChannelUpsert) ClearWaName() *WhatsappChannelUpsert {
  501. u.SetNull(whatsappchannel.FieldWaName)
  502. return u
  503. }
  504. // SetWabaID sets the "waba_id" field.
  505. func (u *WhatsappChannelUpsert) SetWabaID(v uint64) *WhatsappChannelUpsert {
  506. u.Set(whatsappchannel.FieldWabaID, v)
  507. return u
  508. }
  509. // UpdateWabaID sets the "waba_id" field to the value that was provided on create.
  510. func (u *WhatsappChannelUpsert) UpdateWabaID() *WhatsappChannelUpsert {
  511. u.SetExcluded(whatsappchannel.FieldWabaID)
  512. return u
  513. }
  514. // AddWabaID adds v to the "waba_id" field.
  515. func (u *WhatsappChannelUpsert) AddWabaID(v uint64) *WhatsappChannelUpsert {
  516. u.Add(whatsappchannel.FieldWabaID, v)
  517. return u
  518. }
  519. // SetBusinessID sets the "business_id" field.
  520. func (u *WhatsappChannelUpsert) SetBusinessID(v uint64) *WhatsappChannelUpsert {
  521. u.Set(whatsappchannel.FieldBusinessID, v)
  522. return u
  523. }
  524. // UpdateBusinessID sets the "business_id" field to the value that was provided on create.
  525. func (u *WhatsappChannelUpsert) UpdateBusinessID() *WhatsappChannelUpsert {
  526. u.SetExcluded(whatsappchannel.FieldBusinessID)
  527. return u
  528. }
  529. // AddBusinessID adds v to the "business_id" field.
  530. func (u *WhatsappChannelUpsert) AddBusinessID(v uint64) *WhatsappChannelUpsert {
  531. u.Add(whatsappchannel.FieldBusinessID, v)
  532. return u
  533. }
  534. // SetOrganizationID sets the "organization_id" field.
  535. func (u *WhatsappChannelUpsert) SetOrganizationID(v uint64) *WhatsappChannelUpsert {
  536. u.Set(whatsappchannel.FieldOrganizationID, v)
  537. return u
  538. }
  539. // UpdateOrganizationID sets the "organization_id" field to the value that was provided on create.
  540. func (u *WhatsappChannelUpsert) UpdateOrganizationID() *WhatsappChannelUpsert {
  541. u.SetExcluded(whatsappchannel.FieldOrganizationID)
  542. return u
  543. }
  544. // AddOrganizationID adds v to the "organization_id" field.
  545. func (u *WhatsappChannelUpsert) AddOrganizationID(v uint64) *WhatsappChannelUpsert {
  546. u.Add(whatsappchannel.FieldOrganizationID, v)
  547. return u
  548. }
  549. // ClearOrganizationID clears the value of the "organization_id" field.
  550. func (u *WhatsappChannelUpsert) ClearOrganizationID() *WhatsappChannelUpsert {
  551. u.SetNull(whatsappchannel.FieldOrganizationID)
  552. return u
  553. }
  554. // SetVerifyAccount sets the "verify_account" field.
  555. func (u *WhatsappChannelUpsert) SetVerifyAccount(v string) *WhatsappChannelUpsert {
  556. u.Set(whatsappchannel.FieldVerifyAccount, v)
  557. return u
  558. }
  559. // UpdateVerifyAccount sets the "verify_account" field to the value that was provided on create.
  560. func (u *WhatsappChannelUpsert) UpdateVerifyAccount() *WhatsappChannelUpsert {
  561. u.SetExcluded(whatsappchannel.FieldVerifyAccount)
  562. return u
  563. }
  564. // UpdateNewValues updates the mutable fields using the new values that were set on create except the ID field.
  565. // Using this option is equivalent to using:
  566. //
  567. // client.WhatsappChannel.Create().
  568. // OnConflict(
  569. // sql.ResolveWithNewValues(),
  570. // sql.ResolveWith(func(u *sql.UpdateSet) {
  571. // u.SetIgnore(whatsappchannel.FieldID)
  572. // }),
  573. // ).
  574. // Exec(ctx)
  575. func (u *WhatsappChannelUpsertOne) UpdateNewValues() *WhatsappChannelUpsertOne {
  576. u.create.conflict = append(u.create.conflict, sql.ResolveWithNewValues())
  577. u.create.conflict = append(u.create.conflict, sql.ResolveWith(func(s *sql.UpdateSet) {
  578. if _, exists := u.create.mutation.ID(); exists {
  579. s.SetIgnore(whatsappchannel.FieldID)
  580. }
  581. if _, exists := u.create.mutation.CreatedAt(); exists {
  582. s.SetIgnore(whatsappchannel.FieldCreatedAt)
  583. }
  584. }))
  585. return u
  586. }
  587. // Ignore sets each column to itself in case of conflict.
  588. // Using this option is equivalent to using:
  589. //
  590. // client.WhatsappChannel.Create().
  591. // OnConflict(sql.ResolveWithIgnore()).
  592. // Exec(ctx)
  593. func (u *WhatsappChannelUpsertOne) Ignore() *WhatsappChannelUpsertOne {
  594. u.create.conflict = append(u.create.conflict, sql.ResolveWithIgnore())
  595. return u
  596. }
  597. // DoNothing configures the conflict_action to `DO NOTHING`.
  598. // Supported only by SQLite and PostgreSQL.
  599. func (u *WhatsappChannelUpsertOne) DoNothing() *WhatsappChannelUpsertOne {
  600. u.create.conflict = append(u.create.conflict, sql.DoNothing())
  601. return u
  602. }
  603. // Update allows overriding fields `UPDATE` values. See the WhatsappChannelCreate.OnConflict
  604. // documentation for more info.
  605. func (u *WhatsappChannelUpsertOne) Update(set func(*WhatsappChannelUpsert)) *WhatsappChannelUpsertOne {
  606. u.create.conflict = append(u.create.conflict, sql.ResolveWith(func(update *sql.UpdateSet) {
  607. set(&WhatsappChannelUpsert{UpdateSet: update})
  608. }))
  609. return u
  610. }
  611. // SetUpdatedAt sets the "updated_at" field.
  612. func (u *WhatsappChannelUpsertOne) SetUpdatedAt(v time.Time) *WhatsappChannelUpsertOne {
  613. return u.Update(func(s *WhatsappChannelUpsert) {
  614. s.SetUpdatedAt(v)
  615. })
  616. }
  617. // UpdateUpdatedAt sets the "updated_at" field to the value that was provided on create.
  618. func (u *WhatsappChannelUpsertOne) UpdateUpdatedAt() *WhatsappChannelUpsertOne {
  619. return u.Update(func(s *WhatsappChannelUpsert) {
  620. s.UpdateUpdatedAt()
  621. })
  622. }
  623. // SetStatus sets the "status" field.
  624. func (u *WhatsappChannelUpsertOne) SetStatus(v uint8) *WhatsappChannelUpsertOne {
  625. return u.Update(func(s *WhatsappChannelUpsert) {
  626. s.SetStatus(v)
  627. })
  628. }
  629. // AddStatus adds v to the "status" field.
  630. func (u *WhatsappChannelUpsertOne) AddStatus(v uint8) *WhatsappChannelUpsertOne {
  631. return u.Update(func(s *WhatsappChannelUpsert) {
  632. s.AddStatus(v)
  633. })
  634. }
  635. // UpdateStatus sets the "status" field to the value that was provided on create.
  636. func (u *WhatsappChannelUpsertOne) UpdateStatus() *WhatsappChannelUpsertOne {
  637. return u.Update(func(s *WhatsappChannelUpsert) {
  638. s.UpdateStatus()
  639. })
  640. }
  641. // ClearStatus clears the value of the "status" field.
  642. func (u *WhatsappChannelUpsertOne) ClearStatus() *WhatsappChannelUpsertOne {
  643. return u.Update(func(s *WhatsappChannelUpsert) {
  644. s.ClearStatus()
  645. })
  646. }
  647. // SetDeletedAt sets the "deleted_at" field.
  648. func (u *WhatsappChannelUpsertOne) SetDeletedAt(v time.Time) *WhatsappChannelUpsertOne {
  649. return u.Update(func(s *WhatsappChannelUpsert) {
  650. s.SetDeletedAt(v)
  651. })
  652. }
  653. // UpdateDeletedAt sets the "deleted_at" field to the value that was provided on create.
  654. func (u *WhatsappChannelUpsertOne) UpdateDeletedAt() *WhatsappChannelUpsertOne {
  655. return u.Update(func(s *WhatsappChannelUpsert) {
  656. s.UpdateDeletedAt()
  657. })
  658. }
  659. // ClearDeletedAt clears the value of the "deleted_at" field.
  660. func (u *WhatsappChannelUpsertOne) ClearDeletedAt() *WhatsappChannelUpsertOne {
  661. return u.Update(func(s *WhatsappChannelUpsert) {
  662. s.ClearDeletedAt()
  663. })
  664. }
  665. // SetAk sets the "ak" field.
  666. func (u *WhatsappChannelUpsertOne) SetAk(v string) *WhatsappChannelUpsertOne {
  667. return u.Update(func(s *WhatsappChannelUpsert) {
  668. s.SetAk(v)
  669. })
  670. }
  671. // UpdateAk sets the "ak" field to the value that was provided on create.
  672. func (u *WhatsappChannelUpsertOne) UpdateAk() *WhatsappChannelUpsertOne {
  673. return u.Update(func(s *WhatsappChannelUpsert) {
  674. s.UpdateAk()
  675. })
  676. }
  677. // ClearAk clears the value of the "ak" field.
  678. func (u *WhatsappChannelUpsertOne) ClearAk() *WhatsappChannelUpsertOne {
  679. return u.Update(func(s *WhatsappChannelUpsert) {
  680. s.ClearAk()
  681. })
  682. }
  683. // SetSk sets the "sk" field.
  684. func (u *WhatsappChannelUpsertOne) SetSk(v string) *WhatsappChannelUpsertOne {
  685. return u.Update(func(s *WhatsappChannelUpsert) {
  686. s.SetSk(v)
  687. })
  688. }
  689. // UpdateSk sets the "sk" field to the value that was provided on create.
  690. func (u *WhatsappChannelUpsertOne) UpdateSk() *WhatsappChannelUpsertOne {
  691. return u.Update(func(s *WhatsappChannelUpsert) {
  692. s.UpdateSk()
  693. })
  694. }
  695. // SetWaID sets the "wa_id" field.
  696. func (u *WhatsappChannelUpsertOne) SetWaID(v uint64) *WhatsappChannelUpsertOne {
  697. return u.Update(func(s *WhatsappChannelUpsert) {
  698. s.SetWaID(v)
  699. })
  700. }
  701. // AddWaID adds v to the "wa_id" field.
  702. func (u *WhatsappChannelUpsertOne) AddWaID(v uint64) *WhatsappChannelUpsertOne {
  703. return u.Update(func(s *WhatsappChannelUpsert) {
  704. s.AddWaID(v)
  705. })
  706. }
  707. // UpdateWaID sets the "wa_id" field to the value that was provided on create.
  708. func (u *WhatsappChannelUpsertOne) UpdateWaID() *WhatsappChannelUpsertOne {
  709. return u.Update(func(s *WhatsappChannelUpsert) {
  710. s.UpdateWaID()
  711. })
  712. }
  713. // ClearWaID clears the value of the "wa_id" field.
  714. func (u *WhatsappChannelUpsertOne) ClearWaID() *WhatsappChannelUpsertOne {
  715. return u.Update(func(s *WhatsappChannelUpsert) {
  716. s.ClearWaID()
  717. })
  718. }
  719. // SetWaName sets the "wa_name" field.
  720. func (u *WhatsappChannelUpsertOne) SetWaName(v string) *WhatsappChannelUpsertOne {
  721. return u.Update(func(s *WhatsappChannelUpsert) {
  722. s.SetWaName(v)
  723. })
  724. }
  725. // UpdateWaName sets the "wa_name" field to the value that was provided on create.
  726. func (u *WhatsappChannelUpsertOne) UpdateWaName() *WhatsappChannelUpsertOne {
  727. return u.Update(func(s *WhatsappChannelUpsert) {
  728. s.UpdateWaName()
  729. })
  730. }
  731. // ClearWaName clears the value of the "wa_name" field.
  732. func (u *WhatsappChannelUpsertOne) ClearWaName() *WhatsappChannelUpsertOne {
  733. return u.Update(func(s *WhatsappChannelUpsert) {
  734. s.ClearWaName()
  735. })
  736. }
  737. // SetWabaID sets the "waba_id" field.
  738. func (u *WhatsappChannelUpsertOne) SetWabaID(v uint64) *WhatsappChannelUpsertOne {
  739. return u.Update(func(s *WhatsappChannelUpsert) {
  740. s.SetWabaID(v)
  741. })
  742. }
  743. // AddWabaID adds v to the "waba_id" field.
  744. func (u *WhatsappChannelUpsertOne) AddWabaID(v uint64) *WhatsappChannelUpsertOne {
  745. return u.Update(func(s *WhatsappChannelUpsert) {
  746. s.AddWabaID(v)
  747. })
  748. }
  749. // UpdateWabaID sets the "waba_id" field to the value that was provided on create.
  750. func (u *WhatsappChannelUpsertOne) UpdateWabaID() *WhatsappChannelUpsertOne {
  751. return u.Update(func(s *WhatsappChannelUpsert) {
  752. s.UpdateWabaID()
  753. })
  754. }
  755. // SetBusinessID sets the "business_id" field.
  756. func (u *WhatsappChannelUpsertOne) SetBusinessID(v uint64) *WhatsappChannelUpsertOne {
  757. return u.Update(func(s *WhatsappChannelUpsert) {
  758. s.SetBusinessID(v)
  759. })
  760. }
  761. // AddBusinessID adds v to the "business_id" field.
  762. func (u *WhatsappChannelUpsertOne) AddBusinessID(v uint64) *WhatsappChannelUpsertOne {
  763. return u.Update(func(s *WhatsappChannelUpsert) {
  764. s.AddBusinessID(v)
  765. })
  766. }
  767. // UpdateBusinessID sets the "business_id" field to the value that was provided on create.
  768. func (u *WhatsappChannelUpsertOne) UpdateBusinessID() *WhatsappChannelUpsertOne {
  769. return u.Update(func(s *WhatsappChannelUpsert) {
  770. s.UpdateBusinessID()
  771. })
  772. }
  773. // SetOrganizationID sets the "organization_id" field.
  774. func (u *WhatsappChannelUpsertOne) SetOrganizationID(v uint64) *WhatsappChannelUpsertOne {
  775. return u.Update(func(s *WhatsappChannelUpsert) {
  776. s.SetOrganizationID(v)
  777. })
  778. }
  779. // AddOrganizationID adds v to the "organization_id" field.
  780. func (u *WhatsappChannelUpsertOne) AddOrganizationID(v uint64) *WhatsappChannelUpsertOne {
  781. return u.Update(func(s *WhatsappChannelUpsert) {
  782. s.AddOrganizationID(v)
  783. })
  784. }
  785. // UpdateOrganizationID sets the "organization_id" field to the value that was provided on create.
  786. func (u *WhatsappChannelUpsertOne) UpdateOrganizationID() *WhatsappChannelUpsertOne {
  787. return u.Update(func(s *WhatsappChannelUpsert) {
  788. s.UpdateOrganizationID()
  789. })
  790. }
  791. // ClearOrganizationID clears the value of the "organization_id" field.
  792. func (u *WhatsappChannelUpsertOne) ClearOrganizationID() *WhatsappChannelUpsertOne {
  793. return u.Update(func(s *WhatsappChannelUpsert) {
  794. s.ClearOrganizationID()
  795. })
  796. }
  797. // SetVerifyAccount sets the "verify_account" field.
  798. func (u *WhatsappChannelUpsertOne) SetVerifyAccount(v string) *WhatsappChannelUpsertOne {
  799. return u.Update(func(s *WhatsappChannelUpsert) {
  800. s.SetVerifyAccount(v)
  801. })
  802. }
  803. // UpdateVerifyAccount sets the "verify_account" field to the value that was provided on create.
  804. func (u *WhatsappChannelUpsertOne) UpdateVerifyAccount() *WhatsappChannelUpsertOne {
  805. return u.Update(func(s *WhatsappChannelUpsert) {
  806. s.UpdateVerifyAccount()
  807. })
  808. }
  809. // Exec executes the query.
  810. func (u *WhatsappChannelUpsertOne) Exec(ctx context.Context) error {
  811. if len(u.create.conflict) == 0 {
  812. return errors.New("ent: missing options for WhatsappChannelCreate.OnConflict")
  813. }
  814. return u.create.Exec(ctx)
  815. }
  816. // ExecX is like Exec, but panics if an error occurs.
  817. func (u *WhatsappChannelUpsertOne) ExecX(ctx context.Context) {
  818. if err := u.create.Exec(ctx); err != nil {
  819. panic(err)
  820. }
  821. }
  822. // Exec executes the UPSERT query and returns the inserted/updated ID.
  823. func (u *WhatsappChannelUpsertOne) ID(ctx context.Context) (id uint64, err error) {
  824. node, err := u.create.Save(ctx)
  825. if err != nil {
  826. return id, err
  827. }
  828. return node.ID, nil
  829. }
  830. // IDX is like ID, but panics if an error occurs.
  831. func (u *WhatsappChannelUpsertOne) IDX(ctx context.Context) uint64 {
  832. id, err := u.ID(ctx)
  833. if err != nil {
  834. panic(err)
  835. }
  836. return id
  837. }
  838. // WhatsappChannelCreateBulk is the builder for creating many WhatsappChannel entities in bulk.
  839. type WhatsappChannelCreateBulk struct {
  840. config
  841. err error
  842. builders []*WhatsappChannelCreate
  843. conflict []sql.ConflictOption
  844. }
  845. // Save creates the WhatsappChannel entities in the database.
  846. func (wccb *WhatsappChannelCreateBulk) Save(ctx context.Context) ([]*WhatsappChannel, error) {
  847. if wccb.err != nil {
  848. return nil, wccb.err
  849. }
  850. specs := make([]*sqlgraph.CreateSpec, len(wccb.builders))
  851. nodes := make([]*WhatsappChannel, len(wccb.builders))
  852. mutators := make([]Mutator, len(wccb.builders))
  853. for i := range wccb.builders {
  854. func(i int, root context.Context) {
  855. builder := wccb.builders[i]
  856. builder.defaults()
  857. var mut Mutator = MutateFunc(func(ctx context.Context, m Mutation) (Value, error) {
  858. mutation, ok := m.(*WhatsappChannelMutation)
  859. if !ok {
  860. return nil, fmt.Errorf("unexpected mutation type %T", m)
  861. }
  862. if err := builder.check(); err != nil {
  863. return nil, err
  864. }
  865. builder.mutation = mutation
  866. var err error
  867. nodes[i], specs[i] = builder.createSpec()
  868. if i < len(mutators)-1 {
  869. _, err = mutators[i+1].Mutate(root, wccb.builders[i+1].mutation)
  870. } else {
  871. spec := &sqlgraph.BatchCreateSpec{Nodes: specs}
  872. spec.OnConflict = wccb.conflict
  873. // Invoke the actual operation on the latest mutation in the chain.
  874. if err = sqlgraph.BatchCreate(ctx, wccb.driver, spec); err != nil {
  875. if sqlgraph.IsConstraintError(err) {
  876. err = &ConstraintError{msg: err.Error(), wrap: err}
  877. }
  878. }
  879. }
  880. if err != nil {
  881. return nil, err
  882. }
  883. mutation.id = &nodes[i].ID
  884. if specs[i].ID.Value != nil && nodes[i].ID == 0 {
  885. id := specs[i].ID.Value.(int64)
  886. nodes[i].ID = uint64(id)
  887. }
  888. mutation.done = true
  889. return nodes[i], nil
  890. })
  891. for i := len(builder.hooks) - 1; i >= 0; i-- {
  892. mut = builder.hooks[i](mut)
  893. }
  894. mutators[i] = mut
  895. }(i, ctx)
  896. }
  897. if len(mutators) > 0 {
  898. if _, err := mutators[0].Mutate(ctx, wccb.builders[0].mutation); err != nil {
  899. return nil, err
  900. }
  901. }
  902. return nodes, nil
  903. }
  904. // SaveX is like Save, but panics if an error occurs.
  905. func (wccb *WhatsappChannelCreateBulk) SaveX(ctx context.Context) []*WhatsappChannel {
  906. v, err := wccb.Save(ctx)
  907. if err != nil {
  908. panic(err)
  909. }
  910. return v
  911. }
  912. // Exec executes the query.
  913. func (wccb *WhatsappChannelCreateBulk) Exec(ctx context.Context) error {
  914. _, err := wccb.Save(ctx)
  915. return err
  916. }
  917. // ExecX is like Exec, but panics if an error occurs.
  918. func (wccb *WhatsappChannelCreateBulk) ExecX(ctx context.Context) {
  919. if err := wccb.Exec(ctx); err != nil {
  920. panic(err)
  921. }
  922. }
  923. // OnConflict allows configuring the `ON CONFLICT` / `ON DUPLICATE KEY` clause
  924. // of the `INSERT` statement. For example:
  925. //
  926. // client.WhatsappChannel.CreateBulk(builders...).
  927. // OnConflict(
  928. // // Update the row with the new values
  929. // // the was proposed for insertion.
  930. // sql.ResolveWithNewValues(),
  931. // ).
  932. // // Override some of the fields with custom
  933. // // update values.
  934. // Update(func(u *ent.WhatsappChannelUpsert) {
  935. // SetCreatedAt(v+v).
  936. // }).
  937. // Exec(ctx)
  938. func (wccb *WhatsappChannelCreateBulk) OnConflict(opts ...sql.ConflictOption) *WhatsappChannelUpsertBulk {
  939. wccb.conflict = opts
  940. return &WhatsappChannelUpsertBulk{
  941. create: wccb,
  942. }
  943. }
  944. // OnConflictColumns calls `OnConflict` and configures the columns
  945. // as conflict target. Using this option is equivalent to using:
  946. //
  947. // client.WhatsappChannel.Create().
  948. // OnConflict(sql.ConflictColumns(columns...)).
  949. // Exec(ctx)
  950. func (wccb *WhatsappChannelCreateBulk) OnConflictColumns(columns ...string) *WhatsappChannelUpsertBulk {
  951. wccb.conflict = append(wccb.conflict, sql.ConflictColumns(columns...))
  952. return &WhatsappChannelUpsertBulk{
  953. create: wccb,
  954. }
  955. }
  956. // WhatsappChannelUpsertBulk is the builder for "upsert"-ing
  957. // a bulk of WhatsappChannel nodes.
  958. type WhatsappChannelUpsertBulk struct {
  959. create *WhatsappChannelCreateBulk
  960. }
  961. // UpdateNewValues updates the mutable fields using the new values that
  962. // were set on create. Using this option is equivalent to using:
  963. //
  964. // client.WhatsappChannel.Create().
  965. // OnConflict(
  966. // sql.ResolveWithNewValues(),
  967. // sql.ResolveWith(func(u *sql.UpdateSet) {
  968. // u.SetIgnore(whatsappchannel.FieldID)
  969. // }),
  970. // ).
  971. // Exec(ctx)
  972. func (u *WhatsappChannelUpsertBulk) UpdateNewValues() *WhatsappChannelUpsertBulk {
  973. u.create.conflict = append(u.create.conflict, sql.ResolveWithNewValues())
  974. u.create.conflict = append(u.create.conflict, sql.ResolveWith(func(s *sql.UpdateSet) {
  975. for _, b := range u.create.builders {
  976. if _, exists := b.mutation.ID(); exists {
  977. s.SetIgnore(whatsappchannel.FieldID)
  978. }
  979. if _, exists := b.mutation.CreatedAt(); exists {
  980. s.SetIgnore(whatsappchannel.FieldCreatedAt)
  981. }
  982. }
  983. }))
  984. return u
  985. }
  986. // Ignore sets each column to itself in case of conflict.
  987. // Using this option is equivalent to using:
  988. //
  989. // client.WhatsappChannel.Create().
  990. // OnConflict(sql.ResolveWithIgnore()).
  991. // Exec(ctx)
  992. func (u *WhatsappChannelUpsertBulk) Ignore() *WhatsappChannelUpsertBulk {
  993. u.create.conflict = append(u.create.conflict, sql.ResolveWithIgnore())
  994. return u
  995. }
  996. // DoNothing configures the conflict_action to `DO NOTHING`.
  997. // Supported only by SQLite and PostgreSQL.
  998. func (u *WhatsappChannelUpsertBulk) DoNothing() *WhatsappChannelUpsertBulk {
  999. u.create.conflict = append(u.create.conflict, sql.DoNothing())
  1000. return u
  1001. }
  1002. // Update allows overriding fields `UPDATE` values. See the WhatsappChannelCreateBulk.OnConflict
  1003. // documentation for more info.
  1004. func (u *WhatsappChannelUpsertBulk) Update(set func(*WhatsappChannelUpsert)) *WhatsappChannelUpsertBulk {
  1005. u.create.conflict = append(u.create.conflict, sql.ResolveWith(func(update *sql.UpdateSet) {
  1006. set(&WhatsappChannelUpsert{UpdateSet: update})
  1007. }))
  1008. return u
  1009. }
  1010. // SetUpdatedAt sets the "updated_at" field.
  1011. func (u *WhatsappChannelUpsertBulk) SetUpdatedAt(v time.Time) *WhatsappChannelUpsertBulk {
  1012. return u.Update(func(s *WhatsappChannelUpsert) {
  1013. s.SetUpdatedAt(v)
  1014. })
  1015. }
  1016. // UpdateUpdatedAt sets the "updated_at" field to the value that was provided on create.
  1017. func (u *WhatsappChannelUpsertBulk) UpdateUpdatedAt() *WhatsappChannelUpsertBulk {
  1018. return u.Update(func(s *WhatsappChannelUpsert) {
  1019. s.UpdateUpdatedAt()
  1020. })
  1021. }
  1022. // SetStatus sets the "status" field.
  1023. func (u *WhatsappChannelUpsertBulk) SetStatus(v uint8) *WhatsappChannelUpsertBulk {
  1024. return u.Update(func(s *WhatsappChannelUpsert) {
  1025. s.SetStatus(v)
  1026. })
  1027. }
  1028. // AddStatus adds v to the "status" field.
  1029. func (u *WhatsappChannelUpsertBulk) AddStatus(v uint8) *WhatsappChannelUpsertBulk {
  1030. return u.Update(func(s *WhatsappChannelUpsert) {
  1031. s.AddStatus(v)
  1032. })
  1033. }
  1034. // UpdateStatus sets the "status" field to the value that was provided on create.
  1035. func (u *WhatsappChannelUpsertBulk) UpdateStatus() *WhatsappChannelUpsertBulk {
  1036. return u.Update(func(s *WhatsappChannelUpsert) {
  1037. s.UpdateStatus()
  1038. })
  1039. }
  1040. // ClearStatus clears the value of the "status" field.
  1041. func (u *WhatsappChannelUpsertBulk) ClearStatus() *WhatsappChannelUpsertBulk {
  1042. return u.Update(func(s *WhatsappChannelUpsert) {
  1043. s.ClearStatus()
  1044. })
  1045. }
  1046. // SetDeletedAt sets the "deleted_at" field.
  1047. func (u *WhatsappChannelUpsertBulk) SetDeletedAt(v time.Time) *WhatsappChannelUpsertBulk {
  1048. return u.Update(func(s *WhatsappChannelUpsert) {
  1049. s.SetDeletedAt(v)
  1050. })
  1051. }
  1052. // UpdateDeletedAt sets the "deleted_at" field to the value that was provided on create.
  1053. func (u *WhatsappChannelUpsertBulk) UpdateDeletedAt() *WhatsappChannelUpsertBulk {
  1054. return u.Update(func(s *WhatsappChannelUpsert) {
  1055. s.UpdateDeletedAt()
  1056. })
  1057. }
  1058. // ClearDeletedAt clears the value of the "deleted_at" field.
  1059. func (u *WhatsappChannelUpsertBulk) ClearDeletedAt() *WhatsappChannelUpsertBulk {
  1060. return u.Update(func(s *WhatsappChannelUpsert) {
  1061. s.ClearDeletedAt()
  1062. })
  1063. }
  1064. // SetAk sets the "ak" field.
  1065. func (u *WhatsappChannelUpsertBulk) SetAk(v string) *WhatsappChannelUpsertBulk {
  1066. return u.Update(func(s *WhatsappChannelUpsert) {
  1067. s.SetAk(v)
  1068. })
  1069. }
  1070. // UpdateAk sets the "ak" field to the value that was provided on create.
  1071. func (u *WhatsappChannelUpsertBulk) UpdateAk() *WhatsappChannelUpsertBulk {
  1072. return u.Update(func(s *WhatsappChannelUpsert) {
  1073. s.UpdateAk()
  1074. })
  1075. }
  1076. // ClearAk clears the value of the "ak" field.
  1077. func (u *WhatsappChannelUpsertBulk) ClearAk() *WhatsappChannelUpsertBulk {
  1078. return u.Update(func(s *WhatsappChannelUpsert) {
  1079. s.ClearAk()
  1080. })
  1081. }
  1082. // SetSk sets the "sk" field.
  1083. func (u *WhatsappChannelUpsertBulk) SetSk(v string) *WhatsappChannelUpsertBulk {
  1084. return u.Update(func(s *WhatsappChannelUpsert) {
  1085. s.SetSk(v)
  1086. })
  1087. }
  1088. // UpdateSk sets the "sk" field to the value that was provided on create.
  1089. func (u *WhatsappChannelUpsertBulk) UpdateSk() *WhatsappChannelUpsertBulk {
  1090. return u.Update(func(s *WhatsappChannelUpsert) {
  1091. s.UpdateSk()
  1092. })
  1093. }
  1094. // SetWaID sets the "wa_id" field.
  1095. func (u *WhatsappChannelUpsertBulk) SetWaID(v uint64) *WhatsappChannelUpsertBulk {
  1096. return u.Update(func(s *WhatsappChannelUpsert) {
  1097. s.SetWaID(v)
  1098. })
  1099. }
  1100. // AddWaID adds v to the "wa_id" field.
  1101. func (u *WhatsappChannelUpsertBulk) AddWaID(v uint64) *WhatsappChannelUpsertBulk {
  1102. return u.Update(func(s *WhatsappChannelUpsert) {
  1103. s.AddWaID(v)
  1104. })
  1105. }
  1106. // UpdateWaID sets the "wa_id" field to the value that was provided on create.
  1107. func (u *WhatsappChannelUpsertBulk) UpdateWaID() *WhatsappChannelUpsertBulk {
  1108. return u.Update(func(s *WhatsappChannelUpsert) {
  1109. s.UpdateWaID()
  1110. })
  1111. }
  1112. // ClearWaID clears the value of the "wa_id" field.
  1113. func (u *WhatsappChannelUpsertBulk) ClearWaID() *WhatsappChannelUpsertBulk {
  1114. return u.Update(func(s *WhatsappChannelUpsert) {
  1115. s.ClearWaID()
  1116. })
  1117. }
  1118. // SetWaName sets the "wa_name" field.
  1119. func (u *WhatsappChannelUpsertBulk) SetWaName(v string) *WhatsappChannelUpsertBulk {
  1120. return u.Update(func(s *WhatsappChannelUpsert) {
  1121. s.SetWaName(v)
  1122. })
  1123. }
  1124. // UpdateWaName sets the "wa_name" field to the value that was provided on create.
  1125. func (u *WhatsappChannelUpsertBulk) UpdateWaName() *WhatsappChannelUpsertBulk {
  1126. return u.Update(func(s *WhatsappChannelUpsert) {
  1127. s.UpdateWaName()
  1128. })
  1129. }
  1130. // ClearWaName clears the value of the "wa_name" field.
  1131. func (u *WhatsappChannelUpsertBulk) ClearWaName() *WhatsappChannelUpsertBulk {
  1132. return u.Update(func(s *WhatsappChannelUpsert) {
  1133. s.ClearWaName()
  1134. })
  1135. }
  1136. // SetWabaID sets the "waba_id" field.
  1137. func (u *WhatsappChannelUpsertBulk) SetWabaID(v uint64) *WhatsappChannelUpsertBulk {
  1138. return u.Update(func(s *WhatsappChannelUpsert) {
  1139. s.SetWabaID(v)
  1140. })
  1141. }
  1142. // AddWabaID adds v to the "waba_id" field.
  1143. func (u *WhatsappChannelUpsertBulk) AddWabaID(v uint64) *WhatsappChannelUpsertBulk {
  1144. return u.Update(func(s *WhatsappChannelUpsert) {
  1145. s.AddWabaID(v)
  1146. })
  1147. }
  1148. // UpdateWabaID sets the "waba_id" field to the value that was provided on create.
  1149. func (u *WhatsappChannelUpsertBulk) UpdateWabaID() *WhatsappChannelUpsertBulk {
  1150. return u.Update(func(s *WhatsappChannelUpsert) {
  1151. s.UpdateWabaID()
  1152. })
  1153. }
  1154. // SetBusinessID sets the "business_id" field.
  1155. func (u *WhatsappChannelUpsertBulk) SetBusinessID(v uint64) *WhatsappChannelUpsertBulk {
  1156. return u.Update(func(s *WhatsappChannelUpsert) {
  1157. s.SetBusinessID(v)
  1158. })
  1159. }
  1160. // AddBusinessID adds v to the "business_id" field.
  1161. func (u *WhatsappChannelUpsertBulk) AddBusinessID(v uint64) *WhatsappChannelUpsertBulk {
  1162. return u.Update(func(s *WhatsappChannelUpsert) {
  1163. s.AddBusinessID(v)
  1164. })
  1165. }
  1166. // UpdateBusinessID sets the "business_id" field to the value that was provided on create.
  1167. func (u *WhatsappChannelUpsertBulk) UpdateBusinessID() *WhatsappChannelUpsertBulk {
  1168. return u.Update(func(s *WhatsappChannelUpsert) {
  1169. s.UpdateBusinessID()
  1170. })
  1171. }
  1172. // SetOrganizationID sets the "organization_id" field.
  1173. func (u *WhatsappChannelUpsertBulk) SetOrganizationID(v uint64) *WhatsappChannelUpsertBulk {
  1174. return u.Update(func(s *WhatsappChannelUpsert) {
  1175. s.SetOrganizationID(v)
  1176. })
  1177. }
  1178. // AddOrganizationID adds v to the "organization_id" field.
  1179. func (u *WhatsappChannelUpsertBulk) AddOrganizationID(v uint64) *WhatsappChannelUpsertBulk {
  1180. return u.Update(func(s *WhatsappChannelUpsert) {
  1181. s.AddOrganizationID(v)
  1182. })
  1183. }
  1184. // UpdateOrganizationID sets the "organization_id" field to the value that was provided on create.
  1185. func (u *WhatsappChannelUpsertBulk) UpdateOrganizationID() *WhatsappChannelUpsertBulk {
  1186. return u.Update(func(s *WhatsappChannelUpsert) {
  1187. s.UpdateOrganizationID()
  1188. })
  1189. }
  1190. // ClearOrganizationID clears the value of the "organization_id" field.
  1191. func (u *WhatsappChannelUpsertBulk) ClearOrganizationID() *WhatsappChannelUpsertBulk {
  1192. return u.Update(func(s *WhatsappChannelUpsert) {
  1193. s.ClearOrganizationID()
  1194. })
  1195. }
  1196. // SetVerifyAccount sets the "verify_account" field.
  1197. func (u *WhatsappChannelUpsertBulk) SetVerifyAccount(v string) *WhatsappChannelUpsertBulk {
  1198. return u.Update(func(s *WhatsappChannelUpsert) {
  1199. s.SetVerifyAccount(v)
  1200. })
  1201. }
  1202. // UpdateVerifyAccount sets the "verify_account" field to the value that was provided on create.
  1203. func (u *WhatsappChannelUpsertBulk) UpdateVerifyAccount() *WhatsappChannelUpsertBulk {
  1204. return u.Update(func(s *WhatsappChannelUpsert) {
  1205. s.UpdateVerifyAccount()
  1206. })
  1207. }
  1208. // Exec executes the query.
  1209. func (u *WhatsappChannelUpsertBulk) Exec(ctx context.Context) error {
  1210. if u.create.err != nil {
  1211. return u.create.err
  1212. }
  1213. for i, b := range u.create.builders {
  1214. if len(b.conflict) != 0 {
  1215. return fmt.Errorf("ent: OnConflict was set for builder %d. Set it on the WhatsappChannelCreateBulk instead", i)
  1216. }
  1217. }
  1218. if len(u.create.conflict) == 0 {
  1219. return errors.New("ent: missing options for WhatsappChannelCreateBulk.OnConflict")
  1220. }
  1221. return u.create.Exec(ctx)
  1222. }
  1223. // ExecX is like Exec, but panics if an error occurs.
  1224. func (u *WhatsappChannelUpsertBulk) ExecX(ctx context.Context) {
  1225. if err := u.create.Exec(ctx); err != nil {
  1226. panic(err)
  1227. }
  1228. }