agent_create.go 38 KB

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