agent_update.go 46 KB

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