labelrelationship_create.go 28 KB

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