agent_create.go 36 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285
  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/token"
  10. "wechat-api/ent/wx"
  11. "entgo.io/ent/dialect/sql"
  12. "entgo.io/ent/dialect/sql/sqlgraph"
  13. "entgo.io/ent/schema/field"
  14. )
  15. // AgentCreate is the builder for creating a Agent entity.
  16. type AgentCreate struct {
  17. config
  18. mutation *AgentMutation
  19. hooks []Hook
  20. conflict []sql.ConflictOption
  21. }
  22. // SetCreatedAt sets the "created_at" field.
  23. func (ac *AgentCreate) SetCreatedAt(t time.Time) *AgentCreate {
  24. ac.mutation.SetCreatedAt(t)
  25. return ac
  26. }
  27. // SetNillableCreatedAt sets the "created_at" field if the given value is not nil.
  28. func (ac *AgentCreate) SetNillableCreatedAt(t *time.Time) *AgentCreate {
  29. if t != nil {
  30. ac.SetCreatedAt(*t)
  31. }
  32. return ac
  33. }
  34. // SetUpdatedAt sets the "updated_at" field.
  35. func (ac *AgentCreate) SetUpdatedAt(t time.Time) *AgentCreate {
  36. ac.mutation.SetUpdatedAt(t)
  37. return ac
  38. }
  39. // SetNillableUpdatedAt sets the "updated_at" field if the given value is not nil.
  40. func (ac *AgentCreate) SetNillableUpdatedAt(t *time.Time) *AgentCreate {
  41. if t != nil {
  42. ac.SetUpdatedAt(*t)
  43. }
  44. return ac
  45. }
  46. // SetDeletedAt sets the "deleted_at" field.
  47. func (ac *AgentCreate) SetDeletedAt(t time.Time) *AgentCreate {
  48. ac.mutation.SetDeletedAt(t)
  49. return ac
  50. }
  51. // SetNillableDeletedAt sets the "deleted_at" field if the given value is not nil.
  52. func (ac *AgentCreate) SetNillableDeletedAt(t *time.Time) *AgentCreate {
  53. if t != nil {
  54. ac.SetDeletedAt(*t)
  55. }
  56. return ac
  57. }
  58. // SetName sets the "name" field.
  59. func (ac *AgentCreate) SetName(s string) *AgentCreate {
  60. ac.mutation.SetName(s)
  61. return ac
  62. }
  63. // SetRole sets the "role" field.
  64. func (ac *AgentCreate) SetRole(s string) *AgentCreate {
  65. ac.mutation.SetRole(s)
  66. return ac
  67. }
  68. // SetStatus sets the "status" field.
  69. func (ac *AgentCreate) SetStatus(i int) *AgentCreate {
  70. ac.mutation.SetStatus(i)
  71. return ac
  72. }
  73. // SetNillableStatus sets the "status" field if the given value is not nil.
  74. func (ac *AgentCreate) SetNillableStatus(i *int) *AgentCreate {
  75. if i != nil {
  76. ac.SetStatus(*i)
  77. }
  78. return ac
  79. }
  80. // SetBackground sets the "background" field.
  81. func (ac *AgentCreate) SetBackground(s string) *AgentCreate {
  82. ac.mutation.SetBackground(s)
  83. return ac
  84. }
  85. // SetNillableBackground sets the "background" field if the given value is not nil.
  86. func (ac *AgentCreate) SetNillableBackground(s *string) *AgentCreate {
  87. if s != nil {
  88. ac.SetBackground(*s)
  89. }
  90. return ac
  91. }
  92. // SetExamples sets the "examples" field.
  93. func (ac *AgentCreate) SetExamples(s string) *AgentCreate {
  94. ac.mutation.SetExamples(s)
  95. return ac
  96. }
  97. // SetNillableExamples sets the "examples" field if the given value is not nil.
  98. func (ac *AgentCreate) SetNillableExamples(s *string) *AgentCreate {
  99. if s != nil {
  100. ac.SetExamples(*s)
  101. }
  102. return ac
  103. }
  104. // SetOrganizationID sets the "organization_id" field.
  105. func (ac *AgentCreate) SetOrganizationID(u uint64) *AgentCreate {
  106. ac.mutation.SetOrganizationID(u)
  107. return ac
  108. }
  109. // SetDatasetID sets the "dataset_id" field.
  110. func (ac *AgentCreate) SetDatasetID(s string) *AgentCreate {
  111. ac.mutation.SetDatasetID(s)
  112. return ac
  113. }
  114. // SetNillableDatasetID sets the "dataset_id" field if the given value is not nil.
  115. func (ac *AgentCreate) SetNillableDatasetID(s *string) *AgentCreate {
  116. if s != nil {
  117. ac.SetDatasetID(*s)
  118. }
  119. return ac
  120. }
  121. // SetCollectionID sets the "collection_id" field.
  122. func (ac *AgentCreate) SetCollectionID(s string) *AgentCreate {
  123. ac.mutation.SetCollectionID(s)
  124. return ac
  125. }
  126. // SetNillableCollectionID sets the "collection_id" field if the given value is not nil.
  127. func (ac *AgentCreate) SetNillableCollectionID(s *string) *AgentCreate {
  128. if s != nil {
  129. ac.SetCollectionID(*s)
  130. }
  131. return ac
  132. }
  133. // SetID sets the "id" field.
  134. func (ac *AgentCreate) SetID(u uint64) *AgentCreate {
  135. ac.mutation.SetID(u)
  136. return ac
  137. }
  138. // AddWxAgentIDs adds the "wx_agent" edge to the Wx entity by IDs.
  139. func (ac *AgentCreate) AddWxAgentIDs(ids ...uint64) *AgentCreate {
  140. ac.mutation.AddWxAgentIDs(ids...)
  141. return ac
  142. }
  143. // AddWxAgent adds the "wx_agent" edges to the Wx entity.
  144. func (ac *AgentCreate) AddWxAgent(w ...*Wx) *AgentCreate {
  145. ids := make([]uint64, len(w))
  146. for i := range w {
  147. ids[i] = w[i].ID
  148. }
  149. return ac.AddWxAgentIDs(ids...)
  150. }
  151. // AddTokenAgentIDs adds the "token_agent" edge to the Token entity by IDs.
  152. func (ac *AgentCreate) AddTokenAgentIDs(ids ...uint64) *AgentCreate {
  153. ac.mutation.AddTokenAgentIDs(ids...)
  154. return ac
  155. }
  156. // AddTokenAgent adds the "token_agent" edges to the Token entity.
  157. func (ac *AgentCreate) AddTokenAgent(t ...*Token) *AgentCreate {
  158. ids := make([]uint64, len(t))
  159. for i := range t {
  160. ids[i] = t[i].ID
  161. }
  162. return ac.AddTokenAgentIDs(ids...)
  163. }
  164. // Mutation returns the AgentMutation object of the builder.
  165. func (ac *AgentCreate) Mutation() *AgentMutation {
  166. return ac.mutation
  167. }
  168. // Save creates the Agent in the database.
  169. func (ac *AgentCreate) Save(ctx context.Context) (*Agent, error) {
  170. if err := ac.defaults(); err != nil {
  171. return nil, err
  172. }
  173. return withHooks(ctx, ac.sqlSave, ac.mutation, ac.hooks)
  174. }
  175. // SaveX calls Save and panics if Save returns an error.
  176. func (ac *AgentCreate) SaveX(ctx context.Context) *Agent {
  177. v, err := ac.Save(ctx)
  178. if err != nil {
  179. panic(err)
  180. }
  181. return v
  182. }
  183. // Exec executes the query.
  184. func (ac *AgentCreate) Exec(ctx context.Context) error {
  185. _, err := ac.Save(ctx)
  186. return err
  187. }
  188. // ExecX is like Exec, but panics if an error occurs.
  189. func (ac *AgentCreate) ExecX(ctx context.Context) {
  190. if err := ac.Exec(ctx); err != nil {
  191. panic(err)
  192. }
  193. }
  194. // defaults sets the default values of the builder before save.
  195. func (ac *AgentCreate) defaults() error {
  196. if _, ok := ac.mutation.CreatedAt(); !ok {
  197. if agent.DefaultCreatedAt == nil {
  198. return fmt.Errorf("ent: uninitialized agent.DefaultCreatedAt (forgotten import ent/runtime?)")
  199. }
  200. v := agent.DefaultCreatedAt()
  201. ac.mutation.SetCreatedAt(v)
  202. }
  203. if _, ok := ac.mutation.UpdatedAt(); !ok {
  204. if agent.DefaultUpdatedAt == nil {
  205. return fmt.Errorf("ent: uninitialized agent.DefaultUpdatedAt (forgotten import ent/runtime?)")
  206. }
  207. v := agent.DefaultUpdatedAt()
  208. ac.mutation.SetUpdatedAt(v)
  209. }
  210. if _, ok := ac.mutation.Status(); !ok {
  211. v := agent.DefaultStatus
  212. ac.mutation.SetStatus(v)
  213. }
  214. if _, ok := ac.mutation.Background(); !ok {
  215. v := agent.DefaultBackground
  216. ac.mutation.SetBackground(v)
  217. }
  218. if _, ok := ac.mutation.Examples(); !ok {
  219. v := agent.DefaultExamples
  220. ac.mutation.SetExamples(v)
  221. }
  222. if _, ok := ac.mutation.DatasetID(); !ok {
  223. v := agent.DefaultDatasetID
  224. ac.mutation.SetDatasetID(v)
  225. }
  226. if _, ok := ac.mutation.CollectionID(); !ok {
  227. v := agent.DefaultCollectionID
  228. ac.mutation.SetCollectionID(v)
  229. }
  230. return nil
  231. }
  232. // check runs all checks and user-defined validators on the builder.
  233. func (ac *AgentCreate) check() error {
  234. if _, ok := ac.mutation.CreatedAt(); !ok {
  235. return &ValidationError{Name: "created_at", err: errors.New(`ent: missing required field "Agent.created_at"`)}
  236. }
  237. if _, ok := ac.mutation.UpdatedAt(); !ok {
  238. return &ValidationError{Name: "updated_at", err: errors.New(`ent: missing required field "Agent.updated_at"`)}
  239. }
  240. if _, ok := ac.mutation.Name(); !ok {
  241. return &ValidationError{Name: "name", err: errors.New(`ent: missing required field "Agent.name"`)}
  242. }
  243. if v, ok := ac.mutation.Name(); ok {
  244. if err := agent.NameValidator(v); err != nil {
  245. return &ValidationError{Name: "name", err: fmt.Errorf(`ent: validator failed for field "Agent.name": %w`, err)}
  246. }
  247. }
  248. if _, ok := ac.mutation.Role(); !ok {
  249. return &ValidationError{Name: "role", err: errors.New(`ent: missing required field "Agent.role"`)}
  250. }
  251. if v, ok := ac.mutation.Status(); ok {
  252. if err := agent.StatusValidator(v); err != nil {
  253. return &ValidationError{Name: "status", err: fmt.Errorf(`ent: validator failed for field "Agent.status": %w`, err)}
  254. }
  255. }
  256. if _, ok := ac.mutation.OrganizationID(); !ok {
  257. return &ValidationError{Name: "organization_id", err: errors.New(`ent: missing required field "Agent.organization_id"`)}
  258. }
  259. if v, ok := ac.mutation.OrganizationID(); ok {
  260. if err := agent.OrganizationIDValidator(v); err != nil {
  261. return &ValidationError{Name: "organization_id", err: fmt.Errorf(`ent: validator failed for field "Agent.organization_id": %w`, err)}
  262. }
  263. }
  264. if _, ok := ac.mutation.DatasetID(); !ok {
  265. return &ValidationError{Name: "dataset_id", err: errors.New(`ent: missing required field "Agent.dataset_id"`)}
  266. }
  267. if v, ok := ac.mutation.DatasetID(); ok {
  268. if err := agent.DatasetIDValidator(v); err != nil {
  269. return &ValidationError{Name: "dataset_id", err: fmt.Errorf(`ent: validator failed for field "Agent.dataset_id": %w`, err)}
  270. }
  271. }
  272. if _, ok := ac.mutation.CollectionID(); !ok {
  273. return &ValidationError{Name: "collection_id", err: errors.New(`ent: missing required field "Agent.collection_id"`)}
  274. }
  275. if v, ok := ac.mutation.CollectionID(); ok {
  276. if err := agent.CollectionIDValidator(v); err != nil {
  277. return &ValidationError{Name: "collection_id", err: fmt.Errorf(`ent: validator failed for field "Agent.collection_id": %w`, err)}
  278. }
  279. }
  280. return nil
  281. }
  282. func (ac *AgentCreate) sqlSave(ctx context.Context) (*Agent, error) {
  283. if err := ac.check(); err != nil {
  284. return nil, err
  285. }
  286. _node, _spec := ac.createSpec()
  287. if err := sqlgraph.CreateNode(ctx, ac.driver, _spec); err != nil {
  288. if sqlgraph.IsConstraintError(err) {
  289. err = &ConstraintError{msg: err.Error(), wrap: err}
  290. }
  291. return nil, err
  292. }
  293. if _spec.ID.Value != _node.ID {
  294. id := _spec.ID.Value.(int64)
  295. _node.ID = uint64(id)
  296. }
  297. ac.mutation.id = &_node.ID
  298. ac.mutation.done = true
  299. return _node, nil
  300. }
  301. func (ac *AgentCreate) createSpec() (*Agent, *sqlgraph.CreateSpec) {
  302. var (
  303. _node = &Agent{config: ac.config}
  304. _spec = sqlgraph.NewCreateSpec(agent.Table, sqlgraph.NewFieldSpec(agent.FieldID, field.TypeUint64))
  305. )
  306. _spec.OnConflict = ac.conflict
  307. if id, ok := ac.mutation.ID(); ok {
  308. _node.ID = id
  309. _spec.ID.Value = id
  310. }
  311. if value, ok := ac.mutation.CreatedAt(); ok {
  312. _spec.SetField(agent.FieldCreatedAt, field.TypeTime, value)
  313. _node.CreatedAt = value
  314. }
  315. if value, ok := ac.mutation.UpdatedAt(); ok {
  316. _spec.SetField(agent.FieldUpdatedAt, field.TypeTime, value)
  317. _node.UpdatedAt = value
  318. }
  319. if value, ok := ac.mutation.DeletedAt(); ok {
  320. _spec.SetField(agent.FieldDeletedAt, field.TypeTime, value)
  321. _node.DeletedAt = value
  322. }
  323. if value, ok := ac.mutation.Name(); ok {
  324. _spec.SetField(agent.FieldName, field.TypeString, value)
  325. _node.Name = value
  326. }
  327. if value, ok := ac.mutation.Role(); ok {
  328. _spec.SetField(agent.FieldRole, field.TypeString, value)
  329. _node.Role = value
  330. }
  331. if value, ok := ac.mutation.Status(); ok {
  332. _spec.SetField(agent.FieldStatus, field.TypeInt, value)
  333. _node.Status = value
  334. }
  335. if value, ok := ac.mutation.Background(); ok {
  336. _spec.SetField(agent.FieldBackground, field.TypeString, value)
  337. _node.Background = value
  338. }
  339. if value, ok := ac.mutation.Examples(); ok {
  340. _spec.SetField(agent.FieldExamples, field.TypeString, value)
  341. _node.Examples = value
  342. }
  343. if value, ok := ac.mutation.OrganizationID(); ok {
  344. _spec.SetField(agent.FieldOrganizationID, field.TypeUint64, value)
  345. _node.OrganizationID = value
  346. }
  347. if value, ok := ac.mutation.DatasetID(); ok {
  348. _spec.SetField(agent.FieldDatasetID, field.TypeString, value)
  349. _node.DatasetID = value
  350. }
  351. if value, ok := ac.mutation.CollectionID(); ok {
  352. _spec.SetField(agent.FieldCollectionID, field.TypeString, value)
  353. _node.CollectionID = value
  354. }
  355. if nodes := ac.mutation.WxAgentIDs(); len(nodes) > 0 {
  356. edge := &sqlgraph.EdgeSpec{
  357. Rel: sqlgraph.O2M,
  358. Inverse: false,
  359. Table: agent.WxAgentTable,
  360. Columns: []string{agent.WxAgentColumn},
  361. Bidi: false,
  362. Target: &sqlgraph.EdgeTarget{
  363. IDSpec: sqlgraph.NewFieldSpec(wx.FieldID, field.TypeUint64),
  364. },
  365. }
  366. for _, k := range nodes {
  367. edge.Target.Nodes = append(edge.Target.Nodes, k)
  368. }
  369. _spec.Edges = append(_spec.Edges, edge)
  370. }
  371. if nodes := ac.mutation.TokenAgentIDs(); len(nodes) > 0 {
  372. edge := &sqlgraph.EdgeSpec{
  373. Rel: sqlgraph.O2M,
  374. Inverse: false,
  375. Table: agent.TokenAgentTable,
  376. Columns: []string{agent.TokenAgentColumn},
  377. Bidi: false,
  378. Target: &sqlgraph.EdgeTarget{
  379. IDSpec: sqlgraph.NewFieldSpec(token.FieldID, field.TypeUint64),
  380. },
  381. }
  382. for _, k := range nodes {
  383. edge.Target.Nodes = append(edge.Target.Nodes, k)
  384. }
  385. _spec.Edges = append(_spec.Edges, edge)
  386. }
  387. return _node, _spec
  388. }
  389. // OnConflict allows configuring the `ON CONFLICT` / `ON DUPLICATE KEY` clause
  390. // of the `INSERT` statement. For example:
  391. //
  392. // client.Agent.Create().
  393. // SetCreatedAt(v).
  394. // OnConflict(
  395. // // Update the row with the new values
  396. // // the was proposed for insertion.
  397. // sql.ResolveWithNewValues(),
  398. // ).
  399. // // Override some of the fields with custom
  400. // // update values.
  401. // Update(func(u *ent.AgentUpsert) {
  402. // SetCreatedAt(v+v).
  403. // }).
  404. // Exec(ctx)
  405. func (ac *AgentCreate) OnConflict(opts ...sql.ConflictOption) *AgentUpsertOne {
  406. ac.conflict = opts
  407. return &AgentUpsertOne{
  408. create: ac,
  409. }
  410. }
  411. // OnConflictColumns calls `OnConflict` and configures the columns
  412. // as conflict target. Using this option is equivalent to using:
  413. //
  414. // client.Agent.Create().
  415. // OnConflict(sql.ConflictColumns(columns...)).
  416. // Exec(ctx)
  417. func (ac *AgentCreate) OnConflictColumns(columns ...string) *AgentUpsertOne {
  418. ac.conflict = append(ac.conflict, sql.ConflictColumns(columns...))
  419. return &AgentUpsertOne{
  420. create: ac,
  421. }
  422. }
  423. type (
  424. // AgentUpsertOne is the builder for "upsert"-ing
  425. // one Agent node.
  426. AgentUpsertOne struct {
  427. create *AgentCreate
  428. }
  429. // AgentUpsert is the "OnConflict" setter.
  430. AgentUpsert struct {
  431. *sql.UpdateSet
  432. }
  433. )
  434. // SetUpdatedAt sets the "updated_at" field.
  435. func (u *AgentUpsert) SetUpdatedAt(v time.Time) *AgentUpsert {
  436. u.Set(agent.FieldUpdatedAt, v)
  437. return u
  438. }
  439. // UpdateUpdatedAt sets the "updated_at" field to the value that was provided on create.
  440. func (u *AgentUpsert) UpdateUpdatedAt() *AgentUpsert {
  441. u.SetExcluded(agent.FieldUpdatedAt)
  442. return u
  443. }
  444. // SetDeletedAt sets the "deleted_at" field.
  445. func (u *AgentUpsert) SetDeletedAt(v time.Time) *AgentUpsert {
  446. u.Set(agent.FieldDeletedAt, v)
  447. return u
  448. }
  449. // UpdateDeletedAt sets the "deleted_at" field to the value that was provided on create.
  450. func (u *AgentUpsert) UpdateDeletedAt() *AgentUpsert {
  451. u.SetExcluded(agent.FieldDeletedAt)
  452. return u
  453. }
  454. // ClearDeletedAt clears the value of the "deleted_at" field.
  455. func (u *AgentUpsert) ClearDeletedAt() *AgentUpsert {
  456. u.SetNull(agent.FieldDeletedAt)
  457. return u
  458. }
  459. // SetName sets the "name" field.
  460. func (u *AgentUpsert) SetName(v string) *AgentUpsert {
  461. u.Set(agent.FieldName, v)
  462. return u
  463. }
  464. // UpdateName sets the "name" field to the value that was provided on create.
  465. func (u *AgentUpsert) UpdateName() *AgentUpsert {
  466. u.SetExcluded(agent.FieldName)
  467. return u
  468. }
  469. // SetRole sets the "role" field.
  470. func (u *AgentUpsert) SetRole(v string) *AgentUpsert {
  471. u.Set(agent.FieldRole, v)
  472. return u
  473. }
  474. // UpdateRole sets the "role" field to the value that was provided on create.
  475. func (u *AgentUpsert) UpdateRole() *AgentUpsert {
  476. u.SetExcluded(agent.FieldRole)
  477. return u
  478. }
  479. // SetStatus sets the "status" field.
  480. func (u *AgentUpsert) SetStatus(v int) *AgentUpsert {
  481. u.Set(agent.FieldStatus, v)
  482. return u
  483. }
  484. // UpdateStatus sets the "status" field to the value that was provided on create.
  485. func (u *AgentUpsert) UpdateStatus() *AgentUpsert {
  486. u.SetExcluded(agent.FieldStatus)
  487. return u
  488. }
  489. // AddStatus adds v to the "status" field.
  490. func (u *AgentUpsert) AddStatus(v int) *AgentUpsert {
  491. u.Add(agent.FieldStatus, v)
  492. return u
  493. }
  494. // ClearStatus clears the value of the "status" field.
  495. func (u *AgentUpsert) ClearStatus() *AgentUpsert {
  496. u.SetNull(agent.FieldStatus)
  497. return u
  498. }
  499. // SetBackground sets the "background" field.
  500. func (u *AgentUpsert) SetBackground(v string) *AgentUpsert {
  501. u.Set(agent.FieldBackground, v)
  502. return u
  503. }
  504. // UpdateBackground sets the "background" field to the value that was provided on create.
  505. func (u *AgentUpsert) UpdateBackground() *AgentUpsert {
  506. u.SetExcluded(agent.FieldBackground)
  507. return u
  508. }
  509. // ClearBackground clears the value of the "background" field.
  510. func (u *AgentUpsert) ClearBackground() *AgentUpsert {
  511. u.SetNull(agent.FieldBackground)
  512. return u
  513. }
  514. // SetExamples sets the "examples" field.
  515. func (u *AgentUpsert) SetExamples(v string) *AgentUpsert {
  516. u.Set(agent.FieldExamples, v)
  517. return u
  518. }
  519. // UpdateExamples sets the "examples" field to the value that was provided on create.
  520. func (u *AgentUpsert) UpdateExamples() *AgentUpsert {
  521. u.SetExcluded(agent.FieldExamples)
  522. return u
  523. }
  524. // ClearExamples clears the value of the "examples" field.
  525. func (u *AgentUpsert) ClearExamples() *AgentUpsert {
  526. u.SetNull(agent.FieldExamples)
  527. return u
  528. }
  529. // SetOrganizationID sets the "organization_id" field.
  530. func (u *AgentUpsert) SetOrganizationID(v uint64) *AgentUpsert {
  531. u.Set(agent.FieldOrganizationID, v)
  532. return u
  533. }
  534. // UpdateOrganizationID sets the "organization_id" field to the value that was provided on create.
  535. func (u *AgentUpsert) UpdateOrganizationID() *AgentUpsert {
  536. u.SetExcluded(agent.FieldOrganizationID)
  537. return u
  538. }
  539. // AddOrganizationID adds v to the "organization_id" field.
  540. func (u *AgentUpsert) AddOrganizationID(v uint64) *AgentUpsert {
  541. u.Add(agent.FieldOrganizationID, v)
  542. return u
  543. }
  544. // SetDatasetID sets the "dataset_id" field.
  545. func (u *AgentUpsert) SetDatasetID(v string) *AgentUpsert {
  546. u.Set(agent.FieldDatasetID, v)
  547. return u
  548. }
  549. // UpdateDatasetID sets the "dataset_id" field to the value that was provided on create.
  550. func (u *AgentUpsert) UpdateDatasetID() *AgentUpsert {
  551. u.SetExcluded(agent.FieldDatasetID)
  552. return u
  553. }
  554. // SetCollectionID sets the "collection_id" field.
  555. func (u *AgentUpsert) SetCollectionID(v string) *AgentUpsert {
  556. u.Set(agent.FieldCollectionID, v)
  557. return u
  558. }
  559. // UpdateCollectionID sets the "collection_id" field to the value that was provided on create.
  560. func (u *AgentUpsert) UpdateCollectionID() *AgentUpsert {
  561. u.SetExcluded(agent.FieldCollectionID)
  562. return u
  563. }
  564. // UpdateNewValues updates the mutable fields using the new values that were set on create except the ID field.
  565. // Using this option is equivalent to using:
  566. //
  567. // client.Agent.Create().
  568. // OnConflict(
  569. // sql.ResolveWithNewValues(),
  570. // sql.ResolveWith(func(u *sql.UpdateSet) {
  571. // u.SetIgnore(agent.FieldID)
  572. // }),
  573. // ).
  574. // Exec(ctx)
  575. func (u *AgentUpsertOne) UpdateNewValues() *AgentUpsertOne {
  576. u.create.conflict = append(u.create.conflict, sql.ResolveWithNewValues())
  577. u.create.conflict = append(u.create.conflict, sql.ResolveWith(func(s *sql.UpdateSet) {
  578. if _, exists := u.create.mutation.ID(); exists {
  579. s.SetIgnore(agent.FieldID)
  580. }
  581. if _, exists := u.create.mutation.CreatedAt(); exists {
  582. s.SetIgnore(agent.FieldCreatedAt)
  583. }
  584. }))
  585. return u
  586. }
  587. // Ignore sets each column to itself in case of conflict.
  588. // Using this option is equivalent to using:
  589. //
  590. // client.Agent.Create().
  591. // OnConflict(sql.ResolveWithIgnore()).
  592. // Exec(ctx)
  593. func (u *AgentUpsertOne) Ignore() *AgentUpsertOne {
  594. u.create.conflict = append(u.create.conflict, sql.ResolveWithIgnore())
  595. return u
  596. }
  597. // DoNothing configures the conflict_action to `DO NOTHING`.
  598. // Supported only by SQLite and PostgreSQL.
  599. func (u *AgentUpsertOne) DoNothing() *AgentUpsertOne {
  600. u.create.conflict = append(u.create.conflict, sql.DoNothing())
  601. return u
  602. }
  603. // Update allows overriding fields `UPDATE` values. See the AgentCreate.OnConflict
  604. // documentation for more info.
  605. func (u *AgentUpsertOne) Update(set func(*AgentUpsert)) *AgentUpsertOne {
  606. u.create.conflict = append(u.create.conflict, sql.ResolveWith(func(update *sql.UpdateSet) {
  607. set(&AgentUpsert{UpdateSet: update})
  608. }))
  609. return u
  610. }
  611. // SetUpdatedAt sets the "updated_at" field.
  612. func (u *AgentUpsertOne) SetUpdatedAt(v time.Time) *AgentUpsertOne {
  613. return u.Update(func(s *AgentUpsert) {
  614. s.SetUpdatedAt(v)
  615. })
  616. }
  617. // UpdateUpdatedAt sets the "updated_at" field to the value that was provided on create.
  618. func (u *AgentUpsertOne) UpdateUpdatedAt() *AgentUpsertOne {
  619. return u.Update(func(s *AgentUpsert) {
  620. s.UpdateUpdatedAt()
  621. })
  622. }
  623. // SetDeletedAt sets the "deleted_at" field.
  624. func (u *AgentUpsertOne) SetDeletedAt(v time.Time) *AgentUpsertOne {
  625. return u.Update(func(s *AgentUpsert) {
  626. s.SetDeletedAt(v)
  627. })
  628. }
  629. // UpdateDeletedAt sets the "deleted_at" field to the value that was provided on create.
  630. func (u *AgentUpsertOne) UpdateDeletedAt() *AgentUpsertOne {
  631. return u.Update(func(s *AgentUpsert) {
  632. s.UpdateDeletedAt()
  633. })
  634. }
  635. // ClearDeletedAt clears the value of the "deleted_at" field.
  636. func (u *AgentUpsertOne) ClearDeletedAt() *AgentUpsertOne {
  637. return u.Update(func(s *AgentUpsert) {
  638. s.ClearDeletedAt()
  639. })
  640. }
  641. // SetName sets the "name" field.
  642. func (u *AgentUpsertOne) SetName(v string) *AgentUpsertOne {
  643. return u.Update(func(s *AgentUpsert) {
  644. s.SetName(v)
  645. })
  646. }
  647. // UpdateName sets the "name" field to the value that was provided on create.
  648. func (u *AgentUpsertOne) UpdateName() *AgentUpsertOne {
  649. return u.Update(func(s *AgentUpsert) {
  650. s.UpdateName()
  651. })
  652. }
  653. // SetRole sets the "role" field.
  654. func (u *AgentUpsertOne) SetRole(v string) *AgentUpsertOne {
  655. return u.Update(func(s *AgentUpsert) {
  656. s.SetRole(v)
  657. })
  658. }
  659. // UpdateRole sets the "role" field to the value that was provided on create.
  660. func (u *AgentUpsertOne) UpdateRole() *AgentUpsertOne {
  661. return u.Update(func(s *AgentUpsert) {
  662. s.UpdateRole()
  663. })
  664. }
  665. // SetStatus sets the "status" field.
  666. func (u *AgentUpsertOne) SetStatus(v int) *AgentUpsertOne {
  667. return u.Update(func(s *AgentUpsert) {
  668. s.SetStatus(v)
  669. })
  670. }
  671. // AddStatus adds v to the "status" field.
  672. func (u *AgentUpsertOne) AddStatus(v int) *AgentUpsertOne {
  673. return u.Update(func(s *AgentUpsert) {
  674. s.AddStatus(v)
  675. })
  676. }
  677. // UpdateStatus sets the "status" field to the value that was provided on create.
  678. func (u *AgentUpsertOne) UpdateStatus() *AgentUpsertOne {
  679. return u.Update(func(s *AgentUpsert) {
  680. s.UpdateStatus()
  681. })
  682. }
  683. // ClearStatus clears the value of the "status" field.
  684. func (u *AgentUpsertOne) ClearStatus() *AgentUpsertOne {
  685. return u.Update(func(s *AgentUpsert) {
  686. s.ClearStatus()
  687. })
  688. }
  689. // SetBackground sets the "background" field.
  690. func (u *AgentUpsertOne) SetBackground(v string) *AgentUpsertOne {
  691. return u.Update(func(s *AgentUpsert) {
  692. s.SetBackground(v)
  693. })
  694. }
  695. // UpdateBackground sets the "background" field to the value that was provided on create.
  696. func (u *AgentUpsertOne) UpdateBackground() *AgentUpsertOne {
  697. return u.Update(func(s *AgentUpsert) {
  698. s.UpdateBackground()
  699. })
  700. }
  701. // ClearBackground clears the value of the "background" field.
  702. func (u *AgentUpsertOne) ClearBackground() *AgentUpsertOne {
  703. return u.Update(func(s *AgentUpsert) {
  704. s.ClearBackground()
  705. })
  706. }
  707. // SetExamples sets the "examples" field.
  708. func (u *AgentUpsertOne) SetExamples(v string) *AgentUpsertOne {
  709. return u.Update(func(s *AgentUpsert) {
  710. s.SetExamples(v)
  711. })
  712. }
  713. // UpdateExamples sets the "examples" field to the value that was provided on create.
  714. func (u *AgentUpsertOne) UpdateExamples() *AgentUpsertOne {
  715. return u.Update(func(s *AgentUpsert) {
  716. s.UpdateExamples()
  717. })
  718. }
  719. // ClearExamples clears the value of the "examples" field.
  720. func (u *AgentUpsertOne) ClearExamples() *AgentUpsertOne {
  721. return u.Update(func(s *AgentUpsert) {
  722. s.ClearExamples()
  723. })
  724. }
  725. // SetOrganizationID sets the "organization_id" field.
  726. func (u *AgentUpsertOne) SetOrganizationID(v uint64) *AgentUpsertOne {
  727. return u.Update(func(s *AgentUpsert) {
  728. s.SetOrganizationID(v)
  729. })
  730. }
  731. // AddOrganizationID adds v to the "organization_id" field.
  732. func (u *AgentUpsertOne) AddOrganizationID(v uint64) *AgentUpsertOne {
  733. return u.Update(func(s *AgentUpsert) {
  734. s.AddOrganizationID(v)
  735. })
  736. }
  737. // UpdateOrganizationID sets the "organization_id" field to the value that was provided on create.
  738. func (u *AgentUpsertOne) UpdateOrganizationID() *AgentUpsertOne {
  739. return u.Update(func(s *AgentUpsert) {
  740. s.UpdateOrganizationID()
  741. })
  742. }
  743. // SetDatasetID sets the "dataset_id" field.
  744. func (u *AgentUpsertOne) SetDatasetID(v string) *AgentUpsertOne {
  745. return u.Update(func(s *AgentUpsert) {
  746. s.SetDatasetID(v)
  747. })
  748. }
  749. // UpdateDatasetID sets the "dataset_id" field to the value that was provided on create.
  750. func (u *AgentUpsertOne) UpdateDatasetID() *AgentUpsertOne {
  751. return u.Update(func(s *AgentUpsert) {
  752. s.UpdateDatasetID()
  753. })
  754. }
  755. // SetCollectionID sets the "collection_id" field.
  756. func (u *AgentUpsertOne) SetCollectionID(v string) *AgentUpsertOne {
  757. return u.Update(func(s *AgentUpsert) {
  758. s.SetCollectionID(v)
  759. })
  760. }
  761. // UpdateCollectionID sets the "collection_id" field to the value that was provided on create.
  762. func (u *AgentUpsertOne) UpdateCollectionID() *AgentUpsertOne {
  763. return u.Update(func(s *AgentUpsert) {
  764. s.UpdateCollectionID()
  765. })
  766. }
  767. // Exec executes the query.
  768. func (u *AgentUpsertOne) Exec(ctx context.Context) error {
  769. if len(u.create.conflict) == 0 {
  770. return errors.New("ent: missing options for AgentCreate.OnConflict")
  771. }
  772. return u.create.Exec(ctx)
  773. }
  774. // ExecX is like Exec, but panics if an error occurs.
  775. func (u *AgentUpsertOne) ExecX(ctx context.Context) {
  776. if err := u.create.Exec(ctx); err != nil {
  777. panic(err)
  778. }
  779. }
  780. // Exec executes the UPSERT query and returns the inserted/updated ID.
  781. func (u *AgentUpsertOne) ID(ctx context.Context) (id uint64, err error) {
  782. node, err := u.create.Save(ctx)
  783. if err != nil {
  784. return id, err
  785. }
  786. return node.ID, nil
  787. }
  788. // IDX is like ID, but panics if an error occurs.
  789. func (u *AgentUpsertOne) IDX(ctx context.Context) uint64 {
  790. id, err := u.ID(ctx)
  791. if err != nil {
  792. panic(err)
  793. }
  794. return id
  795. }
  796. // AgentCreateBulk is the builder for creating many Agent entities in bulk.
  797. type AgentCreateBulk struct {
  798. config
  799. err error
  800. builders []*AgentCreate
  801. conflict []sql.ConflictOption
  802. }
  803. // Save creates the Agent entities in the database.
  804. func (acb *AgentCreateBulk) Save(ctx context.Context) ([]*Agent, error) {
  805. if acb.err != nil {
  806. return nil, acb.err
  807. }
  808. specs := make([]*sqlgraph.CreateSpec, len(acb.builders))
  809. nodes := make([]*Agent, len(acb.builders))
  810. mutators := make([]Mutator, len(acb.builders))
  811. for i := range acb.builders {
  812. func(i int, root context.Context) {
  813. builder := acb.builders[i]
  814. builder.defaults()
  815. var mut Mutator = MutateFunc(func(ctx context.Context, m Mutation) (Value, error) {
  816. mutation, ok := m.(*AgentMutation)
  817. if !ok {
  818. return nil, fmt.Errorf("unexpected mutation type %T", m)
  819. }
  820. if err := builder.check(); err != nil {
  821. return nil, err
  822. }
  823. builder.mutation = mutation
  824. var err error
  825. nodes[i], specs[i] = builder.createSpec()
  826. if i < len(mutators)-1 {
  827. _, err = mutators[i+1].Mutate(root, acb.builders[i+1].mutation)
  828. } else {
  829. spec := &sqlgraph.BatchCreateSpec{Nodes: specs}
  830. spec.OnConflict = acb.conflict
  831. // Invoke the actual operation on the latest mutation in the chain.
  832. if err = sqlgraph.BatchCreate(ctx, acb.driver, spec); err != nil {
  833. if sqlgraph.IsConstraintError(err) {
  834. err = &ConstraintError{msg: err.Error(), wrap: err}
  835. }
  836. }
  837. }
  838. if err != nil {
  839. return nil, err
  840. }
  841. mutation.id = &nodes[i].ID
  842. if specs[i].ID.Value != nil && nodes[i].ID == 0 {
  843. id := specs[i].ID.Value.(int64)
  844. nodes[i].ID = uint64(id)
  845. }
  846. mutation.done = true
  847. return nodes[i], nil
  848. })
  849. for i := len(builder.hooks) - 1; i >= 0; i-- {
  850. mut = builder.hooks[i](mut)
  851. }
  852. mutators[i] = mut
  853. }(i, ctx)
  854. }
  855. if len(mutators) > 0 {
  856. if _, err := mutators[0].Mutate(ctx, acb.builders[0].mutation); err != nil {
  857. return nil, err
  858. }
  859. }
  860. return nodes, nil
  861. }
  862. // SaveX is like Save, but panics if an error occurs.
  863. func (acb *AgentCreateBulk) SaveX(ctx context.Context) []*Agent {
  864. v, err := acb.Save(ctx)
  865. if err != nil {
  866. panic(err)
  867. }
  868. return v
  869. }
  870. // Exec executes the query.
  871. func (acb *AgentCreateBulk) Exec(ctx context.Context) error {
  872. _, err := acb.Save(ctx)
  873. return err
  874. }
  875. // ExecX is like Exec, but panics if an error occurs.
  876. func (acb *AgentCreateBulk) ExecX(ctx context.Context) {
  877. if err := acb.Exec(ctx); err != nil {
  878. panic(err)
  879. }
  880. }
  881. // OnConflict allows configuring the `ON CONFLICT` / `ON DUPLICATE KEY` clause
  882. // of the `INSERT` statement. For example:
  883. //
  884. // client.Agent.CreateBulk(builders...).
  885. // OnConflict(
  886. // // Update the row with the new values
  887. // // the was proposed for insertion.
  888. // sql.ResolveWithNewValues(),
  889. // ).
  890. // // Override some of the fields with custom
  891. // // update values.
  892. // Update(func(u *ent.AgentUpsert) {
  893. // SetCreatedAt(v+v).
  894. // }).
  895. // Exec(ctx)
  896. func (acb *AgentCreateBulk) OnConflict(opts ...sql.ConflictOption) *AgentUpsertBulk {
  897. acb.conflict = opts
  898. return &AgentUpsertBulk{
  899. create: acb,
  900. }
  901. }
  902. // OnConflictColumns calls `OnConflict` and configures the columns
  903. // as conflict target. Using this option is equivalent to using:
  904. //
  905. // client.Agent.Create().
  906. // OnConflict(sql.ConflictColumns(columns...)).
  907. // Exec(ctx)
  908. func (acb *AgentCreateBulk) OnConflictColumns(columns ...string) *AgentUpsertBulk {
  909. acb.conflict = append(acb.conflict, sql.ConflictColumns(columns...))
  910. return &AgentUpsertBulk{
  911. create: acb,
  912. }
  913. }
  914. // AgentUpsertBulk is the builder for "upsert"-ing
  915. // a bulk of Agent nodes.
  916. type AgentUpsertBulk struct {
  917. create *AgentCreateBulk
  918. }
  919. // UpdateNewValues updates the mutable fields using the new values that
  920. // were set on create. Using this option is equivalent to using:
  921. //
  922. // client.Agent.Create().
  923. // OnConflict(
  924. // sql.ResolveWithNewValues(),
  925. // sql.ResolveWith(func(u *sql.UpdateSet) {
  926. // u.SetIgnore(agent.FieldID)
  927. // }),
  928. // ).
  929. // Exec(ctx)
  930. func (u *AgentUpsertBulk) UpdateNewValues() *AgentUpsertBulk {
  931. u.create.conflict = append(u.create.conflict, sql.ResolveWithNewValues())
  932. u.create.conflict = append(u.create.conflict, sql.ResolveWith(func(s *sql.UpdateSet) {
  933. for _, b := range u.create.builders {
  934. if _, exists := b.mutation.ID(); exists {
  935. s.SetIgnore(agent.FieldID)
  936. }
  937. if _, exists := b.mutation.CreatedAt(); exists {
  938. s.SetIgnore(agent.FieldCreatedAt)
  939. }
  940. }
  941. }))
  942. return u
  943. }
  944. // Ignore sets each column to itself in case of conflict.
  945. // Using this option is equivalent to using:
  946. //
  947. // client.Agent.Create().
  948. // OnConflict(sql.ResolveWithIgnore()).
  949. // Exec(ctx)
  950. func (u *AgentUpsertBulk) Ignore() *AgentUpsertBulk {
  951. u.create.conflict = append(u.create.conflict, sql.ResolveWithIgnore())
  952. return u
  953. }
  954. // DoNothing configures the conflict_action to `DO NOTHING`.
  955. // Supported only by SQLite and PostgreSQL.
  956. func (u *AgentUpsertBulk) DoNothing() *AgentUpsertBulk {
  957. u.create.conflict = append(u.create.conflict, sql.DoNothing())
  958. return u
  959. }
  960. // Update allows overriding fields `UPDATE` values. See the AgentCreateBulk.OnConflict
  961. // documentation for more info.
  962. func (u *AgentUpsertBulk) Update(set func(*AgentUpsert)) *AgentUpsertBulk {
  963. u.create.conflict = append(u.create.conflict, sql.ResolveWith(func(update *sql.UpdateSet) {
  964. set(&AgentUpsert{UpdateSet: update})
  965. }))
  966. return u
  967. }
  968. // SetUpdatedAt sets the "updated_at" field.
  969. func (u *AgentUpsertBulk) SetUpdatedAt(v time.Time) *AgentUpsertBulk {
  970. return u.Update(func(s *AgentUpsert) {
  971. s.SetUpdatedAt(v)
  972. })
  973. }
  974. // UpdateUpdatedAt sets the "updated_at" field to the value that was provided on create.
  975. func (u *AgentUpsertBulk) UpdateUpdatedAt() *AgentUpsertBulk {
  976. return u.Update(func(s *AgentUpsert) {
  977. s.UpdateUpdatedAt()
  978. })
  979. }
  980. // SetDeletedAt sets the "deleted_at" field.
  981. func (u *AgentUpsertBulk) SetDeletedAt(v time.Time) *AgentUpsertBulk {
  982. return u.Update(func(s *AgentUpsert) {
  983. s.SetDeletedAt(v)
  984. })
  985. }
  986. // UpdateDeletedAt sets the "deleted_at" field to the value that was provided on create.
  987. func (u *AgentUpsertBulk) UpdateDeletedAt() *AgentUpsertBulk {
  988. return u.Update(func(s *AgentUpsert) {
  989. s.UpdateDeletedAt()
  990. })
  991. }
  992. // ClearDeletedAt clears the value of the "deleted_at" field.
  993. func (u *AgentUpsertBulk) ClearDeletedAt() *AgentUpsertBulk {
  994. return u.Update(func(s *AgentUpsert) {
  995. s.ClearDeletedAt()
  996. })
  997. }
  998. // SetName sets the "name" field.
  999. func (u *AgentUpsertBulk) SetName(v string) *AgentUpsertBulk {
  1000. return u.Update(func(s *AgentUpsert) {
  1001. s.SetName(v)
  1002. })
  1003. }
  1004. // UpdateName sets the "name" field to the value that was provided on create.
  1005. func (u *AgentUpsertBulk) UpdateName() *AgentUpsertBulk {
  1006. return u.Update(func(s *AgentUpsert) {
  1007. s.UpdateName()
  1008. })
  1009. }
  1010. // SetRole sets the "role" field.
  1011. func (u *AgentUpsertBulk) SetRole(v string) *AgentUpsertBulk {
  1012. return u.Update(func(s *AgentUpsert) {
  1013. s.SetRole(v)
  1014. })
  1015. }
  1016. // UpdateRole sets the "role" field to the value that was provided on create.
  1017. func (u *AgentUpsertBulk) UpdateRole() *AgentUpsertBulk {
  1018. return u.Update(func(s *AgentUpsert) {
  1019. s.UpdateRole()
  1020. })
  1021. }
  1022. // SetStatus sets the "status" field.
  1023. func (u *AgentUpsertBulk) SetStatus(v int) *AgentUpsertBulk {
  1024. return u.Update(func(s *AgentUpsert) {
  1025. s.SetStatus(v)
  1026. })
  1027. }
  1028. // AddStatus adds v to the "status" field.
  1029. func (u *AgentUpsertBulk) AddStatus(v int) *AgentUpsertBulk {
  1030. return u.Update(func(s *AgentUpsert) {
  1031. s.AddStatus(v)
  1032. })
  1033. }
  1034. // UpdateStatus sets the "status" field to the value that was provided on create.
  1035. func (u *AgentUpsertBulk) UpdateStatus() *AgentUpsertBulk {
  1036. return u.Update(func(s *AgentUpsert) {
  1037. s.UpdateStatus()
  1038. })
  1039. }
  1040. // ClearStatus clears the value of the "status" field.
  1041. func (u *AgentUpsertBulk) ClearStatus() *AgentUpsertBulk {
  1042. return u.Update(func(s *AgentUpsert) {
  1043. s.ClearStatus()
  1044. })
  1045. }
  1046. // SetBackground sets the "background" field.
  1047. func (u *AgentUpsertBulk) SetBackground(v string) *AgentUpsertBulk {
  1048. return u.Update(func(s *AgentUpsert) {
  1049. s.SetBackground(v)
  1050. })
  1051. }
  1052. // UpdateBackground sets the "background" field to the value that was provided on create.
  1053. func (u *AgentUpsertBulk) UpdateBackground() *AgentUpsertBulk {
  1054. return u.Update(func(s *AgentUpsert) {
  1055. s.UpdateBackground()
  1056. })
  1057. }
  1058. // ClearBackground clears the value of the "background" field.
  1059. func (u *AgentUpsertBulk) ClearBackground() *AgentUpsertBulk {
  1060. return u.Update(func(s *AgentUpsert) {
  1061. s.ClearBackground()
  1062. })
  1063. }
  1064. // SetExamples sets the "examples" field.
  1065. func (u *AgentUpsertBulk) SetExamples(v string) *AgentUpsertBulk {
  1066. return u.Update(func(s *AgentUpsert) {
  1067. s.SetExamples(v)
  1068. })
  1069. }
  1070. // UpdateExamples sets the "examples" field to the value that was provided on create.
  1071. func (u *AgentUpsertBulk) UpdateExamples() *AgentUpsertBulk {
  1072. return u.Update(func(s *AgentUpsert) {
  1073. s.UpdateExamples()
  1074. })
  1075. }
  1076. // ClearExamples clears the value of the "examples" field.
  1077. func (u *AgentUpsertBulk) ClearExamples() *AgentUpsertBulk {
  1078. return u.Update(func(s *AgentUpsert) {
  1079. s.ClearExamples()
  1080. })
  1081. }
  1082. // SetOrganizationID sets the "organization_id" field.
  1083. func (u *AgentUpsertBulk) SetOrganizationID(v uint64) *AgentUpsertBulk {
  1084. return u.Update(func(s *AgentUpsert) {
  1085. s.SetOrganizationID(v)
  1086. })
  1087. }
  1088. // AddOrganizationID adds v to the "organization_id" field.
  1089. func (u *AgentUpsertBulk) AddOrganizationID(v uint64) *AgentUpsertBulk {
  1090. return u.Update(func(s *AgentUpsert) {
  1091. s.AddOrganizationID(v)
  1092. })
  1093. }
  1094. // UpdateOrganizationID sets the "organization_id" field to the value that was provided on create.
  1095. func (u *AgentUpsertBulk) UpdateOrganizationID() *AgentUpsertBulk {
  1096. return u.Update(func(s *AgentUpsert) {
  1097. s.UpdateOrganizationID()
  1098. })
  1099. }
  1100. // SetDatasetID sets the "dataset_id" field.
  1101. func (u *AgentUpsertBulk) SetDatasetID(v string) *AgentUpsertBulk {
  1102. return u.Update(func(s *AgentUpsert) {
  1103. s.SetDatasetID(v)
  1104. })
  1105. }
  1106. // UpdateDatasetID sets the "dataset_id" field to the value that was provided on create.
  1107. func (u *AgentUpsertBulk) UpdateDatasetID() *AgentUpsertBulk {
  1108. return u.Update(func(s *AgentUpsert) {
  1109. s.UpdateDatasetID()
  1110. })
  1111. }
  1112. // SetCollectionID sets the "collection_id" field.
  1113. func (u *AgentUpsertBulk) SetCollectionID(v string) *AgentUpsertBulk {
  1114. return u.Update(func(s *AgentUpsert) {
  1115. s.SetCollectionID(v)
  1116. })
  1117. }
  1118. // UpdateCollectionID sets the "collection_id" field to the value that was provided on create.
  1119. func (u *AgentUpsertBulk) UpdateCollectionID() *AgentUpsertBulk {
  1120. return u.Update(func(s *AgentUpsert) {
  1121. s.UpdateCollectionID()
  1122. })
  1123. }
  1124. // Exec executes the query.
  1125. func (u *AgentUpsertBulk) Exec(ctx context.Context) error {
  1126. if u.create.err != nil {
  1127. return u.create.err
  1128. }
  1129. for i, b := range u.create.builders {
  1130. if len(b.conflict) != 0 {
  1131. return fmt.Errorf("ent: OnConflict was set for builder %d. Set it on the AgentCreateBulk instead", i)
  1132. }
  1133. }
  1134. if len(u.create.conflict) == 0 {
  1135. return errors.New("ent: missing options for AgentCreateBulk.OnConflict")
  1136. }
  1137. return u.create.Exec(ctx)
  1138. }
  1139. // ExecX is like Exec, but panics if an error occurs.
  1140. func (u *AgentUpsertBulk) ExecX(ctx context.Context) {
  1141. if err := u.create.Exec(ctx); err != nil {
  1142. panic(err)
  1143. }
  1144. }