wxcard_update.go 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952
  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/wxcard"
  10. "entgo.io/ent/dialect/sql"
  11. "entgo.io/ent/dialect/sql/sqlgraph"
  12. "entgo.io/ent/schema/field"
  13. )
  14. // WxCardUpdate is the builder for updating WxCard entities.
  15. type WxCardUpdate struct {
  16. config
  17. hooks []Hook
  18. mutation *WxCardMutation
  19. }
  20. // Where appends a list predicates to the WxCardUpdate builder.
  21. func (wcu *WxCardUpdate) Where(ps ...predicate.WxCard) *WxCardUpdate {
  22. wcu.mutation.Where(ps...)
  23. return wcu
  24. }
  25. // SetUpdatedAt sets the "updated_at" field.
  26. func (wcu *WxCardUpdate) SetUpdatedAt(t time.Time) *WxCardUpdate {
  27. wcu.mutation.SetUpdatedAt(t)
  28. return wcu
  29. }
  30. // SetDeletedAt sets the "deleted_at" field.
  31. func (wcu *WxCardUpdate) SetDeletedAt(t time.Time) *WxCardUpdate {
  32. wcu.mutation.SetDeletedAt(t)
  33. return wcu
  34. }
  35. // SetNillableDeletedAt sets the "deleted_at" field if the given value is not nil.
  36. func (wcu *WxCardUpdate) SetNillableDeletedAt(t *time.Time) *WxCardUpdate {
  37. if t != nil {
  38. wcu.SetDeletedAt(*t)
  39. }
  40. return wcu
  41. }
  42. // ClearDeletedAt clears the value of the "deleted_at" field.
  43. func (wcu *WxCardUpdate) ClearDeletedAt() *WxCardUpdate {
  44. wcu.mutation.ClearDeletedAt()
  45. return wcu
  46. }
  47. // SetUserID sets the "user_id" field.
  48. func (wcu *WxCardUpdate) SetUserID(u uint64) *WxCardUpdate {
  49. wcu.mutation.ResetUserID()
  50. wcu.mutation.SetUserID(u)
  51. return wcu
  52. }
  53. // SetNillableUserID sets the "user_id" field if the given value is not nil.
  54. func (wcu *WxCardUpdate) SetNillableUserID(u *uint64) *WxCardUpdate {
  55. if u != nil {
  56. wcu.SetUserID(*u)
  57. }
  58. return wcu
  59. }
  60. // AddUserID adds u to the "user_id" field.
  61. func (wcu *WxCardUpdate) AddUserID(u int64) *WxCardUpdate {
  62. wcu.mutation.AddUserID(u)
  63. return wcu
  64. }
  65. // ClearUserID clears the value of the "user_id" field.
  66. func (wcu *WxCardUpdate) ClearUserID() *WxCardUpdate {
  67. wcu.mutation.ClearUserID()
  68. return wcu
  69. }
  70. // SetWxUserID sets the "wx_user_id" field.
  71. func (wcu *WxCardUpdate) SetWxUserID(u uint64) *WxCardUpdate {
  72. wcu.mutation.ResetWxUserID()
  73. wcu.mutation.SetWxUserID(u)
  74. return wcu
  75. }
  76. // SetNillableWxUserID sets the "wx_user_id" field if the given value is not nil.
  77. func (wcu *WxCardUpdate) SetNillableWxUserID(u *uint64) *WxCardUpdate {
  78. if u != nil {
  79. wcu.SetWxUserID(*u)
  80. }
  81. return wcu
  82. }
  83. // AddWxUserID adds u to the "wx_user_id" field.
  84. func (wcu *WxCardUpdate) AddWxUserID(u int64) *WxCardUpdate {
  85. wcu.mutation.AddWxUserID(u)
  86. return wcu
  87. }
  88. // ClearWxUserID clears the value of the "wx_user_id" field.
  89. func (wcu *WxCardUpdate) ClearWxUserID() *WxCardUpdate {
  90. wcu.mutation.ClearWxUserID()
  91. return wcu
  92. }
  93. // SetAvatar sets the "avatar" field.
  94. func (wcu *WxCardUpdate) SetAvatar(s string) *WxCardUpdate {
  95. wcu.mutation.SetAvatar(s)
  96. return wcu
  97. }
  98. // SetNillableAvatar sets the "avatar" field if the given value is not nil.
  99. func (wcu *WxCardUpdate) SetNillableAvatar(s *string) *WxCardUpdate {
  100. if s != nil {
  101. wcu.SetAvatar(*s)
  102. }
  103. return wcu
  104. }
  105. // SetLogo sets the "logo" field.
  106. func (wcu *WxCardUpdate) SetLogo(s string) *WxCardUpdate {
  107. wcu.mutation.SetLogo(s)
  108. return wcu
  109. }
  110. // SetNillableLogo sets the "logo" field if the given value is not nil.
  111. func (wcu *WxCardUpdate) SetNillableLogo(s *string) *WxCardUpdate {
  112. if s != nil {
  113. wcu.SetLogo(*s)
  114. }
  115. return wcu
  116. }
  117. // SetName sets the "name" field.
  118. func (wcu *WxCardUpdate) SetName(s string) *WxCardUpdate {
  119. wcu.mutation.SetName(s)
  120. return wcu
  121. }
  122. // SetNillableName sets the "name" field if the given value is not nil.
  123. func (wcu *WxCardUpdate) SetNillableName(s *string) *WxCardUpdate {
  124. if s != nil {
  125. wcu.SetName(*s)
  126. }
  127. return wcu
  128. }
  129. // SetCompany sets the "company" field.
  130. func (wcu *WxCardUpdate) SetCompany(s string) *WxCardUpdate {
  131. wcu.mutation.SetCompany(s)
  132. return wcu
  133. }
  134. // SetNillableCompany sets the "company" field if the given value is not nil.
  135. func (wcu *WxCardUpdate) SetNillableCompany(s *string) *WxCardUpdate {
  136. if s != nil {
  137. wcu.SetCompany(*s)
  138. }
  139. return wcu
  140. }
  141. // SetAddress sets the "address" field.
  142. func (wcu *WxCardUpdate) SetAddress(s string) *WxCardUpdate {
  143. wcu.mutation.SetAddress(s)
  144. return wcu
  145. }
  146. // SetNillableAddress sets the "address" field if the given value is not nil.
  147. func (wcu *WxCardUpdate) SetNillableAddress(s *string) *WxCardUpdate {
  148. if s != nil {
  149. wcu.SetAddress(*s)
  150. }
  151. return wcu
  152. }
  153. // SetPhone sets the "phone" field.
  154. func (wcu *WxCardUpdate) SetPhone(s string) *WxCardUpdate {
  155. wcu.mutation.SetPhone(s)
  156. return wcu
  157. }
  158. // SetNillablePhone sets the "phone" field if the given value is not nil.
  159. func (wcu *WxCardUpdate) SetNillablePhone(s *string) *WxCardUpdate {
  160. if s != nil {
  161. wcu.SetPhone(*s)
  162. }
  163. return wcu
  164. }
  165. // SetOfficialAccount sets the "official_account" field.
  166. func (wcu *WxCardUpdate) SetOfficialAccount(s string) *WxCardUpdate {
  167. wcu.mutation.SetOfficialAccount(s)
  168. return wcu
  169. }
  170. // SetNillableOfficialAccount sets the "official_account" field if the given value is not nil.
  171. func (wcu *WxCardUpdate) SetNillableOfficialAccount(s *string) *WxCardUpdate {
  172. if s != nil {
  173. wcu.SetOfficialAccount(*s)
  174. }
  175. return wcu
  176. }
  177. // SetWechatAccount sets the "wechat_account" field.
  178. func (wcu *WxCardUpdate) SetWechatAccount(s string) *WxCardUpdate {
  179. wcu.mutation.SetWechatAccount(s)
  180. return wcu
  181. }
  182. // SetNillableWechatAccount sets the "wechat_account" field if the given value is not nil.
  183. func (wcu *WxCardUpdate) SetNillableWechatAccount(s *string) *WxCardUpdate {
  184. if s != nil {
  185. wcu.SetWechatAccount(*s)
  186. }
  187. return wcu
  188. }
  189. // SetEmail sets the "email" field.
  190. func (wcu *WxCardUpdate) SetEmail(s string) *WxCardUpdate {
  191. wcu.mutation.SetEmail(s)
  192. return wcu
  193. }
  194. // SetNillableEmail sets the "email" field if the given value is not nil.
  195. func (wcu *WxCardUpdate) SetNillableEmail(s *string) *WxCardUpdate {
  196. if s != nil {
  197. wcu.SetEmail(*s)
  198. }
  199. return wcu
  200. }
  201. // ClearEmail clears the value of the "email" field.
  202. func (wcu *WxCardUpdate) ClearEmail() *WxCardUpdate {
  203. wcu.mutation.ClearEmail()
  204. return wcu
  205. }
  206. // SetAPIBase sets the "api_base" field.
  207. func (wcu *WxCardUpdate) SetAPIBase(s string) *WxCardUpdate {
  208. wcu.mutation.SetAPIBase(s)
  209. return wcu
  210. }
  211. // SetNillableAPIBase sets the "api_base" field if the given value is not nil.
  212. func (wcu *WxCardUpdate) SetNillableAPIBase(s *string) *WxCardUpdate {
  213. if s != nil {
  214. wcu.SetAPIBase(*s)
  215. }
  216. return wcu
  217. }
  218. // ClearAPIBase clears the value of the "api_base" field.
  219. func (wcu *WxCardUpdate) ClearAPIBase() *WxCardUpdate {
  220. wcu.mutation.ClearAPIBase()
  221. return wcu
  222. }
  223. // SetAPIKey sets the "api_key" field.
  224. func (wcu *WxCardUpdate) SetAPIKey(s string) *WxCardUpdate {
  225. wcu.mutation.SetAPIKey(s)
  226. return wcu
  227. }
  228. // SetNillableAPIKey sets the "api_key" field if the given value is not nil.
  229. func (wcu *WxCardUpdate) SetNillableAPIKey(s *string) *WxCardUpdate {
  230. if s != nil {
  231. wcu.SetAPIKey(*s)
  232. }
  233. return wcu
  234. }
  235. // ClearAPIKey clears the value of the "api_key" field.
  236. func (wcu *WxCardUpdate) ClearAPIKey() *WxCardUpdate {
  237. wcu.mutation.ClearAPIKey()
  238. return wcu
  239. }
  240. // SetAiInfo sets the "ai_info" field.
  241. func (wcu *WxCardUpdate) SetAiInfo(s string) *WxCardUpdate {
  242. wcu.mutation.SetAiInfo(s)
  243. return wcu
  244. }
  245. // SetNillableAiInfo sets the "ai_info" field if the given value is not nil.
  246. func (wcu *WxCardUpdate) SetNillableAiInfo(s *string) *WxCardUpdate {
  247. if s != nil {
  248. wcu.SetAiInfo(*s)
  249. }
  250. return wcu
  251. }
  252. // ClearAiInfo clears the value of the "ai_info" field.
  253. func (wcu *WxCardUpdate) ClearAiInfo() *WxCardUpdate {
  254. wcu.mutation.ClearAiInfo()
  255. return wcu
  256. }
  257. // SetIntro sets the "intro" field.
  258. func (wcu *WxCardUpdate) SetIntro(s string) *WxCardUpdate {
  259. wcu.mutation.SetIntro(s)
  260. return wcu
  261. }
  262. // SetNillableIntro sets the "intro" field if the given value is not nil.
  263. func (wcu *WxCardUpdate) SetNillableIntro(s *string) *WxCardUpdate {
  264. if s != nil {
  265. wcu.SetIntro(*s)
  266. }
  267. return wcu
  268. }
  269. // ClearIntro clears the value of the "intro" field.
  270. func (wcu *WxCardUpdate) ClearIntro() *WxCardUpdate {
  271. wcu.mutation.ClearIntro()
  272. return wcu
  273. }
  274. // Mutation returns the WxCardMutation object of the builder.
  275. func (wcu *WxCardUpdate) Mutation() *WxCardMutation {
  276. return wcu.mutation
  277. }
  278. // Save executes the query and returns the number of nodes affected by the update operation.
  279. func (wcu *WxCardUpdate) Save(ctx context.Context) (int, error) {
  280. if err := wcu.defaults(); err != nil {
  281. return 0, err
  282. }
  283. return withHooks(ctx, wcu.sqlSave, wcu.mutation, wcu.hooks)
  284. }
  285. // SaveX is like Save, but panics if an error occurs.
  286. func (wcu *WxCardUpdate) SaveX(ctx context.Context) int {
  287. affected, err := wcu.Save(ctx)
  288. if err != nil {
  289. panic(err)
  290. }
  291. return affected
  292. }
  293. // Exec executes the query.
  294. func (wcu *WxCardUpdate) Exec(ctx context.Context) error {
  295. _, err := wcu.Save(ctx)
  296. return err
  297. }
  298. // ExecX is like Exec, but panics if an error occurs.
  299. func (wcu *WxCardUpdate) ExecX(ctx context.Context) {
  300. if err := wcu.Exec(ctx); err != nil {
  301. panic(err)
  302. }
  303. }
  304. // defaults sets the default values of the builder before save.
  305. func (wcu *WxCardUpdate) defaults() error {
  306. if _, ok := wcu.mutation.UpdatedAt(); !ok {
  307. if wxcard.UpdateDefaultUpdatedAt == nil {
  308. return fmt.Errorf("ent: uninitialized wxcard.UpdateDefaultUpdatedAt (forgotten import ent/runtime?)")
  309. }
  310. v := wxcard.UpdateDefaultUpdatedAt()
  311. wcu.mutation.SetUpdatedAt(v)
  312. }
  313. return nil
  314. }
  315. func (wcu *WxCardUpdate) sqlSave(ctx context.Context) (n int, err error) {
  316. _spec := sqlgraph.NewUpdateSpec(wxcard.Table, wxcard.Columns, sqlgraph.NewFieldSpec(wxcard.FieldID, field.TypeUint64))
  317. if ps := wcu.mutation.predicates; len(ps) > 0 {
  318. _spec.Predicate = func(selector *sql.Selector) {
  319. for i := range ps {
  320. ps[i](selector)
  321. }
  322. }
  323. }
  324. if value, ok := wcu.mutation.UpdatedAt(); ok {
  325. _spec.SetField(wxcard.FieldUpdatedAt, field.TypeTime, value)
  326. }
  327. if value, ok := wcu.mutation.DeletedAt(); ok {
  328. _spec.SetField(wxcard.FieldDeletedAt, field.TypeTime, value)
  329. }
  330. if wcu.mutation.DeletedAtCleared() {
  331. _spec.ClearField(wxcard.FieldDeletedAt, field.TypeTime)
  332. }
  333. if value, ok := wcu.mutation.UserID(); ok {
  334. _spec.SetField(wxcard.FieldUserID, field.TypeUint64, value)
  335. }
  336. if value, ok := wcu.mutation.AddedUserID(); ok {
  337. _spec.AddField(wxcard.FieldUserID, field.TypeUint64, value)
  338. }
  339. if wcu.mutation.UserIDCleared() {
  340. _spec.ClearField(wxcard.FieldUserID, field.TypeUint64)
  341. }
  342. if value, ok := wcu.mutation.WxUserID(); ok {
  343. _spec.SetField(wxcard.FieldWxUserID, field.TypeUint64, value)
  344. }
  345. if value, ok := wcu.mutation.AddedWxUserID(); ok {
  346. _spec.AddField(wxcard.FieldWxUserID, field.TypeUint64, value)
  347. }
  348. if wcu.mutation.WxUserIDCleared() {
  349. _spec.ClearField(wxcard.FieldWxUserID, field.TypeUint64)
  350. }
  351. if value, ok := wcu.mutation.Avatar(); ok {
  352. _spec.SetField(wxcard.FieldAvatar, field.TypeString, value)
  353. }
  354. if value, ok := wcu.mutation.Logo(); ok {
  355. _spec.SetField(wxcard.FieldLogo, field.TypeString, value)
  356. }
  357. if value, ok := wcu.mutation.Name(); ok {
  358. _spec.SetField(wxcard.FieldName, field.TypeString, value)
  359. }
  360. if value, ok := wcu.mutation.Company(); ok {
  361. _spec.SetField(wxcard.FieldCompany, field.TypeString, value)
  362. }
  363. if value, ok := wcu.mutation.Address(); ok {
  364. _spec.SetField(wxcard.FieldAddress, field.TypeString, value)
  365. }
  366. if value, ok := wcu.mutation.Phone(); ok {
  367. _spec.SetField(wxcard.FieldPhone, field.TypeString, value)
  368. }
  369. if value, ok := wcu.mutation.OfficialAccount(); ok {
  370. _spec.SetField(wxcard.FieldOfficialAccount, field.TypeString, value)
  371. }
  372. if value, ok := wcu.mutation.WechatAccount(); ok {
  373. _spec.SetField(wxcard.FieldWechatAccount, field.TypeString, value)
  374. }
  375. if value, ok := wcu.mutation.Email(); ok {
  376. _spec.SetField(wxcard.FieldEmail, field.TypeString, value)
  377. }
  378. if wcu.mutation.EmailCleared() {
  379. _spec.ClearField(wxcard.FieldEmail, field.TypeString)
  380. }
  381. if value, ok := wcu.mutation.APIBase(); ok {
  382. _spec.SetField(wxcard.FieldAPIBase, field.TypeString, value)
  383. }
  384. if wcu.mutation.APIBaseCleared() {
  385. _spec.ClearField(wxcard.FieldAPIBase, field.TypeString)
  386. }
  387. if value, ok := wcu.mutation.APIKey(); ok {
  388. _spec.SetField(wxcard.FieldAPIKey, field.TypeString, value)
  389. }
  390. if wcu.mutation.APIKeyCleared() {
  391. _spec.ClearField(wxcard.FieldAPIKey, field.TypeString)
  392. }
  393. if value, ok := wcu.mutation.AiInfo(); ok {
  394. _spec.SetField(wxcard.FieldAiInfo, field.TypeString, value)
  395. }
  396. if wcu.mutation.AiInfoCleared() {
  397. _spec.ClearField(wxcard.FieldAiInfo, field.TypeString)
  398. }
  399. if value, ok := wcu.mutation.Intro(); ok {
  400. _spec.SetField(wxcard.FieldIntro, field.TypeString, value)
  401. }
  402. if wcu.mutation.IntroCleared() {
  403. _spec.ClearField(wxcard.FieldIntro, field.TypeString)
  404. }
  405. if n, err = sqlgraph.UpdateNodes(ctx, wcu.driver, _spec); err != nil {
  406. if _, ok := err.(*sqlgraph.NotFoundError); ok {
  407. err = &NotFoundError{wxcard.Label}
  408. } else if sqlgraph.IsConstraintError(err) {
  409. err = &ConstraintError{msg: err.Error(), wrap: err}
  410. }
  411. return 0, err
  412. }
  413. wcu.mutation.done = true
  414. return n, nil
  415. }
  416. // WxCardUpdateOne is the builder for updating a single WxCard entity.
  417. type WxCardUpdateOne struct {
  418. config
  419. fields []string
  420. hooks []Hook
  421. mutation *WxCardMutation
  422. }
  423. // SetUpdatedAt sets the "updated_at" field.
  424. func (wcuo *WxCardUpdateOne) SetUpdatedAt(t time.Time) *WxCardUpdateOne {
  425. wcuo.mutation.SetUpdatedAt(t)
  426. return wcuo
  427. }
  428. // SetDeletedAt sets the "deleted_at" field.
  429. func (wcuo *WxCardUpdateOne) SetDeletedAt(t time.Time) *WxCardUpdateOne {
  430. wcuo.mutation.SetDeletedAt(t)
  431. return wcuo
  432. }
  433. // SetNillableDeletedAt sets the "deleted_at" field if the given value is not nil.
  434. func (wcuo *WxCardUpdateOne) SetNillableDeletedAt(t *time.Time) *WxCardUpdateOne {
  435. if t != nil {
  436. wcuo.SetDeletedAt(*t)
  437. }
  438. return wcuo
  439. }
  440. // ClearDeletedAt clears the value of the "deleted_at" field.
  441. func (wcuo *WxCardUpdateOne) ClearDeletedAt() *WxCardUpdateOne {
  442. wcuo.mutation.ClearDeletedAt()
  443. return wcuo
  444. }
  445. // SetUserID sets the "user_id" field.
  446. func (wcuo *WxCardUpdateOne) SetUserID(u uint64) *WxCardUpdateOne {
  447. wcuo.mutation.ResetUserID()
  448. wcuo.mutation.SetUserID(u)
  449. return wcuo
  450. }
  451. // SetNillableUserID sets the "user_id" field if the given value is not nil.
  452. func (wcuo *WxCardUpdateOne) SetNillableUserID(u *uint64) *WxCardUpdateOne {
  453. if u != nil {
  454. wcuo.SetUserID(*u)
  455. }
  456. return wcuo
  457. }
  458. // AddUserID adds u to the "user_id" field.
  459. func (wcuo *WxCardUpdateOne) AddUserID(u int64) *WxCardUpdateOne {
  460. wcuo.mutation.AddUserID(u)
  461. return wcuo
  462. }
  463. // ClearUserID clears the value of the "user_id" field.
  464. func (wcuo *WxCardUpdateOne) ClearUserID() *WxCardUpdateOne {
  465. wcuo.mutation.ClearUserID()
  466. return wcuo
  467. }
  468. // SetWxUserID sets the "wx_user_id" field.
  469. func (wcuo *WxCardUpdateOne) SetWxUserID(u uint64) *WxCardUpdateOne {
  470. wcuo.mutation.ResetWxUserID()
  471. wcuo.mutation.SetWxUserID(u)
  472. return wcuo
  473. }
  474. // SetNillableWxUserID sets the "wx_user_id" field if the given value is not nil.
  475. func (wcuo *WxCardUpdateOne) SetNillableWxUserID(u *uint64) *WxCardUpdateOne {
  476. if u != nil {
  477. wcuo.SetWxUserID(*u)
  478. }
  479. return wcuo
  480. }
  481. // AddWxUserID adds u to the "wx_user_id" field.
  482. func (wcuo *WxCardUpdateOne) AddWxUserID(u int64) *WxCardUpdateOne {
  483. wcuo.mutation.AddWxUserID(u)
  484. return wcuo
  485. }
  486. // ClearWxUserID clears the value of the "wx_user_id" field.
  487. func (wcuo *WxCardUpdateOne) ClearWxUserID() *WxCardUpdateOne {
  488. wcuo.mutation.ClearWxUserID()
  489. return wcuo
  490. }
  491. // SetAvatar sets the "avatar" field.
  492. func (wcuo *WxCardUpdateOne) SetAvatar(s string) *WxCardUpdateOne {
  493. wcuo.mutation.SetAvatar(s)
  494. return wcuo
  495. }
  496. // SetNillableAvatar sets the "avatar" field if the given value is not nil.
  497. func (wcuo *WxCardUpdateOne) SetNillableAvatar(s *string) *WxCardUpdateOne {
  498. if s != nil {
  499. wcuo.SetAvatar(*s)
  500. }
  501. return wcuo
  502. }
  503. // SetLogo sets the "logo" field.
  504. func (wcuo *WxCardUpdateOne) SetLogo(s string) *WxCardUpdateOne {
  505. wcuo.mutation.SetLogo(s)
  506. return wcuo
  507. }
  508. // SetNillableLogo sets the "logo" field if the given value is not nil.
  509. func (wcuo *WxCardUpdateOne) SetNillableLogo(s *string) *WxCardUpdateOne {
  510. if s != nil {
  511. wcuo.SetLogo(*s)
  512. }
  513. return wcuo
  514. }
  515. // SetName sets the "name" field.
  516. func (wcuo *WxCardUpdateOne) SetName(s string) *WxCardUpdateOne {
  517. wcuo.mutation.SetName(s)
  518. return wcuo
  519. }
  520. // SetNillableName sets the "name" field if the given value is not nil.
  521. func (wcuo *WxCardUpdateOne) SetNillableName(s *string) *WxCardUpdateOne {
  522. if s != nil {
  523. wcuo.SetName(*s)
  524. }
  525. return wcuo
  526. }
  527. // SetCompany sets the "company" field.
  528. func (wcuo *WxCardUpdateOne) SetCompany(s string) *WxCardUpdateOne {
  529. wcuo.mutation.SetCompany(s)
  530. return wcuo
  531. }
  532. // SetNillableCompany sets the "company" field if the given value is not nil.
  533. func (wcuo *WxCardUpdateOne) SetNillableCompany(s *string) *WxCardUpdateOne {
  534. if s != nil {
  535. wcuo.SetCompany(*s)
  536. }
  537. return wcuo
  538. }
  539. // SetAddress sets the "address" field.
  540. func (wcuo *WxCardUpdateOne) SetAddress(s string) *WxCardUpdateOne {
  541. wcuo.mutation.SetAddress(s)
  542. return wcuo
  543. }
  544. // SetNillableAddress sets the "address" field if the given value is not nil.
  545. func (wcuo *WxCardUpdateOne) SetNillableAddress(s *string) *WxCardUpdateOne {
  546. if s != nil {
  547. wcuo.SetAddress(*s)
  548. }
  549. return wcuo
  550. }
  551. // SetPhone sets the "phone" field.
  552. func (wcuo *WxCardUpdateOne) SetPhone(s string) *WxCardUpdateOne {
  553. wcuo.mutation.SetPhone(s)
  554. return wcuo
  555. }
  556. // SetNillablePhone sets the "phone" field if the given value is not nil.
  557. func (wcuo *WxCardUpdateOne) SetNillablePhone(s *string) *WxCardUpdateOne {
  558. if s != nil {
  559. wcuo.SetPhone(*s)
  560. }
  561. return wcuo
  562. }
  563. // SetOfficialAccount sets the "official_account" field.
  564. func (wcuo *WxCardUpdateOne) SetOfficialAccount(s string) *WxCardUpdateOne {
  565. wcuo.mutation.SetOfficialAccount(s)
  566. return wcuo
  567. }
  568. // SetNillableOfficialAccount sets the "official_account" field if the given value is not nil.
  569. func (wcuo *WxCardUpdateOne) SetNillableOfficialAccount(s *string) *WxCardUpdateOne {
  570. if s != nil {
  571. wcuo.SetOfficialAccount(*s)
  572. }
  573. return wcuo
  574. }
  575. // SetWechatAccount sets the "wechat_account" field.
  576. func (wcuo *WxCardUpdateOne) SetWechatAccount(s string) *WxCardUpdateOne {
  577. wcuo.mutation.SetWechatAccount(s)
  578. return wcuo
  579. }
  580. // SetNillableWechatAccount sets the "wechat_account" field if the given value is not nil.
  581. func (wcuo *WxCardUpdateOne) SetNillableWechatAccount(s *string) *WxCardUpdateOne {
  582. if s != nil {
  583. wcuo.SetWechatAccount(*s)
  584. }
  585. return wcuo
  586. }
  587. // SetEmail sets the "email" field.
  588. func (wcuo *WxCardUpdateOne) SetEmail(s string) *WxCardUpdateOne {
  589. wcuo.mutation.SetEmail(s)
  590. return wcuo
  591. }
  592. // SetNillableEmail sets the "email" field if the given value is not nil.
  593. func (wcuo *WxCardUpdateOne) SetNillableEmail(s *string) *WxCardUpdateOne {
  594. if s != nil {
  595. wcuo.SetEmail(*s)
  596. }
  597. return wcuo
  598. }
  599. // ClearEmail clears the value of the "email" field.
  600. func (wcuo *WxCardUpdateOne) ClearEmail() *WxCardUpdateOne {
  601. wcuo.mutation.ClearEmail()
  602. return wcuo
  603. }
  604. // SetAPIBase sets the "api_base" field.
  605. func (wcuo *WxCardUpdateOne) SetAPIBase(s string) *WxCardUpdateOne {
  606. wcuo.mutation.SetAPIBase(s)
  607. return wcuo
  608. }
  609. // SetNillableAPIBase sets the "api_base" field if the given value is not nil.
  610. func (wcuo *WxCardUpdateOne) SetNillableAPIBase(s *string) *WxCardUpdateOne {
  611. if s != nil {
  612. wcuo.SetAPIBase(*s)
  613. }
  614. return wcuo
  615. }
  616. // ClearAPIBase clears the value of the "api_base" field.
  617. func (wcuo *WxCardUpdateOne) ClearAPIBase() *WxCardUpdateOne {
  618. wcuo.mutation.ClearAPIBase()
  619. return wcuo
  620. }
  621. // SetAPIKey sets the "api_key" field.
  622. func (wcuo *WxCardUpdateOne) SetAPIKey(s string) *WxCardUpdateOne {
  623. wcuo.mutation.SetAPIKey(s)
  624. return wcuo
  625. }
  626. // SetNillableAPIKey sets the "api_key" field if the given value is not nil.
  627. func (wcuo *WxCardUpdateOne) SetNillableAPIKey(s *string) *WxCardUpdateOne {
  628. if s != nil {
  629. wcuo.SetAPIKey(*s)
  630. }
  631. return wcuo
  632. }
  633. // ClearAPIKey clears the value of the "api_key" field.
  634. func (wcuo *WxCardUpdateOne) ClearAPIKey() *WxCardUpdateOne {
  635. wcuo.mutation.ClearAPIKey()
  636. return wcuo
  637. }
  638. // SetAiInfo sets the "ai_info" field.
  639. func (wcuo *WxCardUpdateOne) SetAiInfo(s string) *WxCardUpdateOne {
  640. wcuo.mutation.SetAiInfo(s)
  641. return wcuo
  642. }
  643. // SetNillableAiInfo sets the "ai_info" field if the given value is not nil.
  644. func (wcuo *WxCardUpdateOne) SetNillableAiInfo(s *string) *WxCardUpdateOne {
  645. if s != nil {
  646. wcuo.SetAiInfo(*s)
  647. }
  648. return wcuo
  649. }
  650. // ClearAiInfo clears the value of the "ai_info" field.
  651. func (wcuo *WxCardUpdateOne) ClearAiInfo() *WxCardUpdateOne {
  652. wcuo.mutation.ClearAiInfo()
  653. return wcuo
  654. }
  655. // SetIntro sets the "intro" field.
  656. func (wcuo *WxCardUpdateOne) SetIntro(s string) *WxCardUpdateOne {
  657. wcuo.mutation.SetIntro(s)
  658. return wcuo
  659. }
  660. // SetNillableIntro sets the "intro" field if the given value is not nil.
  661. func (wcuo *WxCardUpdateOne) SetNillableIntro(s *string) *WxCardUpdateOne {
  662. if s != nil {
  663. wcuo.SetIntro(*s)
  664. }
  665. return wcuo
  666. }
  667. // ClearIntro clears the value of the "intro" field.
  668. func (wcuo *WxCardUpdateOne) ClearIntro() *WxCardUpdateOne {
  669. wcuo.mutation.ClearIntro()
  670. return wcuo
  671. }
  672. // Mutation returns the WxCardMutation object of the builder.
  673. func (wcuo *WxCardUpdateOne) Mutation() *WxCardMutation {
  674. return wcuo.mutation
  675. }
  676. // Where appends a list predicates to the WxCardUpdate builder.
  677. func (wcuo *WxCardUpdateOne) Where(ps ...predicate.WxCard) *WxCardUpdateOne {
  678. wcuo.mutation.Where(ps...)
  679. return wcuo
  680. }
  681. // Select allows selecting one or more fields (columns) of the returned entity.
  682. // The default is selecting all fields defined in the entity schema.
  683. func (wcuo *WxCardUpdateOne) Select(field string, fields ...string) *WxCardUpdateOne {
  684. wcuo.fields = append([]string{field}, fields...)
  685. return wcuo
  686. }
  687. // Save executes the query and returns the updated WxCard entity.
  688. func (wcuo *WxCardUpdateOne) Save(ctx context.Context) (*WxCard, error) {
  689. if err := wcuo.defaults(); err != nil {
  690. return nil, err
  691. }
  692. return withHooks(ctx, wcuo.sqlSave, wcuo.mutation, wcuo.hooks)
  693. }
  694. // SaveX is like Save, but panics if an error occurs.
  695. func (wcuo *WxCardUpdateOne) SaveX(ctx context.Context) *WxCard {
  696. node, err := wcuo.Save(ctx)
  697. if err != nil {
  698. panic(err)
  699. }
  700. return node
  701. }
  702. // Exec executes the query on the entity.
  703. func (wcuo *WxCardUpdateOne) Exec(ctx context.Context) error {
  704. _, err := wcuo.Save(ctx)
  705. return err
  706. }
  707. // ExecX is like Exec, but panics if an error occurs.
  708. func (wcuo *WxCardUpdateOne) ExecX(ctx context.Context) {
  709. if err := wcuo.Exec(ctx); err != nil {
  710. panic(err)
  711. }
  712. }
  713. // defaults sets the default values of the builder before save.
  714. func (wcuo *WxCardUpdateOne) defaults() error {
  715. if _, ok := wcuo.mutation.UpdatedAt(); !ok {
  716. if wxcard.UpdateDefaultUpdatedAt == nil {
  717. return fmt.Errorf("ent: uninitialized wxcard.UpdateDefaultUpdatedAt (forgotten import ent/runtime?)")
  718. }
  719. v := wxcard.UpdateDefaultUpdatedAt()
  720. wcuo.mutation.SetUpdatedAt(v)
  721. }
  722. return nil
  723. }
  724. func (wcuo *WxCardUpdateOne) sqlSave(ctx context.Context) (_node *WxCard, err error) {
  725. _spec := sqlgraph.NewUpdateSpec(wxcard.Table, wxcard.Columns, sqlgraph.NewFieldSpec(wxcard.FieldID, field.TypeUint64))
  726. id, ok := wcuo.mutation.ID()
  727. if !ok {
  728. return nil, &ValidationError{Name: "id", err: errors.New(`ent: missing "WxCard.id" for update`)}
  729. }
  730. _spec.Node.ID.Value = id
  731. if fields := wcuo.fields; len(fields) > 0 {
  732. _spec.Node.Columns = make([]string, 0, len(fields))
  733. _spec.Node.Columns = append(_spec.Node.Columns, wxcard.FieldID)
  734. for _, f := range fields {
  735. if !wxcard.ValidColumn(f) {
  736. return nil, &ValidationError{Name: f, err: fmt.Errorf("ent: invalid field %q for query", f)}
  737. }
  738. if f != wxcard.FieldID {
  739. _spec.Node.Columns = append(_spec.Node.Columns, f)
  740. }
  741. }
  742. }
  743. if ps := wcuo.mutation.predicates; len(ps) > 0 {
  744. _spec.Predicate = func(selector *sql.Selector) {
  745. for i := range ps {
  746. ps[i](selector)
  747. }
  748. }
  749. }
  750. if value, ok := wcuo.mutation.UpdatedAt(); ok {
  751. _spec.SetField(wxcard.FieldUpdatedAt, field.TypeTime, value)
  752. }
  753. if value, ok := wcuo.mutation.DeletedAt(); ok {
  754. _spec.SetField(wxcard.FieldDeletedAt, field.TypeTime, value)
  755. }
  756. if wcuo.mutation.DeletedAtCleared() {
  757. _spec.ClearField(wxcard.FieldDeletedAt, field.TypeTime)
  758. }
  759. if value, ok := wcuo.mutation.UserID(); ok {
  760. _spec.SetField(wxcard.FieldUserID, field.TypeUint64, value)
  761. }
  762. if value, ok := wcuo.mutation.AddedUserID(); ok {
  763. _spec.AddField(wxcard.FieldUserID, field.TypeUint64, value)
  764. }
  765. if wcuo.mutation.UserIDCleared() {
  766. _spec.ClearField(wxcard.FieldUserID, field.TypeUint64)
  767. }
  768. if value, ok := wcuo.mutation.WxUserID(); ok {
  769. _spec.SetField(wxcard.FieldWxUserID, field.TypeUint64, value)
  770. }
  771. if value, ok := wcuo.mutation.AddedWxUserID(); ok {
  772. _spec.AddField(wxcard.FieldWxUserID, field.TypeUint64, value)
  773. }
  774. if wcuo.mutation.WxUserIDCleared() {
  775. _spec.ClearField(wxcard.FieldWxUserID, field.TypeUint64)
  776. }
  777. if value, ok := wcuo.mutation.Avatar(); ok {
  778. _spec.SetField(wxcard.FieldAvatar, field.TypeString, value)
  779. }
  780. if value, ok := wcuo.mutation.Logo(); ok {
  781. _spec.SetField(wxcard.FieldLogo, field.TypeString, value)
  782. }
  783. if value, ok := wcuo.mutation.Name(); ok {
  784. _spec.SetField(wxcard.FieldName, field.TypeString, value)
  785. }
  786. if value, ok := wcuo.mutation.Company(); ok {
  787. _spec.SetField(wxcard.FieldCompany, field.TypeString, value)
  788. }
  789. if value, ok := wcuo.mutation.Address(); ok {
  790. _spec.SetField(wxcard.FieldAddress, field.TypeString, value)
  791. }
  792. if value, ok := wcuo.mutation.Phone(); ok {
  793. _spec.SetField(wxcard.FieldPhone, field.TypeString, value)
  794. }
  795. if value, ok := wcuo.mutation.OfficialAccount(); ok {
  796. _spec.SetField(wxcard.FieldOfficialAccount, field.TypeString, value)
  797. }
  798. if value, ok := wcuo.mutation.WechatAccount(); ok {
  799. _spec.SetField(wxcard.FieldWechatAccount, field.TypeString, value)
  800. }
  801. if value, ok := wcuo.mutation.Email(); ok {
  802. _spec.SetField(wxcard.FieldEmail, field.TypeString, value)
  803. }
  804. if wcuo.mutation.EmailCleared() {
  805. _spec.ClearField(wxcard.FieldEmail, field.TypeString)
  806. }
  807. if value, ok := wcuo.mutation.APIBase(); ok {
  808. _spec.SetField(wxcard.FieldAPIBase, field.TypeString, value)
  809. }
  810. if wcuo.mutation.APIBaseCleared() {
  811. _spec.ClearField(wxcard.FieldAPIBase, field.TypeString)
  812. }
  813. if value, ok := wcuo.mutation.APIKey(); ok {
  814. _spec.SetField(wxcard.FieldAPIKey, field.TypeString, value)
  815. }
  816. if wcuo.mutation.APIKeyCleared() {
  817. _spec.ClearField(wxcard.FieldAPIKey, field.TypeString)
  818. }
  819. if value, ok := wcuo.mutation.AiInfo(); ok {
  820. _spec.SetField(wxcard.FieldAiInfo, field.TypeString, value)
  821. }
  822. if wcuo.mutation.AiInfoCleared() {
  823. _spec.ClearField(wxcard.FieldAiInfo, field.TypeString)
  824. }
  825. if value, ok := wcuo.mutation.Intro(); ok {
  826. _spec.SetField(wxcard.FieldIntro, field.TypeString, value)
  827. }
  828. if wcuo.mutation.IntroCleared() {
  829. _spec.ClearField(wxcard.FieldIntro, field.TypeString)
  830. }
  831. _node = &WxCard{config: wcuo.config}
  832. _spec.Assign = _node.assignValues
  833. _spec.ScanValues = _node.scanValues
  834. if err = sqlgraph.UpdateNode(ctx, wcuo.driver, _spec); err != nil {
  835. if _, ok := err.(*sqlgraph.NotFoundError); ok {
  836. err = &NotFoundError{wxcard.Label}
  837. } else if sqlgraph.IsConstraintError(err) {
  838. err = &ConstraintError{msg: err.Error(), wrap: err}
  839. }
  840. return nil, err
  841. }
  842. wcuo.mutation.done = true
  843. return _node, nil
  844. }