label_create.go 31 KB

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