employeeconfig_create.go 28 KB

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