wx_update.go 34 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281
  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/dialect/sql/sqljson"
  15. "entgo.io/ent/schema/field"
  16. )
  17. // WxUpdate is the builder for updating Wx entities.
  18. type WxUpdate struct {
  19. config
  20. hooks []Hook
  21. mutation *WxMutation
  22. }
  23. // Where appends a list predicates to the WxUpdate builder.
  24. func (wu *WxUpdate) Where(ps ...predicate.Wx) *WxUpdate {
  25. wu.mutation.Where(ps...)
  26. return wu
  27. }
  28. // SetUpdatedAt sets the "updated_at" field.
  29. func (wu *WxUpdate) SetUpdatedAt(t time.Time) *WxUpdate {
  30. wu.mutation.SetUpdatedAt(t)
  31. return wu
  32. }
  33. // SetStatus sets the "status" field.
  34. func (wu *WxUpdate) SetStatus(u uint8) *WxUpdate {
  35. wu.mutation.ResetStatus()
  36. wu.mutation.SetStatus(u)
  37. return wu
  38. }
  39. // SetNillableStatus sets the "status" field if the given value is not nil.
  40. func (wu *WxUpdate) SetNillableStatus(u *uint8) *WxUpdate {
  41. if u != nil {
  42. wu.SetStatus(*u)
  43. }
  44. return wu
  45. }
  46. // AddStatus adds u to the "status" field.
  47. func (wu *WxUpdate) AddStatus(u int8) *WxUpdate {
  48. wu.mutation.AddStatus(u)
  49. return wu
  50. }
  51. // ClearStatus clears the value of the "status" field.
  52. func (wu *WxUpdate) ClearStatus() *WxUpdate {
  53. wu.mutation.ClearStatus()
  54. return wu
  55. }
  56. // SetDeletedAt sets the "deleted_at" field.
  57. func (wu *WxUpdate) SetDeletedAt(t time.Time) *WxUpdate {
  58. wu.mutation.SetDeletedAt(t)
  59. return wu
  60. }
  61. // SetNillableDeletedAt sets the "deleted_at" field if the given value is not nil.
  62. func (wu *WxUpdate) SetNillableDeletedAt(t *time.Time) *WxUpdate {
  63. if t != nil {
  64. wu.SetDeletedAt(*t)
  65. }
  66. return wu
  67. }
  68. // ClearDeletedAt clears the value of the "deleted_at" field.
  69. func (wu *WxUpdate) ClearDeletedAt() *WxUpdate {
  70. wu.mutation.ClearDeletedAt()
  71. return wu
  72. }
  73. // SetServerID sets the "server_id" field.
  74. func (wu *WxUpdate) SetServerID(u uint64) *WxUpdate {
  75. wu.mutation.SetServerID(u)
  76. return wu
  77. }
  78. // SetNillableServerID sets the "server_id" field if the given value is not nil.
  79. func (wu *WxUpdate) SetNillableServerID(u *uint64) *WxUpdate {
  80. if u != nil {
  81. wu.SetServerID(*u)
  82. }
  83. return wu
  84. }
  85. // ClearServerID clears the value of the "server_id" field.
  86. func (wu *WxUpdate) ClearServerID() *WxUpdate {
  87. wu.mutation.ClearServerID()
  88. return wu
  89. }
  90. // SetPort sets the "port" field.
  91. func (wu *WxUpdate) SetPort(s string) *WxUpdate {
  92. wu.mutation.SetPort(s)
  93. return wu
  94. }
  95. // SetNillablePort sets the "port" field if the given value is not nil.
  96. func (wu *WxUpdate) SetNillablePort(s *string) *WxUpdate {
  97. if s != nil {
  98. wu.SetPort(*s)
  99. }
  100. return wu
  101. }
  102. // SetProcessID sets the "process_id" field.
  103. func (wu *WxUpdate) SetProcessID(s string) *WxUpdate {
  104. wu.mutation.SetProcessID(s)
  105. return wu
  106. }
  107. // SetNillableProcessID sets the "process_id" field if the given value is not nil.
  108. func (wu *WxUpdate) SetNillableProcessID(s *string) *WxUpdate {
  109. if s != nil {
  110. wu.SetProcessID(*s)
  111. }
  112. return wu
  113. }
  114. // SetCallback sets the "callback" field.
  115. func (wu *WxUpdate) SetCallback(s string) *WxUpdate {
  116. wu.mutation.SetCallback(s)
  117. return wu
  118. }
  119. // SetNillableCallback sets the "callback" field if the given value is not nil.
  120. func (wu *WxUpdate) SetNillableCallback(s *string) *WxUpdate {
  121. if s != nil {
  122. wu.SetCallback(*s)
  123. }
  124. return wu
  125. }
  126. // SetWxid sets the "wxid" field.
  127. func (wu *WxUpdate) SetWxid(s string) *WxUpdate {
  128. wu.mutation.SetWxid(s)
  129. return wu
  130. }
  131. // SetNillableWxid sets the "wxid" field if the given value is not nil.
  132. func (wu *WxUpdate) SetNillableWxid(s *string) *WxUpdate {
  133. if s != nil {
  134. wu.SetWxid(*s)
  135. }
  136. return wu
  137. }
  138. // SetAccount sets the "account" field.
  139. func (wu *WxUpdate) SetAccount(s string) *WxUpdate {
  140. wu.mutation.SetAccount(s)
  141. return wu
  142. }
  143. // SetNillableAccount sets the "account" field if the given value is not nil.
  144. func (wu *WxUpdate) SetNillableAccount(s *string) *WxUpdate {
  145. if s != nil {
  146. wu.SetAccount(*s)
  147. }
  148. return wu
  149. }
  150. // SetNickname sets the "nickname" field.
  151. func (wu *WxUpdate) SetNickname(s string) *WxUpdate {
  152. wu.mutation.SetNickname(s)
  153. return wu
  154. }
  155. // SetNillableNickname sets the "nickname" field if the given value is not nil.
  156. func (wu *WxUpdate) SetNillableNickname(s *string) *WxUpdate {
  157. if s != nil {
  158. wu.SetNickname(*s)
  159. }
  160. return wu
  161. }
  162. // SetTel sets the "tel" field.
  163. func (wu *WxUpdate) SetTel(s string) *WxUpdate {
  164. wu.mutation.SetTel(s)
  165. return wu
  166. }
  167. // SetNillableTel sets the "tel" field if the given value is not nil.
  168. func (wu *WxUpdate) SetNillableTel(s *string) *WxUpdate {
  169. if s != nil {
  170. wu.SetTel(*s)
  171. }
  172. return wu
  173. }
  174. // SetHeadBig sets the "head_big" field.
  175. func (wu *WxUpdate) SetHeadBig(s string) *WxUpdate {
  176. wu.mutation.SetHeadBig(s)
  177. return wu
  178. }
  179. // SetNillableHeadBig sets the "head_big" field if the given value is not nil.
  180. func (wu *WxUpdate) SetNillableHeadBig(s *string) *WxUpdate {
  181. if s != nil {
  182. wu.SetHeadBig(*s)
  183. }
  184. return wu
  185. }
  186. // SetOrganizationID sets the "organization_id" field.
  187. func (wu *WxUpdate) SetOrganizationID(u uint64) *WxUpdate {
  188. wu.mutation.ResetOrganizationID()
  189. wu.mutation.SetOrganizationID(u)
  190. return wu
  191. }
  192. // SetNillableOrganizationID sets the "organization_id" field if the given value is not nil.
  193. func (wu *WxUpdate) SetNillableOrganizationID(u *uint64) *WxUpdate {
  194. if u != nil {
  195. wu.SetOrganizationID(*u)
  196. }
  197. return wu
  198. }
  199. // AddOrganizationID adds u to the "organization_id" field.
  200. func (wu *WxUpdate) AddOrganizationID(u int64) *WxUpdate {
  201. wu.mutation.AddOrganizationID(u)
  202. return wu
  203. }
  204. // ClearOrganizationID clears the value of the "organization_id" field.
  205. func (wu *WxUpdate) ClearOrganizationID() *WxUpdate {
  206. wu.mutation.ClearOrganizationID()
  207. return wu
  208. }
  209. // SetAgentID sets the "agent_id" field.
  210. func (wu *WxUpdate) SetAgentID(u uint64) *WxUpdate {
  211. wu.mutation.SetAgentID(u)
  212. return wu
  213. }
  214. // SetNillableAgentID sets the "agent_id" field if the given value is not nil.
  215. func (wu *WxUpdate) SetNillableAgentID(u *uint64) *WxUpdate {
  216. if u != nil {
  217. wu.SetAgentID(*u)
  218. }
  219. return wu
  220. }
  221. // SetAPIBase sets the "api_base" field.
  222. func (wu *WxUpdate) SetAPIBase(s string) *WxUpdate {
  223. wu.mutation.SetAPIBase(s)
  224. return wu
  225. }
  226. // SetNillableAPIBase sets the "api_base" field if the given value is not nil.
  227. func (wu *WxUpdate) SetNillableAPIBase(s *string) *WxUpdate {
  228. if s != nil {
  229. wu.SetAPIBase(*s)
  230. }
  231. return wu
  232. }
  233. // ClearAPIBase clears the value of the "api_base" field.
  234. func (wu *WxUpdate) ClearAPIBase() *WxUpdate {
  235. wu.mutation.ClearAPIBase()
  236. return wu
  237. }
  238. // SetAPIKey sets the "api_key" field.
  239. func (wu *WxUpdate) SetAPIKey(s string) *WxUpdate {
  240. wu.mutation.SetAPIKey(s)
  241. return wu
  242. }
  243. // SetNillableAPIKey sets the "api_key" field if the given value is not nil.
  244. func (wu *WxUpdate) SetNillableAPIKey(s *string) *WxUpdate {
  245. if s != nil {
  246. wu.SetAPIKey(*s)
  247. }
  248. return wu
  249. }
  250. // ClearAPIKey clears the value of the "api_key" field.
  251. func (wu *WxUpdate) ClearAPIKey() *WxUpdate {
  252. wu.mutation.ClearAPIKey()
  253. return wu
  254. }
  255. // SetAllowList sets the "allow_list" field.
  256. func (wu *WxUpdate) SetAllowList(s []string) *WxUpdate {
  257. wu.mutation.SetAllowList(s)
  258. return wu
  259. }
  260. // AppendAllowList appends s to the "allow_list" field.
  261. func (wu *WxUpdate) AppendAllowList(s []string) *WxUpdate {
  262. wu.mutation.AppendAllowList(s)
  263. return wu
  264. }
  265. // SetGroupAllowList sets the "group_allow_list" field.
  266. func (wu *WxUpdate) SetGroupAllowList(s []string) *WxUpdate {
  267. wu.mutation.SetGroupAllowList(s)
  268. return wu
  269. }
  270. // AppendGroupAllowList appends s to the "group_allow_list" field.
  271. func (wu *WxUpdate) AppendGroupAllowList(s []string) *WxUpdate {
  272. wu.mutation.AppendGroupAllowList(s)
  273. return wu
  274. }
  275. // SetBlockList sets the "block_list" field.
  276. func (wu *WxUpdate) SetBlockList(s []string) *WxUpdate {
  277. wu.mutation.SetBlockList(s)
  278. return wu
  279. }
  280. // AppendBlockList appends s to the "block_list" field.
  281. func (wu *WxUpdate) AppendBlockList(s []string) *WxUpdate {
  282. wu.mutation.AppendBlockList(s)
  283. return wu
  284. }
  285. // SetGroupBlockList sets the "group_block_list" field.
  286. func (wu *WxUpdate) SetGroupBlockList(s []string) *WxUpdate {
  287. wu.mutation.SetGroupBlockList(s)
  288. return wu
  289. }
  290. // AppendGroupBlockList appends s to the "group_block_list" field.
  291. func (wu *WxUpdate) AppendGroupBlockList(s []string) *WxUpdate {
  292. wu.mutation.AppendGroupBlockList(s)
  293. return wu
  294. }
  295. // SetCtype sets the "ctype" field.
  296. func (wu *WxUpdate) SetCtype(u uint64) *WxUpdate {
  297. wu.mutation.ResetCtype()
  298. wu.mutation.SetCtype(u)
  299. return wu
  300. }
  301. // SetNillableCtype sets the "ctype" field if the given value is not nil.
  302. func (wu *WxUpdate) SetNillableCtype(u *uint64) *WxUpdate {
  303. if u != nil {
  304. wu.SetCtype(*u)
  305. }
  306. return wu
  307. }
  308. // AddCtype adds u to the "ctype" field.
  309. func (wu *WxUpdate) AddCtype(u int64) *WxUpdate {
  310. wu.mutation.AddCtype(u)
  311. return wu
  312. }
  313. // ClearCtype clears the value of the "ctype" field.
  314. func (wu *WxUpdate) ClearCtype() *WxUpdate {
  315. wu.mutation.ClearCtype()
  316. return wu
  317. }
  318. // SetServer sets the "server" edge to the Server entity.
  319. func (wu *WxUpdate) SetServer(s *Server) *WxUpdate {
  320. return wu.SetServerID(s.ID)
  321. }
  322. // SetAgent sets the "agent" edge to the Agent entity.
  323. func (wu *WxUpdate) SetAgent(a *Agent) *WxUpdate {
  324. return wu.SetAgentID(a.ID)
  325. }
  326. // Mutation returns the WxMutation object of the builder.
  327. func (wu *WxUpdate) Mutation() *WxMutation {
  328. return wu.mutation
  329. }
  330. // ClearServer clears the "server" edge to the Server entity.
  331. func (wu *WxUpdate) ClearServer() *WxUpdate {
  332. wu.mutation.ClearServer()
  333. return wu
  334. }
  335. // ClearAgent clears the "agent" edge to the Agent entity.
  336. func (wu *WxUpdate) ClearAgent() *WxUpdate {
  337. wu.mutation.ClearAgent()
  338. return wu
  339. }
  340. // Save executes the query and returns the number of nodes affected by the update operation.
  341. func (wu *WxUpdate) Save(ctx context.Context) (int, error) {
  342. if err := wu.defaults(); err != nil {
  343. return 0, err
  344. }
  345. return withHooks(ctx, wu.sqlSave, wu.mutation, wu.hooks)
  346. }
  347. // SaveX is like Save, but panics if an error occurs.
  348. func (wu *WxUpdate) SaveX(ctx context.Context) int {
  349. affected, err := wu.Save(ctx)
  350. if err != nil {
  351. panic(err)
  352. }
  353. return affected
  354. }
  355. // Exec executes the query.
  356. func (wu *WxUpdate) Exec(ctx context.Context) error {
  357. _, err := wu.Save(ctx)
  358. return err
  359. }
  360. // ExecX is like Exec, but panics if an error occurs.
  361. func (wu *WxUpdate) ExecX(ctx context.Context) {
  362. if err := wu.Exec(ctx); err != nil {
  363. panic(err)
  364. }
  365. }
  366. // defaults sets the default values of the builder before save.
  367. func (wu *WxUpdate) defaults() error {
  368. if _, ok := wu.mutation.UpdatedAt(); !ok {
  369. if wx.UpdateDefaultUpdatedAt == nil {
  370. return fmt.Errorf("ent: uninitialized wx.UpdateDefaultUpdatedAt (forgotten import ent/runtime?)")
  371. }
  372. v := wx.UpdateDefaultUpdatedAt()
  373. wu.mutation.SetUpdatedAt(v)
  374. }
  375. return nil
  376. }
  377. // check runs all checks and user-defined validators on the builder.
  378. func (wu *WxUpdate) check() error {
  379. if _, ok := wu.mutation.AgentID(); wu.mutation.AgentCleared() && !ok {
  380. return errors.New(`ent: clearing a required unique edge "Wx.agent"`)
  381. }
  382. return nil
  383. }
  384. func (wu *WxUpdate) sqlSave(ctx context.Context) (n int, err error) {
  385. if err := wu.check(); err != nil {
  386. return n, err
  387. }
  388. _spec := sqlgraph.NewUpdateSpec(wx.Table, wx.Columns, sqlgraph.NewFieldSpec(wx.FieldID, field.TypeUint64))
  389. if ps := wu.mutation.predicates; len(ps) > 0 {
  390. _spec.Predicate = func(selector *sql.Selector) {
  391. for i := range ps {
  392. ps[i](selector)
  393. }
  394. }
  395. }
  396. if value, ok := wu.mutation.UpdatedAt(); ok {
  397. _spec.SetField(wx.FieldUpdatedAt, field.TypeTime, value)
  398. }
  399. if value, ok := wu.mutation.Status(); ok {
  400. _spec.SetField(wx.FieldStatus, field.TypeUint8, value)
  401. }
  402. if value, ok := wu.mutation.AddedStatus(); ok {
  403. _spec.AddField(wx.FieldStatus, field.TypeUint8, value)
  404. }
  405. if wu.mutation.StatusCleared() {
  406. _spec.ClearField(wx.FieldStatus, field.TypeUint8)
  407. }
  408. if value, ok := wu.mutation.DeletedAt(); ok {
  409. _spec.SetField(wx.FieldDeletedAt, field.TypeTime, value)
  410. }
  411. if wu.mutation.DeletedAtCleared() {
  412. _spec.ClearField(wx.FieldDeletedAt, field.TypeTime)
  413. }
  414. if value, ok := wu.mutation.Port(); ok {
  415. _spec.SetField(wx.FieldPort, field.TypeString, value)
  416. }
  417. if value, ok := wu.mutation.ProcessID(); ok {
  418. _spec.SetField(wx.FieldProcessID, field.TypeString, value)
  419. }
  420. if value, ok := wu.mutation.Callback(); ok {
  421. _spec.SetField(wx.FieldCallback, field.TypeString, value)
  422. }
  423. if value, ok := wu.mutation.Wxid(); ok {
  424. _spec.SetField(wx.FieldWxid, field.TypeString, value)
  425. }
  426. if value, ok := wu.mutation.Account(); ok {
  427. _spec.SetField(wx.FieldAccount, field.TypeString, value)
  428. }
  429. if value, ok := wu.mutation.Nickname(); ok {
  430. _spec.SetField(wx.FieldNickname, field.TypeString, value)
  431. }
  432. if value, ok := wu.mutation.Tel(); ok {
  433. _spec.SetField(wx.FieldTel, field.TypeString, value)
  434. }
  435. if value, ok := wu.mutation.HeadBig(); ok {
  436. _spec.SetField(wx.FieldHeadBig, field.TypeString, value)
  437. }
  438. if value, ok := wu.mutation.OrganizationID(); ok {
  439. _spec.SetField(wx.FieldOrganizationID, field.TypeUint64, value)
  440. }
  441. if value, ok := wu.mutation.AddedOrganizationID(); ok {
  442. _spec.AddField(wx.FieldOrganizationID, field.TypeUint64, value)
  443. }
  444. if wu.mutation.OrganizationIDCleared() {
  445. _spec.ClearField(wx.FieldOrganizationID, field.TypeUint64)
  446. }
  447. if value, ok := wu.mutation.APIBase(); ok {
  448. _spec.SetField(wx.FieldAPIBase, field.TypeString, value)
  449. }
  450. if wu.mutation.APIBaseCleared() {
  451. _spec.ClearField(wx.FieldAPIBase, field.TypeString)
  452. }
  453. if value, ok := wu.mutation.APIKey(); ok {
  454. _spec.SetField(wx.FieldAPIKey, field.TypeString, value)
  455. }
  456. if wu.mutation.APIKeyCleared() {
  457. _spec.ClearField(wx.FieldAPIKey, field.TypeString)
  458. }
  459. if value, ok := wu.mutation.AllowList(); ok {
  460. _spec.SetField(wx.FieldAllowList, field.TypeJSON, value)
  461. }
  462. if value, ok := wu.mutation.AppendedAllowList(); ok {
  463. _spec.AddModifier(func(u *sql.UpdateBuilder) {
  464. sqljson.Append(u, wx.FieldAllowList, value)
  465. })
  466. }
  467. if value, ok := wu.mutation.GroupAllowList(); ok {
  468. _spec.SetField(wx.FieldGroupAllowList, field.TypeJSON, value)
  469. }
  470. if value, ok := wu.mutation.AppendedGroupAllowList(); ok {
  471. _spec.AddModifier(func(u *sql.UpdateBuilder) {
  472. sqljson.Append(u, wx.FieldGroupAllowList, value)
  473. })
  474. }
  475. if value, ok := wu.mutation.BlockList(); ok {
  476. _spec.SetField(wx.FieldBlockList, field.TypeJSON, value)
  477. }
  478. if value, ok := wu.mutation.AppendedBlockList(); ok {
  479. _spec.AddModifier(func(u *sql.UpdateBuilder) {
  480. sqljson.Append(u, wx.FieldBlockList, value)
  481. })
  482. }
  483. if value, ok := wu.mutation.GroupBlockList(); ok {
  484. _spec.SetField(wx.FieldGroupBlockList, field.TypeJSON, value)
  485. }
  486. if value, ok := wu.mutation.AppendedGroupBlockList(); ok {
  487. _spec.AddModifier(func(u *sql.UpdateBuilder) {
  488. sqljson.Append(u, wx.FieldGroupBlockList, value)
  489. })
  490. }
  491. if value, ok := wu.mutation.Ctype(); ok {
  492. _spec.SetField(wx.FieldCtype, field.TypeUint64, value)
  493. }
  494. if value, ok := wu.mutation.AddedCtype(); ok {
  495. _spec.AddField(wx.FieldCtype, field.TypeUint64, value)
  496. }
  497. if wu.mutation.CtypeCleared() {
  498. _spec.ClearField(wx.FieldCtype, field.TypeUint64)
  499. }
  500. if wu.mutation.ServerCleared() {
  501. edge := &sqlgraph.EdgeSpec{
  502. Rel: sqlgraph.M2O,
  503. Inverse: true,
  504. Table: wx.ServerTable,
  505. Columns: []string{wx.ServerColumn},
  506. Bidi: false,
  507. Target: &sqlgraph.EdgeTarget{
  508. IDSpec: sqlgraph.NewFieldSpec(server.FieldID, field.TypeUint64),
  509. },
  510. }
  511. _spec.Edges.Clear = append(_spec.Edges.Clear, edge)
  512. }
  513. if nodes := wu.mutation.ServerIDs(); len(nodes) > 0 {
  514. edge := &sqlgraph.EdgeSpec{
  515. Rel: sqlgraph.M2O,
  516. Inverse: true,
  517. Table: wx.ServerTable,
  518. Columns: []string{wx.ServerColumn},
  519. Bidi: false,
  520. Target: &sqlgraph.EdgeTarget{
  521. IDSpec: sqlgraph.NewFieldSpec(server.FieldID, field.TypeUint64),
  522. },
  523. }
  524. for _, k := range nodes {
  525. edge.Target.Nodes = append(edge.Target.Nodes, k)
  526. }
  527. _spec.Edges.Add = append(_spec.Edges.Add, edge)
  528. }
  529. if wu.mutation.AgentCleared() {
  530. edge := &sqlgraph.EdgeSpec{
  531. Rel: sqlgraph.M2O,
  532. Inverse: true,
  533. Table: wx.AgentTable,
  534. Columns: []string{wx.AgentColumn},
  535. Bidi: false,
  536. Target: &sqlgraph.EdgeTarget{
  537. IDSpec: sqlgraph.NewFieldSpec(agent.FieldID, field.TypeUint64),
  538. },
  539. }
  540. _spec.Edges.Clear = append(_spec.Edges.Clear, edge)
  541. }
  542. if nodes := wu.mutation.AgentIDs(); len(nodes) > 0 {
  543. edge := &sqlgraph.EdgeSpec{
  544. Rel: sqlgraph.M2O,
  545. Inverse: true,
  546. Table: wx.AgentTable,
  547. Columns: []string{wx.AgentColumn},
  548. Bidi: false,
  549. Target: &sqlgraph.EdgeTarget{
  550. IDSpec: sqlgraph.NewFieldSpec(agent.FieldID, field.TypeUint64),
  551. },
  552. }
  553. for _, k := range nodes {
  554. edge.Target.Nodes = append(edge.Target.Nodes, k)
  555. }
  556. _spec.Edges.Add = append(_spec.Edges.Add, edge)
  557. }
  558. if n, err = sqlgraph.UpdateNodes(ctx, wu.driver, _spec); err != nil {
  559. if _, ok := err.(*sqlgraph.NotFoundError); ok {
  560. err = &NotFoundError{wx.Label}
  561. } else if sqlgraph.IsConstraintError(err) {
  562. err = &ConstraintError{msg: err.Error(), wrap: err}
  563. }
  564. return 0, err
  565. }
  566. wu.mutation.done = true
  567. return n, nil
  568. }
  569. // WxUpdateOne is the builder for updating a single Wx entity.
  570. type WxUpdateOne struct {
  571. config
  572. fields []string
  573. hooks []Hook
  574. mutation *WxMutation
  575. }
  576. // SetUpdatedAt sets the "updated_at" field.
  577. func (wuo *WxUpdateOne) SetUpdatedAt(t time.Time) *WxUpdateOne {
  578. wuo.mutation.SetUpdatedAt(t)
  579. return wuo
  580. }
  581. // SetStatus sets the "status" field.
  582. func (wuo *WxUpdateOne) SetStatus(u uint8) *WxUpdateOne {
  583. wuo.mutation.ResetStatus()
  584. wuo.mutation.SetStatus(u)
  585. return wuo
  586. }
  587. // SetNillableStatus sets the "status" field if the given value is not nil.
  588. func (wuo *WxUpdateOne) SetNillableStatus(u *uint8) *WxUpdateOne {
  589. if u != nil {
  590. wuo.SetStatus(*u)
  591. }
  592. return wuo
  593. }
  594. // AddStatus adds u to the "status" field.
  595. func (wuo *WxUpdateOne) AddStatus(u int8) *WxUpdateOne {
  596. wuo.mutation.AddStatus(u)
  597. return wuo
  598. }
  599. // ClearStatus clears the value of the "status" field.
  600. func (wuo *WxUpdateOne) ClearStatus() *WxUpdateOne {
  601. wuo.mutation.ClearStatus()
  602. return wuo
  603. }
  604. // SetDeletedAt sets the "deleted_at" field.
  605. func (wuo *WxUpdateOne) SetDeletedAt(t time.Time) *WxUpdateOne {
  606. wuo.mutation.SetDeletedAt(t)
  607. return wuo
  608. }
  609. // SetNillableDeletedAt sets the "deleted_at" field if the given value is not nil.
  610. func (wuo *WxUpdateOne) SetNillableDeletedAt(t *time.Time) *WxUpdateOne {
  611. if t != nil {
  612. wuo.SetDeletedAt(*t)
  613. }
  614. return wuo
  615. }
  616. // ClearDeletedAt clears the value of the "deleted_at" field.
  617. func (wuo *WxUpdateOne) ClearDeletedAt() *WxUpdateOne {
  618. wuo.mutation.ClearDeletedAt()
  619. return wuo
  620. }
  621. // SetServerID sets the "server_id" field.
  622. func (wuo *WxUpdateOne) SetServerID(u uint64) *WxUpdateOne {
  623. wuo.mutation.SetServerID(u)
  624. return wuo
  625. }
  626. // SetNillableServerID sets the "server_id" field if the given value is not nil.
  627. func (wuo *WxUpdateOne) SetNillableServerID(u *uint64) *WxUpdateOne {
  628. if u != nil {
  629. wuo.SetServerID(*u)
  630. }
  631. return wuo
  632. }
  633. // ClearServerID clears the value of the "server_id" field.
  634. func (wuo *WxUpdateOne) ClearServerID() *WxUpdateOne {
  635. wuo.mutation.ClearServerID()
  636. return wuo
  637. }
  638. // SetPort sets the "port" field.
  639. func (wuo *WxUpdateOne) SetPort(s string) *WxUpdateOne {
  640. wuo.mutation.SetPort(s)
  641. return wuo
  642. }
  643. // SetNillablePort sets the "port" field if the given value is not nil.
  644. func (wuo *WxUpdateOne) SetNillablePort(s *string) *WxUpdateOne {
  645. if s != nil {
  646. wuo.SetPort(*s)
  647. }
  648. return wuo
  649. }
  650. // SetProcessID sets the "process_id" field.
  651. func (wuo *WxUpdateOne) SetProcessID(s string) *WxUpdateOne {
  652. wuo.mutation.SetProcessID(s)
  653. return wuo
  654. }
  655. // SetNillableProcessID sets the "process_id" field if the given value is not nil.
  656. func (wuo *WxUpdateOne) SetNillableProcessID(s *string) *WxUpdateOne {
  657. if s != nil {
  658. wuo.SetProcessID(*s)
  659. }
  660. return wuo
  661. }
  662. // SetCallback sets the "callback" field.
  663. func (wuo *WxUpdateOne) SetCallback(s string) *WxUpdateOne {
  664. wuo.mutation.SetCallback(s)
  665. return wuo
  666. }
  667. // SetNillableCallback sets the "callback" field if the given value is not nil.
  668. func (wuo *WxUpdateOne) SetNillableCallback(s *string) *WxUpdateOne {
  669. if s != nil {
  670. wuo.SetCallback(*s)
  671. }
  672. return wuo
  673. }
  674. // SetWxid sets the "wxid" field.
  675. func (wuo *WxUpdateOne) SetWxid(s string) *WxUpdateOne {
  676. wuo.mutation.SetWxid(s)
  677. return wuo
  678. }
  679. // SetNillableWxid sets the "wxid" field if the given value is not nil.
  680. func (wuo *WxUpdateOne) SetNillableWxid(s *string) *WxUpdateOne {
  681. if s != nil {
  682. wuo.SetWxid(*s)
  683. }
  684. return wuo
  685. }
  686. // SetAccount sets the "account" field.
  687. func (wuo *WxUpdateOne) SetAccount(s string) *WxUpdateOne {
  688. wuo.mutation.SetAccount(s)
  689. return wuo
  690. }
  691. // SetNillableAccount sets the "account" field if the given value is not nil.
  692. func (wuo *WxUpdateOne) SetNillableAccount(s *string) *WxUpdateOne {
  693. if s != nil {
  694. wuo.SetAccount(*s)
  695. }
  696. return wuo
  697. }
  698. // SetNickname sets the "nickname" field.
  699. func (wuo *WxUpdateOne) SetNickname(s string) *WxUpdateOne {
  700. wuo.mutation.SetNickname(s)
  701. return wuo
  702. }
  703. // SetNillableNickname sets the "nickname" field if the given value is not nil.
  704. func (wuo *WxUpdateOne) SetNillableNickname(s *string) *WxUpdateOne {
  705. if s != nil {
  706. wuo.SetNickname(*s)
  707. }
  708. return wuo
  709. }
  710. // SetTel sets the "tel" field.
  711. func (wuo *WxUpdateOne) SetTel(s string) *WxUpdateOne {
  712. wuo.mutation.SetTel(s)
  713. return wuo
  714. }
  715. // SetNillableTel sets the "tel" field if the given value is not nil.
  716. func (wuo *WxUpdateOne) SetNillableTel(s *string) *WxUpdateOne {
  717. if s != nil {
  718. wuo.SetTel(*s)
  719. }
  720. return wuo
  721. }
  722. // SetHeadBig sets the "head_big" field.
  723. func (wuo *WxUpdateOne) SetHeadBig(s string) *WxUpdateOne {
  724. wuo.mutation.SetHeadBig(s)
  725. return wuo
  726. }
  727. // SetNillableHeadBig sets the "head_big" field if the given value is not nil.
  728. func (wuo *WxUpdateOne) SetNillableHeadBig(s *string) *WxUpdateOne {
  729. if s != nil {
  730. wuo.SetHeadBig(*s)
  731. }
  732. return wuo
  733. }
  734. // SetOrganizationID sets the "organization_id" field.
  735. func (wuo *WxUpdateOne) SetOrganizationID(u uint64) *WxUpdateOne {
  736. wuo.mutation.ResetOrganizationID()
  737. wuo.mutation.SetOrganizationID(u)
  738. return wuo
  739. }
  740. // SetNillableOrganizationID sets the "organization_id" field if the given value is not nil.
  741. func (wuo *WxUpdateOne) SetNillableOrganizationID(u *uint64) *WxUpdateOne {
  742. if u != nil {
  743. wuo.SetOrganizationID(*u)
  744. }
  745. return wuo
  746. }
  747. // AddOrganizationID adds u to the "organization_id" field.
  748. func (wuo *WxUpdateOne) AddOrganizationID(u int64) *WxUpdateOne {
  749. wuo.mutation.AddOrganizationID(u)
  750. return wuo
  751. }
  752. // ClearOrganizationID clears the value of the "organization_id" field.
  753. func (wuo *WxUpdateOne) ClearOrganizationID() *WxUpdateOne {
  754. wuo.mutation.ClearOrganizationID()
  755. return wuo
  756. }
  757. // SetAgentID sets the "agent_id" field.
  758. func (wuo *WxUpdateOne) SetAgentID(u uint64) *WxUpdateOne {
  759. wuo.mutation.SetAgentID(u)
  760. return wuo
  761. }
  762. // SetNillableAgentID sets the "agent_id" field if the given value is not nil.
  763. func (wuo *WxUpdateOne) SetNillableAgentID(u *uint64) *WxUpdateOne {
  764. if u != nil {
  765. wuo.SetAgentID(*u)
  766. }
  767. return wuo
  768. }
  769. // SetAPIBase sets the "api_base" field.
  770. func (wuo *WxUpdateOne) SetAPIBase(s string) *WxUpdateOne {
  771. wuo.mutation.SetAPIBase(s)
  772. return wuo
  773. }
  774. // SetNillableAPIBase sets the "api_base" field if the given value is not nil.
  775. func (wuo *WxUpdateOne) SetNillableAPIBase(s *string) *WxUpdateOne {
  776. if s != nil {
  777. wuo.SetAPIBase(*s)
  778. }
  779. return wuo
  780. }
  781. // ClearAPIBase clears the value of the "api_base" field.
  782. func (wuo *WxUpdateOne) ClearAPIBase() *WxUpdateOne {
  783. wuo.mutation.ClearAPIBase()
  784. return wuo
  785. }
  786. // SetAPIKey sets the "api_key" field.
  787. func (wuo *WxUpdateOne) SetAPIKey(s string) *WxUpdateOne {
  788. wuo.mutation.SetAPIKey(s)
  789. return wuo
  790. }
  791. // SetNillableAPIKey sets the "api_key" field if the given value is not nil.
  792. func (wuo *WxUpdateOne) SetNillableAPIKey(s *string) *WxUpdateOne {
  793. if s != nil {
  794. wuo.SetAPIKey(*s)
  795. }
  796. return wuo
  797. }
  798. // ClearAPIKey clears the value of the "api_key" field.
  799. func (wuo *WxUpdateOne) ClearAPIKey() *WxUpdateOne {
  800. wuo.mutation.ClearAPIKey()
  801. return wuo
  802. }
  803. // SetAllowList sets the "allow_list" field.
  804. func (wuo *WxUpdateOne) SetAllowList(s []string) *WxUpdateOne {
  805. wuo.mutation.SetAllowList(s)
  806. return wuo
  807. }
  808. // AppendAllowList appends s to the "allow_list" field.
  809. func (wuo *WxUpdateOne) AppendAllowList(s []string) *WxUpdateOne {
  810. wuo.mutation.AppendAllowList(s)
  811. return wuo
  812. }
  813. // SetGroupAllowList sets the "group_allow_list" field.
  814. func (wuo *WxUpdateOne) SetGroupAllowList(s []string) *WxUpdateOne {
  815. wuo.mutation.SetGroupAllowList(s)
  816. return wuo
  817. }
  818. // AppendGroupAllowList appends s to the "group_allow_list" field.
  819. func (wuo *WxUpdateOne) AppendGroupAllowList(s []string) *WxUpdateOne {
  820. wuo.mutation.AppendGroupAllowList(s)
  821. return wuo
  822. }
  823. // SetBlockList sets the "block_list" field.
  824. func (wuo *WxUpdateOne) SetBlockList(s []string) *WxUpdateOne {
  825. wuo.mutation.SetBlockList(s)
  826. return wuo
  827. }
  828. // AppendBlockList appends s to the "block_list" field.
  829. func (wuo *WxUpdateOne) AppendBlockList(s []string) *WxUpdateOne {
  830. wuo.mutation.AppendBlockList(s)
  831. return wuo
  832. }
  833. // SetGroupBlockList sets the "group_block_list" field.
  834. func (wuo *WxUpdateOne) SetGroupBlockList(s []string) *WxUpdateOne {
  835. wuo.mutation.SetGroupBlockList(s)
  836. return wuo
  837. }
  838. // AppendGroupBlockList appends s to the "group_block_list" field.
  839. func (wuo *WxUpdateOne) AppendGroupBlockList(s []string) *WxUpdateOne {
  840. wuo.mutation.AppendGroupBlockList(s)
  841. return wuo
  842. }
  843. // SetCtype sets the "ctype" field.
  844. func (wuo *WxUpdateOne) SetCtype(u uint64) *WxUpdateOne {
  845. wuo.mutation.ResetCtype()
  846. wuo.mutation.SetCtype(u)
  847. return wuo
  848. }
  849. // SetNillableCtype sets the "ctype" field if the given value is not nil.
  850. func (wuo *WxUpdateOne) SetNillableCtype(u *uint64) *WxUpdateOne {
  851. if u != nil {
  852. wuo.SetCtype(*u)
  853. }
  854. return wuo
  855. }
  856. // AddCtype adds u to the "ctype" field.
  857. func (wuo *WxUpdateOne) AddCtype(u int64) *WxUpdateOne {
  858. wuo.mutation.AddCtype(u)
  859. return wuo
  860. }
  861. // ClearCtype clears the value of the "ctype" field.
  862. func (wuo *WxUpdateOne) ClearCtype() *WxUpdateOne {
  863. wuo.mutation.ClearCtype()
  864. return wuo
  865. }
  866. // SetServer sets the "server" edge to the Server entity.
  867. func (wuo *WxUpdateOne) SetServer(s *Server) *WxUpdateOne {
  868. return wuo.SetServerID(s.ID)
  869. }
  870. // SetAgent sets the "agent" edge to the Agent entity.
  871. func (wuo *WxUpdateOne) SetAgent(a *Agent) *WxUpdateOne {
  872. return wuo.SetAgentID(a.ID)
  873. }
  874. // Mutation returns the WxMutation object of the builder.
  875. func (wuo *WxUpdateOne) Mutation() *WxMutation {
  876. return wuo.mutation
  877. }
  878. // ClearServer clears the "server" edge to the Server entity.
  879. func (wuo *WxUpdateOne) ClearServer() *WxUpdateOne {
  880. wuo.mutation.ClearServer()
  881. return wuo
  882. }
  883. // ClearAgent clears the "agent" edge to the Agent entity.
  884. func (wuo *WxUpdateOne) ClearAgent() *WxUpdateOne {
  885. wuo.mutation.ClearAgent()
  886. return wuo
  887. }
  888. // Where appends a list predicates to the WxUpdate builder.
  889. func (wuo *WxUpdateOne) Where(ps ...predicate.Wx) *WxUpdateOne {
  890. wuo.mutation.Where(ps...)
  891. return wuo
  892. }
  893. // Select allows selecting one or more fields (columns) of the returned entity.
  894. // The default is selecting all fields defined in the entity schema.
  895. func (wuo *WxUpdateOne) Select(field string, fields ...string) *WxUpdateOne {
  896. wuo.fields = append([]string{field}, fields...)
  897. return wuo
  898. }
  899. // Save executes the query and returns the updated Wx entity.
  900. func (wuo *WxUpdateOne) Save(ctx context.Context) (*Wx, error) {
  901. if err := wuo.defaults(); err != nil {
  902. return nil, err
  903. }
  904. return withHooks(ctx, wuo.sqlSave, wuo.mutation, wuo.hooks)
  905. }
  906. // SaveX is like Save, but panics if an error occurs.
  907. func (wuo *WxUpdateOne) SaveX(ctx context.Context) *Wx {
  908. node, err := wuo.Save(ctx)
  909. if err != nil {
  910. panic(err)
  911. }
  912. return node
  913. }
  914. // Exec executes the query on the entity.
  915. func (wuo *WxUpdateOne) Exec(ctx context.Context) error {
  916. _, err := wuo.Save(ctx)
  917. return err
  918. }
  919. // ExecX is like Exec, but panics if an error occurs.
  920. func (wuo *WxUpdateOne) ExecX(ctx context.Context) {
  921. if err := wuo.Exec(ctx); err != nil {
  922. panic(err)
  923. }
  924. }
  925. // defaults sets the default values of the builder before save.
  926. func (wuo *WxUpdateOne) defaults() error {
  927. if _, ok := wuo.mutation.UpdatedAt(); !ok {
  928. if wx.UpdateDefaultUpdatedAt == nil {
  929. return fmt.Errorf("ent: uninitialized wx.UpdateDefaultUpdatedAt (forgotten import ent/runtime?)")
  930. }
  931. v := wx.UpdateDefaultUpdatedAt()
  932. wuo.mutation.SetUpdatedAt(v)
  933. }
  934. return nil
  935. }
  936. // check runs all checks and user-defined validators on the builder.
  937. func (wuo *WxUpdateOne) check() error {
  938. if _, ok := wuo.mutation.AgentID(); wuo.mutation.AgentCleared() && !ok {
  939. return errors.New(`ent: clearing a required unique edge "Wx.agent"`)
  940. }
  941. return nil
  942. }
  943. func (wuo *WxUpdateOne) sqlSave(ctx context.Context) (_node *Wx, err error) {
  944. if err := wuo.check(); err != nil {
  945. return _node, err
  946. }
  947. _spec := sqlgraph.NewUpdateSpec(wx.Table, wx.Columns, sqlgraph.NewFieldSpec(wx.FieldID, field.TypeUint64))
  948. id, ok := wuo.mutation.ID()
  949. if !ok {
  950. return nil, &ValidationError{Name: "id", err: errors.New(`ent: missing "Wx.id" for update`)}
  951. }
  952. _spec.Node.ID.Value = id
  953. if fields := wuo.fields; len(fields) > 0 {
  954. _spec.Node.Columns = make([]string, 0, len(fields))
  955. _spec.Node.Columns = append(_spec.Node.Columns, wx.FieldID)
  956. for _, f := range fields {
  957. if !wx.ValidColumn(f) {
  958. return nil, &ValidationError{Name: f, err: fmt.Errorf("ent: invalid field %q for query", f)}
  959. }
  960. if f != wx.FieldID {
  961. _spec.Node.Columns = append(_spec.Node.Columns, f)
  962. }
  963. }
  964. }
  965. if ps := wuo.mutation.predicates; len(ps) > 0 {
  966. _spec.Predicate = func(selector *sql.Selector) {
  967. for i := range ps {
  968. ps[i](selector)
  969. }
  970. }
  971. }
  972. if value, ok := wuo.mutation.UpdatedAt(); ok {
  973. _spec.SetField(wx.FieldUpdatedAt, field.TypeTime, value)
  974. }
  975. if value, ok := wuo.mutation.Status(); ok {
  976. _spec.SetField(wx.FieldStatus, field.TypeUint8, value)
  977. }
  978. if value, ok := wuo.mutation.AddedStatus(); ok {
  979. _spec.AddField(wx.FieldStatus, field.TypeUint8, value)
  980. }
  981. if wuo.mutation.StatusCleared() {
  982. _spec.ClearField(wx.FieldStatus, field.TypeUint8)
  983. }
  984. if value, ok := wuo.mutation.DeletedAt(); ok {
  985. _spec.SetField(wx.FieldDeletedAt, field.TypeTime, value)
  986. }
  987. if wuo.mutation.DeletedAtCleared() {
  988. _spec.ClearField(wx.FieldDeletedAt, field.TypeTime)
  989. }
  990. if value, ok := wuo.mutation.Port(); ok {
  991. _spec.SetField(wx.FieldPort, field.TypeString, value)
  992. }
  993. if value, ok := wuo.mutation.ProcessID(); ok {
  994. _spec.SetField(wx.FieldProcessID, field.TypeString, value)
  995. }
  996. if value, ok := wuo.mutation.Callback(); ok {
  997. _spec.SetField(wx.FieldCallback, field.TypeString, value)
  998. }
  999. if value, ok := wuo.mutation.Wxid(); ok {
  1000. _spec.SetField(wx.FieldWxid, field.TypeString, value)
  1001. }
  1002. if value, ok := wuo.mutation.Account(); ok {
  1003. _spec.SetField(wx.FieldAccount, field.TypeString, value)
  1004. }
  1005. if value, ok := wuo.mutation.Nickname(); ok {
  1006. _spec.SetField(wx.FieldNickname, field.TypeString, value)
  1007. }
  1008. if value, ok := wuo.mutation.Tel(); ok {
  1009. _spec.SetField(wx.FieldTel, field.TypeString, value)
  1010. }
  1011. if value, ok := wuo.mutation.HeadBig(); ok {
  1012. _spec.SetField(wx.FieldHeadBig, field.TypeString, value)
  1013. }
  1014. if value, ok := wuo.mutation.OrganizationID(); ok {
  1015. _spec.SetField(wx.FieldOrganizationID, field.TypeUint64, value)
  1016. }
  1017. if value, ok := wuo.mutation.AddedOrganizationID(); ok {
  1018. _spec.AddField(wx.FieldOrganizationID, field.TypeUint64, value)
  1019. }
  1020. if wuo.mutation.OrganizationIDCleared() {
  1021. _spec.ClearField(wx.FieldOrganizationID, field.TypeUint64)
  1022. }
  1023. if value, ok := wuo.mutation.APIBase(); ok {
  1024. _spec.SetField(wx.FieldAPIBase, field.TypeString, value)
  1025. }
  1026. if wuo.mutation.APIBaseCleared() {
  1027. _spec.ClearField(wx.FieldAPIBase, field.TypeString)
  1028. }
  1029. if value, ok := wuo.mutation.APIKey(); ok {
  1030. _spec.SetField(wx.FieldAPIKey, field.TypeString, value)
  1031. }
  1032. if wuo.mutation.APIKeyCleared() {
  1033. _spec.ClearField(wx.FieldAPIKey, field.TypeString)
  1034. }
  1035. if value, ok := wuo.mutation.AllowList(); ok {
  1036. _spec.SetField(wx.FieldAllowList, field.TypeJSON, value)
  1037. }
  1038. if value, ok := wuo.mutation.AppendedAllowList(); ok {
  1039. _spec.AddModifier(func(u *sql.UpdateBuilder) {
  1040. sqljson.Append(u, wx.FieldAllowList, value)
  1041. })
  1042. }
  1043. if value, ok := wuo.mutation.GroupAllowList(); ok {
  1044. _spec.SetField(wx.FieldGroupAllowList, field.TypeJSON, value)
  1045. }
  1046. if value, ok := wuo.mutation.AppendedGroupAllowList(); ok {
  1047. _spec.AddModifier(func(u *sql.UpdateBuilder) {
  1048. sqljson.Append(u, wx.FieldGroupAllowList, value)
  1049. })
  1050. }
  1051. if value, ok := wuo.mutation.BlockList(); ok {
  1052. _spec.SetField(wx.FieldBlockList, field.TypeJSON, value)
  1053. }
  1054. if value, ok := wuo.mutation.AppendedBlockList(); ok {
  1055. _spec.AddModifier(func(u *sql.UpdateBuilder) {
  1056. sqljson.Append(u, wx.FieldBlockList, value)
  1057. })
  1058. }
  1059. if value, ok := wuo.mutation.GroupBlockList(); ok {
  1060. _spec.SetField(wx.FieldGroupBlockList, field.TypeJSON, value)
  1061. }
  1062. if value, ok := wuo.mutation.AppendedGroupBlockList(); ok {
  1063. _spec.AddModifier(func(u *sql.UpdateBuilder) {
  1064. sqljson.Append(u, wx.FieldGroupBlockList, value)
  1065. })
  1066. }
  1067. if value, ok := wuo.mutation.Ctype(); ok {
  1068. _spec.SetField(wx.FieldCtype, field.TypeUint64, value)
  1069. }
  1070. if value, ok := wuo.mutation.AddedCtype(); ok {
  1071. _spec.AddField(wx.FieldCtype, field.TypeUint64, value)
  1072. }
  1073. if wuo.mutation.CtypeCleared() {
  1074. _spec.ClearField(wx.FieldCtype, field.TypeUint64)
  1075. }
  1076. if wuo.mutation.ServerCleared() {
  1077. edge := &sqlgraph.EdgeSpec{
  1078. Rel: sqlgraph.M2O,
  1079. Inverse: true,
  1080. Table: wx.ServerTable,
  1081. Columns: []string{wx.ServerColumn},
  1082. Bidi: false,
  1083. Target: &sqlgraph.EdgeTarget{
  1084. IDSpec: sqlgraph.NewFieldSpec(server.FieldID, field.TypeUint64),
  1085. },
  1086. }
  1087. _spec.Edges.Clear = append(_spec.Edges.Clear, edge)
  1088. }
  1089. if nodes := wuo.mutation.ServerIDs(); len(nodes) > 0 {
  1090. edge := &sqlgraph.EdgeSpec{
  1091. Rel: sqlgraph.M2O,
  1092. Inverse: true,
  1093. Table: wx.ServerTable,
  1094. Columns: []string{wx.ServerColumn},
  1095. Bidi: false,
  1096. Target: &sqlgraph.EdgeTarget{
  1097. IDSpec: sqlgraph.NewFieldSpec(server.FieldID, field.TypeUint64),
  1098. },
  1099. }
  1100. for _, k := range nodes {
  1101. edge.Target.Nodes = append(edge.Target.Nodes, k)
  1102. }
  1103. _spec.Edges.Add = append(_spec.Edges.Add, edge)
  1104. }
  1105. if wuo.mutation.AgentCleared() {
  1106. edge := &sqlgraph.EdgeSpec{
  1107. Rel: sqlgraph.M2O,
  1108. Inverse: true,
  1109. Table: wx.AgentTable,
  1110. Columns: []string{wx.AgentColumn},
  1111. Bidi: false,
  1112. Target: &sqlgraph.EdgeTarget{
  1113. IDSpec: sqlgraph.NewFieldSpec(agent.FieldID, field.TypeUint64),
  1114. },
  1115. }
  1116. _spec.Edges.Clear = append(_spec.Edges.Clear, edge)
  1117. }
  1118. if nodes := wuo.mutation.AgentIDs(); len(nodes) > 0 {
  1119. edge := &sqlgraph.EdgeSpec{
  1120. Rel: sqlgraph.M2O,
  1121. Inverse: true,
  1122. Table: wx.AgentTable,
  1123. Columns: []string{wx.AgentColumn},
  1124. Bidi: false,
  1125. Target: &sqlgraph.EdgeTarget{
  1126. IDSpec: sqlgraph.NewFieldSpec(agent.FieldID, field.TypeUint64),
  1127. },
  1128. }
  1129. for _, k := range nodes {
  1130. edge.Target.Nodes = append(edge.Target.Nodes, k)
  1131. }
  1132. _spec.Edges.Add = append(_spec.Edges.Add, edge)
  1133. }
  1134. _node = &Wx{config: wuo.config}
  1135. _spec.Assign = _node.assignValues
  1136. _spec.ScanValues = _node.scanValues
  1137. if err = sqlgraph.UpdateNode(ctx, wuo.driver, _spec); err != nil {
  1138. if _, ok := err.(*sqlgraph.NotFoundError); ok {
  1139. err = &NotFoundError{wx.Label}
  1140. } else if sqlgraph.IsConstraintError(err) {
  1141. err = &ConstraintError{msg: err.Error(), wrap: err}
  1142. }
  1143. return nil, err
  1144. }
  1145. wuo.mutation.done = true
  1146. return _node, nil
  1147. }