wx_update.go 25 KB

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