contactfield_create.go 27 KB

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