agent_create.go 47 KB

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