agent_create.go 35 KB

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