agent_create.go 38 KB

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