workexperience_create.go 31 KB

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