labellog_create.go 24 KB

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