wx_update.go 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813
  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. // SetOrganizationID sets the "organization_id" field.
  185. func (wu *WxUpdate) SetOrganizationID(u uint64) *WxUpdate {
  186. wu.mutation.ResetOrganizationID()
  187. wu.mutation.SetOrganizationID(u)
  188. return wu
  189. }
  190. // SetNillableOrganizationID sets the "organization_id" field if the given value is not nil.
  191. func (wu *WxUpdate) SetNillableOrganizationID(u *uint64) *WxUpdate {
  192. if u != nil {
  193. wu.SetOrganizationID(*u)
  194. }
  195. return wu
  196. }
  197. // AddOrganizationID adds u to the "organization_id" field.
  198. func (wu *WxUpdate) AddOrganizationID(u int64) *WxUpdate {
  199. wu.mutation.AddOrganizationID(u)
  200. return wu
  201. }
  202. // ClearOrganizationID clears the value of the "organization_id" field.
  203. func (wu *WxUpdate) ClearOrganizationID() *WxUpdate {
  204. wu.mutation.ClearOrganizationID()
  205. return wu
  206. }
  207. // SetServer sets the "server" edge to the Server entity.
  208. func (wu *WxUpdate) SetServer(s *Server) *WxUpdate {
  209. return wu.SetServerID(s.ID)
  210. }
  211. // Mutation returns the WxMutation object of the builder.
  212. func (wu *WxUpdate) Mutation() *WxMutation {
  213. return wu.mutation
  214. }
  215. // ClearServer clears the "server" edge to the Server entity.
  216. func (wu *WxUpdate) ClearServer() *WxUpdate {
  217. wu.mutation.ClearServer()
  218. return wu
  219. }
  220. // Save executes the query and returns the number of nodes affected by the update operation.
  221. func (wu *WxUpdate) Save(ctx context.Context) (int, error) {
  222. if err := wu.defaults(); err != nil {
  223. return 0, err
  224. }
  225. return withHooks(ctx, wu.sqlSave, wu.mutation, wu.hooks)
  226. }
  227. // SaveX is like Save, but panics if an error occurs.
  228. func (wu *WxUpdate) SaveX(ctx context.Context) int {
  229. affected, err := wu.Save(ctx)
  230. if err != nil {
  231. panic(err)
  232. }
  233. return affected
  234. }
  235. // Exec executes the query.
  236. func (wu *WxUpdate) Exec(ctx context.Context) error {
  237. _, err := wu.Save(ctx)
  238. return err
  239. }
  240. // ExecX is like Exec, but panics if an error occurs.
  241. func (wu *WxUpdate) ExecX(ctx context.Context) {
  242. if err := wu.Exec(ctx); err != nil {
  243. panic(err)
  244. }
  245. }
  246. // defaults sets the default values of the builder before save.
  247. func (wu *WxUpdate) defaults() error {
  248. if _, ok := wu.mutation.UpdatedAt(); !ok {
  249. if wx.UpdateDefaultUpdatedAt == nil {
  250. return fmt.Errorf("ent: uninitialized wx.UpdateDefaultUpdatedAt (forgotten import ent/runtime?)")
  251. }
  252. v := wx.UpdateDefaultUpdatedAt()
  253. wu.mutation.SetUpdatedAt(v)
  254. }
  255. return nil
  256. }
  257. func (wu *WxUpdate) sqlSave(ctx context.Context) (n int, err error) {
  258. _spec := sqlgraph.NewUpdateSpec(wx.Table, wx.Columns, sqlgraph.NewFieldSpec(wx.FieldID, field.TypeUint64))
  259. if ps := wu.mutation.predicates; len(ps) > 0 {
  260. _spec.Predicate = func(selector *sql.Selector) {
  261. for i := range ps {
  262. ps[i](selector)
  263. }
  264. }
  265. }
  266. if value, ok := wu.mutation.UpdatedAt(); ok {
  267. _spec.SetField(wx.FieldUpdatedAt, field.TypeTime, value)
  268. }
  269. if value, ok := wu.mutation.Status(); ok {
  270. _spec.SetField(wx.FieldStatus, field.TypeUint8, value)
  271. }
  272. if value, ok := wu.mutation.AddedStatus(); ok {
  273. _spec.AddField(wx.FieldStatus, field.TypeUint8, value)
  274. }
  275. if wu.mutation.StatusCleared() {
  276. _spec.ClearField(wx.FieldStatus, field.TypeUint8)
  277. }
  278. if value, ok := wu.mutation.DeletedAt(); ok {
  279. _spec.SetField(wx.FieldDeletedAt, field.TypeTime, value)
  280. }
  281. if wu.mutation.DeletedAtCleared() {
  282. _spec.ClearField(wx.FieldDeletedAt, field.TypeTime)
  283. }
  284. if value, ok := wu.mutation.Port(); ok {
  285. _spec.SetField(wx.FieldPort, field.TypeString, value)
  286. }
  287. if value, ok := wu.mutation.ProcessID(); ok {
  288. _spec.SetField(wx.FieldProcessID, field.TypeString, value)
  289. }
  290. if value, ok := wu.mutation.Callback(); ok {
  291. _spec.SetField(wx.FieldCallback, field.TypeString, value)
  292. }
  293. if value, ok := wu.mutation.Wxid(); ok {
  294. _spec.SetField(wx.FieldWxid, field.TypeString, value)
  295. }
  296. if value, ok := wu.mutation.Account(); ok {
  297. _spec.SetField(wx.FieldAccount, field.TypeString, value)
  298. }
  299. if value, ok := wu.mutation.Nickname(); ok {
  300. _spec.SetField(wx.FieldNickname, field.TypeString, value)
  301. }
  302. if value, ok := wu.mutation.Tel(); ok {
  303. _spec.SetField(wx.FieldTel, field.TypeString, value)
  304. }
  305. if value, ok := wu.mutation.HeadBig(); ok {
  306. _spec.SetField(wx.FieldHeadBig, field.TypeString, value)
  307. }
  308. if value, ok := wu.mutation.OrganizationID(); ok {
  309. _spec.SetField(wx.FieldOrganizationID, field.TypeUint64, value)
  310. }
  311. if value, ok := wu.mutation.AddedOrganizationID(); ok {
  312. _spec.AddField(wx.FieldOrganizationID, field.TypeUint64, value)
  313. }
  314. if wu.mutation.OrganizationIDCleared() {
  315. _spec.ClearField(wx.FieldOrganizationID, field.TypeUint64)
  316. }
  317. if wu.mutation.ServerCleared() {
  318. edge := &sqlgraph.EdgeSpec{
  319. Rel: sqlgraph.M2O,
  320. Inverse: true,
  321. Table: wx.ServerTable,
  322. Columns: []string{wx.ServerColumn},
  323. Bidi: false,
  324. Target: &sqlgraph.EdgeTarget{
  325. IDSpec: sqlgraph.NewFieldSpec(server.FieldID, field.TypeUint64),
  326. },
  327. }
  328. _spec.Edges.Clear = append(_spec.Edges.Clear, edge)
  329. }
  330. if nodes := wu.mutation.ServerIDs(); len(nodes) > 0 {
  331. edge := &sqlgraph.EdgeSpec{
  332. Rel: sqlgraph.M2O,
  333. Inverse: true,
  334. Table: wx.ServerTable,
  335. Columns: []string{wx.ServerColumn},
  336. Bidi: false,
  337. Target: &sqlgraph.EdgeTarget{
  338. IDSpec: sqlgraph.NewFieldSpec(server.FieldID, field.TypeUint64),
  339. },
  340. }
  341. for _, k := range nodes {
  342. edge.Target.Nodes = append(edge.Target.Nodes, k)
  343. }
  344. _spec.Edges.Add = append(_spec.Edges.Add, edge)
  345. }
  346. if n, err = sqlgraph.UpdateNodes(ctx, wu.driver, _spec); err != nil {
  347. if _, ok := err.(*sqlgraph.NotFoundError); ok {
  348. err = &NotFoundError{wx.Label}
  349. } else if sqlgraph.IsConstraintError(err) {
  350. err = &ConstraintError{msg: err.Error(), wrap: err}
  351. }
  352. return 0, err
  353. }
  354. wu.mutation.done = true
  355. return n, nil
  356. }
  357. // WxUpdateOne is the builder for updating a single Wx entity.
  358. type WxUpdateOne struct {
  359. config
  360. fields []string
  361. hooks []Hook
  362. mutation *WxMutation
  363. }
  364. // SetUpdatedAt sets the "updated_at" field.
  365. func (wuo *WxUpdateOne) SetUpdatedAt(t time.Time) *WxUpdateOne {
  366. wuo.mutation.SetUpdatedAt(t)
  367. return wuo
  368. }
  369. // SetStatus sets the "status" field.
  370. func (wuo *WxUpdateOne) SetStatus(u uint8) *WxUpdateOne {
  371. wuo.mutation.ResetStatus()
  372. wuo.mutation.SetStatus(u)
  373. return wuo
  374. }
  375. // SetNillableStatus sets the "status" field if the given value is not nil.
  376. func (wuo *WxUpdateOne) SetNillableStatus(u *uint8) *WxUpdateOne {
  377. if u != nil {
  378. wuo.SetStatus(*u)
  379. }
  380. return wuo
  381. }
  382. // AddStatus adds u to the "status" field.
  383. func (wuo *WxUpdateOne) AddStatus(u int8) *WxUpdateOne {
  384. wuo.mutation.AddStatus(u)
  385. return wuo
  386. }
  387. // ClearStatus clears the value of the "status" field.
  388. func (wuo *WxUpdateOne) ClearStatus() *WxUpdateOne {
  389. wuo.mutation.ClearStatus()
  390. return wuo
  391. }
  392. // SetDeletedAt sets the "deleted_at" field.
  393. func (wuo *WxUpdateOne) SetDeletedAt(t time.Time) *WxUpdateOne {
  394. wuo.mutation.SetDeletedAt(t)
  395. return wuo
  396. }
  397. // SetNillableDeletedAt sets the "deleted_at" field if the given value is not nil.
  398. func (wuo *WxUpdateOne) SetNillableDeletedAt(t *time.Time) *WxUpdateOne {
  399. if t != nil {
  400. wuo.SetDeletedAt(*t)
  401. }
  402. return wuo
  403. }
  404. // ClearDeletedAt clears the value of the "deleted_at" field.
  405. func (wuo *WxUpdateOne) ClearDeletedAt() *WxUpdateOne {
  406. wuo.mutation.ClearDeletedAt()
  407. return wuo
  408. }
  409. // SetServerID sets the "server_id" field.
  410. func (wuo *WxUpdateOne) SetServerID(u uint64) *WxUpdateOne {
  411. wuo.mutation.SetServerID(u)
  412. return wuo
  413. }
  414. // SetNillableServerID sets the "server_id" field if the given value is not nil.
  415. func (wuo *WxUpdateOne) SetNillableServerID(u *uint64) *WxUpdateOne {
  416. if u != nil {
  417. wuo.SetServerID(*u)
  418. }
  419. return wuo
  420. }
  421. // ClearServerID clears the value of the "server_id" field.
  422. func (wuo *WxUpdateOne) ClearServerID() *WxUpdateOne {
  423. wuo.mutation.ClearServerID()
  424. return wuo
  425. }
  426. // SetPort sets the "port" field.
  427. func (wuo *WxUpdateOne) SetPort(s string) *WxUpdateOne {
  428. wuo.mutation.SetPort(s)
  429. return wuo
  430. }
  431. // SetNillablePort sets the "port" field if the given value is not nil.
  432. func (wuo *WxUpdateOne) SetNillablePort(s *string) *WxUpdateOne {
  433. if s != nil {
  434. wuo.SetPort(*s)
  435. }
  436. return wuo
  437. }
  438. // SetProcessID sets the "process_id" field.
  439. func (wuo *WxUpdateOne) SetProcessID(s string) *WxUpdateOne {
  440. wuo.mutation.SetProcessID(s)
  441. return wuo
  442. }
  443. // SetNillableProcessID sets the "process_id" field if the given value is not nil.
  444. func (wuo *WxUpdateOne) SetNillableProcessID(s *string) *WxUpdateOne {
  445. if s != nil {
  446. wuo.SetProcessID(*s)
  447. }
  448. return wuo
  449. }
  450. // SetCallback sets the "callback" field.
  451. func (wuo *WxUpdateOne) SetCallback(s string) *WxUpdateOne {
  452. wuo.mutation.SetCallback(s)
  453. return wuo
  454. }
  455. // SetNillableCallback sets the "callback" field if the given value is not nil.
  456. func (wuo *WxUpdateOne) SetNillableCallback(s *string) *WxUpdateOne {
  457. if s != nil {
  458. wuo.SetCallback(*s)
  459. }
  460. return wuo
  461. }
  462. // SetWxid sets the "wxid" field.
  463. func (wuo *WxUpdateOne) SetWxid(s string) *WxUpdateOne {
  464. wuo.mutation.SetWxid(s)
  465. return wuo
  466. }
  467. // SetNillableWxid sets the "wxid" field if the given value is not nil.
  468. func (wuo *WxUpdateOne) SetNillableWxid(s *string) *WxUpdateOne {
  469. if s != nil {
  470. wuo.SetWxid(*s)
  471. }
  472. return wuo
  473. }
  474. // SetAccount sets the "account" field.
  475. func (wuo *WxUpdateOne) SetAccount(s string) *WxUpdateOne {
  476. wuo.mutation.SetAccount(s)
  477. return wuo
  478. }
  479. // SetNillableAccount sets the "account" field if the given value is not nil.
  480. func (wuo *WxUpdateOne) SetNillableAccount(s *string) *WxUpdateOne {
  481. if s != nil {
  482. wuo.SetAccount(*s)
  483. }
  484. return wuo
  485. }
  486. // SetNickname sets the "nickname" field.
  487. func (wuo *WxUpdateOne) SetNickname(s string) *WxUpdateOne {
  488. wuo.mutation.SetNickname(s)
  489. return wuo
  490. }
  491. // SetNillableNickname sets the "nickname" field if the given value is not nil.
  492. func (wuo *WxUpdateOne) SetNillableNickname(s *string) *WxUpdateOne {
  493. if s != nil {
  494. wuo.SetNickname(*s)
  495. }
  496. return wuo
  497. }
  498. // SetTel sets the "tel" field.
  499. func (wuo *WxUpdateOne) SetTel(s string) *WxUpdateOne {
  500. wuo.mutation.SetTel(s)
  501. return wuo
  502. }
  503. // SetNillableTel sets the "tel" field if the given value is not nil.
  504. func (wuo *WxUpdateOne) SetNillableTel(s *string) *WxUpdateOne {
  505. if s != nil {
  506. wuo.SetTel(*s)
  507. }
  508. return wuo
  509. }
  510. // SetHeadBig sets the "head_big" field.
  511. func (wuo *WxUpdateOne) SetHeadBig(s string) *WxUpdateOne {
  512. wuo.mutation.SetHeadBig(s)
  513. return wuo
  514. }
  515. // SetNillableHeadBig sets the "head_big" field if the given value is not nil.
  516. func (wuo *WxUpdateOne) SetNillableHeadBig(s *string) *WxUpdateOne {
  517. if s != nil {
  518. wuo.SetHeadBig(*s)
  519. }
  520. return wuo
  521. }
  522. // SetOrganizationID sets the "organization_id" field.
  523. func (wuo *WxUpdateOne) SetOrganizationID(u uint64) *WxUpdateOne {
  524. wuo.mutation.ResetOrganizationID()
  525. wuo.mutation.SetOrganizationID(u)
  526. return wuo
  527. }
  528. // SetNillableOrganizationID sets the "organization_id" field if the given value is not nil.
  529. func (wuo *WxUpdateOne) SetNillableOrganizationID(u *uint64) *WxUpdateOne {
  530. if u != nil {
  531. wuo.SetOrganizationID(*u)
  532. }
  533. return wuo
  534. }
  535. // AddOrganizationID adds u to the "organization_id" field.
  536. func (wuo *WxUpdateOne) AddOrganizationID(u int64) *WxUpdateOne {
  537. wuo.mutation.AddOrganizationID(u)
  538. return wuo
  539. }
  540. // ClearOrganizationID clears the value of the "organization_id" field.
  541. func (wuo *WxUpdateOne) ClearOrganizationID() *WxUpdateOne {
  542. wuo.mutation.ClearOrganizationID()
  543. return wuo
  544. }
  545. // SetServer sets the "server" edge to the Server entity.
  546. func (wuo *WxUpdateOne) SetServer(s *Server) *WxUpdateOne {
  547. return wuo.SetServerID(s.ID)
  548. }
  549. // Mutation returns the WxMutation object of the builder.
  550. func (wuo *WxUpdateOne) Mutation() *WxMutation {
  551. return wuo.mutation
  552. }
  553. // ClearServer clears the "server" edge to the Server entity.
  554. func (wuo *WxUpdateOne) ClearServer() *WxUpdateOne {
  555. wuo.mutation.ClearServer()
  556. return wuo
  557. }
  558. // Where appends a list predicates to the WxUpdate builder.
  559. func (wuo *WxUpdateOne) Where(ps ...predicate.Wx) *WxUpdateOne {
  560. wuo.mutation.Where(ps...)
  561. return wuo
  562. }
  563. // Select allows selecting one or more fields (columns) of the returned entity.
  564. // The default is selecting all fields defined in the entity schema.
  565. func (wuo *WxUpdateOne) Select(field string, fields ...string) *WxUpdateOne {
  566. wuo.fields = append([]string{field}, fields...)
  567. return wuo
  568. }
  569. // Save executes the query and returns the updated Wx entity.
  570. func (wuo *WxUpdateOne) Save(ctx context.Context) (*Wx, error) {
  571. if err := wuo.defaults(); err != nil {
  572. return nil, err
  573. }
  574. return withHooks(ctx, wuo.sqlSave, wuo.mutation, wuo.hooks)
  575. }
  576. // SaveX is like Save, but panics if an error occurs.
  577. func (wuo *WxUpdateOne) SaveX(ctx context.Context) *Wx {
  578. node, err := wuo.Save(ctx)
  579. if err != nil {
  580. panic(err)
  581. }
  582. return node
  583. }
  584. // Exec executes the query on the entity.
  585. func (wuo *WxUpdateOne) Exec(ctx context.Context) error {
  586. _, err := wuo.Save(ctx)
  587. return err
  588. }
  589. // ExecX is like Exec, but panics if an error occurs.
  590. func (wuo *WxUpdateOne) ExecX(ctx context.Context) {
  591. if err := wuo.Exec(ctx); err != nil {
  592. panic(err)
  593. }
  594. }
  595. // defaults sets the default values of the builder before save.
  596. func (wuo *WxUpdateOne) defaults() error {
  597. if _, ok := wuo.mutation.UpdatedAt(); !ok {
  598. if wx.UpdateDefaultUpdatedAt == nil {
  599. return fmt.Errorf("ent: uninitialized wx.UpdateDefaultUpdatedAt (forgotten import ent/runtime?)")
  600. }
  601. v := wx.UpdateDefaultUpdatedAt()
  602. wuo.mutation.SetUpdatedAt(v)
  603. }
  604. return nil
  605. }
  606. func (wuo *WxUpdateOne) sqlSave(ctx context.Context) (_node *Wx, err error) {
  607. _spec := sqlgraph.NewUpdateSpec(wx.Table, wx.Columns, sqlgraph.NewFieldSpec(wx.FieldID, field.TypeUint64))
  608. id, ok := wuo.mutation.ID()
  609. if !ok {
  610. return nil, &ValidationError{Name: "id", err: errors.New(`ent: missing "Wx.id" for update`)}
  611. }
  612. _spec.Node.ID.Value = id
  613. if fields := wuo.fields; len(fields) > 0 {
  614. _spec.Node.Columns = make([]string, 0, len(fields))
  615. _spec.Node.Columns = append(_spec.Node.Columns, wx.FieldID)
  616. for _, f := range fields {
  617. if !wx.ValidColumn(f) {
  618. return nil, &ValidationError{Name: f, err: fmt.Errorf("ent: invalid field %q for query", f)}
  619. }
  620. if f != wx.FieldID {
  621. _spec.Node.Columns = append(_spec.Node.Columns, f)
  622. }
  623. }
  624. }
  625. if ps := wuo.mutation.predicates; len(ps) > 0 {
  626. _spec.Predicate = func(selector *sql.Selector) {
  627. for i := range ps {
  628. ps[i](selector)
  629. }
  630. }
  631. }
  632. if value, ok := wuo.mutation.UpdatedAt(); ok {
  633. _spec.SetField(wx.FieldUpdatedAt, field.TypeTime, value)
  634. }
  635. if value, ok := wuo.mutation.Status(); ok {
  636. _spec.SetField(wx.FieldStatus, field.TypeUint8, value)
  637. }
  638. if value, ok := wuo.mutation.AddedStatus(); ok {
  639. _spec.AddField(wx.FieldStatus, field.TypeUint8, value)
  640. }
  641. if wuo.mutation.StatusCleared() {
  642. _spec.ClearField(wx.FieldStatus, field.TypeUint8)
  643. }
  644. if value, ok := wuo.mutation.DeletedAt(); ok {
  645. _spec.SetField(wx.FieldDeletedAt, field.TypeTime, value)
  646. }
  647. if wuo.mutation.DeletedAtCleared() {
  648. _spec.ClearField(wx.FieldDeletedAt, field.TypeTime)
  649. }
  650. if value, ok := wuo.mutation.Port(); ok {
  651. _spec.SetField(wx.FieldPort, field.TypeString, value)
  652. }
  653. if value, ok := wuo.mutation.ProcessID(); ok {
  654. _spec.SetField(wx.FieldProcessID, field.TypeString, value)
  655. }
  656. if value, ok := wuo.mutation.Callback(); ok {
  657. _spec.SetField(wx.FieldCallback, field.TypeString, value)
  658. }
  659. if value, ok := wuo.mutation.Wxid(); ok {
  660. _spec.SetField(wx.FieldWxid, field.TypeString, value)
  661. }
  662. if value, ok := wuo.mutation.Account(); ok {
  663. _spec.SetField(wx.FieldAccount, field.TypeString, value)
  664. }
  665. if value, ok := wuo.mutation.Nickname(); ok {
  666. _spec.SetField(wx.FieldNickname, field.TypeString, value)
  667. }
  668. if value, ok := wuo.mutation.Tel(); ok {
  669. _spec.SetField(wx.FieldTel, field.TypeString, value)
  670. }
  671. if value, ok := wuo.mutation.HeadBig(); ok {
  672. _spec.SetField(wx.FieldHeadBig, field.TypeString, value)
  673. }
  674. if value, ok := wuo.mutation.OrganizationID(); ok {
  675. _spec.SetField(wx.FieldOrganizationID, field.TypeUint64, value)
  676. }
  677. if value, ok := wuo.mutation.AddedOrganizationID(); ok {
  678. _spec.AddField(wx.FieldOrganizationID, field.TypeUint64, value)
  679. }
  680. if wuo.mutation.OrganizationIDCleared() {
  681. _spec.ClearField(wx.FieldOrganizationID, field.TypeUint64)
  682. }
  683. if wuo.mutation.ServerCleared() {
  684. edge := &sqlgraph.EdgeSpec{
  685. Rel: sqlgraph.M2O,
  686. Inverse: true,
  687. Table: wx.ServerTable,
  688. Columns: []string{wx.ServerColumn},
  689. Bidi: false,
  690. Target: &sqlgraph.EdgeTarget{
  691. IDSpec: sqlgraph.NewFieldSpec(server.FieldID, field.TypeUint64),
  692. },
  693. }
  694. _spec.Edges.Clear = append(_spec.Edges.Clear, edge)
  695. }
  696. if nodes := wuo.mutation.ServerIDs(); len(nodes) > 0 {
  697. edge := &sqlgraph.EdgeSpec{
  698. Rel: sqlgraph.M2O,
  699. Inverse: true,
  700. Table: wx.ServerTable,
  701. Columns: []string{wx.ServerColumn},
  702. Bidi: false,
  703. Target: &sqlgraph.EdgeTarget{
  704. IDSpec: sqlgraph.NewFieldSpec(server.FieldID, field.TypeUint64),
  705. },
  706. }
  707. for _, k := range nodes {
  708. edge.Target.Nodes = append(edge.Target.Nodes, k)
  709. }
  710. _spec.Edges.Add = append(_spec.Edges.Add, edge)
  711. }
  712. _node = &Wx{config: wuo.config}
  713. _spec.Assign = _node.assignValues
  714. _spec.ScanValues = _node.scanValues
  715. if err = sqlgraph.UpdateNode(ctx, wuo.driver, _spec); err != nil {
  716. if _, ok := err.(*sqlgraph.NotFoundError); ok {
  717. err = &NotFoundError{wx.Label}
  718. } else if sqlgraph.IsConstraintError(err) {
  719. err = &ConstraintError{msg: err.Error(), wrap: err}
  720. }
  721. return nil, err
  722. }
  723. wuo.mutation.done = true
  724. return _node, nil
  725. }