agent_create.go 35 KB

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