agent_update.go 49 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685
  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/apikey"
  10. "wechat-api/ent/predicate"
  11. "wechat-api/ent/token"
  12. "wechat-api/ent/whatsapp"
  13. "wechat-api/ent/wx"
  14. "wechat-api/ent/xunjiservice"
  15. "entgo.io/ent/dialect/sql"
  16. "entgo.io/ent/dialect/sql/sqlgraph"
  17. "entgo.io/ent/schema/field"
  18. )
  19. // AgentUpdate is the builder for updating Agent entities.
  20. type AgentUpdate struct {
  21. config
  22. hooks []Hook
  23. mutation *AgentMutation
  24. }
  25. // Where appends a list predicates to the AgentUpdate builder.
  26. func (au *AgentUpdate) Where(ps ...predicate.Agent) *AgentUpdate {
  27. au.mutation.Where(ps...)
  28. return au
  29. }
  30. // SetUpdatedAt sets the "updated_at" field.
  31. func (au *AgentUpdate) SetUpdatedAt(t time.Time) *AgentUpdate {
  32. au.mutation.SetUpdatedAt(t)
  33. return au
  34. }
  35. // SetDeletedAt sets the "deleted_at" field.
  36. func (au *AgentUpdate) SetDeletedAt(t time.Time) *AgentUpdate {
  37. au.mutation.SetDeletedAt(t)
  38. return au
  39. }
  40. // SetNillableDeletedAt sets the "deleted_at" field if the given value is not nil.
  41. func (au *AgentUpdate) SetNillableDeletedAt(t *time.Time) *AgentUpdate {
  42. if t != nil {
  43. au.SetDeletedAt(*t)
  44. }
  45. return au
  46. }
  47. // ClearDeletedAt clears the value of the "deleted_at" field.
  48. func (au *AgentUpdate) ClearDeletedAt() *AgentUpdate {
  49. au.mutation.ClearDeletedAt()
  50. return au
  51. }
  52. // SetName sets the "name" field.
  53. func (au *AgentUpdate) SetName(s string) *AgentUpdate {
  54. au.mutation.SetName(s)
  55. return au
  56. }
  57. // SetNillableName sets the "name" field if the given value is not nil.
  58. func (au *AgentUpdate) SetNillableName(s *string) *AgentUpdate {
  59. if s != nil {
  60. au.SetName(*s)
  61. }
  62. return au
  63. }
  64. // SetRole sets the "role" field.
  65. func (au *AgentUpdate) SetRole(s string) *AgentUpdate {
  66. au.mutation.SetRole(s)
  67. return au
  68. }
  69. // SetNillableRole sets the "role" field if the given value is not nil.
  70. func (au *AgentUpdate) SetNillableRole(s *string) *AgentUpdate {
  71. if s != nil {
  72. au.SetRole(*s)
  73. }
  74. return au
  75. }
  76. // SetStatus sets the "status" field.
  77. func (au *AgentUpdate) SetStatus(i int) *AgentUpdate {
  78. au.mutation.ResetStatus()
  79. au.mutation.SetStatus(i)
  80. return au
  81. }
  82. // SetNillableStatus sets the "status" field if the given value is not nil.
  83. func (au *AgentUpdate) SetNillableStatus(i *int) *AgentUpdate {
  84. if i != nil {
  85. au.SetStatus(*i)
  86. }
  87. return au
  88. }
  89. // AddStatus adds i to the "status" field.
  90. func (au *AgentUpdate) AddStatus(i int) *AgentUpdate {
  91. au.mutation.AddStatus(i)
  92. return au
  93. }
  94. // ClearStatus clears the value of the "status" field.
  95. func (au *AgentUpdate) ClearStatus() *AgentUpdate {
  96. au.mutation.ClearStatus()
  97. return au
  98. }
  99. // SetBackground sets the "background" field.
  100. func (au *AgentUpdate) SetBackground(s string) *AgentUpdate {
  101. au.mutation.SetBackground(s)
  102. return au
  103. }
  104. // SetNillableBackground sets the "background" field if the given value is not nil.
  105. func (au *AgentUpdate) SetNillableBackground(s *string) *AgentUpdate {
  106. if s != nil {
  107. au.SetBackground(*s)
  108. }
  109. return au
  110. }
  111. // ClearBackground clears the value of the "background" field.
  112. func (au *AgentUpdate) ClearBackground() *AgentUpdate {
  113. au.mutation.ClearBackground()
  114. return au
  115. }
  116. // SetExamples sets the "examples" field.
  117. func (au *AgentUpdate) SetExamples(s string) *AgentUpdate {
  118. au.mutation.SetExamples(s)
  119. return au
  120. }
  121. // SetNillableExamples sets the "examples" field if the given value is not nil.
  122. func (au *AgentUpdate) SetNillableExamples(s *string) *AgentUpdate {
  123. if s != nil {
  124. au.SetExamples(*s)
  125. }
  126. return au
  127. }
  128. // ClearExamples clears the value of the "examples" field.
  129. func (au *AgentUpdate) ClearExamples() *AgentUpdate {
  130. au.mutation.ClearExamples()
  131. return au
  132. }
  133. // SetOrganizationID sets the "organization_id" field.
  134. func (au *AgentUpdate) SetOrganizationID(u uint64) *AgentUpdate {
  135. au.mutation.ResetOrganizationID()
  136. au.mutation.SetOrganizationID(u)
  137. return au
  138. }
  139. // SetNillableOrganizationID sets the "organization_id" field if the given value is not nil.
  140. func (au *AgentUpdate) SetNillableOrganizationID(u *uint64) *AgentUpdate {
  141. if u != nil {
  142. au.SetOrganizationID(*u)
  143. }
  144. return au
  145. }
  146. // AddOrganizationID adds u to the "organization_id" field.
  147. func (au *AgentUpdate) AddOrganizationID(u int64) *AgentUpdate {
  148. au.mutation.AddOrganizationID(u)
  149. return au
  150. }
  151. // SetDatasetID sets the "dataset_id" field.
  152. func (au *AgentUpdate) SetDatasetID(s string) *AgentUpdate {
  153. au.mutation.SetDatasetID(s)
  154. return au
  155. }
  156. // SetNillableDatasetID sets the "dataset_id" field if the given value is not nil.
  157. func (au *AgentUpdate) SetNillableDatasetID(s *string) *AgentUpdate {
  158. if s != nil {
  159. au.SetDatasetID(*s)
  160. }
  161. return au
  162. }
  163. // SetCollectionID sets the "collection_id" field.
  164. func (au *AgentUpdate) SetCollectionID(s string) *AgentUpdate {
  165. au.mutation.SetCollectionID(s)
  166. return au
  167. }
  168. // SetNillableCollectionID sets the "collection_id" field if the given value is not nil.
  169. func (au *AgentUpdate) SetNillableCollectionID(s *string) *AgentUpdate {
  170. if s != nil {
  171. au.SetCollectionID(*s)
  172. }
  173. return au
  174. }
  175. // AddWxAgentIDs adds the "wx_agent" edge to the Wx entity by IDs.
  176. func (au *AgentUpdate) AddWxAgentIDs(ids ...uint64) *AgentUpdate {
  177. au.mutation.AddWxAgentIDs(ids...)
  178. return au
  179. }
  180. // AddWxAgent adds the "wx_agent" edges to the Wx entity.
  181. func (au *AgentUpdate) AddWxAgent(w ...*Wx) *AgentUpdate {
  182. ids := make([]uint64, len(w))
  183. for i := range w {
  184. ids[i] = w[i].ID
  185. }
  186. return au.AddWxAgentIDs(ids...)
  187. }
  188. // AddTokenAgentIDs adds the "token_agent" edge to the Token entity by IDs.
  189. func (au *AgentUpdate) AddTokenAgentIDs(ids ...uint64) *AgentUpdate {
  190. au.mutation.AddTokenAgentIDs(ids...)
  191. return au
  192. }
  193. // AddTokenAgent adds the "token_agent" edges to the Token entity.
  194. func (au *AgentUpdate) AddTokenAgent(t ...*Token) *AgentUpdate {
  195. ids := make([]uint64, len(t))
  196. for i := range t {
  197. ids[i] = t[i].ID
  198. }
  199. return au.AddTokenAgentIDs(ids...)
  200. }
  201. // AddWaAgentIDs adds the "wa_agent" edge to the Whatsapp entity by IDs.
  202. func (au *AgentUpdate) AddWaAgentIDs(ids ...uint64) *AgentUpdate {
  203. au.mutation.AddWaAgentIDs(ids...)
  204. return au
  205. }
  206. // AddWaAgent adds the "wa_agent" edges to the Whatsapp entity.
  207. func (au *AgentUpdate) AddWaAgent(w ...*Whatsapp) *AgentUpdate {
  208. ids := make([]uint64, len(w))
  209. for i := range w {
  210. ids[i] = w[i].ID
  211. }
  212. return au.AddWaAgentIDs(ids...)
  213. }
  214. // AddXjsAgentIDs adds the "xjs_agent" edge to the XunjiService entity by IDs.
  215. func (au *AgentUpdate) AddXjsAgentIDs(ids ...uint64) *AgentUpdate {
  216. au.mutation.AddXjsAgentIDs(ids...)
  217. return au
  218. }
  219. // AddXjsAgent adds the "xjs_agent" edges to the XunjiService entity.
  220. func (au *AgentUpdate) AddXjsAgent(x ...*XunjiService) *AgentUpdate {
  221. ids := make([]uint64, len(x))
  222. for i := range x {
  223. ids[i] = x[i].ID
  224. }
  225. return au.AddXjsAgentIDs(ids...)
  226. }
  227. // AddKeyAgentIDs adds the "key_agent" edge to the ApiKey entity by IDs.
  228. func (au *AgentUpdate) AddKeyAgentIDs(ids ...uint64) *AgentUpdate {
  229. au.mutation.AddKeyAgentIDs(ids...)
  230. return au
  231. }
  232. // AddKeyAgent adds the "key_agent" edges to the ApiKey entity.
  233. func (au *AgentUpdate) AddKeyAgent(a ...*ApiKey) *AgentUpdate {
  234. ids := make([]uint64, len(a))
  235. for i := range a {
  236. ids[i] = a[i].ID
  237. }
  238. return au.AddKeyAgentIDs(ids...)
  239. }
  240. // AddXjsAgentIDs adds the "xjs_agent" edge to the XunjiService entity by IDs.
  241. func (au *AgentUpdate) AddXjsAgentIDs(ids ...uint64) *AgentUpdate {
  242. au.mutation.AddXjsAgentIDs(ids...)
  243. return au
  244. }
  245. // AddXjsAgent adds the "xjs_agent" edges to the XunjiService entity.
  246. func (au *AgentUpdate) AddXjsAgent(x ...*XunjiService) *AgentUpdate {
  247. ids := make([]uint64, len(x))
  248. for i := range x {
  249. ids[i] = x[i].ID
  250. }
  251. return au.AddXjsAgentIDs(ids...)
  252. }
  253. // Mutation returns the AgentMutation object of the builder.
  254. func (au *AgentUpdate) Mutation() *AgentMutation {
  255. return au.mutation
  256. }
  257. // ClearWxAgent clears all "wx_agent" edges to the Wx entity.
  258. func (au *AgentUpdate) ClearWxAgent() *AgentUpdate {
  259. au.mutation.ClearWxAgent()
  260. return au
  261. }
  262. // RemoveWxAgentIDs removes the "wx_agent" edge to Wx entities by IDs.
  263. func (au *AgentUpdate) RemoveWxAgentIDs(ids ...uint64) *AgentUpdate {
  264. au.mutation.RemoveWxAgentIDs(ids...)
  265. return au
  266. }
  267. // RemoveWxAgent removes "wx_agent" edges to Wx entities.
  268. func (au *AgentUpdate) RemoveWxAgent(w ...*Wx) *AgentUpdate {
  269. ids := make([]uint64, len(w))
  270. for i := range w {
  271. ids[i] = w[i].ID
  272. }
  273. return au.RemoveWxAgentIDs(ids...)
  274. }
  275. // ClearTokenAgent clears all "token_agent" edges to the Token entity.
  276. func (au *AgentUpdate) ClearTokenAgent() *AgentUpdate {
  277. au.mutation.ClearTokenAgent()
  278. return au
  279. }
  280. // RemoveTokenAgentIDs removes the "token_agent" edge to Token entities by IDs.
  281. func (au *AgentUpdate) RemoveTokenAgentIDs(ids ...uint64) *AgentUpdate {
  282. au.mutation.RemoveTokenAgentIDs(ids...)
  283. return au
  284. }
  285. // RemoveTokenAgent removes "token_agent" edges to Token entities.
  286. func (au *AgentUpdate) RemoveTokenAgent(t ...*Token) *AgentUpdate {
  287. ids := make([]uint64, len(t))
  288. for i := range t {
  289. ids[i] = t[i].ID
  290. }
  291. return au.RemoveTokenAgentIDs(ids...)
  292. }
  293. // ClearWaAgent clears all "wa_agent" edges to the Whatsapp entity.
  294. func (au *AgentUpdate) ClearWaAgent() *AgentUpdate {
  295. au.mutation.ClearWaAgent()
  296. return au
  297. }
  298. // RemoveWaAgentIDs removes the "wa_agent" edge to Whatsapp entities by IDs.
  299. func (au *AgentUpdate) RemoveWaAgentIDs(ids ...uint64) *AgentUpdate {
  300. au.mutation.RemoveWaAgentIDs(ids...)
  301. return au
  302. }
  303. // RemoveWaAgent removes "wa_agent" edges to Whatsapp entities.
  304. func (au *AgentUpdate) RemoveWaAgent(w ...*Whatsapp) *AgentUpdate {
  305. ids := make([]uint64, len(w))
  306. for i := range w {
  307. ids[i] = w[i].ID
  308. }
  309. return au.RemoveWaAgentIDs(ids...)
  310. }
  311. // ClearXjsAgent clears all "xjs_agent" edges to the XunjiService entity.
  312. func (au *AgentUpdate) ClearXjsAgent() *AgentUpdate {
  313. au.mutation.ClearXjsAgent()
  314. return au
  315. }
  316. // RemoveXjsAgentIDs removes the "xjs_agent" edge to XunjiService entities by IDs.
  317. func (au *AgentUpdate) RemoveXjsAgentIDs(ids ...uint64) *AgentUpdate {
  318. au.mutation.RemoveXjsAgentIDs(ids...)
  319. return au
  320. }
  321. // RemoveXjsAgent removes "xjs_agent" edges to XunjiService entities.
  322. func (au *AgentUpdate) RemoveXjsAgent(x ...*XunjiService) *AgentUpdate {
  323. ids := make([]uint64, len(x))
  324. for i := range x {
  325. ids[i] = x[i].ID
  326. }
  327. return au.RemoveXjsAgentIDs(ids...)
  328. }
  329. // ClearKeyAgent clears all "key_agent" edges to the ApiKey entity.
  330. func (au *AgentUpdate) ClearKeyAgent() *AgentUpdate {
  331. au.mutation.ClearKeyAgent()
  332. return au
  333. }
  334. // RemoveKeyAgentIDs removes the "key_agent" edge to ApiKey entities by IDs.
  335. func (au *AgentUpdate) RemoveKeyAgentIDs(ids ...uint64) *AgentUpdate {
  336. au.mutation.RemoveKeyAgentIDs(ids...)
  337. return au
  338. }
  339. // RemoveKeyAgent removes "key_agent" edges to ApiKey entities.
  340. func (au *AgentUpdate) RemoveKeyAgent(a ...*ApiKey) *AgentUpdate {
  341. ids := make([]uint64, len(a))
  342. for i := range a {
  343. ids[i] = a[i].ID
  344. }
  345. return au.RemoveKeyAgentIDs(ids...)
  346. }
  347. // ClearXjsAgent clears all "xjs_agent" edges to the XunjiService entity.
  348. func (au *AgentUpdate) ClearXjsAgent() *AgentUpdate {
  349. au.mutation.ClearXjsAgent()
  350. return au
  351. }
  352. // RemoveXjsAgentIDs removes the "xjs_agent" edge to XunjiService entities by IDs.
  353. func (au *AgentUpdate) RemoveXjsAgentIDs(ids ...uint64) *AgentUpdate {
  354. au.mutation.RemoveXjsAgentIDs(ids...)
  355. return au
  356. }
  357. // RemoveXjsAgent removes "xjs_agent" edges to XunjiService entities.
  358. func (au *AgentUpdate) RemoveXjsAgent(x ...*XunjiService) *AgentUpdate {
  359. ids := make([]uint64, len(x))
  360. for i := range x {
  361. ids[i] = x[i].ID
  362. }
  363. return au.RemoveXjsAgentIDs(ids...)
  364. }
  365. // Save executes the query and returns the number of nodes affected by the update operation.
  366. func (au *AgentUpdate) Save(ctx context.Context) (int, error) {
  367. if err := au.defaults(); err != nil {
  368. return 0, err
  369. }
  370. return withHooks(ctx, au.sqlSave, au.mutation, au.hooks)
  371. }
  372. // SaveX is like Save, but panics if an error occurs.
  373. func (au *AgentUpdate) SaveX(ctx context.Context) int {
  374. affected, err := au.Save(ctx)
  375. if err != nil {
  376. panic(err)
  377. }
  378. return affected
  379. }
  380. // Exec executes the query.
  381. func (au *AgentUpdate) Exec(ctx context.Context) error {
  382. _, err := au.Save(ctx)
  383. return err
  384. }
  385. // ExecX is like Exec, but panics if an error occurs.
  386. func (au *AgentUpdate) ExecX(ctx context.Context) {
  387. if err := au.Exec(ctx); err != nil {
  388. panic(err)
  389. }
  390. }
  391. // defaults sets the default values of the builder before save.
  392. func (au *AgentUpdate) defaults() error {
  393. if _, ok := au.mutation.UpdatedAt(); !ok {
  394. if agent.UpdateDefaultUpdatedAt == nil {
  395. return fmt.Errorf("ent: uninitialized agent.UpdateDefaultUpdatedAt (forgotten import ent/runtime?)")
  396. }
  397. v := agent.UpdateDefaultUpdatedAt()
  398. au.mutation.SetUpdatedAt(v)
  399. }
  400. return nil
  401. }
  402. // check runs all checks and user-defined validators on the builder.
  403. func (au *AgentUpdate) check() error {
  404. if v, ok := au.mutation.Name(); ok {
  405. if err := agent.NameValidator(v); err != nil {
  406. return &ValidationError{Name: "name", err: fmt.Errorf(`ent: validator failed for field "Agent.name": %w`, err)}
  407. }
  408. }
  409. if v, ok := au.mutation.Status(); ok {
  410. if err := agent.StatusValidator(v); err != nil {
  411. return &ValidationError{Name: "status", err: fmt.Errorf(`ent: validator failed for field "Agent.status": %w`, err)}
  412. }
  413. }
  414. if v, ok := au.mutation.OrganizationID(); ok {
  415. if err := agent.OrganizationIDValidator(v); err != nil {
  416. return &ValidationError{Name: "organization_id", err: fmt.Errorf(`ent: validator failed for field "Agent.organization_id": %w`, err)}
  417. }
  418. }
  419. if v, ok := au.mutation.DatasetID(); ok {
  420. if err := agent.DatasetIDValidator(v); err != nil {
  421. return &ValidationError{Name: "dataset_id", err: fmt.Errorf(`ent: validator failed for field "Agent.dataset_id": %w`, err)}
  422. }
  423. }
  424. if v, ok := au.mutation.CollectionID(); ok {
  425. if err := agent.CollectionIDValidator(v); err != nil {
  426. return &ValidationError{Name: "collection_id", err: fmt.Errorf(`ent: validator failed for field "Agent.collection_id": %w`, err)}
  427. }
  428. }
  429. return nil
  430. }
  431. func (au *AgentUpdate) sqlSave(ctx context.Context) (n int, err error) {
  432. if err := au.check(); err != nil {
  433. return n, err
  434. }
  435. _spec := sqlgraph.NewUpdateSpec(agent.Table, agent.Columns, sqlgraph.NewFieldSpec(agent.FieldID, field.TypeUint64))
  436. if ps := au.mutation.predicates; len(ps) > 0 {
  437. _spec.Predicate = func(selector *sql.Selector) {
  438. for i := range ps {
  439. ps[i](selector)
  440. }
  441. }
  442. }
  443. if value, ok := au.mutation.UpdatedAt(); ok {
  444. _spec.SetField(agent.FieldUpdatedAt, field.TypeTime, value)
  445. }
  446. if value, ok := au.mutation.DeletedAt(); ok {
  447. _spec.SetField(agent.FieldDeletedAt, field.TypeTime, value)
  448. }
  449. if au.mutation.DeletedAtCleared() {
  450. _spec.ClearField(agent.FieldDeletedAt, field.TypeTime)
  451. }
  452. if value, ok := au.mutation.Name(); ok {
  453. _spec.SetField(agent.FieldName, field.TypeString, value)
  454. }
  455. if value, ok := au.mutation.Role(); ok {
  456. _spec.SetField(agent.FieldRole, field.TypeString, value)
  457. }
  458. if value, ok := au.mutation.Status(); ok {
  459. _spec.SetField(agent.FieldStatus, field.TypeInt, value)
  460. }
  461. if value, ok := au.mutation.AddedStatus(); ok {
  462. _spec.AddField(agent.FieldStatus, field.TypeInt, value)
  463. }
  464. if au.mutation.StatusCleared() {
  465. _spec.ClearField(agent.FieldStatus, field.TypeInt)
  466. }
  467. if value, ok := au.mutation.Background(); ok {
  468. _spec.SetField(agent.FieldBackground, field.TypeString, value)
  469. }
  470. if au.mutation.BackgroundCleared() {
  471. _spec.ClearField(agent.FieldBackground, field.TypeString)
  472. }
  473. if value, ok := au.mutation.Examples(); ok {
  474. _spec.SetField(agent.FieldExamples, field.TypeString, value)
  475. }
  476. if au.mutation.ExamplesCleared() {
  477. _spec.ClearField(agent.FieldExamples, field.TypeString)
  478. }
  479. if value, ok := au.mutation.OrganizationID(); ok {
  480. _spec.SetField(agent.FieldOrganizationID, field.TypeUint64, value)
  481. }
  482. if value, ok := au.mutation.AddedOrganizationID(); ok {
  483. _spec.AddField(agent.FieldOrganizationID, field.TypeUint64, value)
  484. }
  485. if value, ok := au.mutation.DatasetID(); ok {
  486. _spec.SetField(agent.FieldDatasetID, field.TypeString, value)
  487. }
  488. if value, ok := au.mutation.CollectionID(); ok {
  489. _spec.SetField(agent.FieldCollectionID, field.TypeString, value)
  490. }
  491. if au.mutation.WxAgentCleared() {
  492. edge := &sqlgraph.EdgeSpec{
  493. Rel: sqlgraph.O2M,
  494. Inverse: false,
  495. Table: agent.WxAgentTable,
  496. Columns: []string{agent.WxAgentColumn},
  497. Bidi: false,
  498. Target: &sqlgraph.EdgeTarget{
  499. IDSpec: sqlgraph.NewFieldSpec(wx.FieldID, field.TypeUint64),
  500. },
  501. }
  502. _spec.Edges.Clear = append(_spec.Edges.Clear, edge)
  503. }
  504. if nodes := au.mutation.RemovedWxAgentIDs(); len(nodes) > 0 && !au.mutation.WxAgentCleared() {
  505. edge := &sqlgraph.EdgeSpec{
  506. Rel: sqlgraph.O2M,
  507. Inverse: false,
  508. Table: agent.WxAgentTable,
  509. Columns: []string{agent.WxAgentColumn},
  510. Bidi: false,
  511. Target: &sqlgraph.EdgeTarget{
  512. IDSpec: sqlgraph.NewFieldSpec(wx.FieldID, field.TypeUint64),
  513. },
  514. }
  515. for _, k := range nodes {
  516. edge.Target.Nodes = append(edge.Target.Nodes, k)
  517. }
  518. _spec.Edges.Clear = append(_spec.Edges.Clear, edge)
  519. }
  520. if nodes := au.mutation.WxAgentIDs(); len(nodes) > 0 {
  521. edge := &sqlgraph.EdgeSpec{
  522. Rel: sqlgraph.O2M,
  523. Inverse: false,
  524. Table: agent.WxAgentTable,
  525. Columns: []string{agent.WxAgentColumn},
  526. Bidi: false,
  527. Target: &sqlgraph.EdgeTarget{
  528. IDSpec: sqlgraph.NewFieldSpec(wx.FieldID, field.TypeUint64),
  529. },
  530. }
  531. for _, k := range nodes {
  532. edge.Target.Nodes = append(edge.Target.Nodes, k)
  533. }
  534. _spec.Edges.Add = append(_spec.Edges.Add, edge)
  535. }
  536. if au.mutation.TokenAgentCleared() {
  537. edge := &sqlgraph.EdgeSpec{
  538. Rel: sqlgraph.O2M,
  539. Inverse: false,
  540. Table: agent.TokenAgentTable,
  541. Columns: []string{agent.TokenAgentColumn},
  542. Bidi: false,
  543. Target: &sqlgraph.EdgeTarget{
  544. IDSpec: sqlgraph.NewFieldSpec(token.FieldID, field.TypeUint64),
  545. },
  546. }
  547. _spec.Edges.Clear = append(_spec.Edges.Clear, edge)
  548. }
  549. if nodes := au.mutation.RemovedTokenAgentIDs(); len(nodes) > 0 && !au.mutation.TokenAgentCleared() {
  550. edge := &sqlgraph.EdgeSpec{
  551. Rel: sqlgraph.O2M,
  552. Inverse: false,
  553. Table: agent.TokenAgentTable,
  554. Columns: []string{agent.TokenAgentColumn},
  555. Bidi: false,
  556. Target: &sqlgraph.EdgeTarget{
  557. IDSpec: sqlgraph.NewFieldSpec(token.FieldID, field.TypeUint64),
  558. },
  559. }
  560. for _, k := range nodes {
  561. edge.Target.Nodes = append(edge.Target.Nodes, k)
  562. }
  563. _spec.Edges.Clear = append(_spec.Edges.Clear, edge)
  564. }
  565. if nodes := au.mutation.TokenAgentIDs(); len(nodes) > 0 {
  566. edge := &sqlgraph.EdgeSpec{
  567. Rel: sqlgraph.O2M,
  568. Inverse: false,
  569. Table: agent.TokenAgentTable,
  570. Columns: []string{agent.TokenAgentColumn},
  571. Bidi: false,
  572. Target: &sqlgraph.EdgeTarget{
  573. IDSpec: sqlgraph.NewFieldSpec(token.FieldID, field.TypeUint64),
  574. },
  575. }
  576. for _, k := range nodes {
  577. edge.Target.Nodes = append(edge.Target.Nodes, k)
  578. }
  579. _spec.Edges.Add = append(_spec.Edges.Add, edge)
  580. }
  581. if au.mutation.WaAgentCleared() {
  582. edge := &sqlgraph.EdgeSpec{
  583. Rel: sqlgraph.O2M,
  584. Inverse: false,
  585. Table: agent.WaAgentTable,
  586. Columns: []string{agent.WaAgentColumn},
  587. Bidi: false,
  588. Target: &sqlgraph.EdgeTarget{
  589. IDSpec: sqlgraph.NewFieldSpec(whatsapp.FieldID, field.TypeUint64),
  590. },
  591. }
  592. _spec.Edges.Clear = append(_spec.Edges.Clear, edge)
  593. }
  594. if nodes := au.mutation.RemovedWaAgentIDs(); len(nodes) > 0 && !au.mutation.WaAgentCleared() {
  595. edge := &sqlgraph.EdgeSpec{
  596. Rel: sqlgraph.O2M,
  597. Inverse: false,
  598. Table: agent.WaAgentTable,
  599. Columns: []string{agent.WaAgentColumn},
  600. Bidi: false,
  601. Target: &sqlgraph.EdgeTarget{
  602. IDSpec: sqlgraph.NewFieldSpec(whatsapp.FieldID, field.TypeUint64),
  603. },
  604. }
  605. for _, k := range nodes {
  606. edge.Target.Nodes = append(edge.Target.Nodes, k)
  607. }
  608. _spec.Edges.Clear = append(_spec.Edges.Clear, edge)
  609. }
  610. if nodes := au.mutation.WaAgentIDs(); len(nodes) > 0 {
  611. edge := &sqlgraph.EdgeSpec{
  612. Rel: sqlgraph.O2M,
  613. Inverse: false,
  614. Table: agent.WaAgentTable,
  615. Columns: []string{agent.WaAgentColumn},
  616. Bidi: false,
  617. Target: &sqlgraph.EdgeTarget{
  618. IDSpec: sqlgraph.NewFieldSpec(whatsapp.FieldID, field.TypeUint64),
  619. },
  620. }
  621. for _, k := range nodes {
  622. edge.Target.Nodes = append(edge.Target.Nodes, k)
  623. }
  624. _spec.Edges.Add = append(_spec.Edges.Add, edge)
  625. }
  626. if au.mutation.XjsAgentCleared() {
  627. edge := &sqlgraph.EdgeSpec{
  628. Rel: sqlgraph.O2M,
  629. Inverse: false,
  630. Table: agent.XjsAgentTable,
  631. Columns: []string{agent.XjsAgentColumn},
  632. Bidi: false,
  633. Target: &sqlgraph.EdgeTarget{
  634. IDSpec: sqlgraph.NewFieldSpec(xunjiservice.FieldID, field.TypeUint64),
  635. },
  636. }
  637. _spec.Edges.Clear = append(_spec.Edges.Clear, edge)
  638. }
  639. if nodes := au.mutation.RemovedXjsAgentIDs(); len(nodes) > 0 && !au.mutation.XjsAgentCleared() {
  640. edge := &sqlgraph.EdgeSpec{
  641. Rel: sqlgraph.O2M,
  642. Inverse: false,
  643. Table: agent.XjsAgentTable,
  644. Columns: []string{agent.XjsAgentColumn},
  645. Bidi: false,
  646. Target: &sqlgraph.EdgeTarget{
  647. IDSpec: sqlgraph.NewFieldSpec(xunjiservice.FieldID, field.TypeUint64),
  648. },
  649. }
  650. for _, k := range nodes {
  651. edge.Target.Nodes = append(edge.Target.Nodes, k)
  652. }
  653. _spec.Edges.Clear = append(_spec.Edges.Clear, edge)
  654. }
  655. if nodes := au.mutation.XjsAgentIDs(); len(nodes) > 0 {
  656. edge := &sqlgraph.EdgeSpec{
  657. Rel: sqlgraph.O2M,
  658. Inverse: false,
  659. Table: agent.XjsAgentTable,
  660. Columns: []string{agent.XjsAgentColumn},
  661. Bidi: false,
  662. Target: &sqlgraph.EdgeTarget{
  663. IDSpec: sqlgraph.NewFieldSpec(xunjiservice.FieldID, field.TypeUint64),
  664. },
  665. }
  666. for _, k := range nodes {
  667. edge.Target.Nodes = append(edge.Target.Nodes, k)
  668. }
  669. _spec.Edges.Add = append(_spec.Edges.Add, edge)
  670. }
  671. if au.mutation.KeyAgentCleared() {
  672. edge := &sqlgraph.EdgeSpec{
  673. Rel: sqlgraph.O2M,
  674. Inverse: false,
  675. Table: agent.KeyAgentTable,
  676. Columns: []string{agent.KeyAgentColumn},
  677. Bidi: false,
  678. Target: &sqlgraph.EdgeTarget{
  679. IDSpec: sqlgraph.NewFieldSpec(apikey.FieldID, field.TypeUint64),
  680. },
  681. }
  682. _spec.Edges.Clear = append(_spec.Edges.Clear, edge)
  683. }
  684. if nodes := au.mutation.RemovedKeyAgentIDs(); len(nodes) > 0 && !au.mutation.KeyAgentCleared() {
  685. edge := &sqlgraph.EdgeSpec{
  686. Rel: sqlgraph.O2M,
  687. Inverse: false,
  688. Table: agent.KeyAgentTable,
  689. Columns: []string{agent.KeyAgentColumn},
  690. Bidi: false,
  691. Target: &sqlgraph.EdgeTarget{
  692. IDSpec: sqlgraph.NewFieldSpec(apikey.FieldID, field.TypeUint64),
  693. },
  694. }
  695. for _, k := range nodes {
  696. edge.Target.Nodes = append(edge.Target.Nodes, k)
  697. }
  698. _spec.Edges.Clear = append(_spec.Edges.Clear, edge)
  699. }
  700. if nodes := au.mutation.KeyAgentIDs(); len(nodes) > 0 {
  701. edge := &sqlgraph.EdgeSpec{
  702. Rel: sqlgraph.O2M,
  703. Inverse: false,
  704. Table: agent.KeyAgentTable,
  705. Columns: []string{agent.KeyAgentColumn},
  706. Bidi: false,
  707. Target: &sqlgraph.EdgeTarget{
  708. IDSpec: sqlgraph.NewFieldSpec(apikey.FieldID, field.TypeUint64),
  709. },
  710. }
  711. for _, k := range nodes {
  712. edge.Target.Nodes = append(edge.Target.Nodes, k)
  713. }
  714. _spec.Edges.Add = append(_spec.Edges.Add, edge)
  715. }
  716. if au.mutation.XjsAgentCleared() {
  717. edge := &sqlgraph.EdgeSpec{
  718. Rel: sqlgraph.O2M,
  719. Inverse: false,
  720. Table: agent.XjsAgentTable,
  721. Columns: []string{agent.XjsAgentColumn},
  722. Bidi: false,
  723. Target: &sqlgraph.EdgeTarget{
  724. IDSpec: sqlgraph.NewFieldSpec(xunjiservice.FieldID, field.TypeUint64),
  725. },
  726. }
  727. _spec.Edges.Clear = append(_spec.Edges.Clear, edge)
  728. }
  729. if nodes := au.mutation.RemovedXjsAgentIDs(); len(nodes) > 0 && !au.mutation.XjsAgentCleared() {
  730. edge := &sqlgraph.EdgeSpec{
  731. Rel: sqlgraph.O2M,
  732. Inverse: false,
  733. Table: agent.XjsAgentTable,
  734. Columns: []string{agent.XjsAgentColumn},
  735. Bidi: false,
  736. Target: &sqlgraph.EdgeTarget{
  737. IDSpec: sqlgraph.NewFieldSpec(xunjiservice.FieldID, field.TypeUint64),
  738. },
  739. }
  740. for _, k := range nodes {
  741. edge.Target.Nodes = append(edge.Target.Nodes, k)
  742. }
  743. _spec.Edges.Clear = append(_spec.Edges.Clear, edge)
  744. }
  745. if nodes := au.mutation.XjsAgentIDs(); len(nodes) > 0 {
  746. edge := &sqlgraph.EdgeSpec{
  747. Rel: sqlgraph.O2M,
  748. Inverse: false,
  749. Table: agent.XjsAgentTable,
  750. Columns: []string{agent.XjsAgentColumn},
  751. Bidi: false,
  752. Target: &sqlgraph.EdgeTarget{
  753. IDSpec: sqlgraph.NewFieldSpec(xunjiservice.FieldID, field.TypeUint64),
  754. },
  755. }
  756. for _, k := range nodes {
  757. edge.Target.Nodes = append(edge.Target.Nodes, k)
  758. }
  759. _spec.Edges.Add = append(_spec.Edges.Add, edge)
  760. }
  761. if n, err = sqlgraph.UpdateNodes(ctx, au.driver, _spec); err != nil {
  762. if _, ok := err.(*sqlgraph.NotFoundError); ok {
  763. err = &NotFoundError{agent.Label}
  764. } else if sqlgraph.IsConstraintError(err) {
  765. err = &ConstraintError{msg: err.Error(), wrap: err}
  766. }
  767. return 0, err
  768. }
  769. au.mutation.done = true
  770. return n, nil
  771. }
  772. // AgentUpdateOne is the builder for updating a single Agent entity.
  773. type AgentUpdateOne struct {
  774. config
  775. fields []string
  776. hooks []Hook
  777. mutation *AgentMutation
  778. }
  779. // SetUpdatedAt sets the "updated_at" field.
  780. func (auo *AgentUpdateOne) SetUpdatedAt(t time.Time) *AgentUpdateOne {
  781. auo.mutation.SetUpdatedAt(t)
  782. return auo
  783. }
  784. // SetDeletedAt sets the "deleted_at" field.
  785. func (auo *AgentUpdateOne) SetDeletedAt(t time.Time) *AgentUpdateOne {
  786. auo.mutation.SetDeletedAt(t)
  787. return auo
  788. }
  789. // SetNillableDeletedAt sets the "deleted_at" field if the given value is not nil.
  790. func (auo *AgentUpdateOne) SetNillableDeletedAt(t *time.Time) *AgentUpdateOne {
  791. if t != nil {
  792. auo.SetDeletedAt(*t)
  793. }
  794. return auo
  795. }
  796. // ClearDeletedAt clears the value of the "deleted_at" field.
  797. func (auo *AgentUpdateOne) ClearDeletedAt() *AgentUpdateOne {
  798. auo.mutation.ClearDeletedAt()
  799. return auo
  800. }
  801. // SetName sets the "name" field.
  802. func (auo *AgentUpdateOne) SetName(s string) *AgentUpdateOne {
  803. auo.mutation.SetName(s)
  804. return auo
  805. }
  806. // SetNillableName sets the "name" field if the given value is not nil.
  807. func (auo *AgentUpdateOne) SetNillableName(s *string) *AgentUpdateOne {
  808. if s != nil {
  809. auo.SetName(*s)
  810. }
  811. return auo
  812. }
  813. // SetRole sets the "role" field.
  814. func (auo *AgentUpdateOne) SetRole(s string) *AgentUpdateOne {
  815. auo.mutation.SetRole(s)
  816. return auo
  817. }
  818. // SetNillableRole sets the "role" field if the given value is not nil.
  819. func (auo *AgentUpdateOne) SetNillableRole(s *string) *AgentUpdateOne {
  820. if s != nil {
  821. auo.SetRole(*s)
  822. }
  823. return auo
  824. }
  825. // SetStatus sets the "status" field.
  826. func (auo *AgentUpdateOne) SetStatus(i int) *AgentUpdateOne {
  827. auo.mutation.ResetStatus()
  828. auo.mutation.SetStatus(i)
  829. return auo
  830. }
  831. // SetNillableStatus sets the "status" field if the given value is not nil.
  832. func (auo *AgentUpdateOne) SetNillableStatus(i *int) *AgentUpdateOne {
  833. if i != nil {
  834. auo.SetStatus(*i)
  835. }
  836. return auo
  837. }
  838. // AddStatus adds i to the "status" field.
  839. func (auo *AgentUpdateOne) AddStatus(i int) *AgentUpdateOne {
  840. auo.mutation.AddStatus(i)
  841. return auo
  842. }
  843. // ClearStatus clears the value of the "status" field.
  844. func (auo *AgentUpdateOne) ClearStatus() *AgentUpdateOne {
  845. auo.mutation.ClearStatus()
  846. return auo
  847. }
  848. // SetBackground sets the "background" field.
  849. func (auo *AgentUpdateOne) SetBackground(s string) *AgentUpdateOne {
  850. auo.mutation.SetBackground(s)
  851. return auo
  852. }
  853. // SetNillableBackground sets the "background" field if the given value is not nil.
  854. func (auo *AgentUpdateOne) SetNillableBackground(s *string) *AgentUpdateOne {
  855. if s != nil {
  856. auo.SetBackground(*s)
  857. }
  858. return auo
  859. }
  860. // ClearBackground clears the value of the "background" field.
  861. func (auo *AgentUpdateOne) ClearBackground() *AgentUpdateOne {
  862. auo.mutation.ClearBackground()
  863. return auo
  864. }
  865. // SetExamples sets the "examples" field.
  866. func (auo *AgentUpdateOne) SetExamples(s string) *AgentUpdateOne {
  867. auo.mutation.SetExamples(s)
  868. return auo
  869. }
  870. // SetNillableExamples sets the "examples" field if the given value is not nil.
  871. func (auo *AgentUpdateOne) SetNillableExamples(s *string) *AgentUpdateOne {
  872. if s != nil {
  873. auo.SetExamples(*s)
  874. }
  875. return auo
  876. }
  877. // ClearExamples clears the value of the "examples" field.
  878. func (auo *AgentUpdateOne) ClearExamples() *AgentUpdateOne {
  879. auo.mutation.ClearExamples()
  880. return auo
  881. }
  882. // SetOrganizationID sets the "organization_id" field.
  883. func (auo *AgentUpdateOne) SetOrganizationID(u uint64) *AgentUpdateOne {
  884. auo.mutation.ResetOrganizationID()
  885. auo.mutation.SetOrganizationID(u)
  886. return auo
  887. }
  888. // SetNillableOrganizationID sets the "organization_id" field if the given value is not nil.
  889. func (auo *AgentUpdateOne) SetNillableOrganizationID(u *uint64) *AgentUpdateOne {
  890. if u != nil {
  891. auo.SetOrganizationID(*u)
  892. }
  893. return auo
  894. }
  895. // AddOrganizationID adds u to the "organization_id" field.
  896. func (auo *AgentUpdateOne) AddOrganizationID(u int64) *AgentUpdateOne {
  897. auo.mutation.AddOrganizationID(u)
  898. return auo
  899. }
  900. // SetDatasetID sets the "dataset_id" field.
  901. func (auo *AgentUpdateOne) SetDatasetID(s string) *AgentUpdateOne {
  902. auo.mutation.SetDatasetID(s)
  903. return auo
  904. }
  905. // SetNillableDatasetID sets the "dataset_id" field if the given value is not nil.
  906. func (auo *AgentUpdateOne) SetNillableDatasetID(s *string) *AgentUpdateOne {
  907. if s != nil {
  908. auo.SetDatasetID(*s)
  909. }
  910. return auo
  911. }
  912. // SetCollectionID sets the "collection_id" field.
  913. func (auo *AgentUpdateOne) SetCollectionID(s string) *AgentUpdateOne {
  914. auo.mutation.SetCollectionID(s)
  915. return auo
  916. }
  917. // SetNillableCollectionID sets the "collection_id" field if the given value is not nil.
  918. func (auo *AgentUpdateOne) SetNillableCollectionID(s *string) *AgentUpdateOne {
  919. if s != nil {
  920. auo.SetCollectionID(*s)
  921. }
  922. return auo
  923. }
  924. // AddWxAgentIDs adds the "wx_agent" edge to the Wx entity by IDs.
  925. func (auo *AgentUpdateOne) AddWxAgentIDs(ids ...uint64) *AgentUpdateOne {
  926. auo.mutation.AddWxAgentIDs(ids...)
  927. return auo
  928. }
  929. // AddWxAgent adds the "wx_agent" edges to the Wx entity.
  930. func (auo *AgentUpdateOne) AddWxAgent(w ...*Wx) *AgentUpdateOne {
  931. ids := make([]uint64, len(w))
  932. for i := range w {
  933. ids[i] = w[i].ID
  934. }
  935. return auo.AddWxAgentIDs(ids...)
  936. }
  937. // AddTokenAgentIDs adds the "token_agent" edge to the Token entity by IDs.
  938. func (auo *AgentUpdateOne) AddTokenAgentIDs(ids ...uint64) *AgentUpdateOne {
  939. auo.mutation.AddTokenAgentIDs(ids...)
  940. return auo
  941. }
  942. // AddTokenAgent adds the "token_agent" edges to the Token entity.
  943. func (auo *AgentUpdateOne) AddTokenAgent(t ...*Token) *AgentUpdateOne {
  944. ids := make([]uint64, len(t))
  945. for i := range t {
  946. ids[i] = t[i].ID
  947. }
  948. return auo.AddTokenAgentIDs(ids...)
  949. }
  950. // AddWaAgentIDs adds the "wa_agent" edge to the Whatsapp entity by IDs.
  951. func (auo *AgentUpdateOne) AddWaAgentIDs(ids ...uint64) *AgentUpdateOne {
  952. auo.mutation.AddWaAgentIDs(ids...)
  953. return auo
  954. }
  955. // AddWaAgent adds the "wa_agent" edges to the Whatsapp entity.
  956. func (auo *AgentUpdateOne) AddWaAgent(w ...*Whatsapp) *AgentUpdateOne {
  957. ids := make([]uint64, len(w))
  958. for i := range w {
  959. ids[i] = w[i].ID
  960. }
  961. return auo.AddWaAgentIDs(ids...)
  962. }
  963. // AddXjsAgentIDs adds the "xjs_agent" edge to the XunjiService entity by IDs.
  964. func (auo *AgentUpdateOne) AddXjsAgentIDs(ids ...uint64) *AgentUpdateOne {
  965. auo.mutation.AddXjsAgentIDs(ids...)
  966. return auo
  967. }
  968. // AddXjsAgent adds the "xjs_agent" edges to the XunjiService entity.
  969. func (auo *AgentUpdateOne) AddXjsAgent(x ...*XunjiService) *AgentUpdateOne {
  970. ids := make([]uint64, len(x))
  971. for i := range x {
  972. ids[i] = x[i].ID
  973. }
  974. return auo.AddXjsAgentIDs(ids...)
  975. }
  976. // AddKeyAgentIDs adds the "key_agent" edge to the ApiKey entity by IDs.
  977. func (auo *AgentUpdateOne) AddKeyAgentIDs(ids ...uint64) *AgentUpdateOne {
  978. auo.mutation.AddKeyAgentIDs(ids...)
  979. return auo
  980. }
  981. // AddKeyAgent adds the "key_agent" edges to the ApiKey entity.
  982. func (auo *AgentUpdateOne) AddKeyAgent(a ...*ApiKey) *AgentUpdateOne {
  983. ids := make([]uint64, len(a))
  984. for i := range a {
  985. ids[i] = a[i].ID
  986. }
  987. return auo.AddKeyAgentIDs(ids...)
  988. }
  989. // AddXjsAgentIDs adds the "xjs_agent" edge to the XunjiService entity by IDs.
  990. func (auo *AgentUpdateOne) AddXjsAgentIDs(ids ...uint64) *AgentUpdateOne {
  991. auo.mutation.AddXjsAgentIDs(ids...)
  992. return auo
  993. }
  994. // AddXjsAgent adds the "xjs_agent" edges to the XunjiService entity.
  995. func (auo *AgentUpdateOne) AddXjsAgent(x ...*XunjiService) *AgentUpdateOne {
  996. ids := make([]uint64, len(x))
  997. for i := range x {
  998. ids[i] = x[i].ID
  999. }
  1000. return auo.AddXjsAgentIDs(ids...)
  1001. }
  1002. // Mutation returns the AgentMutation object of the builder.
  1003. func (auo *AgentUpdateOne) Mutation() *AgentMutation {
  1004. return auo.mutation
  1005. }
  1006. // ClearWxAgent clears all "wx_agent" edges to the Wx entity.
  1007. func (auo *AgentUpdateOne) ClearWxAgent() *AgentUpdateOne {
  1008. auo.mutation.ClearWxAgent()
  1009. return auo
  1010. }
  1011. // RemoveWxAgentIDs removes the "wx_agent" edge to Wx entities by IDs.
  1012. func (auo *AgentUpdateOne) RemoveWxAgentIDs(ids ...uint64) *AgentUpdateOne {
  1013. auo.mutation.RemoveWxAgentIDs(ids...)
  1014. return auo
  1015. }
  1016. // RemoveWxAgent removes "wx_agent" edges to Wx entities.
  1017. func (auo *AgentUpdateOne) RemoveWxAgent(w ...*Wx) *AgentUpdateOne {
  1018. ids := make([]uint64, len(w))
  1019. for i := range w {
  1020. ids[i] = w[i].ID
  1021. }
  1022. return auo.RemoveWxAgentIDs(ids...)
  1023. }
  1024. // ClearTokenAgent clears all "token_agent" edges to the Token entity.
  1025. func (auo *AgentUpdateOne) ClearTokenAgent() *AgentUpdateOne {
  1026. auo.mutation.ClearTokenAgent()
  1027. return auo
  1028. }
  1029. // RemoveTokenAgentIDs removes the "token_agent" edge to Token entities by IDs.
  1030. func (auo *AgentUpdateOne) RemoveTokenAgentIDs(ids ...uint64) *AgentUpdateOne {
  1031. auo.mutation.RemoveTokenAgentIDs(ids...)
  1032. return auo
  1033. }
  1034. // RemoveTokenAgent removes "token_agent" edges to Token entities.
  1035. func (auo *AgentUpdateOne) RemoveTokenAgent(t ...*Token) *AgentUpdateOne {
  1036. ids := make([]uint64, len(t))
  1037. for i := range t {
  1038. ids[i] = t[i].ID
  1039. }
  1040. return auo.RemoveTokenAgentIDs(ids...)
  1041. }
  1042. // ClearWaAgent clears all "wa_agent" edges to the Whatsapp entity.
  1043. func (auo *AgentUpdateOne) ClearWaAgent() *AgentUpdateOne {
  1044. auo.mutation.ClearWaAgent()
  1045. return auo
  1046. }
  1047. // RemoveWaAgentIDs removes the "wa_agent" edge to Whatsapp entities by IDs.
  1048. func (auo *AgentUpdateOne) RemoveWaAgentIDs(ids ...uint64) *AgentUpdateOne {
  1049. auo.mutation.RemoveWaAgentIDs(ids...)
  1050. return auo
  1051. }
  1052. // RemoveWaAgent removes "wa_agent" edges to Whatsapp entities.
  1053. func (auo *AgentUpdateOne) RemoveWaAgent(w ...*Whatsapp) *AgentUpdateOne {
  1054. ids := make([]uint64, len(w))
  1055. for i := range w {
  1056. ids[i] = w[i].ID
  1057. }
  1058. return auo.RemoveWaAgentIDs(ids...)
  1059. }
  1060. // ClearXjsAgent clears all "xjs_agent" edges to the XunjiService entity.
  1061. func (auo *AgentUpdateOne) ClearXjsAgent() *AgentUpdateOne {
  1062. auo.mutation.ClearXjsAgent()
  1063. return auo
  1064. }
  1065. // RemoveXjsAgentIDs removes the "xjs_agent" edge to XunjiService entities by IDs.
  1066. func (auo *AgentUpdateOne) RemoveXjsAgentIDs(ids ...uint64) *AgentUpdateOne {
  1067. auo.mutation.RemoveXjsAgentIDs(ids...)
  1068. return auo
  1069. }
  1070. // RemoveXjsAgent removes "xjs_agent" edges to XunjiService entities.
  1071. func (auo *AgentUpdateOne) RemoveXjsAgent(x ...*XunjiService) *AgentUpdateOne {
  1072. ids := make([]uint64, len(x))
  1073. for i := range x {
  1074. ids[i] = x[i].ID
  1075. }
  1076. return auo.RemoveXjsAgentIDs(ids...)
  1077. }
  1078. // ClearKeyAgent clears all "key_agent" edges to the ApiKey entity.
  1079. func (auo *AgentUpdateOne) ClearKeyAgent() *AgentUpdateOne {
  1080. auo.mutation.ClearKeyAgent()
  1081. return auo
  1082. }
  1083. // RemoveKeyAgentIDs removes the "key_agent" edge to ApiKey entities by IDs.
  1084. func (auo *AgentUpdateOne) RemoveKeyAgentIDs(ids ...uint64) *AgentUpdateOne {
  1085. auo.mutation.RemoveKeyAgentIDs(ids...)
  1086. return auo
  1087. }
  1088. // RemoveKeyAgent removes "key_agent" edges to ApiKey entities.
  1089. func (auo *AgentUpdateOne) RemoveKeyAgent(a ...*ApiKey) *AgentUpdateOne {
  1090. ids := make([]uint64, len(a))
  1091. for i := range a {
  1092. ids[i] = a[i].ID
  1093. }
  1094. return auo.RemoveKeyAgentIDs(ids...)
  1095. }
  1096. // ClearXjsAgent clears all "xjs_agent" edges to the XunjiService entity.
  1097. func (auo *AgentUpdateOne) ClearXjsAgent() *AgentUpdateOne {
  1098. auo.mutation.ClearXjsAgent()
  1099. return auo
  1100. }
  1101. // RemoveXjsAgentIDs removes the "xjs_agent" edge to XunjiService entities by IDs.
  1102. func (auo *AgentUpdateOne) RemoveXjsAgentIDs(ids ...uint64) *AgentUpdateOne {
  1103. auo.mutation.RemoveXjsAgentIDs(ids...)
  1104. return auo
  1105. }
  1106. // RemoveXjsAgent removes "xjs_agent" edges to XunjiService entities.
  1107. func (auo *AgentUpdateOne) RemoveXjsAgent(x ...*XunjiService) *AgentUpdateOne {
  1108. ids := make([]uint64, len(x))
  1109. for i := range x {
  1110. ids[i] = x[i].ID
  1111. }
  1112. return auo.RemoveXjsAgentIDs(ids...)
  1113. }
  1114. // Where appends a list predicates to the AgentUpdate builder.
  1115. func (auo *AgentUpdateOne) Where(ps ...predicate.Agent) *AgentUpdateOne {
  1116. auo.mutation.Where(ps...)
  1117. return auo
  1118. }
  1119. // Select allows selecting one or more fields (columns) of the returned entity.
  1120. // The default is selecting all fields defined in the entity schema.
  1121. func (auo *AgentUpdateOne) Select(field string, fields ...string) *AgentUpdateOne {
  1122. auo.fields = append([]string{field}, fields...)
  1123. return auo
  1124. }
  1125. // Save executes the query and returns the updated Agent entity.
  1126. func (auo *AgentUpdateOne) Save(ctx context.Context) (*Agent, error) {
  1127. if err := auo.defaults(); err != nil {
  1128. return nil, err
  1129. }
  1130. return withHooks(ctx, auo.sqlSave, auo.mutation, auo.hooks)
  1131. }
  1132. // SaveX is like Save, but panics if an error occurs.
  1133. func (auo *AgentUpdateOne) SaveX(ctx context.Context) *Agent {
  1134. node, err := auo.Save(ctx)
  1135. if err != nil {
  1136. panic(err)
  1137. }
  1138. return node
  1139. }
  1140. // Exec executes the query on the entity.
  1141. func (auo *AgentUpdateOne) Exec(ctx context.Context) error {
  1142. _, err := auo.Save(ctx)
  1143. return err
  1144. }
  1145. // ExecX is like Exec, but panics if an error occurs.
  1146. func (auo *AgentUpdateOne) ExecX(ctx context.Context) {
  1147. if err := auo.Exec(ctx); err != nil {
  1148. panic(err)
  1149. }
  1150. }
  1151. // defaults sets the default values of the builder before save.
  1152. func (auo *AgentUpdateOne) defaults() error {
  1153. if _, ok := auo.mutation.UpdatedAt(); !ok {
  1154. if agent.UpdateDefaultUpdatedAt == nil {
  1155. return fmt.Errorf("ent: uninitialized agent.UpdateDefaultUpdatedAt (forgotten import ent/runtime?)")
  1156. }
  1157. v := agent.UpdateDefaultUpdatedAt()
  1158. auo.mutation.SetUpdatedAt(v)
  1159. }
  1160. return nil
  1161. }
  1162. // check runs all checks and user-defined validators on the builder.
  1163. func (auo *AgentUpdateOne) check() error {
  1164. if v, ok := auo.mutation.Name(); ok {
  1165. if err := agent.NameValidator(v); err != nil {
  1166. return &ValidationError{Name: "name", err: fmt.Errorf(`ent: validator failed for field "Agent.name": %w`, err)}
  1167. }
  1168. }
  1169. if v, ok := auo.mutation.Status(); ok {
  1170. if err := agent.StatusValidator(v); err != nil {
  1171. return &ValidationError{Name: "status", err: fmt.Errorf(`ent: validator failed for field "Agent.status": %w`, err)}
  1172. }
  1173. }
  1174. if v, ok := auo.mutation.OrganizationID(); ok {
  1175. if err := agent.OrganizationIDValidator(v); err != nil {
  1176. return &ValidationError{Name: "organization_id", err: fmt.Errorf(`ent: validator failed for field "Agent.organization_id": %w`, err)}
  1177. }
  1178. }
  1179. if v, ok := auo.mutation.DatasetID(); ok {
  1180. if err := agent.DatasetIDValidator(v); err != nil {
  1181. return &ValidationError{Name: "dataset_id", err: fmt.Errorf(`ent: validator failed for field "Agent.dataset_id": %w`, err)}
  1182. }
  1183. }
  1184. if v, ok := auo.mutation.CollectionID(); ok {
  1185. if err := agent.CollectionIDValidator(v); err != nil {
  1186. return &ValidationError{Name: "collection_id", err: fmt.Errorf(`ent: validator failed for field "Agent.collection_id": %w`, err)}
  1187. }
  1188. }
  1189. return nil
  1190. }
  1191. func (auo *AgentUpdateOne) sqlSave(ctx context.Context) (_node *Agent, err error) {
  1192. if err := auo.check(); err != nil {
  1193. return _node, err
  1194. }
  1195. _spec := sqlgraph.NewUpdateSpec(agent.Table, agent.Columns, sqlgraph.NewFieldSpec(agent.FieldID, field.TypeUint64))
  1196. id, ok := auo.mutation.ID()
  1197. if !ok {
  1198. return nil, &ValidationError{Name: "id", err: errors.New(`ent: missing "Agent.id" for update`)}
  1199. }
  1200. _spec.Node.ID.Value = id
  1201. if fields := auo.fields; len(fields) > 0 {
  1202. _spec.Node.Columns = make([]string, 0, len(fields))
  1203. _spec.Node.Columns = append(_spec.Node.Columns, agent.FieldID)
  1204. for _, f := range fields {
  1205. if !agent.ValidColumn(f) {
  1206. return nil, &ValidationError{Name: f, err: fmt.Errorf("ent: invalid field %q for query", f)}
  1207. }
  1208. if f != agent.FieldID {
  1209. _spec.Node.Columns = append(_spec.Node.Columns, f)
  1210. }
  1211. }
  1212. }
  1213. if ps := auo.mutation.predicates; len(ps) > 0 {
  1214. _spec.Predicate = func(selector *sql.Selector) {
  1215. for i := range ps {
  1216. ps[i](selector)
  1217. }
  1218. }
  1219. }
  1220. if value, ok := auo.mutation.UpdatedAt(); ok {
  1221. _spec.SetField(agent.FieldUpdatedAt, field.TypeTime, value)
  1222. }
  1223. if value, ok := auo.mutation.DeletedAt(); ok {
  1224. _spec.SetField(agent.FieldDeletedAt, field.TypeTime, value)
  1225. }
  1226. if auo.mutation.DeletedAtCleared() {
  1227. _spec.ClearField(agent.FieldDeletedAt, field.TypeTime)
  1228. }
  1229. if value, ok := auo.mutation.Name(); ok {
  1230. _spec.SetField(agent.FieldName, field.TypeString, value)
  1231. }
  1232. if value, ok := auo.mutation.Role(); ok {
  1233. _spec.SetField(agent.FieldRole, field.TypeString, value)
  1234. }
  1235. if value, ok := auo.mutation.Status(); ok {
  1236. _spec.SetField(agent.FieldStatus, field.TypeInt, value)
  1237. }
  1238. if value, ok := auo.mutation.AddedStatus(); ok {
  1239. _spec.AddField(agent.FieldStatus, field.TypeInt, value)
  1240. }
  1241. if auo.mutation.StatusCleared() {
  1242. _spec.ClearField(agent.FieldStatus, field.TypeInt)
  1243. }
  1244. if value, ok := auo.mutation.Background(); ok {
  1245. _spec.SetField(agent.FieldBackground, field.TypeString, value)
  1246. }
  1247. if auo.mutation.BackgroundCleared() {
  1248. _spec.ClearField(agent.FieldBackground, field.TypeString)
  1249. }
  1250. if value, ok := auo.mutation.Examples(); ok {
  1251. _spec.SetField(agent.FieldExamples, field.TypeString, value)
  1252. }
  1253. if auo.mutation.ExamplesCleared() {
  1254. _spec.ClearField(agent.FieldExamples, field.TypeString)
  1255. }
  1256. if value, ok := auo.mutation.OrganizationID(); ok {
  1257. _spec.SetField(agent.FieldOrganizationID, field.TypeUint64, value)
  1258. }
  1259. if value, ok := auo.mutation.AddedOrganizationID(); ok {
  1260. _spec.AddField(agent.FieldOrganizationID, field.TypeUint64, value)
  1261. }
  1262. if value, ok := auo.mutation.DatasetID(); ok {
  1263. _spec.SetField(agent.FieldDatasetID, field.TypeString, value)
  1264. }
  1265. if value, ok := auo.mutation.CollectionID(); ok {
  1266. _spec.SetField(agent.FieldCollectionID, field.TypeString, value)
  1267. }
  1268. if auo.mutation.WxAgentCleared() {
  1269. edge := &sqlgraph.EdgeSpec{
  1270. Rel: sqlgraph.O2M,
  1271. Inverse: false,
  1272. Table: agent.WxAgentTable,
  1273. Columns: []string{agent.WxAgentColumn},
  1274. Bidi: false,
  1275. Target: &sqlgraph.EdgeTarget{
  1276. IDSpec: sqlgraph.NewFieldSpec(wx.FieldID, field.TypeUint64),
  1277. },
  1278. }
  1279. _spec.Edges.Clear = append(_spec.Edges.Clear, edge)
  1280. }
  1281. if nodes := auo.mutation.RemovedWxAgentIDs(); len(nodes) > 0 && !auo.mutation.WxAgentCleared() {
  1282. edge := &sqlgraph.EdgeSpec{
  1283. Rel: sqlgraph.O2M,
  1284. Inverse: false,
  1285. Table: agent.WxAgentTable,
  1286. Columns: []string{agent.WxAgentColumn},
  1287. Bidi: false,
  1288. Target: &sqlgraph.EdgeTarget{
  1289. IDSpec: sqlgraph.NewFieldSpec(wx.FieldID, field.TypeUint64),
  1290. },
  1291. }
  1292. for _, k := range nodes {
  1293. edge.Target.Nodes = append(edge.Target.Nodes, k)
  1294. }
  1295. _spec.Edges.Clear = append(_spec.Edges.Clear, edge)
  1296. }
  1297. if nodes := auo.mutation.WxAgentIDs(); len(nodes) > 0 {
  1298. edge := &sqlgraph.EdgeSpec{
  1299. Rel: sqlgraph.O2M,
  1300. Inverse: false,
  1301. Table: agent.WxAgentTable,
  1302. Columns: []string{agent.WxAgentColumn},
  1303. Bidi: false,
  1304. Target: &sqlgraph.EdgeTarget{
  1305. IDSpec: sqlgraph.NewFieldSpec(wx.FieldID, field.TypeUint64),
  1306. },
  1307. }
  1308. for _, k := range nodes {
  1309. edge.Target.Nodes = append(edge.Target.Nodes, k)
  1310. }
  1311. _spec.Edges.Add = append(_spec.Edges.Add, edge)
  1312. }
  1313. if auo.mutation.TokenAgentCleared() {
  1314. edge := &sqlgraph.EdgeSpec{
  1315. Rel: sqlgraph.O2M,
  1316. Inverse: false,
  1317. Table: agent.TokenAgentTable,
  1318. Columns: []string{agent.TokenAgentColumn},
  1319. Bidi: false,
  1320. Target: &sqlgraph.EdgeTarget{
  1321. IDSpec: sqlgraph.NewFieldSpec(token.FieldID, field.TypeUint64),
  1322. },
  1323. }
  1324. _spec.Edges.Clear = append(_spec.Edges.Clear, edge)
  1325. }
  1326. if nodes := auo.mutation.RemovedTokenAgentIDs(); len(nodes) > 0 && !auo.mutation.TokenAgentCleared() {
  1327. edge := &sqlgraph.EdgeSpec{
  1328. Rel: sqlgraph.O2M,
  1329. Inverse: false,
  1330. Table: agent.TokenAgentTable,
  1331. Columns: []string{agent.TokenAgentColumn},
  1332. Bidi: false,
  1333. Target: &sqlgraph.EdgeTarget{
  1334. IDSpec: sqlgraph.NewFieldSpec(token.FieldID, field.TypeUint64),
  1335. },
  1336. }
  1337. for _, k := range nodes {
  1338. edge.Target.Nodes = append(edge.Target.Nodes, k)
  1339. }
  1340. _spec.Edges.Clear = append(_spec.Edges.Clear, edge)
  1341. }
  1342. if nodes := auo.mutation.TokenAgentIDs(); len(nodes) > 0 {
  1343. edge := &sqlgraph.EdgeSpec{
  1344. Rel: sqlgraph.O2M,
  1345. Inverse: false,
  1346. Table: agent.TokenAgentTable,
  1347. Columns: []string{agent.TokenAgentColumn},
  1348. Bidi: false,
  1349. Target: &sqlgraph.EdgeTarget{
  1350. IDSpec: sqlgraph.NewFieldSpec(token.FieldID, field.TypeUint64),
  1351. },
  1352. }
  1353. for _, k := range nodes {
  1354. edge.Target.Nodes = append(edge.Target.Nodes, k)
  1355. }
  1356. _spec.Edges.Add = append(_spec.Edges.Add, edge)
  1357. }
  1358. if auo.mutation.WaAgentCleared() {
  1359. edge := &sqlgraph.EdgeSpec{
  1360. Rel: sqlgraph.O2M,
  1361. Inverse: false,
  1362. Table: agent.WaAgentTable,
  1363. Columns: []string{agent.WaAgentColumn},
  1364. Bidi: false,
  1365. Target: &sqlgraph.EdgeTarget{
  1366. IDSpec: sqlgraph.NewFieldSpec(whatsapp.FieldID, field.TypeUint64),
  1367. },
  1368. }
  1369. _spec.Edges.Clear = append(_spec.Edges.Clear, edge)
  1370. }
  1371. if nodes := auo.mutation.RemovedWaAgentIDs(); len(nodes) > 0 && !auo.mutation.WaAgentCleared() {
  1372. edge := &sqlgraph.EdgeSpec{
  1373. Rel: sqlgraph.O2M,
  1374. Inverse: false,
  1375. Table: agent.WaAgentTable,
  1376. Columns: []string{agent.WaAgentColumn},
  1377. Bidi: false,
  1378. Target: &sqlgraph.EdgeTarget{
  1379. IDSpec: sqlgraph.NewFieldSpec(whatsapp.FieldID, field.TypeUint64),
  1380. },
  1381. }
  1382. for _, k := range nodes {
  1383. edge.Target.Nodes = append(edge.Target.Nodes, k)
  1384. }
  1385. _spec.Edges.Clear = append(_spec.Edges.Clear, edge)
  1386. }
  1387. if nodes := auo.mutation.WaAgentIDs(); len(nodes) > 0 {
  1388. edge := &sqlgraph.EdgeSpec{
  1389. Rel: sqlgraph.O2M,
  1390. Inverse: false,
  1391. Table: agent.WaAgentTable,
  1392. Columns: []string{agent.WaAgentColumn},
  1393. Bidi: false,
  1394. Target: &sqlgraph.EdgeTarget{
  1395. IDSpec: sqlgraph.NewFieldSpec(whatsapp.FieldID, field.TypeUint64),
  1396. },
  1397. }
  1398. for _, k := range nodes {
  1399. edge.Target.Nodes = append(edge.Target.Nodes, k)
  1400. }
  1401. _spec.Edges.Add = append(_spec.Edges.Add, edge)
  1402. }
  1403. if auo.mutation.XjsAgentCleared() {
  1404. edge := &sqlgraph.EdgeSpec{
  1405. Rel: sqlgraph.O2M,
  1406. Inverse: false,
  1407. Table: agent.XjsAgentTable,
  1408. Columns: []string{agent.XjsAgentColumn},
  1409. Bidi: false,
  1410. Target: &sqlgraph.EdgeTarget{
  1411. IDSpec: sqlgraph.NewFieldSpec(xunjiservice.FieldID, field.TypeUint64),
  1412. },
  1413. }
  1414. _spec.Edges.Clear = append(_spec.Edges.Clear, edge)
  1415. }
  1416. if nodes := auo.mutation.RemovedXjsAgentIDs(); len(nodes) > 0 && !auo.mutation.XjsAgentCleared() {
  1417. edge := &sqlgraph.EdgeSpec{
  1418. Rel: sqlgraph.O2M,
  1419. Inverse: false,
  1420. Table: agent.XjsAgentTable,
  1421. Columns: []string{agent.XjsAgentColumn},
  1422. Bidi: false,
  1423. Target: &sqlgraph.EdgeTarget{
  1424. IDSpec: sqlgraph.NewFieldSpec(xunjiservice.FieldID, field.TypeUint64),
  1425. },
  1426. }
  1427. for _, k := range nodes {
  1428. edge.Target.Nodes = append(edge.Target.Nodes, k)
  1429. }
  1430. _spec.Edges.Clear = append(_spec.Edges.Clear, edge)
  1431. }
  1432. if nodes := auo.mutation.XjsAgentIDs(); len(nodes) > 0 {
  1433. edge := &sqlgraph.EdgeSpec{
  1434. Rel: sqlgraph.O2M,
  1435. Inverse: false,
  1436. Table: agent.XjsAgentTable,
  1437. Columns: []string{agent.XjsAgentColumn},
  1438. Bidi: false,
  1439. Target: &sqlgraph.EdgeTarget{
  1440. IDSpec: sqlgraph.NewFieldSpec(xunjiservice.FieldID, field.TypeUint64),
  1441. },
  1442. }
  1443. for _, k := range nodes {
  1444. edge.Target.Nodes = append(edge.Target.Nodes, k)
  1445. }
  1446. _spec.Edges.Add = append(_spec.Edges.Add, edge)
  1447. }
  1448. if auo.mutation.KeyAgentCleared() {
  1449. edge := &sqlgraph.EdgeSpec{
  1450. Rel: sqlgraph.O2M,
  1451. Inverse: false,
  1452. Table: agent.KeyAgentTable,
  1453. Columns: []string{agent.KeyAgentColumn},
  1454. Bidi: false,
  1455. Target: &sqlgraph.EdgeTarget{
  1456. IDSpec: sqlgraph.NewFieldSpec(apikey.FieldID, field.TypeUint64),
  1457. },
  1458. }
  1459. _spec.Edges.Clear = append(_spec.Edges.Clear, edge)
  1460. }
  1461. if nodes := auo.mutation.RemovedKeyAgentIDs(); len(nodes) > 0 && !auo.mutation.KeyAgentCleared() {
  1462. edge := &sqlgraph.EdgeSpec{
  1463. Rel: sqlgraph.O2M,
  1464. Inverse: false,
  1465. Table: agent.KeyAgentTable,
  1466. Columns: []string{agent.KeyAgentColumn},
  1467. Bidi: false,
  1468. Target: &sqlgraph.EdgeTarget{
  1469. IDSpec: sqlgraph.NewFieldSpec(apikey.FieldID, field.TypeUint64),
  1470. },
  1471. }
  1472. for _, k := range nodes {
  1473. edge.Target.Nodes = append(edge.Target.Nodes, k)
  1474. }
  1475. _spec.Edges.Clear = append(_spec.Edges.Clear, edge)
  1476. }
  1477. if nodes := auo.mutation.KeyAgentIDs(); len(nodes) > 0 {
  1478. edge := &sqlgraph.EdgeSpec{
  1479. Rel: sqlgraph.O2M,
  1480. Inverse: false,
  1481. Table: agent.KeyAgentTable,
  1482. Columns: []string{agent.KeyAgentColumn},
  1483. Bidi: false,
  1484. Target: &sqlgraph.EdgeTarget{
  1485. IDSpec: sqlgraph.NewFieldSpec(apikey.FieldID, field.TypeUint64),
  1486. },
  1487. }
  1488. for _, k := range nodes {
  1489. edge.Target.Nodes = append(edge.Target.Nodes, k)
  1490. }
  1491. _spec.Edges.Add = append(_spec.Edges.Add, edge)
  1492. }
  1493. if auo.mutation.XjsAgentCleared() {
  1494. edge := &sqlgraph.EdgeSpec{
  1495. Rel: sqlgraph.O2M,
  1496. Inverse: false,
  1497. Table: agent.XjsAgentTable,
  1498. Columns: []string{agent.XjsAgentColumn},
  1499. Bidi: false,
  1500. Target: &sqlgraph.EdgeTarget{
  1501. IDSpec: sqlgraph.NewFieldSpec(xunjiservice.FieldID, field.TypeUint64),
  1502. },
  1503. }
  1504. _spec.Edges.Clear = append(_spec.Edges.Clear, edge)
  1505. }
  1506. if nodes := auo.mutation.RemovedXjsAgentIDs(); len(nodes) > 0 && !auo.mutation.XjsAgentCleared() {
  1507. edge := &sqlgraph.EdgeSpec{
  1508. Rel: sqlgraph.O2M,
  1509. Inverse: false,
  1510. Table: agent.XjsAgentTable,
  1511. Columns: []string{agent.XjsAgentColumn},
  1512. Bidi: false,
  1513. Target: &sqlgraph.EdgeTarget{
  1514. IDSpec: sqlgraph.NewFieldSpec(xunjiservice.FieldID, field.TypeUint64),
  1515. },
  1516. }
  1517. for _, k := range nodes {
  1518. edge.Target.Nodes = append(edge.Target.Nodes, k)
  1519. }
  1520. _spec.Edges.Clear = append(_spec.Edges.Clear, edge)
  1521. }
  1522. if nodes := auo.mutation.XjsAgentIDs(); len(nodes) > 0 {
  1523. edge := &sqlgraph.EdgeSpec{
  1524. Rel: sqlgraph.O2M,
  1525. Inverse: false,
  1526. Table: agent.XjsAgentTable,
  1527. Columns: []string{agent.XjsAgentColumn},
  1528. Bidi: false,
  1529. Target: &sqlgraph.EdgeTarget{
  1530. IDSpec: sqlgraph.NewFieldSpec(xunjiservice.FieldID, field.TypeUint64),
  1531. },
  1532. }
  1533. for _, k := range nodes {
  1534. edge.Target.Nodes = append(edge.Target.Nodes, k)
  1535. }
  1536. _spec.Edges.Add = append(_spec.Edges.Add, edge)
  1537. }
  1538. _node = &Agent{config: auo.config}
  1539. _spec.Assign = _node.assignValues
  1540. _spec.ScanValues = _node.scanValues
  1541. if err = sqlgraph.UpdateNode(ctx, auo.driver, _spec); err != nil {
  1542. if _, ok := err.(*sqlgraph.NotFoundError); ok {
  1543. err = &NotFoundError{agent.Label}
  1544. } else if sqlgraph.IsConstraintError(err) {
  1545. err = &ConstraintError{msg: err.Error(), wrap: err}
  1546. }
  1547. return nil, err
  1548. }
  1549. auo.mutation.done = true
  1550. return _node, nil
  1551. }