agent_create.go 37 KB

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