agent_update.go 51 KB

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