agent_create.go 39 KB

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