allocagent_create.go 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965
  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/allocagent"
  9. "entgo.io/ent/dialect/sql"
  10. "entgo.io/ent/dialect/sql/sqlgraph"
  11. "entgo.io/ent/schema/field"
  12. )
  13. // AllocAgentCreate is the builder for creating a AllocAgent entity.
  14. type AllocAgentCreate struct {
  15. config
  16. mutation *AllocAgentMutation
  17. hooks []Hook
  18. conflict []sql.ConflictOption
  19. }
  20. // SetCreatedAt sets the "created_at" field.
  21. func (aac *AllocAgentCreate) SetCreatedAt(t time.Time) *AllocAgentCreate {
  22. aac.mutation.SetCreatedAt(t)
  23. return aac
  24. }
  25. // SetNillableCreatedAt sets the "created_at" field if the given value is not nil.
  26. func (aac *AllocAgentCreate) SetNillableCreatedAt(t *time.Time) *AllocAgentCreate {
  27. if t != nil {
  28. aac.SetCreatedAt(*t)
  29. }
  30. return aac
  31. }
  32. // SetUpdatedAt sets the "updated_at" field.
  33. func (aac *AllocAgentCreate) SetUpdatedAt(t time.Time) *AllocAgentCreate {
  34. aac.mutation.SetUpdatedAt(t)
  35. return aac
  36. }
  37. // SetNillableUpdatedAt sets the "updated_at" field if the given value is not nil.
  38. func (aac *AllocAgentCreate) SetNillableUpdatedAt(t *time.Time) *AllocAgentCreate {
  39. if t != nil {
  40. aac.SetUpdatedAt(*t)
  41. }
  42. return aac
  43. }
  44. // SetDeletedAt sets the "deleted_at" field.
  45. func (aac *AllocAgentCreate) SetDeletedAt(t time.Time) *AllocAgentCreate {
  46. aac.mutation.SetDeletedAt(t)
  47. return aac
  48. }
  49. // SetNillableDeletedAt sets the "deleted_at" field if the given value is not nil.
  50. func (aac *AllocAgentCreate) SetNillableDeletedAt(t *time.Time) *AllocAgentCreate {
  51. if t != nil {
  52. aac.SetDeletedAt(*t)
  53. }
  54. return aac
  55. }
  56. // SetUserID sets the "user_id" field.
  57. func (aac *AllocAgentCreate) SetUserID(s string) *AllocAgentCreate {
  58. aac.mutation.SetUserID(s)
  59. return aac
  60. }
  61. // SetNillableUserID sets the "user_id" field if the given value is not nil.
  62. func (aac *AllocAgentCreate) SetNillableUserID(s *string) *AllocAgentCreate {
  63. if s != nil {
  64. aac.SetUserID(*s)
  65. }
  66. return aac
  67. }
  68. // SetOrganizationID sets the "organization_id" field.
  69. func (aac *AllocAgentCreate) SetOrganizationID(u uint64) *AllocAgentCreate {
  70. aac.mutation.SetOrganizationID(u)
  71. return aac
  72. }
  73. // SetNillableOrganizationID sets the "organization_id" field if the given value is not nil.
  74. func (aac *AllocAgentCreate) SetNillableOrganizationID(u *uint64) *AllocAgentCreate {
  75. if u != nil {
  76. aac.SetOrganizationID(*u)
  77. }
  78. return aac
  79. }
  80. // SetAgents sets the "agents" field.
  81. func (aac *AllocAgentCreate) SetAgents(u []uint64) *AllocAgentCreate {
  82. aac.mutation.SetAgents(u)
  83. return aac
  84. }
  85. // SetStatus sets the "status" field.
  86. func (aac *AllocAgentCreate) SetStatus(i int) *AllocAgentCreate {
  87. aac.mutation.SetStatus(i)
  88. return aac
  89. }
  90. // SetNillableStatus sets the "status" field if the given value is not nil.
  91. func (aac *AllocAgentCreate) SetNillableStatus(i *int) *AllocAgentCreate {
  92. if i != nil {
  93. aac.SetStatus(*i)
  94. }
  95. return aac
  96. }
  97. // SetID sets the "id" field.
  98. func (aac *AllocAgentCreate) SetID(u uint64) *AllocAgentCreate {
  99. aac.mutation.SetID(u)
  100. return aac
  101. }
  102. // Mutation returns the AllocAgentMutation object of the builder.
  103. func (aac *AllocAgentCreate) Mutation() *AllocAgentMutation {
  104. return aac.mutation
  105. }
  106. // Save creates the AllocAgent in the database.
  107. func (aac *AllocAgentCreate) Save(ctx context.Context) (*AllocAgent, error) {
  108. if err := aac.defaults(); err != nil {
  109. return nil, err
  110. }
  111. return withHooks(ctx, aac.sqlSave, aac.mutation, aac.hooks)
  112. }
  113. // SaveX calls Save and panics if Save returns an error.
  114. func (aac *AllocAgentCreate) SaveX(ctx context.Context) *AllocAgent {
  115. v, err := aac.Save(ctx)
  116. if err != nil {
  117. panic(err)
  118. }
  119. return v
  120. }
  121. // Exec executes the query.
  122. func (aac *AllocAgentCreate) Exec(ctx context.Context) error {
  123. _, err := aac.Save(ctx)
  124. return err
  125. }
  126. // ExecX is like Exec, but panics if an error occurs.
  127. func (aac *AllocAgentCreate) ExecX(ctx context.Context) {
  128. if err := aac.Exec(ctx); err != nil {
  129. panic(err)
  130. }
  131. }
  132. // defaults sets the default values of the builder before save.
  133. func (aac *AllocAgentCreate) defaults() error {
  134. if _, ok := aac.mutation.CreatedAt(); !ok {
  135. if allocagent.DefaultCreatedAt == nil {
  136. return fmt.Errorf("ent: uninitialized allocagent.DefaultCreatedAt (forgotten import ent/runtime?)")
  137. }
  138. v := allocagent.DefaultCreatedAt()
  139. aac.mutation.SetCreatedAt(v)
  140. }
  141. if _, ok := aac.mutation.UpdatedAt(); !ok {
  142. if allocagent.DefaultUpdatedAt == nil {
  143. return fmt.Errorf("ent: uninitialized allocagent.DefaultUpdatedAt (forgotten import ent/runtime?)")
  144. }
  145. v := allocagent.DefaultUpdatedAt()
  146. aac.mutation.SetUpdatedAt(v)
  147. }
  148. if _, ok := aac.mutation.UserID(); !ok {
  149. v := allocagent.DefaultUserID
  150. aac.mutation.SetUserID(v)
  151. }
  152. if _, ok := aac.mutation.OrganizationID(); !ok {
  153. v := allocagent.DefaultOrganizationID
  154. aac.mutation.SetOrganizationID(v)
  155. }
  156. if _, ok := aac.mutation.Status(); !ok {
  157. v := allocagent.DefaultStatus
  158. aac.mutation.SetStatus(v)
  159. }
  160. return nil
  161. }
  162. // check runs all checks and user-defined validators on the builder.
  163. func (aac *AllocAgentCreate) check() error {
  164. if _, ok := aac.mutation.CreatedAt(); !ok {
  165. return &ValidationError{Name: "created_at", err: errors.New(`ent: missing required field "AllocAgent.created_at"`)}
  166. }
  167. if _, ok := aac.mutation.UpdatedAt(); !ok {
  168. return &ValidationError{Name: "updated_at", err: errors.New(`ent: missing required field "AllocAgent.updated_at"`)}
  169. }
  170. if _, ok := aac.mutation.Agents(); !ok {
  171. return &ValidationError{Name: "agents", err: errors.New(`ent: missing required field "AllocAgent.agents"`)}
  172. }
  173. if v, ok := aac.mutation.Status(); ok {
  174. if err := allocagent.StatusValidator(v); err != nil {
  175. return &ValidationError{Name: "status", err: fmt.Errorf(`ent: validator failed for field "AllocAgent.status": %w`, err)}
  176. }
  177. }
  178. return nil
  179. }
  180. func (aac *AllocAgentCreate) sqlSave(ctx context.Context) (*AllocAgent, error) {
  181. if err := aac.check(); err != nil {
  182. return nil, err
  183. }
  184. _node, _spec := aac.createSpec()
  185. if err := sqlgraph.CreateNode(ctx, aac.driver, _spec); err != nil {
  186. if sqlgraph.IsConstraintError(err) {
  187. err = &ConstraintError{msg: err.Error(), wrap: err}
  188. }
  189. return nil, err
  190. }
  191. if _spec.ID.Value != _node.ID {
  192. id := _spec.ID.Value.(int64)
  193. _node.ID = uint64(id)
  194. }
  195. aac.mutation.id = &_node.ID
  196. aac.mutation.done = true
  197. return _node, nil
  198. }
  199. func (aac *AllocAgentCreate) createSpec() (*AllocAgent, *sqlgraph.CreateSpec) {
  200. var (
  201. _node = &AllocAgent{config: aac.config}
  202. _spec = sqlgraph.NewCreateSpec(allocagent.Table, sqlgraph.NewFieldSpec(allocagent.FieldID, field.TypeUint64))
  203. )
  204. _spec.OnConflict = aac.conflict
  205. if id, ok := aac.mutation.ID(); ok {
  206. _node.ID = id
  207. _spec.ID.Value = id
  208. }
  209. if value, ok := aac.mutation.CreatedAt(); ok {
  210. _spec.SetField(allocagent.FieldCreatedAt, field.TypeTime, value)
  211. _node.CreatedAt = value
  212. }
  213. if value, ok := aac.mutation.UpdatedAt(); ok {
  214. _spec.SetField(allocagent.FieldUpdatedAt, field.TypeTime, value)
  215. _node.UpdatedAt = value
  216. }
  217. if value, ok := aac.mutation.DeletedAt(); ok {
  218. _spec.SetField(allocagent.FieldDeletedAt, field.TypeTime, value)
  219. _node.DeletedAt = value
  220. }
  221. if value, ok := aac.mutation.UserID(); ok {
  222. _spec.SetField(allocagent.FieldUserID, field.TypeString, value)
  223. _node.UserID = value
  224. }
  225. if value, ok := aac.mutation.OrganizationID(); ok {
  226. _spec.SetField(allocagent.FieldOrganizationID, field.TypeUint64, value)
  227. _node.OrganizationID = value
  228. }
  229. if value, ok := aac.mutation.Agents(); ok {
  230. _spec.SetField(allocagent.FieldAgents, field.TypeJSON, value)
  231. _node.Agents = value
  232. }
  233. if value, ok := aac.mutation.Status(); ok {
  234. _spec.SetField(allocagent.FieldStatus, field.TypeInt, value)
  235. _node.Status = value
  236. }
  237. return _node, _spec
  238. }
  239. // OnConflict allows configuring the `ON CONFLICT` / `ON DUPLICATE KEY` clause
  240. // of the `INSERT` statement. For example:
  241. //
  242. // client.AllocAgent.Create().
  243. // SetCreatedAt(v).
  244. // OnConflict(
  245. // // Update the row with the new values
  246. // // the was proposed for insertion.
  247. // sql.ResolveWithNewValues(),
  248. // ).
  249. // // Override some of the fields with custom
  250. // // update values.
  251. // Update(func(u *ent.AllocAgentUpsert) {
  252. // SetCreatedAt(v+v).
  253. // }).
  254. // Exec(ctx)
  255. func (aac *AllocAgentCreate) OnConflict(opts ...sql.ConflictOption) *AllocAgentUpsertOne {
  256. aac.conflict = opts
  257. return &AllocAgentUpsertOne{
  258. create: aac,
  259. }
  260. }
  261. // OnConflictColumns calls `OnConflict` and configures the columns
  262. // as conflict target. Using this option is equivalent to using:
  263. //
  264. // client.AllocAgent.Create().
  265. // OnConflict(sql.ConflictColumns(columns...)).
  266. // Exec(ctx)
  267. func (aac *AllocAgentCreate) OnConflictColumns(columns ...string) *AllocAgentUpsertOne {
  268. aac.conflict = append(aac.conflict, sql.ConflictColumns(columns...))
  269. return &AllocAgentUpsertOne{
  270. create: aac,
  271. }
  272. }
  273. type (
  274. // AllocAgentUpsertOne is the builder for "upsert"-ing
  275. // one AllocAgent node.
  276. AllocAgentUpsertOne struct {
  277. create *AllocAgentCreate
  278. }
  279. // AllocAgentUpsert is the "OnConflict" setter.
  280. AllocAgentUpsert struct {
  281. *sql.UpdateSet
  282. }
  283. )
  284. // SetUpdatedAt sets the "updated_at" field.
  285. func (u *AllocAgentUpsert) SetUpdatedAt(v time.Time) *AllocAgentUpsert {
  286. u.Set(allocagent.FieldUpdatedAt, v)
  287. return u
  288. }
  289. // UpdateUpdatedAt sets the "updated_at" field to the value that was provided on create.
  290. func (u *AllocAgentUpsert) UpdateUpdatedAt() *AllocAgentUpsert {
  291. u.SetExcluded(allocagent.FieldUpdatedAt)
  292. return u
  293. }
  294. // SetDeletedAt sets the "deleted_at" field.
  295. func (u *AllocAgentUpsert) SetDeletedAt(v time.Time) *AllocAgentUpsert {
  296. u.Set(allocagent.FieldDeletedAt, v)
  297. return u
  298. }
  299. // UpdateDeletedAt sets the "deleted_at" field to the value that was provided on create.
  300. func (u *AllocAgentUpsert) UpdateDeletedAt() *AllocAgentUpsert {
  301. u.SetExcluded(allocagent.FieldDeletedAt)
  302. return u
  303. }
  304. // ClearDeletedAt clears the value of the "deleted_at" field.
  305. func (u *AllocAgentUpsert) ClearDeletedAt() *AllocAgentUpsert {
  306. u.SetNull(allocagent.FieldDeletedAt)
  307. return u
  308. }
  309. // SetUserID sets the "user_id" field.
  310. func (u *AllocAgentUpsert) SetUserID(v string) *AllocAgentUpsert {
  311. u.Set(allocagent.FieldUserID, v)
  312. return u
  313. }
  314. // UpdateUserID sets the "user_id" field to the value that was provided on create.
  315. func (u *AllocAgentUpsert) UpdateUserID() *AllocAgentUpsert {
  316. u.SetExcluded(allocagent.FieldUserID)
  317. return u
  318. }
  319. // ClearUserID clears the value of the "user_id" field.
  320. func (u *AllocAgentUpsert) ClearUserID() *AllocAgentUpsert {
  321. u.SetNull(allocagent.FieldUserID)
  322. return u
  323. }
  324. // SetOrganizationID sets the "organization_id" field.
  325. func (u *AllocAgentUpsert) SetOrganizationID(v uint64) *AllocAgentUpsert {
  326. u.Set(allocagent.FieldOrganizationID, v)
  327. return u
  328. }
  329. // UpdateOrganizationID sets the "organization_id" field to the value that was provided on create.
  330. func (u *AllocAgentUpsert) UpdateOrganizationID() *AllocAgentUpsert {
  331. u.SetExcluded(allocagent.FieldOrganizationID)
  332. return u
  333. }
  334. // AddOrganizationID adds v to the "organization_id" field.
  335. func (u *AllocAgentUpsert) AddOrganizationID(v uint64) *AllocAgentUpsert {
  336. u.Add(allocagent.FieldOrganizationID, v)
  337. return u
  338. }
  339. // ClearOrganizationID clears the value of the "organization_id" field.
  340. func (u *AllocAgentUpsert) ClearOrganizationID() *AllocAgentUpsert {
  341. u.SetNull(allocagent.FieldOrganizationID)
  342. return u
  343. }
  344. // SetAgents sets the "agents" field.
  345. func (u *AllocAgentUpsert) SetAgents(v []uint64) *AllocAgentUpsert {
  346. u.Set(allocagent.FieldAgents, v)
  347. return u
  348. }
  349. // UpdateAgents sets the "agents" field to the value that was provided on create.
  350. func (u *AllocAgentUpsert) UpdateAgents() *AllocAgentUpsert {
  351. u.SetExcluded(allocagent.FieldAgents)
  352. return u
  353. }
  354. // SetStatus sets the "status" field.
  355. func (u *AllocAgentUpsert) SetStatus(v int) *AllocAgentUpsert {
  356. u.Set(allocagent.FieldStatus, v)
  357. return u
  358. }
  359. // UpdateStatus sets the "status" field to the value that was provided on create.
  360. func (u *AllocAgentUpsert) UpdateStatus() *AllocAgentUpsert {
  361. u.SetExcluded(allocagent.FieldStatus)
  362. return u
  363. }
  364. // AddStatus adds v to the "status" field.
  365. func (u *AllocAgentUpsert) AddStatus(v int) *AllocAgentUpsert {
  366. u.Add(allocagent.FieldStatus, v)
  367. return u
  368. }
  369. // ClearStatus clears the value of the "status" field.
  370. func (u *AllocAgentUpsert) ClearStatus() *AllocAgentUpsert {
  371. u.SetNull(allocagent.FieldStatus)
  372. return u
  373. }
  374. // UpdateNewValues updates the mutable fields using the new values that were set on create except the ID field.
  375. // Using this option is equivalent to using:
  376. //
  377. // client.AllocAgent.Create().
  378. // OnConflict(
  379. // sql.ResolveWithNewValues(),
  380. // sql.ResolveWith(func(u *sql.UpdateSet) {
  381. // u.SetIgnore(allocagent.FieldID)
  382. // }),
  383. // ).
  384. // Exec(ctx)
  385. func (u *AllocAgentUpsertOne) UpdateNewValues() *AllocAgentUpsertOne {
  386. u.create.conflict = append(u.create.conflict, sql.ResolveWithNewValues())
  387. u.create.conflict = append(u.create.conflict, sql.ResolveWith(func(s *sql.UpdateSet) {
  388. if _, exists := u.create.mutation.ID(); exists {
  389. s.SetIgnore(allocagent.FieldID)
  390. }
  391. if _, exists := u.create.mutation.CreatedAt(); exists {
  392. s.SetIgnore(allocagent.FieldCreatedAt)
  393. }
  394. }))
  395. return u
  396. }
  397. // Ignore sets each column to itself in case of conflict.
  398. // Using this option is equivalent to using:
  399. //
  400. // client.AllocAgent.Create().
  401. // OnConflict(sql.ResolveWithIgnore()).
  402. // Exec(ctx)
  403. func (u *AllocAgentUpsertOne) Ignore() *AllocAgentUpsertOne {
  404. u.create.conflict = append(u.create.conflict, sql.ResolveWithIgnore())
  405. return u
  406. }
  407. // DoNothing configures the conflict_action to `DO NOTHING`.
  408. // Supported only by SQLite and PostgreSQL.
  409. func (u *AllocAgentUpsertOne) DoNothing() *AllocAgentUpsertOne {
  410. u.create.conflict = append(u.create.conflict, sql.DoNothing())
  411. return u
  412. }
  413. // Update allows overriding fields `UPDATE` values. See the AllocAgentCreate.OnConflict
  414. // documentation for more info.
  415. func (u *AllocAgentUpsertOne) Update(set func(*AllocAgentUpsert)) *AllocAgentUpsertOne {
  416. u.create.conflict = append(u.create.conflict, sql.ResolveWith(func(update *sql.UpdateSet) {
  417. set(&AllocAgentUpsert{UpdateSet: update})
  418. }))
  419. return u
  420. }
  421. // SetUpdatedAt sets the "updated_at" field.
  422. func (u *AllocAgentUpsertOne) SetUpdatedAt(v time.Time) *AllocAgentUpsertOne {
  423. return u.Update(func(s *AllocAgentUpsert) {
  424. s.SetUpdatedAt(v)
  425. })
  426. }
  427. // UpdateUpdatedAt sets the "updated_at" field to the value that was provided on create.
  428. func (u *AllocAgentUpsertOne) UpdateUpdatedAt() *AllocAgentUpsertOne {
  429. return u.Update(func(s *AllocAgentUpsert) {
  430. s.UpdateUpdatedAt()
  431. })
  432. }
  433. // SetDeletedAt sets the "deleted_at" field.
  434. func (u *AllocAgentUpsertOne) SetDeletedAt(v time.Time) *AllocAgentUpsertOne {
  435. return u.Update(func(s *AllocAgentUpsert) {
  436. s.SetDeletedAt(v)
  437. })
  438. }
  439. // UpdateDeletedAt sets the "deleted_at" field to the value that was provided on create.
  440. func (u *AllocAgentUpsertOne) UpdateDeletedAt() *AllocAgentUpsertOne {
  441. return u.Update(func(s *AllocAgentUpsert) {
  442. s.UpdateDeletedAt()
  443. })
  444. }
  445. // ClearDeletedAt clears the value of the "deleted_at" field.
  446. func (u *AllocAgentUpsertOne) ClearDeletedAt() *AllocAgentUpsertOne {
  447. return u.Update(func(s *AllocAgentUpsert) {
  448. s.ClearDeletedAt()
  449. })
  450. }
  451. // SetUserID sets the "user_id" field.
  452. func (u *AllocAgentUpsertOne) SetUserID(v string) *AllocAgentUpsertOne {
  453. return u.Update(func(s *AllocAgentUpsert) {
  454. s.SetUserID(v)
  455. })
  456. }
  457. // UpdateUserID sets the "user_id" field to the value that was provided on create.
  458. func (u *AllocAgentUpsertOne) UpdateUserID() *AllocAgentUpsertOne {
  459. return u.Update(func(s *AllocAgentUpsert) {
  460. s.UpdateUserID()
  461. })
  462. }
  463. // ClearUserID clears the value of the "user_id" field.
  464. func (u *AllocAgentUpsertOne) ClearUserID() *AllocAgentUpsertOne {
  465. return u.Update(func(s *AllocAgentUpsert) {
  466. s.ClearUserID()
  467. })
  468. }
  469. // SetOrganizationID sets the "organization_id" field.
  470. func (u *AllocAgentUpsertOne) SetOrganizationID(v uint64) *AllocAgentUpsertOne {
  471. return u.Update(func(s *AllocAgentUpsert) {
  472. s.SetOrganizationID(v)
  473. })
  474. }
  475. // AddOrganizationID adds v to the "organization_id" field.
  476. func (u *AllocAgentUpsertOne) AddOrganizationID(v uint64) *AllocAgentUpsertOne {
  477. return u.Update(func(s *AllocAgentUpsert) {
  478. s.AddOrganizationID(v)
  479. })
  480. }
  481. // UpdateOrganizationID sets the "organization_id" field to the value that was provided on create.
  482. func (u *AllocAgentUpsertOne) UpdateOrganizationID() *AllocAgentUpsertOne {
  483. return u.Update(func(s *AllocAgentUpsert) {
  484. s.UpdateOrganizationID()
  485. })
  486. }
  487. // ClearOrganizationID clears the value of the "organization_id" field.
  488. func (u *AllocAgentUpsertOne) ClearOrganizationID() *AllocAgentUpsertOne {
  489. return u.Update(func(s *AllocAgentUpsert) {
  490. s.ClearOrganizationID()
  491. })
  492. }
  493. // SetAgents sets the "agents" field.
  494. func (u *AllocAgentUpsertOne) SetAgents(v []uint64) *AllocAgentUpsertOne {
  495. return u.Update(func(s *AllocAgentUpsert) {
  496. s.SetAgents(v)
  497. })
  498. }
  499. // UpdateAgents sets the "agents" field to the value that was provided on create.
  500. func (u *AllocAgentUpsertOne) UpdateAgents() *AllocAgentUpsertOne {
  501. return u.Update(func(s *AllocAgentUpsert) {
  502. s.UpdateAgents()
  503. })
  504. }
  505. // SetStatus sets the "status" field.
  506. func (u *AllocAgentUpsertOne) SetStatus(v int) *AllocAgentUpsertOne {
  507. return u.Update(func(s *AllocAgentUpsert) {
  508. s.SetStatus(v)
  509. })
  510. }
  511. // AddStatus adds v to the "status" field.
  512. func (u *AllocAgentUpsertOne) AddStatus(v int) *AllocAgentUpsertOne {
  513. return u.Update(func(s *AllocAgentUpsert) {
  514. s.AddStatus(v)
  515. })
  516. }
  517. // UpdateStatus sets the "status" field to the value that was provided on create.
  518. func (u *AllocAgentUpsertOne) UpdateStatus() *AllocAgentUpsertOne {
  519. return u.Update(func(s *AllocAgentUpsert) {
  520. s.UpdateStatus()
  521. })
  522. }
  523. // ClearStatus clears the value of the "status" field.
  524. func (u *AllocAgentUpsertOne) ClearStatus() *AllocAgentUpsertOne {
  525. return u.Update(func(s *AllocAgentUpsert) {
  526. s.ClearStatus()
  527. })
  528. }
  529. // Exec executes the query.
  530. func (u *AllocAgentUpsertOne) Exec(ctx context.Context) error {
  531. if len(u.create.conflict) == 0 {
  532. return errors.New("ent: missing options for AllocAgentCreate.OnConflict")
  533. }
  534. return u.create.Exec(ctx)
  535. }
  536. // ExecX is like Exec, but panics if an error occurs.
  537. func (u *AllocAgentUpsertOne) ExecX(ctx context.Context) {
  538. if err := u.create.Exec(ctx); err != nil {
  539. panic(err)
  540. }
  541. }
  542. // Exec executes the UPSERT query and returns the inserted/updated ID.
  543. func (u *AllocAgentUpsertOne) ID(ctx context.Context) (id uint64, err error) {
  544. node, err := u.create.Save(ctx)
  545. if err != nil {
  546. return id, err
  547. }
  548. return node.ID, nil
  549. }
  550. // IDX is like ID, but panics if an error occurs.
  551. func (u *AllocAgentUpsertOne) IDX(ctx context.Context) uint64 {
  552. id, err := u.ID(ctx)
  553. if err != nil {
  554. panic(err)
  555. }
  556. return id
  557. }
  558. // AllocAgentCreateBulk is the builder for creating many AllocAgent entities in bulk.
  559. type AllocAgentCreateBulk struct {
  560. config
  561. err error
  562. builders []*AllocAgentCreate
  563. conflict []sql.ConflictOption
  564. }
  565. // Save creates the AllocAgent entities in the database.
  566. func (aacb *AllocAgentCreateBulk) Save(ctx context.Context) ([]*AllocAgent, error) {
  567. if aacb.err != nil {
  568. return nil, aacb.err
  569. }
  570. specs := make([]*sqlgraph.CreateSpec, len(aacb.builders))
  571. nodes := make([]*AllocAgent, len(aacb.builders))
  572. mutators := make([]Mutator, len(aacb.builders))
  573. for i := range aacb.builders {
  574. func(i int, root context.Context) {
  575. builder := aacb.builders[i]
  576. builder.defaults()
  577. var mut Mutator = MutateFunc(func(ctx context.Context, m Mutation) (Value, error) {
  578. mutation, ok := m.(*AllocAgentMutation)
  579. if !ok {
  580. return nil, fmt.Errorf("unexpected mutation type %T", m)
  581. }
  582. if err := builder.check(); err != nil {
  583. return nil, err
  584. }
  585. builder.mutation = mutation
  586. var err error
  587. nodes[i], specs[i] = builder.createSpec()
  588. if i < len(mutators)-1 {
  589. _, err = mutators[i+1].Mutate(root, aacb.builders[i+1].mutation)
  590. } else {
  591. spec := &sqlgraph.BatchCreateSpec{Nodes: specs}
  592. spec.OnConflict = aacb.conflict
  593. // Invoke the actual operation on the latest mutation in the chain.
  594. if err = sqlgraph.BatchCreate(ctx, aacb.driver, spec); err != nil {
  595. if sqlgraph.IsConstraintError(err) {
  596. err = &ConstraintError{msg: err.Error(), wrap: err}
  597. }
  598. }
  599. }
  600. if err != nil {
  601. return nil, err
  602. }
  603. mutation.id = &nodes[i].ID
  604. if specs[i].ID.Value != nil && nodes[i].ID == 0 {
  605. id := specs[i].ID.Value.(int64)
  606. nodes[i].ID = uint64(id)
  607. }
  608. mutation.done = true
  609. return nodes[i], nil
  610. })
  611. for i := len(builder.hooks) - 1; i >= 0; i-- {
  612. mut = builder.hooks[i](mut)
  613. }
  614. mutators[i] = mut
  615. }(i, ctx)
  616. }
  617. if len(mutators) > 0 {
  618. if _, err := mutators[0].Mutate(ctx, aacb.builders[0].mutation); err != nil {
  619. return nil, err
  620. }
  621. }
  622. return nodes, nil
  623. }
  624. // SaveX is like Save, but panics if an error occurs.
  625. func (aacb *AllocAgentCreateBulk) SaveX(ctx context.Context) []*AllocAgent {
  626. v, err := aacb.Save(ctx)
  627. if err != nil {
  628. panic(err)
  629. }
  630. return v
  631. }
  632. // Exec executes the query.
  633. func (aacb *AllocAgentCreateBulk) Exec(ctx context.Context) error {
  634. _, err := aacb.Save(ctx)
  635. return err
  636. }
  637. // ExecX is like Exec, but panics if an error occurs.
  638. func (aacb *AllocAgentCreateBulk) ExecX(ctx context.Context) {
  639. if err := aacb.Exec(ctx); err != nil {
  640. panic(err)
  641. }
  642. }
  643. // OnConflict allows configuring the `ON CONFLICT` / `ON DUPLICATE KEY` clause
  644. // of the `INSERT` statement. For example:
  645. //
  646. // client.AllocAgent.CreateBulk(builders...).
  647. // OnConflict(
  648. // // Update the row with the new values
  649. // // the was proposed for insertion.
  650. // sql.ResolveWithNewValues(),
  651. // ).
  652. // // Override some of the fields with custom
  653. // // update values.
  654. // Update(func(u *ent.AllocAgentUpsert) {
  655. // SetCreatedAt(v+v).
  656. // }).
  657. // Exec(ctx)
  658. func (aacb *AllocAgentCreateBulk) OnConflict(opts ...sql.ConflictOption) *AllocAgentUpsertBulk {
  659. aacb.conflict = opts
  660. return &AllocAgentUpsertBulk{
  661. create: aacb,
  662. }
  663. }
  664. // OnConflictColumns calls `OnConflict` and configures the columns
  665. // as conflict target. Using this option is equivalent to using:
  666. //
  667. // client.AllocAgent.Create().
  668. // OnConflict(sql.ConflictColumns(columns...)).
  669. // Exec(ctx)
  670. func (aacb *AllocAgentCreateBulk) OnConflictColumns(columns ...string) *AllocAgentUpsertBulk {
  671. aacb.conflict = append(aacb.conflict, sql.ConflictColumns(columns...))
  672. return &AllocAgentUpsertBulk{
  673. create: aacb,
  674. }
  675. }
  676. // AllocAgentUpsertBulk is the builder for "upsert"-ing
  677. // a bulk of AllocAgent nodes.
  678. type AllocAgentUpsertBulk struct {
  679. create *AllocAgentCreateBulk
  680. }
  681. // UpdateNewValues updates the mutable fields using the new values that
  682. // were set on create. Using this option is equivalent to using:
  683. //
  684. // client.AllocAgent.Create().
  685. // OnConflict(
  686. // sql.ResolveWithNewValues(),
  687. // sql.ResolveWith(func(u *sql.UpdateSet) {
  688. // u.SetIgnore(allocagent.FieldID)
  689. // }),
  690. // ).
  691. // Exec(ctx)
  692. func (u *AllocAgentUpsertBulk) UpdateNewValues() *AllocAgentUpsertBulk {
  693. u.create.conflict = append(u.create.conflict, sql.ResolveWithNewValues())
  694. u.create.conflict = append(u.create.conflict, sql.ResolveWith(func(s *sql.UpdateSet) {
  695. for _, b := range u.create.builders {
  696. if _, exists := b.mutation.ID(); exists {
  697. s.SetIgnore(allocagent.FieldID)
  698. }
  699. if _, exists := b.mutation.CreatedAt(); exists {
  700. s.SetIgnore(allocagent.FieldCreatedAt)
  701. }
  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.AllocAgent.Create().
  710. // OnConflict(sql.ResolveWithIgnore()).
  711. // Exec(ctx)
  712. func (u *AllocAgentUpsertBulk) Ignore() *AllocAgentUpsertBulk {
  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 *AllocAgentUpsertBulk) DoNothing() *AllocAgentUpsertBulk {
  719. u.create.conflict = append(u.create.conflict, sql.DoNothing())
  720. return u
  721. }
  722. // Update allows overriding fields `UPDATE` values. See the AllocAgentCreateBulk.OnConflict
  723. // documentation for more info.
  724. func (u *AllocAgentUpsertBulk) Update(set func(*AllocAgentUpsert)) *AllocAgentUpsertBulk {
  725. u.create.conflict = append(u.create.conflict, sql.ResolveWith(func(update *sql.UpdateSet) {
  726. set(&AllocAgentUpsert{UpdateSet: update})
  727. }))
  728. return u
  729. }
  730. // SetUpdatedAt sets the "updated_at" field.
  731. func (u *AllocAgentUpsertBulk) SetUpdatedAt(v time.Time) *AllocAgentUpsertBulk {
  732. return u.Update(func(s *AllocAgentUpsert) {
  733. s.SetUpdatedAt(v)
  734. })
  735. }
  736. // UpdateUpdatedAt sets the "updated_at" field to the value that was provided on create.
  737. func (u *AllocAgentUpsertBulk) UpdateUpdatedAt() *AllocAgentUpsertBulk {
  738. return u.Update(func(s *AllocAgentUpsert) {
  739. s.UpdateUpdatedAt()
  740. })
  741. }
  742. // SetDeletedAt sets the "deleted_at" field.
  743. func (u *AllocAgentUpsertBulk) SetDeletedAt(v time.Time) *AllocAgentUpsertBulk {
  744. return u.Update(func(s *AllocAgentUpsert) {
  745. s.SetDeletedAt(v)
  746. })
  747. }
  748. // UpdateDeletedAt sets the "deleted_at" field to the value that was provided on create.
  749. func (u *AllocAgentUpsertBulk) UpdateDeletedAt() *AllocAgentUpsertBulk {
  750. return u.Update(func(s *AllocAgentUpsert) {
  751. s.UpdateDeletedAt()
  752. })
  753. }
  754. // ClearDeletedAt clears the value of the "deleted_at" field.
  755. func (u *AllocAgentUpsertBulk) ClearDeletedAt() *AllocAgentUpsertBulk {
  756. return u.Update(func(s *AllocAgentUpsert) {
  757. s.ClearDeletedAt()
  758. })
  759. }
  760. // SetUserID sets the "user_id" field.
  761. func (u *AllocAgentUpsertBulk) SetUserID(v string) *AllocAgentUpsertBulk {
  762. return u.Update(func(s *AllocAgentUpsert) {
  763. s.SetUserID(v)
  764. })
  765. }
  766. // UpdateUserID sets the "user_id" field to the value that was provided on create.
  767. func (u *AllocAgentUpsertBulk) UpdateUserID() *AllocAgentUpsertBulk {
  768. return u.Update(func(s *AllocAgentUpsert) {
  769. s.UpdateUserID()
  770. })
  771. }
  772. // ClearUserID clears the value of the "user_id" field.
  773. func (u *AllocAgentUpsertBulk) ClearUserID() *AllocAgentUpsertBulk {
  774. return u.Update(func(s *AllocAgentUpsert) {
  775. s.ClearUserID()
  776. })
  777. }
  778. // SetOrganizationID sets the "organization_id" field.
  779. func (u *AllocAgentUpsertBulk) SetOrganizationID(v uint64) *AllocAgentUpsertBulk {
  780. return u.Update(func(s *AllocAgentUpsert) {
  781. s.SetOrganizationID(v)
  782. })
  783. }
  784. // AddOrganizationID adds v to the "organization_id" field.
  785. func (u *AllocAgentUpsertBulk) AddOrganizationID(v uint64) *AllocAgentUpsertBulk {
  786. return u.Update(func(s *AllocAgentUpsert) {
  787. s.AddOrganizationID(v)
  788. })
  789. }
  790. // UpdateOrganizationID sets the "organization_id" field to the value that was provided on create.
  791. func (u *AllocAgentUpsertBulk) UpdateOrganizationID() *AllocAgentUpsertBulk {
  792. return u.Update(func(s *AllocAgentUpsert) {
  793. s.UpdateOrganizationID()
  794. })
  795. }
  796. // ClearOrganizationID clears the value of the "organization_id" field.
  797. func (u *AllocAgentUpsertBulk) ClearOrganizationID() *AllocAgentUpsertBulk {
  798. return u.Update(func(s *AllocAgentUpsert) {
  799. s.ClearOrganizationID()
  800. })
  801. }
  802. // SetAgents sets the "agents" field.
  803. func (u *AllocAgentUpsertBulk) SetAgents(v []uint64) *AllocAgentUpsertBulk {
  804. return u.Update(func(s *AllocAgentUpsert) {
  805. s.SetAgents(v)
  806. })
  807. }
  808. // UpdateAgents sets the "agents" field to the value that was provided on create.
  809. func (u *AllocAgentUpsertBulk) UpdateAgents() *AllocAgentUpsertBulk {
  810. return u.Update(func(s *AllocAgentUpsert) {
  811. s.UpdateAgents()
  812. })
  813. }
  814. // SetStatus sets the "status" field.
  815. func (u *AllocAgentUpsertBulk) SetStatus(v int) *AllocAgentUpsertBulk {
  816. return u.Update(func(s *AllocAgentUpsert) {
  817. s.SetStatus(v)
  818. })
  819. }
  820. // AddStatus adds v to the "status" field.
  821. func (u *AllocAgentUpsertBulk) AddStatus(v int) *AllocAgentUpsertBulk {
  822. return u.Update(func(s *AllocAgentUpsert) {
  823. s.AddStatus(v)
  824. })
  825. }
  826. // UpdateStatus sets the "status" field to the value that was provided on create.
  827. func (u *AllocAgentUpsertBulk) UpdateStatus() *AllocAgentUpsertBulk {
  828. return u.Update(func(s *AllocAgentUpsert) {
  829. s.UpdateStatus()
  830. })
  831. }
  832. // ClearStatus clears the value of the "status" field.
  833. func (u *AllocAgentUpsertBulk) ClearStatus() *AllocAgentUpsertBulk {
  834. return u.Update(func(s *AllocAgentUpsert) {
  835. s.ClearStatus()
  836. })
  837. }
  838. // Exec executes the query.
  839. func (u *AllocAgentUpsertBulk) Exec(ctx context.Context) error {
  840. if u.create.err != nil {
  841. return u.create.err
  842. }
  843. for i, b := range u.create.builders {
  844. if len(b.conflict) != 0 {
  845. return fmt.Errorf("ent: OnConflict was set for builder %d. Set it on the AllocAgentCreateBulk instead", i)
  846. }
  847. }
  848. if len(u.create.conflict) == 0 {
  849. return errors.New("ent: missing options for AllocAgentCreateBulk.OnConflict")
  850. }
  851. return u.create.Exec(ctx)
  852. }
  853. // ExecX is like Exec, but panics if an error occurs.
  854. func (u *AllocAgentUpsertBulk) ExecX(ctx context.Context) {
  855. if err := u.create.Exec(ctx); err != nil {
  856. panic(err)
  857. }
  858. }