label_create.go 34 KB

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