labelrelationship_create.go 29 KB

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