label_create.go 33 KB

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