wx_update.go 28 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048
  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. // SetAPIBase sets the "api_base" field.
  221. func (wu *WxUpdate) SetAPIBase(s string) *WxUpdate {
  222. wu.mutation.SetAPIBase(s)
  223. return wu
  224. }
  225. // SetNillableAPIBase sets the "api_base" field if the given value is not nil.
  226. func (wu *WxUpdate) SetNillableAPIBase(s *string) *WxUpdate {
  227. if s != nil {
  228. wu.SetAPIBase(*s)
  229. }
  230. return wu
  231. }
  232. // ClearAPIBase clears the value of the "api_base" field.
  233. func (wu *WxUpdate) ClearAPIBase() *WxUpdate {
  234. wu.mutation.ClearAPIBase()
  235. return wu
  236. }
  237. // SetAPIKey sets the "api_key" field.
  238. func (wu *WxUpdate) SetAPIKey(s string) *WxUpdate {
  239. wu.mutation.SetAPIKey(s)
  240. return wu
  241. }
  242. // SetNillableAPIKey sets the "api_key" field if the given value is not nil.
  243. func (wu *WxUpdate) SetNillableAPIKey(s *string) *WxUpdate {
  244. if s != nil {
  245. wu.SetAPIKey(*s)
  246. }
  247. return wu
  248. }
  249. // ClearAPIKey clears the value of the "api_key" field.
  250. func (wu *WxUpdate) ClearAPIKey() *WxUpdate {
  251. wu.mutation.ClearAPIKey()
  252. return wu
  253. }
  254. // SetServer sets the "server" edge to the Server entity.
  255. func (wu *WxUpdate) SetServer(s *Server) *WxUpdate {
  256. return wu.SetServerID(s.ID)
  257. }
  258. // SetAgent sets the "agent" edge to the Agent entity.
  259. func (wu *WxUpdate) SetAgent(a *Agent) *WxUpdate {
  260. return wu.SetAgentID(a.ID)
  261. }
  262. // Mutation returns the WxMutation object of the builder.
  263. func (wu *WxUpdate) Mutation() *WxMutation {
  264. return wu.mutation
  265. }
  266. // ClearServer clears the "server" edge to the Server entity.
  267. func (wu *WxUpdate) ClearServer() *WxUpdate {
  268. wu.mutation.ClearServer()
  269. return wu
  270. }
  271. // ClearAgent clears the "agent" edge to the Agent entity.
  272. func (wu *WxUpdate) ClearAgent() *WxUpdate {
  273. wu.mutation.ClearAgent()
  274. return wu
  275. }
  276. // Save executes the query and returns the number of nodes affected by the update operation.
  277. func (wu *WxUpdate) Save(ctx context.Context) (int, error) {
  278. if err := wu.defaults(); err != nil {
  279. return 0, err
  280. }
  281. return withHooks(ctx, wu.sqlSave, wu.mutation, wu.hooks)
  282. }
  283. // SaveX is like Save, but panics if an error occurs.
  284. func (wu *WxUpdate) SaveX(ctx context.Context) int {
  285. affected, err := wu.Save(ctx)
  286. if err != nil {
  287. panic(err)
  288. }
  289. return affected
  290. }
  291. // Exec executes the query.
  292. func (wu *WxUpdate) Exec(ctx context.Context) error {
  293. _, err := wu.Save(ctx)
  294. return err
  295. }
  296. // ExecX is like Exec, but panics if an error occurs.
  297. func (wu *WxUpdate) ExecX(ctx context.Context) {
  298. if err := wu.Exec(ctx); err != nil {
  299. panic(err)
  300. }
  301. }
  302. // defaults sets the default values of the builder before save.
  303. func (wu *WxUpdate) defaults() error {
  304. if _, ok := wu.mutation.UpdatedAt(); !ok {
  305. if wx.UpdateDefaultUpdatedAt == nil {
  306. return fmt.Errorf("ent: uninitialized wx.UpdateDefaultUpdatedAt (forgotten import ent/runtime?)")
  307. }
  308. v := wx.UpdateDefaultUpdatedAt()
  309. wu.mutation.SetUpdatedAt(v)
  310. }
  311. return nil
  312. }
  313. // check runs all checks and user-defined validators on the builder.
  314. func (wu *WxUpdate) check() error {
  315. if _, ok := wu.mutation.AgentID(); wu.mutation.AgentCleared() && !ok {
  316. return errors.New(`ent: clearing a required unique edge "Wx.agent"`)
  317. }
  318. return nil
  319. }
  320. func (wu *WxUpdate) sqlSave(ctx context.Context) (n int, err error) {
  321. if err := wu.check(); err != nil {
  322. return n, err
  323. }
  324. _spec := sqlgraph.NewUpdateSpec(wx.Table, wx.Columns, sqlgraph.NewFieldSpec(wx.FieldID, field.TypeUint64))
  325. if ps := wu.mutation.predicates; len(ps) > 0 {
  326. _spec.Predicate = func(selector *sql.Selector) {
  327. for i := range ps {
  328. ps[i](selector)
  329. }
  330. }
  331. }
  332. if value, ok := wu.mutation.UpdatedAt(); ok {
  333. _spec.SetField(wx.FieldUpdatedAt, field.TypeTime, value)
  334. }
  335. if value, ok := wu.mutation.Status(); ok {
  336. _spec.SetField(wx.FieldStatus, field.TypeUint8, value)
  337. }
  338. if value, ok := wu.mutation.AddedStatus(); ok {
  339. _spec.AddField(wx.FieldStatus, field.TypeUint8, value)
  340. }
  341. if wu.mutation.StatusCleared() {
  342. _spec.ClearField(wx.FieldStatus, field.TypeUint8)
  343. }
  344. if value, ok := wu.mutation.DeletedAt(); ok {
  345. _spec.SetField(wx.FieldDeletedAt, field.TypeTime, value)
  346. }
  347. if wu.mutation.DeletedAtCleared() {
  348. _spec.ClearField(wx.FieldDeletedAt, field.TypeTime)
  349. }
  350. if value, ok := wu.mutation.Port(); ok {
  351. _spec.SetField(wx.FieldPort, field.TypeString, value)
  352. }
  353. if value, ok := wu.mutation.ProcessID(); ok {
  354. _spec.SetField(wx.FieldProcessID, field.TypeString, value)
  355. }
  356. if value, ok := wu.mutation.Callback(); ok {
  357. _spec.SetField(wx.FieldCallback, field.TypeString, value)
  358. }
  359. if value, ok := wu.mutation.Wxid(); ok {
  360. _spec.SetField(wx.FieldWxid, field.TypeString, value)
  361. }
  362. if value, ok := wu.mutation.Account(); ok {
  363. _spec.SetField(wx.FieldAccount, field.TypeString, value)
  364. }
  365. if value, ok := wu.mutation.Nickname(); ok {
  366. _spec.SetField(wx.FieldNickname, field.TypeString, value)
  367. }
  368. if value, ok := wu.mutation.Tel(); ok {
  369. _spec.SetField(wx.FieldTel, field.TypeString, value)
  370. }
  371. if value, ok := wu.mutation.HeadBig(); ok {
  372. _spec.SetField(wx.FieldHeadBig, field.TypeString, value)
  373. }
  374. if value, ok := wu.mutation.OrganizationID(); ok {
  375. _spec.SetField(wx.FieldOrganizationID, field.TypeUint64, value)
  376. }
  377. if value, ok := wu.mutation.AddedOrganizationID(); ok {
  378. _spec.AddField(wx.FieldOrganizationID, field.TypeUint64, value)
  379. }
  380. if wu.mutation.OrganizationIDCleared() {
  381. _spec.ClearField(wx.FieldOrganizationID, field.TypeUint64)
  382. }
  383. if value, ok := wu.mutation.APIBase(); ok {
  384. _spec.SetField(wx.FieldAPIBase, field.TypeString, value)
  385. }
  386. if wu.mutation.APIBaseCleared() {
  387. _spec.ClearField(wx.FieldAPIBase, field.TypeString)
  388. }
  389. if value, ok := wu.mutation.APIKey(); ok {
  390. _spec.SetField(wx.FieldAPIKey, field.TypeString, value)
  391. }
  392. if wu.mutation.APIKeyCleared() {
  393. _spec.ClearField(wx.FieldAPIKey, field.TypeString)
  394. }
  395. if wu.mutation.ServerCleared() {
  396. edge := &sqlgraph.EdgeSpec{
  397. Rel: sqlgraph.M2O,
  398. Inverse: true,
  399. Table: wx.ServerTable,
  400. Columns: []string{wx.ServerColumn},
  401. Bidi: false,
  402. Target: &sqlgraph.EdgeTarget{
  403. IDSpec: sqlgraph.NewFieldSpec(server.FieldID, field.TypeUint64),
  404. },
  405. }
  406. _spec.Edges.Clear = append(_spec.Edges.Clear, edge)
  407. }
  408. if nodes := wu.mutation.ServerIDs(); len(nodes) > 0 {
  409. edge := &sqlgraph.EdgeSpec{
  410. Rel: sqlgraph.M2O,
  411. Inverse: true,
  412. Table: wx.ServerTable,
  413. Columns: []string{wx.ServerColumn},
  414. Bidi: false,
  415. Target: &sqlgraph.EdgeTarget{
  416. IDSpec: sqlgraph.NewFieldSpec(server.FieldID, field.TypeUint64),
  417. },
  418. }
  419. for _, k := range nodes {
  420. edge.Target.Nodes = append(edge.Target.Nodes, k)
  421. }
  422. _spec.Edges.Add = append(_spec.Edges.Add, edge)
  423. }
  424. if wu.mutation.AgentCleared() {
  425. edge := &sqlgraph.EdgeSpec{
  426. Rel: sqlgraph.M2O,
  427. Inverse: true,
  428. Table: wx.AgentTable,
  429. Columns: []string{wx.AgentColumn},
  430. Bidi: false,
  431. Target: &sqlgraph.EdgeTarget{
  432. IDSpec: sqlgraph.NewFieldSpec(agent.FieldID, field.TypeUint64),
  433. },
  434. }
  435. _spec.Edges.Clear = append(_spec.Edges.Clear, edge)
  436. }
  437. if nodes := wu.mutation.AgentIDs(); len(nodes) > 0 {
  438. edge := &sqlgraph.EdgeSpec{
  439. Rel: sqlgraph.M2O,
  440. Inverse: true,
  441. Table: wx.AgentTable,
  442. Columns: []string{wx.AgentColumn},
  443. Bidi: false,
  444. Target: &sqlgraph.EdgeTarget{
  445. IDSpec: sqlgraph.NewFieldSpec(agent.FieldID, field.TypeUint64),
  446. },
  447. }
  448. for _, k := range nodes {
  449. edge.Target.Nodes = append(edge.Target.Nodes, k)
  450. }
  451. _spec.Edges.Add = append(_spec.Edges.Add, edge)
  452. }
  453. if n, err = sqlgraph.UpdateNodes(ctx, wu.driver, _spec); err != nil {
  454. if _, ok := err.(*sqlgraph.NotFoundError); ok {
  455. err = &NotFoundError{wx.Label}
  456. } else if sqlgraph.IsConstraintError(err) {
  457. err = &ConstraintError{msg: err.Error(), wrap: err}
  458. }
  459. return 0, err
  460. }
  461. wu.mutation.done = true
  462. return n, nil
  463. }
  464. // WxUpdateOne is the builder for updating a single Wx entity.
  465. type WxUpdateOne struct {
  466. config
  467. fields []string
  468. hooks []Hook
  469. mutation *WxMutation
  470. }
  471. // SetUpdatedAt sets the "updated_at" field.
  472. func (wuo *WxUpdateOne) SetUpdatedAt(t time.Time) *WxUpdateOne {
  473. wuo.mutation.SetUpdatedAt(t)
  474. return wuo
  475. }
  476. // SetStatus sets the "status" field.
  477. func (wuo *WxUpdateOne) SetStatus(u uint8) *WxUpdateOne {
  478. wuo.mutation.ResetStatus()
  479. wuo.mutation.SetStatus(u)
  480. return wuo
  481. }
  482. // SetNillableStatus sets the "status" field if the given value is not nil.
  483. func (wuo *WxUpdateOne) SetNillableStatus(u *uint8) *WxUpdateOne {
  484. if u != nil {
  485. wuo.SetStatus(*u)
  486. }
  487. return wuo
  488. }
  489. // AddStatus adds u to the "status" field.
  490. func (wuo *WxUpdateOne) AddStatus(u int8) *WxUpdateOne {
  491. wuo.mutation.AddStatus(u)
  492. return wuo
  493. }
  494. // ClearStatus clears the value of the "status" field.
  495. func (wuo *WxUpdateOne) ClearStatus() *WxUpdateOne {
  496. wuo.mutation.ClearStatus()
  497. return wuo
  498. }
  499. // SetDeletedAt sets the "deleted_at" field.
  500. func (wuo *WxUpdateOne) SetDeletedAt(t time.Time) *WxUpdateOne {
  501. wuo.mutation.SetDeletedAt(t)
  502. return wuo
  503. }
  504. // SetNillableDeletedAt sets the "deleted_at" field if the given value is not nil.
  505. func (wuo *WxUpdateOne) SetNillableDeletedAt(t *time.Time) *WxUpdateOne {
  506. if t != nil {
  507. wuo.SetDeletedAt(*t)
  508. }
  509. return wuo
  510. }
  511. // ClearDeletedAt clears the value of the "deleted_at" field.
  512. func (wuo *WxUpdateOne) ClearDeletedAt() *WxUpdateOne {
  513. wuo.mutation.ClearDeletedAt()
  514. return wuo
  515. }
  516. // SetServerID sets the "server_id" field.
  517. func (wuo *WxUpdateOne) SetServerID(u uint64) *WxUpdateOne {
  518. wuo.mutation.SetServerID(u)
  519. return wuo
  520. }
  521. // SetNillableServerID sets the "server_id" field if the given value is not nil.
  522. func (wuo *WxUpdateOne) SetNillableServerID(u *uint64) *WxUpdateOne {
  523. if u != nil {
  524. wuo.SetServerID(*u)
  525. }
  526. return wuo
  527. }
  528. // ClearServerID clears the value of the "server_id" field.
  529. func (wuo *WxUpdateOne) ClearServerID() *WxUpdateOne {
  530. wuo.mutation.ClearServerID()
  531. return wuo
  532. }
  533. // SetPort sets the "port" field.
  534. func (wuo *WxUpdateOne) SetPort(s string) *WxUpdateOne {
  535. wuo.mutation.SetPort(s)
  536. return wuo
  537. }
  538. // SetNillablePort sets the "port" field if the given value is not nil.
  539. func (wuo *WxUpdateOne) SetNillablePort(s *string) *WxUpdateOne {
  540. if s != nil {
  541. wuo.SetPort(*s)
  542. }
  543. return wuo
  544. }
  545. // SetProcessID sets the "process_id" field.
  546. func (wuo *WxUpdateOne) SetProcessID(s string) *WxUpdateOne {
  547. wuo.mutation.SetProcessID(s)
  548. return wuo
  549. }
  550. // SetNillableProcessID sets the "process_id" field if the given value is not nil.
  551. func (wuo *WxUpdateOne) SetNillableProcessID(s *string) *WxUpdateOne {
  552. if s != nil {
  553. wuo.SetProcessID(*s)
  554. }
  555. return wuo
  556. }
  557. // SetCallback sets the "callback" field.
  558. func (wuo *WxUpdateOne) SetCallback(s string) *WxUpdateOne {
  559. wuo.mutation.SetCallback(s)
  560. return wuo
  561. }
  562. // SetNillableCallback sets the "callback" field if the given value is not nil.
  563. func (wuo *WxUpdateOne) SetNillableCallback(s *string) *WxUpdateOne {
  564. if s != nil {
  565. wuo.SetCallback(*s)
  566. }
  567. return wuo
  568. }
  569. // SetWxid sets the "wxid" field.
  570. func (wuo *WxUpdateOne) SetWxid(s string) *WxUpdateOne {
  571. wuo.mutation.SetWxid(s)
  572. return wuo
  573. }
  574. // SetNillableWxid sets the "wxid" field if the given value is not nil.
  575. func (wuo *WxUpdateOne) SetNillableWxid(s *string) *WxUpdateOne {
  576. if s != nil {
  577. wuo.SetWxid(*s)
  578. }
  579. return wuo
  580. }
  581. // SetAccount sets the "account" field.
  582. func (wuo *WxUpdateOne) SetAccount(s string) *WxUpdateOne {
  583. wuo.mutation.SetAccount(s)
  584. return wuo
  585. }
  586. // SetNillableAccount sets the "account" field if the given value is not nil.
  587. func (wuo *WxUpdateOne) SetNillableAccount(s *string) *WxUpdateOne {
  588. if s != nil {
  589. wuo.SetAccount(*s)
  590. }
  591. return wuo
  592. }
  593. // SetNickname sets the "nickname" field.
  594. func (wuo *WxUpdateOne) SetNickname(s string) *WxUpdateOne {
  595. wuo.mutation.SetNickname(s)
  596. return wuo
  597. }
  598. // SetNillableNickname sets the "nickname" field if the given value is not nil.
  599. func (wuo *WxUpdateOne) SetNillableNickname(s *string) *WxUpdateOne {
  600. if s != nil {
  601. wuo.SetNickname(*s)
  602. }
  603. return wuo
  604. }
  605. // SetTel sets the "tel" field.
  606. func (wuo *WxUpdateOne) SetTel(s string) *WxUpdateOne {
  607. wuo.mutation.SetTel(s)
  608. return wuo
  609. }
  610. // SetNillableTel sets the "tel" field if the given value is not nil.
  611. func (wuo *WxUpdateOne) SetNillableTel(s *string) *WxUpdateOne {
  612. if s != nil {
  613. wuo.SetTel(*s)
  614. }
  615. return wuo
  616. }
  617. // SetHeadBig sets the "head_big" field.
  618. func (wuo *WxUpdateOne) SetHeadBig(s string) *WxUpdateOne {
  619. wuo.mutation.SetHeadBig(s)
  620. return wuo
  621. }
  622. // SetNillableHeadBig sets the "head_big" field if the given value is not nil.
  623. func (wuo *WxUpdateOne) SetNillableHeadBig(s *string) *WxUpdateOne {
  624. if s != nil {
  625. wuo.SetHeadBig(*s)
  626. }
  627. return wuo
  628. }
  629. // SetOrganizationID sets the "organization_id" field.
  630. func (wuo *WxUpdateOne) SetOrganizationID(u uint64) *WxUpdateOne {
  631. wuo.mutation.ResetOrganizationID()
  632. wuo.mutation.SetOrganizationID(u)
  633. return wuo
  634. }
  635. // SetNillableOrganizationID sets the "organization_id" field if the given value is not nil.
  636. func (wuo *WxUpdateOne) SetNillableOrganizationID(u *uint64) *WxUpdateOne {
  637. if u != nil {
  638. wuo.SetOrganizationID(*u)
  639. }
  640. return wuo
  641. }
  642. // AddOrganizationID adds u to the "organization_id" field.
  643. func (wuo *WxUpdateOne) AddOrganizationID(u int64) *WxUpdateOne {
  644. wuo.mutation.AddOrganizationID(u)
  645. return wuo
  646. }
  647. // ClearOrganizationID clears the value of the "organization_id" field.
  648. func (wuo *WxUpdateOne) ClearOrganizationID() *WxUpdateOne {
  649. wuo.mutation.ClearOrganizationID()
  650. return wuo
  651. }
  652. // SetAgentID sets the "agent_id" field.
  653. func (wuo *WxUpdateOne) SetAgentID(u uint64) *WxUpdateOne {
  654. wuo.mutation.SetAgentID(u)
  655. return wuo
  656. }
  657. // SetNillableAgentID sets the "agent_id" field if the given value is not nil.
  658. func (wuo *WxUpdateOne) SetNillableAgentID(u *uint64) *WxUpdateOne {
  659. if u != nil {
  660. wuo.SetAgentID(*u)
  661. }
  662. return wuo
  663. }
  664. // SetAPIBase sets the "api_base" field.
  665. func (wuo *WxUpdateOne) SetAPIBase(s string) *WxUpdateOne {
  666. wuo.mutation.SetAPIBase(s)
  667. return wuo
  668. }
  669. // SetNillableAPIBase sets the "api_base" field if the given value is not nil.
  670. func (wuo *WxUpdateOne) SetNillableAPIBase(s *string) *WxUpdateOne {
  671. if s != nil {
  672. wuo.SetAPIBase(*s)
  673. }
  674. return wuo
  675. }
  676. // ClearAPIBase clears the value of the "api_base" field.
  677. func (wuo *WxUpdateOne) ClearAPIBase() *WxUpdateOne {
  678. wuo.mutation.ClearAPIBase()
  679. return wuo
  680. }
  681. // SetAPIKey sets the "api_key" field.
  682. func (wuo *WxUpdateOne) SetAPIKey(s string) *WxUpdateOne {
  683. wuo.mutation.SetAPIKey(s)
  684. return wuo
  685. }
  686. // SetNillableAPIKey sets the "api_key" field if the given value is not nil.
  687. func (wuo *WxUpdateOne) SetNillableAPIKey(s *string) *WxUpdateOne {
  688. if s != nil {
  689. wuo.SetAPIKey(*s)
  690. }
  691. return wuo
  692. }
  693. // ClearAPIKey clears the value of the "api_key" field.
  694. func (wuo *WxUpdateOne) ClearAPIKey() *WxUpdateOne {
  695. wuo.mutation.ClearAPIKey()
  696. return wuo
  697. }
  698. // SetServer sets the "server" edge to the Server entity.
  699. func (wuo *WxUpdateOne) SetServer(s *Server) *WxUpdateOne {
  700. return wuo.SetServerID(s.ID)
  701. }
  702. // SetAgent sets the "agent" edge to the Agent entity.
  703. func (wuo *WxUpdateOne) SetAgent(a *Agent) *WxUpdateOne {
  704. return wuo.SetAgentID(a.ID)
  705. }
  706. // Mutation returns the WxMutation object of the builder.
  707. func (wuo *WxUpdateOne) Mutation() *WxMutation {
  708. return wuo.mutation
  709. }
  710. // ClearServer clears the "server" edge to the Server entity.
  711. func (wuo *WxUpdateOne) ClearServer() *WxUpdateOne {
  712. wuo.mutation.ClearServer()
  713. return wuo
  714. }
  715. // ClearAgent clears the "agent" edge to the Agent entity.
  716. func (wuo *WxUpdateOne) ClearAgent() *WxUpdateOne {
  717. wuo.mutation.ClearAgent()
  718. return wuo
  719. }
  720. // Where appends a list predicates to the WxUpdate builder.
  721. func (wuo *WxUpdateOne) Where(ps ...predicate.Wx) *WxUpdateOne {
  722. wuo.mutation.Where(ps...)
  723. return wuo
  724. }
  725. // Select allows selecting one or more fields (columns) of the returned entity.
  726. // The default is selecting all fields defined in the entity schema.
  727. func (wuo *WxUpdateOne) Select(field string, fields ...string) *WxUpdateOne {
  728. wuo.fields = append([]string{field}, fields...)
  729. return wuo
  730. }
  731. // Save executes the query and returns the updated Wx entity.
  732. func (wuo *WxUpdateOne) Save(ctx context.Context) (*Wx, error) {
  733. if err := wuo.defaults(); err != nil {
  734. return nil, err
  735. }
  736. return withHooks(ctx, wuo.sqlSave, wuo.mutation, wuo.hooks)
  737. }
  738. // SaveX is like Save, but panics if an error occurs.
  739. func (wuo *WxUpdateOne) SaveX(ctx context.Context) *Wx {
  740. node, err := wuo.Save(ctx)
  741. if err != nil {
  742. panic(err)
  743. }
  744. return node
  745. }
  746. // Exec executes the query on the entity.
  747. func (wuo *WxUpdateOne) Exec(ctx context.Context) error {
  748. _, err := wuo.Save(ctx)
  749. return err
  750. }
  751. // ExecX is like Exec, but panics if an error occurs.
  752. func (wuo *WxUpdateOne) ExecX(ctx context.Context) {
  753. if err := wuo.Exec(ctx); err != nil {
  754. panic(err)
  755. }
  756. }
  757. // defaults sets the default values of the builder before save.
  758. func (wuo *WxUpdateOne) defaults() error {
  759. if _, ok := wuo.mutation.UpdatedAt(); !ok {
  760. if wx.UpdateDefaultUpdatedAt == nil {
  761. return fmt.Errorf("ent: uninitialized wx.UpdateDefaultUpdatedAt (forgotten import ent/runtime?)")
  762. }
  763. v := wx.UpdateDefaultUpdatedAt()
  764. wuo.mutation.SetUpdatedAt(v)
  765. }
  766. return nil
  767. }
  768. // check runs all checks and user-defined validators on the builder.
  769. func (wuo *WxUpdateOne) check() error {
  770. if _, ok := wuo.mutation.AgentID(); wuo.mutation.AgentCleared() && !ok {
  771. return errors.New(`ent: clearing a required unique edge "Wx.agent"`)
  772. }
  773. return nil
  774. }
  775. func (wuo *WxUpdateOne) sqlSave(ctx context.Context) (_node *Wx, err error) {
  776. if err := wuo.check(); err != nil {
  777. return _node, err
  778. }
  779. _spec := sqlgraph.NewUpdateSpec(wx.Table, wx.Columns, sqlgraph.NewFieldSpec(wx.FieldID, field.TypeUint64))
  780. id, ok := wuo.mutation.ID()
  781. if !ok {
  782. return nil, &ValidationError{Name: "id", err: errors.New(`ent: missing "Wx.id" for update`)}
  783. }
  784. _spec.Node.ID.Value = id
  785. if fields := wuo.fields; len(fields) > 0 {
  786. _spec.Node.Columns = make([]string, 0, len(fields))
  787. _spec.Node.Columns = append(_spec.Node.Columns, wx.FieldID)
  788. for _, f := range fields {
  789. if !wx.ValidColumn(f) {
  790. return nil, &ValidationError{Name: f, err: fmt.Errorf("ent: invalid field %q for query", f)}
  791. }
  792. if f != wx.FieldID {
  793. _spec.Node.Columns = append(_spec.Node.Columns, f)
  794. }
  795. }
  796. }
  797. if ps := wuo.mutation.predicates; len(ps) > 0 {
  798. _spec.Predicate = func(selector *sql.Selector) {
  799. for i := range ps {
  800. ps[i](selector)
  801. }
  802. }
  803. }
  804. if value, ok := wuo.mutation.UpdatedAt(); ok {
  805. _spec.SetField(wx.FieldUpdatedAt, field.TypeTime, value)
  806. }
  807. if value, ok := wuo.mutation.Status(); ok {
  808. _spec.SetField(wx.FieldStatus, field.TypeUint8, value)
  809. }
  810. if value, ok := wuo.mutation.AddedStatus(); ok {
  811. _spec.AddField(wx.FieldStatus, field.TypeUint8, value)
  812. }
  813. if wuo.mutation.StatusCleared() {
  814. _spec.ClearField(wx.FieldStatus, field.TypeUint8)
  815. }
  816. if value, ok := wuo.mutation.DeletedAt(); ok {
  817. _spec.SetField(wx.FieldDeletedAt, field.TypeTime, value)
  818. }
  819. if wuo.mutation.DeletedAtCleared() {
  820. _spec.ClearField(wx.FieldDeletedAt, field.TypeTime)
  821. }
  822. if value, ok := wuo.mutation.Port(); ok {
  823. _spec.SetField(wx.FieldPort, field.TypeString, value)
  824. }
  825. if value, ok := wuo.mutation.ProcessID(); ok {
  826. _spec.SetField(wx.FieldProcessID, field.TypeString, value)
  827. }
  828. if value, ok := wuo.mutation.Callback(); ok {
  829. _spec.SetField(wx.FieldCallback, field.TypeString, value)
  830. }
  831. if value, ok := wuo.mutation.Wxid(); ok {
  832. _spec.SetField(wx.FieldWxid, field.TypeString, value)
  833. }
  834. if value, ok := wuo.mutation.Account(); ok {
  835. _spec.SetField(wx.FieldAccount, field.TypeString, value)
  836. }
  837. if value, ok := wuo.mutation.Nickname(); ok {
  838. _spec.SetField(wx.FieldNickname, field.TypeString, value)
  839. }
  840. if value, ok := wuo.mutation.Tel(); ok {
  841. _spec.SetField(wx.FieldTel, field.TypeString, value)
  842. }
  843. if value, ok := wuo.mutation.HeadBig(); ok {
  844. _spec.SetField(wx.FieldHeadBig, field.TypeString, value)
  845. }
  846. if value, ok := wuo.mutation.OrganizationID(); ok {
  847. _spec.SetField(wx.FieldOrganizationID, field.TypeUint64, value)
  848. }
  849. if value, ok := wuo.mutation.AddedOrganizationID(); ok {
  850. _spec.AddField(wx.FieldOrganizationID, field.TypeUint64, value)
  851. }
  852. if wuo.mutation.OrganizationIDCleared() {
  853. _spec.ClearField(wx.FieldOrganizationID, field.TypeUint64)
  854. }
  855. if value, ok := wuo.mutation.APIBase(); ok {
  856. _spec.SetField(wx.FieldAPIBase, field.TypeString, value)
  857. }
  858. if wuo.mutation.APIBaseCleared() {
  859. _spec.ClearField(wx.FieldAPIBase, field.TypeString)
  860. }
  861. if value, ok := wuo.mutation.APIKey(); ok {
  862. _spec.SetField(wx.FieldAPIKey, field.TypeString, value)
  863. }
  864. if wuo.mutation.APIKeyCleared() {
  865. _spec.ClearField(wx.FieldAPIKey, field.TypeString)
  866. }
  867. if wuo.mutation.ServerCleared() {
  868. edge := &sqlgraph.EdgeSpec{
  869. Rel: sqlgraph.M2O,
  870. Inverse: true,
  871. Table: wx.ServerTable,
  872. Columns: []string{wx.ServerColumn},
  873. Bidi: false,
  874. Target: &sqlgraph.EdgeTarget{
  875. IDSpec: sqlgraph.NewFieldSpec(server.FieldID, field.TypeUint64),
  876. },
  877. }
  878. _spec.Edges.Clear = append(_spec.Edges.Clear, edge)
  879. }
  880. if nodes := wuo.mutation.ServerIDs(); len(nodes) > 0 {
  881. edge := &sqlgraph.EdgeSpec{
  882. Rel: sqlgraph.M2O,
  883. Inverse: true,
  884. Table: wx.ServerTable,
  885. Columns: []string{wx.ServerColumn},
  886. Bidi: false,
  887. Target: &sqlgraph.EdgeTarget{
  888. IDSpec: sqlgraph.NewFieldSpec(server.FieldID, field.TypeUint64),
  889. },
  890. }
  891. for _, k := range nodes {
  892. edge.Target.Nodes = append(edge.Target.Nodes, k)
  893. }
  894. _spec.Edges.Add = append(_spec.Edges.Add, edge)
  895. }
  896. if wuo.mutation.AgentCleared() {
  897. edge := &sqlgraph.EdgeSpec{
  898. Rel: sqlgraph.M2O,
  899. Inverse: true,
  900. Table: wx.AgentTable,
  901. Columns: []string{wx.AgentColumn},
  902. Bidi: false,
  903. Target: &sqlgraph.EdgeTarget{
  904. IDSpec: sqlgraph.NewFieldSpec(agent.FieldID, field.TypeUint64),
  905. },
  906. }
  907. _spec.Edges.Clear = append(_spec.Edges.Clear, edge)
  908. }
  909. if nodes := wuo.mutation.AgentIDs(); len(nodes) > 0 {
  910. edge := &sqlgraph.EdgeSpec{
  911. Rel: sqlgraph.M2O,
  912. Inverse: true,
  913. Table: wx.AgentTable,
  914. Columns: []string{wx.AgentColumn},
  915. Bidi: false,
  916. Target: &sqlgraph.EdgeTarget{
  917. IDSpec: sqlgraph.NewFieldSpec(agent.FieldID, field.TypeUint64),
  918. },
  919. }
  920. for _, k := range nodes {
  921. edge.Target.Nodes = append(edge.Target.Nodes, k)
  922. }
  923. _spec.Edges.Add = append(_spec.Edges.Add, edge)
  924. }
  925. _node = &Wx{config: wuo.config}
  926. _spec.Assign = _node.assignValues
  927. _spec.ScanValues = _node.scanValues
  928. if err = sqlgraph.UpdateNode(ctx, wuo.driver, _spec); err != nil {
  929. if _, ok := err.(*sqlgraph.NotFoundError); ok {
  930. err = &NotFoundError{wx.Label}
  931. } else if sqlgraph.IsConstraintError(err) {
  932. err = &ConstraintError{msg: err.Error(), wrap: err}
  933. }
  934. return nil, err
  935. }
  936. wuo.mutation.done = true
  937. return _node, nil
  938. }