contactfieldtemplate_create.go 28 KB

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