whatsappchannel_update.go 23 KB

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