agent_update.go 39 KB

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