wx_update.go 19 KB

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