labelrelationship_create.go 32 KB

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