whatsappchannel_update.go 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772
  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/predicate"
  9. "wechat-api/ent/whatsappchannel"
  10. "entgo.io/ent/dialect/sql"
  11. "entgo.io/ent/dialect/sql/sqlgraph"
  12. "entgo.io/ent/schema/field"
  13. )
  14. // WhatsappChannelUpdate is the builder for updating WhatsappChannel entities.
  15. type WhatsappChannelUpdate struct {
  16. config
  17. hooks []Hook
  18. mutation *WhatsappChannelMutation
  19. }
  20. // Where appends a list predicates to the WhatsappChannelUpdate builder.
  21. func (wcu *WhatsappChannelUpdate) Where(ps ...predicate.WhatsappChannel) *WhatsappChannelUpdate {
  22. wcu.mutation.Where(ps...)
  23. return wcu
  24. }
  25. // SetUpdatedAt sets the "updated_at" field.
  26. func (wcu *WhatsappChannelUpdate) SetUpdatedAt(t time.Time) *WhatsappChannelUpdate {
  27. wcu.mutation.SetUpdatedAt(t)
  28. return wcu
  29. }
  30. // SetStatus sets the "status" field.
  31. func (wcu *WhatsappChannelUpdate) SetStatus(u uint8) *WhatsappChannelUpdate {
  32. wcu.mutation.ResetStatus()
  33. wcu.mutation.SetStatus(u)
  34. return wcu
  35. }
  36. // SetNillableStatus sets the "status" field if the given value is not nil.
  37. func (wcu *WhatsappChannelUpdate) SetNillableStatus(u *uint8) *WhatsappChannelUpdate {
  38. if u != nil {
  39. wcu.SetStatus(*u)
  40. }
  41. return wcu
  42. }
  43. // AddStatus adds u to the "status" field.
  44. func (wcu *WhatsappChannelUpdate) AddStatus(u int8) *WhatsappChannelUpdate {
  45. wcu.mutation.AddStatus(u)
  46. return wcu
  47. }
  48. // ClearStatus clears the value of the "status" field.
  49. func (wcu *WhatsappChannelUpdate) ClearStatus() *WhatsappChannelUpdate {
  50. wcu.mutation.ClearStatus()
  51. return wcu
  52. }
  53. // SetDeletedAt sets the "deleted_at" field.
  54. func (wcu *WhatsappChannelUpdate) SetDeletedAt(t time.Time) *WhatsappChannelUpdate {
  55. wcu.mutation.SetDeletedAt(t)
  56. return wcu
  57. }
  58. // SetNillableDeletedAt sets the "deleted_at" field if the given value is not nil.
  59. func (wcu *WhatsappChannelUpdate) SetNillableDeletedAt(t *time.Time) *WhatsappChannelUpdate {
  60. if t != nil {
  61. wcu.SetDeletedAt(*t)
  62. }
  63. return wcu
  64. }
  65. // ClearDeletedAt clears the value of the "deleted_at" field.
  66. func (wcu *WhatsappChannelUpdate) ClearDeletedAt() *WhatsappChannelUpdate {
  67. wcu.mutation.ClearDeletedAt()
  68. return wcu
  69. }
  70. // SetAk sets the "ak" field.
  71. func (wcu *WhatsappChannelUpdate) SetAk(s string) *WhatsappChannelUpdate {
  72. wcu.mutation.SetAk(s)
  73. return wcu
  74. }
  75. // SetNillableAk sets the "ak" field if the given value is not nil.
  76. func (wcu *WhatsappChannelUpdate) SetNillableAk(s *string) *WhatsappChannelUpdate {
  77. if s != nil {
  78. wcu.SetAk(*s)
  79. }
  80. return wcu
  81. }
  82. // ClearAk clears the value of the "ak" field.
  83. func (wcu *WhatsappChannelUpdate) ClearAk() *WhatsappChannelUpdate {
  84. wcu.mutation.ClearAk()
  85. return wcu
  86. }
  87. // SetSk sets the "sk" field.
  88. func (wcu *WhatsappChannelUpdate) SetSk(s string) *WhatsappChannelUpdate {
  89. wcu.mutation.SetSk(s)
  90. return wcu
  91. }
  92. // SetNillableSk sets the "sk" field if the given value is not nil.
  93. func (wcu *WhatsappChannelUpdate) SetNillableSk(s *string) *WhatsappChannelUpdate {
  94. if s != nil {
  95. wcu.SetSk(*s)
  96. }
  97. return wcu
  98. }
  99. // SetWaID sets the "wa_id" field.
  100. func (wcu *WhatsappChannelUpdate) SetWaID(u uint64) *WhatsappChannelUpdate {
  101. wcu.mutation.ResetWaID()
  102. wcu.mutation.SetWaID(u)
  103. return wcu
  104. }
  105. // SetNillableWaID sets the "wa_id" field if the given value is not nil.
  106. func (wcu *WhatsappChannelUpdate) SetNillableWaID(u *uint64) *WhatsappChannelUpdate {
  107. if u != nil {
  108. wcu.SetWaID(*u)
  109. }
  110. return wcu
  111. }
  112. // AddWaID adds u to the "wa_id" field.
  113. func (wcu *WhatsappChannelUpdate) AddWaID(u int64) *WhatsappChannelUpdate {
  114. wcu.mutation.AddWaID(u)
  115. return wcu
  116. }
  117. // ClearWaID clears the value of the "wa_id" field.
  118. func (wcu *WhatsappChannelUpdate) ClearWaID() *WhatsappChannelUpdate {
  119. wcu.mutation.ClearWaID()
  120. return wcu
  121. }
  122. // SetWaName sets the "wa_name" field.
  123. func (wcu *WhatsappChannelUpdate) SetWaName(s string) *WhatsappChannelUpdate {
  124. wcu.mutation.SetWaName(s)
  125. return wcu
  126. }
  127. // SetNillableWaName sets the "wa_name" field if the given value is not nil.
  128. func (wcu *WhatsappChannelUpdate) SetNillableWaName(s *string) *WhatsappChannelUpdate {
  129. if s != nil {
  130. wcu.SetWaName(*s)
  131. }
  132. return wcu
  133. }
  134. // ClearWaName clears the value of the "wa_name" field.
  135. func (wcu *WhatsappChannelUpdate) ClearWaName() *WhatsappChannelUpdate {
  136. wcu.mutation.ClearWaName()
  137. return wcu
  138. }
  139. // SetWabaID sets the "waba_id" field.
  140. func (wcu *WhatsappChannelUpdate) SetWabaID(u uint64) *WhatsappChannelUpdate {
  141. wcu.mutation.ResetWabaID()
  142. wcu.mutation.SetWabaID(u)
  143. return wcu
  144. }
  145. // SetNillableWabaID sets the "waba_id" field if the given value is not nil.
  146. func (wcu *WhatsappChannelUpdate) SetNillableWabaID(u *uint64) *WhatsappChannelUpdate {
  147. if u != nil {
  148. wcu.SetWabaID(*u)
  149. }
  150. return wcu
  151. }
  152. // AddWabaID adds u to the "waba_id" field.
  153. func (wcu *WhatsappChannelUpdate) AddWabaID(u int64) *WhatsappChannelUpdate {
  154. wcu.mutation.AddWabaID(u)
  155. return wcu
  156. }
  157. // SetBusinessID sets the "business_id" field.
  158. func (wcu *WhatsappChannelUpdate) SetBusinessID(u uint64) *WhatsappChannelUpdate {
  159. wcu.mutation.ResetBusinessID()
  160. wcu.mutation.SetBusinessID(u)
  161. return wcu
  162. }
  163. // SetNillableBusinessID sets the "business_id" field if the given value is not nil.
  164. func (wcu *WhatsappChannelUpdate) SetNillableBusinessID(u *uint64) *WhatsappChannelUpdate {
  165. if u != nil {
  166. wcu.SetBusinessID(*u)
  167. }
  168. return wcu
  169. }
  170. // AddBusinessID adds u to the "business_id" field.
  171. func (wcu *WhatsappChannelUpdate) AddBusinessID(u int64) *WhatsappChannelUpdate {
  172. wcu.mutation.AddBusinessID(u)
  173. return wcu
  174. }
  175. // SetOrganizationID sets the "organization_id" field.
  176. func (wcu *WhatsappChannelUpdate) SetOrganizationID(u uint64) *WhatsappChannelUpdate {
  177. wcu.mutation.ResetOrganizationID()
  178. wcu.mutation.SetOrganizationID(u)
  179. return wcu
  180. }
  181. // SetNillableOrganizationID sets the "organization_id" field if the given value is not nil.
  182. func (wcu *WhatsappChannelUpdate) SetNillableOrganizationID(u *uint64) *WhatsappChannelUpdate {
  183. if u != nil {
  184. wcu.SetOrganizationID(*u)
  185. }
  186. return wcu
  187. }
  188. // AddOrganizationID adds u to the "organization_id" field.
  189. func (wcu *WhatsappChannelUpdate) AddOrganizationID(u int64) *WhatsappChannelUpdate {
  190. wcu.mutation.AddOrganizationID(u)
  191. return wcu
  192. }
  193. // ClearOrganizationID clears the value of the "organization_id" field.
  194. func (wcu *WhatsappChannelUpdate) ClearOrganizationID() *WhatsappChannelUpdate {
  195. wcu.mutation.ClearOrganizationID()
  196. return wcu
  197. }
  198. // SetVerifyAccount sets the "verify_account" field.
  199. func (wcu *WhatsappChannelUpdate) SetVerifyAccount(s string) *WhatsappChannelUpdate {
  200. wcu.mutation.SetVerifyAccount(s)
  201. return wcu
  202. }
  203. // SetNillableVerifyAccount sets the "verify_account" field if the given value is not nil.
  204. func (wcu *WhatsappChannelUpdate) SetNillableVerifyAccount(s *string) *WhatsappChannelUpdate {
  205. if s != nil {
  206. wcu.SetVerifyAccount(*s)
  207. }
  208. return wcu
  209. }
  210. // Mutation returns the WhatsappChannelMutation object of the builder.
  211. func (wcu *WhatsappChannelUpdate) Mutation() *WhatsappChannelMutation {
  212. return wcu.mutation
  213. }
  214. // Save executes the query and returns the number of nodes affected by the update operation.
  215. func (wcu *WhatsappChannelUpdate) Save(ctx context.Context) (int, error) {
  216. if err := wcu.defaults(); err != nil {
  217. return 0, err
  218. }
  219. return withHooks(ctx, wcu.sqlSave, wcu.mutation, wcu.hooks)
  220. }
  221. // SaveX is like Save, but panics if an error occurs.
  222. func (wcu *WhatsappChannelUpdate) SaveX(ctx context.Context) int {
  223. affected, err := wcu.Save(ctx)
  224. if err != nil {
  225. panic(err)
  226. }
  227. return affected
  228. }
  229. // Exec executes the query.
  230. func (wcu *WhatsappChannelUpdate) Exec(ctx context.Context) error {
  231. _, err := wcu.Save(ctx)
  232. return err
  233. }
  234. // ExecX is like Exec, but panics if an error occurs.
  235. func (wcu *WhatsappChannelUpdate) ExecX(ctx context.Context) {
  236. if err := wcu.Exec(ctx); err != nil {
  237. panic(err)
  238. }
  239. }
  240. // defaults sets the default values of the builder before save.
  241. func (wcu *WhatsappChannelUpdate) defaults() error {
  242. if _, ok := wcu.mutation.UpdatedAt(); !ok {
  243. if whatsappchannel.UpdateDefaultUpdatedAt == nil {
  244. return fmt.Errorf("ent: uninitialized whatsappchannel.UpdateDefaultUpdatedAt (forgotten import ent/runtime?)")
  245. }
  246. v := whatsappchannel.UpdateDefaultUpdatedAt()
  247. wcu.mutation.SetUpdatedAt(v)
  248. }
  249. return nil
  250. }
  251. func (wcu *WhatsappChannelUpdate) sqlSave(ctx context.Context) (n int, err error) {
  252. _spec := sqlgraph.NewUpdateSpec(whatsappchannel.Table, whatsappchannel.Columns, sqlgraph.NewFieldSpec(whatsappchannel.FieldID, field.TypeUint64))
  253. if ps := wcu.mutation.predicates; len(ps) > 0 {
  254. _spec.Predicate = func(selector *sql.Selector) {
  255. for i := range ps {
  256. ps[i](selector)
  257. }
  258. }
  259. }
  260. if value, ok := wcu.mutation.UpdatedAt(); ok {
  261. _spec.SetField(whatsappchannel.FieldUpdatedAt, field.TypeTime, value)
  262. }
  263. if value, ok := wcu.mutation.Status(); ok {
  264. _spec.SetField(whatsappchannel.FieldStatus, field.TypeUint8, value)
  265. }
  266. if value, ok := wcu.mutation.AddedStatus(); ok {
  267. _spec.AddField(whatsappchannel.FieldStatus, field.TypeUint8, value)
  268. }
  269. if wcu.mutation.StatusCleared() {
  270. _spec.ClearField(whatsappchannel.FieldStatus, field.TypeUint8)
  271. }
  272. if value, ok := wcu.mutation.DeletedAt(); ok {
  273. _spec.SetField(whatsappchannel.FieldDeletedAt, field.TypeTime, value)
  274. }
  275. if wcu.mutation.DeletedAtCleared() {
  276. _spec.ClearField(whatsappchannel.FieldDeletedAt, field.TypeTime)
  277. }
  278. if value, ok := wcu.mutation.Ak(); ok {
  279. _spec.SetField(whatsappchannel.FieldAk, field.TypeString, value)
  280. }
  281. if wcu.mutation.AkCleared() {
  282. _spec.ClearField(whatsappchannel.FieldAk, field.TypeString)
  283. }
  284. if value, ok := wcu.mutation.Sk(); ok {
  285. _spec.SetField(whatsappchannel.FieldSk, field.TypeString, value)
  286. }
  287. if value, ok := wcu.mutation.WaID(); ok {
  288. _spec.SetField(whatsappchannel.FieldWaID, field.TypeUint64, value)
  289. }
  290. if value, ok := wcu.mutation.AddedWaID(); ok {
  291. _spec.AddField(whatsappchannel.FieldWaID, field.TypeUint64, value)
  292. }
  293. if wcu.mutation.WaIDCleared() {
  294. _spec.ClearField(whatsappchannel.FieldWaID, field.TypeUint64)
  295. }
  296. if value, ok := wcu.mutation.WaName(); ok {
  297. _spec.SetField(whatsappchannel.FieldWaName, field.TypeString, value)
  298. }
  299. if wcu.mutation.WaNameCleared() {
  300. _spec.ClearField(whatsappchannel.FieldWaName, field.TypeString)
  301. }
  302. if value, ok := wcu.mutation.WabaID(); ok {
  303. _spec.SetField(whatsappchannel.FieldWabaID, field.TypeUint64, value)
  304. }
  305. if value, ok := wcu.mutation.AddedWabaID(); ok {
  306. _spec.AddField(whatsappchannel.FieldWabaID, field.TypeUint64, value)
  307. }
  308. if value, ok := wcu.mutation.BusinessID(); ok {
  309. _spec.SetField(whatsappchannel.FieldBusinessID, field.TypeUint64, value)
  310. }
  311. if value, ok := wcu.mutation.AddedBusinessID(); ok {
  312. _spec.AddField(whatsappchannel.FieldBusinessID, field.TypeUint64, value)
  313. }
  314. if value, ok := wcu.mutation.OrganizationID(); ok {
  315. _spec.SetField(whatsappchannel.FieldOrganizationID, field.TypeUint64, value)
  316. }
  317. if value, ok := wcu.mutation.AddedOrganizationID(); ok {
  318. _spec.AddField(whatsappchannel.FieldOrganizationID, field.TypeUint64, value)
  319. }
  320. if wcu.mutation.OrganizationIDCleared() {
  321. _spec.ClearField(whatsappchannel.FieldOrganizationID, field.TypeUint64)
  322. }
  323. if value, ok := wcu.mutation.VerifyAccount(); ok {
  324. _spec.SetField(whatsappchannel.FieldVerifyAccount, field.TypeString, value)
  325. }
  326. if n, err = sqlgraph.UpdateNodes(ctx, wcu.driver, _spec); err != nil {
  327. if _, ok := err.(*sqlgraph.NotFoundError); ok {
  328. err = &NotFoundError{whatsappchannel.Label}
  329. } else if sqlgraph.IsConstraintError(err) {
  330. err = &ConstraintError{msg: err.Error(), wrap: err}
  331. }
  332. return 0, err
  333. }
  334. wcu.mutation.done = true
  335. return n, nil
  336. }
  337. // WhatsappChannelUpdateOne is the builder for updating a single WhatsappChannel entity.
  338. type WhatsappChannelUpdateOne struct {
  339. config
  340. fields []string
  341. hooks []Hook
  342. mutation *WhatsappChannelMutation
  343. }
  344. // SetUpdatedAt sets the "updated_at" field.
  345. func (wcuo *WhatsappChannelUpdateOne) SetUpdatedAt(t time.Time) *WhatsappChannelUpdateOne {
  346. wcuo.mutation.SetUpdatedAt(t)
  347. return wcuo
  348. }
  349. // SetStatus sets the "status" field.
  350. func (wcuo *WhatsappChannelUpdateOne) SetStatus(u uint8) *WhatsappChannelUpdateOne {
  351. wcuo.mutation.ResetStatus()
  352. wcuo.mutation.SetStatus(u)
  353. return wcuo
  354. }
  355. // SetNillableStatus sets the "status" field if the given value is not nil.
  356. func (wcuo *WhatsappChannelUpdateOne) SetNillableStatus(u *uint8) *WhatsappChannelUpdateOne {
  357. if u != nil {
  358. wcuo.SetStatus(*u)
  359. }
  360. return wcuo
  361. }
  362. // AddStatus adds u to the "status" field.
  363. func (wcuo *WhatsappChannelUpdateOne) AddStatus(u int8) *WhatsappChannelUpdateOne {
  364. wcuo.mutation.AddStatus(u)
  365. return wcuo
  366. }
  367. // ClearStatus clears the value of the "status" field.
  368. func (wcuo *WhatsappChannelUpdateOne) ClearStatus() *WhatsappChannelUpdateOne {
  369. wcuo.mutation.ClearStatus()
  370. return wcuo
  371. }
  372. // SetDeletedAt sets the "deleted_at" field.
  373. func (wcuo *WhatsappChannelUpdateOne) SetDeletedAt(t time.Time) *WhatsappChannelUpdateOne {
  374. wcuo.mutation.SetDeletedAt(t)
  375. return wcuo
  376. }
  377. // SetNillableDeletedAt sets the "deleted_at" field if the given value is not nil.
  378. func (wcuo *WhatsappChannelUpdateOne) SetNillableDeletedAt(t *time.Time) *WhatsappChannelUpdateOne {
  379. if t != nil {
  380. wcuo.SetDeletedAt(*t)
  381. }
  382. return wcuo
  383. }
  384. // ClearDeletedAt clears the value of the "deleted_at" field.
  385. func (wcuo *WhatsappChannelUpdateOne) ClearDeletedAt() *WhatsappChannelUpdateOne {
  386. wcuo.mutation.ClearDeletedAt()
  387. return wcuo
  388. }
  389. // SetAk sets the "ak" field.
  390. func (wcuo *WhatsappChannelUpdateOne) SetAk(s string) *WhatsappChannelUpdateOne {
  391. wcuo.mutation.SetAk(s)
  392. return wcuo
  393. }
  394. // SetNillableAk sets the "ak" field if the given value is not nil.
  395. func (wcuo *WhatsappChannelUpdateOne) SetNillableAk(s *string) *WhatsappChannelUpdateOne {
  396. if s != nil {
  397. wcuo.SetAk(*s)
  398. }
  399. return wcuo
  400. }
  401. // ClearAk clears the value of the "ak" field.
  402. func (wcuo *WhatsappChannelUpdateOne) ClearAk() *WhatsappChannelUpdateOne {
  403. wcuo.mutation.ClearAk()
  404. return wcuo
  405. }
  406. // SetSk sets the "sk" field.
  407. func (wcuo *WhatsappChannelUpdateOne) SetSk(s string) *WhatsappChannelUpdateOne {
  408. wcuo.mutation.SetSk(s)
  409. return wcuo
  410. }
  411. // SetNillableSk sets the "sk" field if the given value is not nil.
  412. func (wcuo *WhatsappChannelUpdateOne) SetNillableSk(s *string) *WhatsappChannelUpdateOne {
  413. if s != nil {
  414. wcuo.SetSk(*s)
  415. }
  416. return wcuo
  417. }
  418. // SetWaID sets the "wa_id" field.
  419. func (wcuo *WhatsappChannelUpdateOne) SetWaID(u uint64) *WhatsappChannelUpdateOne {
  420. wcuo.mutation.ResetWaID()
  421. wcuo.mutation.SetWaID(u)
  422. return wcuo
  423. }
  424. // SetNillableWaID sets the "wa_id" field if the given value is not nil.
  425. func (wcuo *WhatsappChannelUpdateOne) SetNillableWaID(u *uint64) *WhatsappChannelUpdateOne {
  426. if u != nil {
  427. wcuo.SetWaID(*u)
  428. }
  429. return wcuo
  430. }
  431. // AddWaID adds u to the "wa_id" field.
  432. func (wcuo *WhatsappChannelUpdateOne) AddWaID(u int64) *WhatsappChannelUpdateOne {
  433. wcuo.mutation.AddWaID(u)
  434. return wcuo
  435. }
  436. // ClearWaID clears the value of the "wa_id" field.
  437. func (wcuo *WhatsappChannelUpdateOne) ClearWaID() *WhatsappChannelUpdateOne {
  438. wcuo.mutation.ClearWaID()
  439. return wcuo
  440. }
  441. // SetWaName sets the "wa_name" field.
  442. func (wcuo *WhatsappChannelUpdateOne) SetWaName(s string) *WhatsappChannelUpdateOne {
  443. wcuo.mutation.SetWaName(s)
  444. return wcuo
  445. }
  446. // SetNillableWaName sets the "wa_name" field if the given value is not nil.
  447. func (wcuo *WhatsappChannelUpdateOne) SetNillableWaName(s *string) *WhatsappChannelUpdateOne {
  448. if s != nil {
  449. wcuo.SetWaName(*s)
  450. }
  451. return wcuo
  452. }
  453. // ClearWaName clears the value of the "wa_name" field.
  454. func (wcuo *WhatsappChannelUpdateOne) ClearWaName() *WhatsappChannelUpdateOne {
  455. wcuo.mutation.ClearWaName()
  456. return wcuo
  457. }
  458. // SetWabaID sets the "waba_id" field.
  459. func (wcuo *WhatsappChannelUpdateOne) SetWabaID(u uint64) *WhatsappChannelUpdateOne {
  460. wcuo.mutation.ResetWabaID()
  461. wcuo.mutation.SetWabaID(u)
  462. return wcuo
  463. }
  464. // SetNillableWabaID sets the "waba_id" field if the given value is not nil.
  465. func (wcuo *WhatsappChannelUpdateOne) SetNillableWabaID(u *uint64) *WhatsappChannelUpdateOne {
  466. if u != nil {
  467. wcuo.SetWabaID(*u)
  468. }
  469. return wcuo
  470. }
  471. // AddWabaID adds u to the "waba_id" field.
  472. func (wcuo *WhatsappChannelUpdateOne) AddWabaID(u int64) *WhatsappChannelUpdateOne {
  473. wcuo.mutation.AddWabaID(u)
  474. return wcuo
  475. }
  476. // SetBusinessID sets the "business_id" field.
  477. func (wcuo *WhatsappChannelUpdateOne) SetBusinessID(u uint64) *WhatsappChannelUpdateOne {
  478. wcuo.mutation.ResetBusinessID()
  479. wcuo.mutation.SetBusinessID(u)
  480. return wcuo
  481. }
  482. // SetNillableBusinessID sets the "business_id" field if the given value is not nil.
  483. func (wcuo *WhatsappChannelUpdateOne) SetNillableBusinessID(u *uint64) *WhatsappChannelUpdateOne {
  484. if u != nil {
  485. wcuo.SetBusinessID(*u)
  486. }
  487. return wcuo
  488. }
  489. // AddBusinessID adds u to the "business_id" field.
  490. func (wcuo *WhatsappChannelUpdateOne) AddBusinessID(u int64) *WhatsappChannelUpdateOne {
  491. wcuo.mutation.AddBusinessID(u)
  492. return wcuo
  493. }
  494. // SetOrganizationID sets the "organization_id" field.
  495. func (wcuo *WhatsappChannelUpdateOne) SetOrganizationID(u uint64) *WhatsappChannelUpdateOne {
  496. wcuo.mutation.ResetOrganizationID()
  497. wcuo.mutation.SetOrganizationID(u)
  498. return wcuo
  499. }
  500. // SetNillableOrganizationID sets the "organization_id" field if the given value is not nil.
  501. func (wcuo *WhatsappChannelUpdateOne) SetNillableOrganizationID(u *uint64) *WhatsappChannelUpdateOne {
  502. if u != nil {
  503. wcuo.SetOrganizationID(*u)
  504. }
  505. return wcuo
  506. }
  507. // AddOrganizationID adds u to the "organization_id" field.
  508. func (wcuo *WhatsappChannelUpdateOne) AddOrganizationID(u int64) *WhatsappChannelUpdateOne {
  509. wcuo.mutation.AddOrganizationID(u)
  510. return wcuo
  511. }
  512. // ClearOrganizationID clears the value of the "organization_id" field.
  513. func (wcuo *WhatsappChannelUpdateOne) ClearOrganizationID() *WhatsappChannelUpdateOne {
  514. wcuo.mutation.ClearOrganizationID()
  515. return wcuo
  516. }
  517. // SetVerifyAccount sets the "verify_account" field.
  518. func (wcuo *WhatsappChannelUpdateOne) SetVerifyAccount(s string) *WhatsappChannelUpdateOne {
  519. wcuo.mutation.SetVerifyAccount(s)
  520. return wcuo
  521. }
  522. // SetNillableVerifyAccount sets the "verify_account" field if the given value is not nil.
  523. func (wcuo *WhatsappChannelUpdateOne) SetNillableVerifyAccount(s *string) *WhatsappChannelUpdateOne {
  524. if s != nil {
  525. wcuo.SetVerifyAccount(*s)
  526. }
  527. return wcuo
  528. }
  529. // Mutation returns the WhatsappChannelMutation object of the builder.
  530. func (wcuo *WhatsappChannelUpdateOne) Mutation() *WhatsappChannelMutation {
  531. return wcuo.mutation
  532. }
  533. // Where appends a list predicates to the WhatsappChannelUpdate builder.
  534. func (wcuo *WhatsappChannelUpdateOne) Where(ps ...predicate.WhatsappChannel) *WhatsappChannelUpdateOne {
  535. wcuo.mutation.Where(ps...)
  536. return wcuo
  537. }
  538. // Select allows selecting one or more fields (columns) of the returned entity.
  539. // The default is selecting all fields defined in the entity schema.
  540. func (wcuo *WhatsappChannelUpdateOne) Select(field string, fields ...string) *WhatsappChannelUpdateOne {
  541. wcuo.fields = append([]string{field}, fields...)
  542. return wcuo
  543. }
  544. // Save executes the query and returns the updated WhatsappChannel entity.
  545. func (wcuo *WhatsappChannelUpdateOne) Save(ctx context.Context) (*WhatsappChannel, error) {
  546. if err := wcuo.defaults(); err != nil {
  547. return nil, err
  548. }
  549. return withHooks(ctx, wcuo.sqlSave, wcuo.mutation, wcuo.hooks)
  550. }
  551. // SaveX is like Save, but panics if an error occurs.
  552. func (wcuo *WhatsappChannelUpdateOne) SaveX(ctx context.Context) *WhatsappChannel {
  553. node, err := wcuo.Save(ctx)
  554. if err != nil {
  555. panic(err)
  556. }
  557. return node
  558. }
  559. // Exec executes the query on the entity.
  560. func (wcuo *WhatsappChannelUpdateOne) Exec(ctx context.Context) error {
  561. _, err := wcuo.Save(ctx)
  562. return err
  563. }
  564. // ExecX is like Exec, but panics if an error occurs.
  565. func (wcuo *WhatsappChannelUpdateOne) ExecX(ctx context.Context) {
  566. if err := wcuo.Exec(ctx); err != nil {
  567. panic(err)
  568. }
  569. }
  570. // defaults sets the default values of the builder before save.
  571. func (wcuo *WhatsappChannelUpdateOne) defaults() error {
  572. if _, ok := wcuo.mutation.UpdatedAt(); !ok {
  573. if whatsappchannel.UpdateDefaultUpdatedAt == nil {
  574. return fmt.Errorf("ent: uninitialized whatsappchannel.UpdateDefaultUpdatedAt (forgotten import ent/runtime?)")
  575. }
  576. v := whatsappchannel.UpdateDefaultUpdatedAt()
  577. wcuo.mutation.SetUpdatedAt(v)
  578. }
  579. return nil
  580. }
  581. func (wcuo *WhatsappChannelUpdateOne) sqlSave(ctx context.Context) (_node *WhatsappChannel, err error) {
  582. _spec := sqlgraph.NewUpdateSpec(whatsappchannel.Table, whatsappchannel.Columns, sqlgraph.NewFieldSpec(whatsappchannel.FieldID, field.TypeUint64))
  583. id, ok := wcuo.mutation.ID()
  584. if !ok {
  585. return nil, &ValidationError{Name: "id", err: errors.New(`ent: missing "WhatsappChannel.id" for update`)}
  586. }
  587. _spec.Node.ID.Value = id
  588. if fields := wcuo.fields; len(fields) > 0 {
  589. _spec.Node.Columns = make([]string, 0, len(fields))
  590. _spec.Node.Columns = append(_spec.Node.Columns, whatsappchannel.FieldID)
  591. for _, f := range fields {
  592. if !whatsappchannel.ValidColumn(f) {
  593. return nil, &ValidationError{Name: f, err: fmt.Errorf("ent: invalid field %q for query", f)}
  594. }
  595. if f != whatsappchannel.FieldID {
  596. _spec.Node.Columns = append(_spec.Node.Columns, f)
  597. }
  598. }
  599. }
  600. if ps := wcuo.mutation.predicates; len(ps) > 0 {
  601. _spec.Predicate = func(selector *sql.Selector) {
  602. for i := range ps {
  603. ps[i](selector)
  604. }
  605. }
  606. }
  607. if value, ok := wcuo.mutation.UpdatedAt(); ok {
  608. _spec.SetField(whatsappchannel.FieldUpdatedAt, field.TypeTime, value)
  609. }
  610. if value, ok := wcuo.mutation.Status(); ok {
  611. _spec.SetField(whatsappchannel.FieldStatus, field.TypeUint8, value)
  612. }
  613. if value, ok := wcuo.mutation.AddedStatus(); ok {
  614. _spec.AddField(whatsappchannel.FieldStatus, field.TypeUint8, value)
  615. }
  616. if wcuo.mutation.StatusCleared() {
  617. _spec.ClearField(whatsappchannel.FieldStatus, field.TypeUint8)
  618. }
  619. if value, ok := wcuo.mutation.DeletedAt(); ok {
  620. _spec.SetField(whatsappchannel.FieldDeletedAt, field.TypeTime, value)
  621. }
  622. if wcuo.mutation.DeletedAtCleared() {
  623. _spec.ClearField(whatsappchannel.FieldDeletedAt, field.TypeTime)
  624. }
  625. if value, ok := wcuo.mutation.Ak(); ok {
  626. _spec.SetField(whatsappchannel.FieldAk, field.TypeString, value)
  627. }
  628. if wcuo.mutation.AkCleared() {
  629. _spec.ClearField(whatsappchannel.FieldAk, field.TypeString)
  630. }
  631. if value, ok := wcuo.mutation.Sk(); ok {
  632. _spec.SetField(whatsappchannel.FieldSk, field.TypeString, value)
  633. }
  634. if value, ok := wcuo.mutation.WaID(); ok {
  635. _spec.SetField(whatsappchannel.FieldWaID, field.TypeUint64, value)
  636. }
  637. if value, ok := wcuo.mutation.AddedWaID(); ok {
  638. _spec.AddField(whatsappchannel.FieldWaID, field.TypeUint64, value)
  639. }
  640. if wcuo.mutation.WaIDCleared() {
  641. _spec.ClearField(whatsappchannel.FieldWaID, field.TypeUint64)
  642. }
  643. if value, ok := wcuo.mutation.WaName(); ok {
  644. _spec.SetField(whatsappchannel.FieldWaName, field.TypeString, value)
  645. }
  646. if wcuo.mutation.WaNameCleared() {
  647. _spec.ClearField(whatsappchannel.FieldWaName, field.TypeString)
  648. }
  649. if value, ok := wcuo.mutation.WabaID(); ok {
  650. _spec.SetField(whatsappchannel.FieldWabaID, field.TypeUint64, value)
  651. }
  652. if value, ok := wcuo.mutation.AddedWabaID(); ok {
  653. _spec.AddField(whatsappchannel.FieldWabaID, field.TypeUint64, value)
  654. }
  655. if value, ok := wcuo.mutation.BusinessID(); ok {
  656. _spec.SetField(whatsappchannel.FieldBusinessID, field.TypeUint64, value)
  657. }
  658. if value, ok := wcuo.mutation.AddedBusinessID(); ok {
  659. _spec.AddField(whatsappchannel.FieldBusinessID, field.TypeUint64, value)
  660. }
  661. if value, ok := wcuo.mutation.OrganizationID(); ok {
  662. _spec.SetField(whatsappchannel.FieldOrganizationID, field.TypeUint64, value)
  663. }
  664. if value, ok := wcuo.mutation.AddedOrganizationID(); ok {
  665. _spec.AddField(whatsappchannel.FieldOrganizationID, field.TypeUint64, value)
  666. }
  667. if wcuo.mutation.OrganizationIDCleared() {
  668. _spec.ClearField(whatsappchannel.FieldOrganizationID, field.TypeUint64)
  669. }
  670. if value, ok := wcuo.mutation.VerifyAccount(); ok {
  671. _spec.SetField(whatsappchannel.FieldVerifyAccount, field.TypeString, value)
  672. }
  673. _node = &WhatsappChannel{config: wcuo.config}
  674. _spec.Assign = _node.assignValues
  675. _spec.ScanValues = _node.scanValues
  676. if err = sqlgraph.UpdateNode(ctx, wcuo.driver, _spec); err != nil {
  677. if _, ok := err.(*sqlgraph.NotFoundError); ok {
  678. err = &NotFoundError{whatsappchannel.Label}
  679. } else if sqlgraph.IsConstraintError(err) {
  680. err = &ConstraintError{msg: err.Error(), wrap: err}
  681. }
  682. return nil, err
  683. }
  684. wcuo.mutation.done = true
  685. return _node, nil
  686. }