employee_update.go 44 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416
  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/predicate"
  10. "wechat-api/ent/tutorial"
  11. "wechat-api/ent/workexperience"
  12. "entgo.io/ent/dialect/sql"
  13. "entgo.io/ent/dialect/sql/sqlgraph"
  14. "entgo.io/ent/schema/field"
  15. )
  16. // EmployeeUpdate is the builder for updating Employee entities.
  17. type EmployeeUpdate struct {
  18. config
  19. hooks []Hook
  20. mutation *EmployeeMutation
  21. }
  22. // Where appends a list predicates to the EmployeeUpdate builder.
  23. func (eu *EmployeeUpdate) Where(ps ...predicate.Employee) *EmployeeUpdate {
  24. eu.mutation.Where(ps...)
  25. return eu
  26. }
  27. // SetUpdatedAt sets the "updated_at" field.
  28. func (eu *EmployeeUpdate) SetUpdatedAt(t time.Time) *EmployeeUpdate {
  29. eu.mutation.SetUpdatedAt(t)
  30. return eu
  31. }
  32. // SetDeletedAt sets the "deleted_at" field.
  33. func (eu *EmployeeUpdate) SetDeletedAt(t time.Time) *EmployeeUpdate {
  34. eu.mutation.SetDeletedAt(t)
  35. return eu
  36. }
  37. // SetNillableDeletedAt sets the "deleted_at" field if the given value is not nil.
  38. func (eu *EmployeeUpdate) SetNillableDeletedAt(t *time.Time) *EmployeeUpdate {
  39. if t != nil {
  40. eu.SetDeletedAt(*t)
  41. }
  42. return eu
  43. }
  44. // ClearDeletedAt clears the value of the "deleted_at" field.
  45. func (eu *EmployeeUpdate) ClearDeletedAt() *EmployeeUpdate {
  46. eu.mutation.ClearDeletedAt()
  47. return eu
  48. }
  49. // SetTitle sets the "title" field.
  50. func (eu *EmployeeUpdate) SetTitle(s string) *EmployeeUpdate {
  51. eu.mutation.SetTitle(s)
  52. return eu
  53. }
  54. // SetNillableTitle sets the "title" field if the given value is not nil.
  55. func (eu *EmployeeUpdate) SetNillableTitle(s *string) *EmployeeUpdate {
  56. if s != nil {
  57. eu.SetTitle(*s)
  58. }
  59. return eu
  60. }
  61. // SetAvatar sets the "avatar" field.
  62. func (eu *EmployeeUpdate) SetAvatar(s string) *EmployeeUpdate {
  63. eu.mutation.SetAvatar(s)
  64. return eu
  65. }
  66. // SetNillableAvatar sets the "avatar" field if the given value is not nil.
  67. func (eu *EmployeeUpdate) SetNillableAvatar(s *string) *EmployeeUpdate {
  68. if s != nil {
  69. eu.SetAvatar(*s)
  70. }
  71. return eu
  72. }
  73. // SetTags sets the "tags" field.
  74. func (eu *EmployeeUpdate) SetTags(s string) *EmployeeUpdate {
  75. eu.mutation.SetTags(s)
  76. return eu
  77. }
  78. // SetNillableTags sets the "tags" field if the given value is not nil.
  79. func (eu *EmployeeUpdate) SetNillableTags(s *string) *EmployeeUpdate {
  80. if s != nil {
  81. eu.SetTags(*s)
  82. }
  83. return eu
  84. }
  85. // SetHireCount sets the "hire_count" field.
  86. func (eu *EmployeeUpdate) SetHireCount(i int) *EmployeeUpdate {
  87. eu.mutation.ResetHireCount()
  88. eu.mutation.SetHireCount(i)
  89. return eu
  90. }
  91. // SetNillableHireCount sets the "hire_count" field if the given value is not nil.
  92. func (eu *EmployeeUpdate) SetNillableHireCount(i *int) *EmployeeUpdate {
  93. if i != nil {
  94. eu.SetHireCount(*i)
  95. }
  96. return eu
  97. }
  98. // AddHireCount adds i to the "hire_count" field.
  99. func (eu *EmployeeUpdate) AddHireCount(i int) *EmployeeUpdate {
  100. eu.mutation.AddHireCount(i)
  101. return eu
  102. }
  103. // SetServiceCount sets the "service_count" field.
  104. func (eu *EmployeeUpdate) SetServiceCount(i int) *EmployeeUpdate {
  105. eu.mutation.ResetServiceCount()
  106. eu.mutation.SetServiceCount(i)
  107. return eu
  108. }
  109. // SetNillableServiceCount sets the "service_count" field if the given value is not nil.
  110. func (eu *EmployeeUpdate) SetNillableServiceCount(i *int) *EmployeeUpdate {
  111. if i != nil {
  112. eu.SetServiceCount(*i)
  113. }
  114. return eu
  115. }
  116. // AddServiceCount adds i to the "service_count" field.
  117. func (eu *EmployeeUpdate) AddServiceCount(i int) *EmployeeUpdate {
  118. eu.mutation.AddServiceCount(i)
  119. return eu
  120. }
  121. // SetAchievementCount sets the "achievement_count" field.
  122. func (eu *EmployeeUpdate) SetAchievementCount(i int) *EmployeeUpdate {
  123. eu.mutation.ResetAchievementCount()
  124. eu.mutation.SetAchievementCount(i)
  125. return eu
  126. }
  127. // SetNillableAchievementCount sets the "achievement_count" field if the given value is not nil.
  128. func (eu *EmployeeUpdate) SetNillableAchievementCount(i *int) *EmployeeUpdate {
  129. if i != nil {
  130. eu.SetAchievementCount(*i)
  131. }
  132. return eu
  133. }
  134. // AddAchievementCount adds i to the "achievement_count" field.
  135. func (eu *EmployeeUpdate) AddAchievementCount(i int) *EmployeeUpdate {
  136. eu.mutation.AddAchievementCount(i)
  137. return eu
  138. }
  139. // SetIntro sets the "intro" field.
  140. func (eu *EmployeeUpdate) SetIntro(s string) *EmployeeUpdate {
  141. eu.mutation.SetIntro(s)
  142. return eu
  143. }
  144. // SetNillableIntro sets the "intro" field if the given value is not nil.
  145. func (eu *EmployeeUpdate) SetNillableIntro(s *string) *EmployeeUpdate {
  146. if s != nil {
  147. eu.SetIntro(*s)
  148. }
  149. return eu
  150. }
  151. // SetEstimate sets the "estimate" field.
  152. func (eu *EmployeeUpdate) SetEstimate(s string) *EmployeeUpdate {
  153. eu.mutation.SetEstimate(s)
  154. return eu
  155. }
  156. // SetNillableEstimate sets the "estimate" field if the given value is not nil.
  157. func (eu *EmployeeUpdate) SetNillableEstimate(s *string) *EmployeeUpdate {
  158. if s != nil {
  159. eu.SetEstimate(*s)
  160. }
  161. return eu
  162. }
  163. // SetSkill sets the "skill" field.
  164. func (eu *EmployeeUpdate) SetSkill(s string) *EmployeeUpdate {
  165. eu.mutation.SetSkill(s)
  166. return eu
  167. }
  168. // SetNillableSkill sets the "skill" field if the given value is not nil.
  169. func (eu *EmployeeUpdate) SetNillableSkill(s *string) *EmployeeUpdate {
  170. if s != nil {
  171. eu.SetSkill(*s)
  172. }
  173. return eu
  174. }
  175. // SetAbilityType sets the "ability_type" field.
  176. func (eu *EmployeeUpdate) SetAbilityType(s string) *EmployeeUpdate {
  177. eu.mutation.SetAbilityType(s)
  178. return eu
  179. }
  180. // SetNillableAbilityType sets the "ability_type" field if the given value is not nil.
  181. func (eu *EmployeeUpdate) SetNillableAbilityType(s *string) *EmployeeUpdate {
  182. if s != nil {
  183. eu.SetAbilityType(*s)
  184. }
  185. return eu
  186. }
  187. // SetScene sets the "scene" field.
  188. func (eu *EmployeeUpdate) SetScene(s string) *EmployeeUpdate {
  189. eu.mutation.SetScene(s)
  190. return eu
  191. }
  192. // SetNillableScene sets the "scene" field if the given value is not nil.
  193. func (eu *EmployeeUpdate) SetNillableScene(s *string) *EmployeeUpdate {
  194. if s != nil {
  195. eu.SetScene(*s)
  196. }
  197. return eu
  198. }
  199. // SetSwitchIn sets the "switch_in" field.
  200. func (eu *EmployeeUpdate) SetSwitchIn(s string) *EmployeeUpdate {
  201. eu.mutation.SetSwitchIn(s)
  202. return eu
  203. }
  204. // SetNillableSwitchIn sets the "switch_in" field if the given value is not nil.
  205. func (eu *EmployeeUpdate) SetNillableSwitchIn(s *string) *EmployeeUpdate {
  206. if s != nil {
  207. eu.SetSwitchIn(*s)
  208. }
  209. return eu
  210. }
  211. // SetVideoURL sets the "video_url" field.
  212. func (eu *EmployeeUpdate) SetVideoURL(s string) *EmployeeUpdate {
  213. eu.mutation.SetVideoURL(s)
  214. return eu
  215. }
  216. // SetNillableVideoURL sets the "video_url" field if the given value is not nil.
  217. func (eu *EmployeeUpdate) SetNillableVideoURL(s *string) *EmployeeUpdate {
  218. if s != nil {
  219. eu.SetVideoURL(*s)
  220. }
  221. return eu
  222. }
  223. // SetOrganizationID sets the "organization_id" field.
  224. func (eu *EmployeeUpdate) SetOrganizationID(u uint64) *EmployeeUpdate {
  225. eu.mutation.ResetOrganizationID()
  226. eu.mutation.SetOrganizationID(u)
  227. return eu
  228. }
  229. // SetNillableOrganizationID sets the "organization_id" field if the given value is not nil.
  230. func (eu *EmployeeUpdate) SetNillableOrganizationID(u *uint64) *EmployeeUpdate {
  231. if u != nil {
  232. eu.SetOrganizationID(*u)
  233. }
  234. return eu
  235. }
  236. // AddOrganizationID adds u to the "organization_id" field.
  237. func (eu *EmployeeUpdate) AddOrganizationID(u int64) *EmployeeUpdate {
  238. eu.mutation.AddOrganizationID(u)
  239. return eu
  240. }
  241. // SetCategoryID sets the "category_id" field.
  242. func (eu *EmployeeUpdate) SetCategoryID(u uint64) *EmployeeUpdate {
  243. eu.mutation.ResetCategoryID()
  244. eu.mutation.SetCategoryID(u)
  245. return eu
  246. }
  247. // SetNillableCategoryID sets the "category_id" field if the given value is not nil.
  248. func (eu *EmployeeUpdate) SetNillableCategoryID(u *uint64) *EmployeeUpdate {
  249. if u != nil {
  250. eu.SetCategoryID(*u)
  251. }
  252. return eu
  253. }
  254. // AddCategoryID adds u to the "category_id" field.
  255. func (eu *EmployeeUpdate) AddCategoryID(u int64) *EmployeeUpdate {
  256. eu.mutation.AddCategoryID(u)
  257. return eu
  258. }
  259. // SetAPIBase sets the "api_base" field.
  260. func (eu *EmployeeUpdate) SetAPIBase(s string) *EmployeeUpdate {
  261. eu.mutation.SetAPIBase(s)
  262. return eu
  263. }
  264. // SetNillableAPIBase sets the "api_base" field if the given value is not nil.
  265. func (eu *EmployeeUpdate) SetNillableAPIBase(s *string) *EmployeeUpdate {
  266. if s != nil {
  267. eu.SetAPIBase(*s)
  268. }
  269. return eu
  270. }
  271. // SetAPIKey sets the "api_key" field.
  272. func (eu *EmployeeUpdate) SetAPIKey(s string) *EmployeeUpdate {
  273. eu.mutation.SetAPIKey(s)
  274. return eu
  275. }
  276. // SetNillableAPIKey sets the "api_key" field if the given value is not nil.
  277. func (eu *EmployeeUpdate) SetNillableAPIKey(s *string) *EmployeeUpdate {
  278. if s != nil {
  279. eu.SetAPIKey(*s)
  280. }
  281. return eu
  282. }
  283. // AddEmWorkExperienceIDs adds the "em_work_experiences" edge to the WorkExperience entity by IDs.
  284. func (eu *EmployeeUpdate) AddEmWorkExperienceIDs(ids ...uint64) *EmployeeUpdate {
  285. eu.mutation.AddEmWorkExperienceIDs(ids...)
  286. return eu
  287. }
  288. // AddEmWorkExperiences adds the "em_work_experiences" edges to the WorkExperience entity.
  289. func (eu *EmployeeUpdate) AddEmWorkExperiences(w ...*WorkExperience) *EmployeeUpdate {
  290. ids := make([]uint64, len(w))
  291. for i := range w {
  292. ids[i] = w[i].ID
  293. }
  294. return eu.AddEmWorkExperienceIDs(ids...)
  295. }
  296. // AddEmTutorialIDs adds the "em_tutorial" edge to the Tutorial entity by IDs.
  297. func (eu *EmployeeUpdate) AddEmTutorialIDs(ids ...uint64) *EmployeeUpdate {
  298. eu.mutation.AddEmTutorialIDs(ids...)
  299. return eu
  300. }
  301. // AddEmTutorial adds the "em_tutorial" edges to the Tutorial entity.
  302. func (eu *EmployeeUpdate) AddEmTutorial(t ...*Tutorial) *EmployeeUpdate {
  303. ids := make([]uint64, len(t))
  304. for i := range t {
  305. ids[i] = t[i].ID
  306. }
  307. return eu.AddEmTutorialIDs(ids...)
  308. }
  309. // Mutation returns the EmployeeMutation object of the builder.
  310. func (eu *EmployeeUpdate) Mutation() *EmployeeMutation {
  311. return eu.mutation
  312. }
  313. // ClearEmWorkExperiences clears all "em_work_experiences" edges to the WorkExperience entity.
  314. func (eu *EmployeeUpdate) ClearEmWorkExperiences() *EmployeeUpdate {
  315. eu.mutation.ClearEmWorkExperiences()
  316. return eu
  317. }
  318. // RemoveEmWorkExperienceIDs removes the "em_work_experiences" edge to WorkExperience entities by IDs.
  319. func (eu *EmployeeUpdate) RemoveEmWorkExperienceIDs(ids ...uint64) *EmployeeUpdate {
  320. eu.mutation.RemoveEmWorkExperienceIDs(ids...)
  321. return eu
  322. }
  323. // RemoveEmWorkExperiences removes "em_work_experiences" edges to WorkExperience entities.
  324. func (eu *EmployeeUpdate) RemoveEmWorkExperiences(w ...*WorkExperience) *EmployeeUpdate {
  325. ids := make([]uint64, len(w))
  326. for i := range w {
  327. ids[i] = w[i].ID
  328. }
  329. return eu.RemoveEmWorkExperienceIDs(ids...)
  330. }
  331. // ClearEmTutorial clears all "em_tutorial" edges to the Tutorial entity.
  332. func (eu *EmployeeUpdate) ClearEmTutorial() *EmployeeUpdate {
  333. eu.mutation.ClearEmTutorial()
  334. return eu
  335. }
  336. // RemoveEmTutorialIDs removes the "em_tutorial" edge to Tutorial entities by IDs.
  337. func (eu *EmployeeUpdate) RemoveEmTutorialIDs(ids ...uint64) *EmployeeUpdate {
  338. eu.mutation.RemoveEmTutorialIDs(ids...)
  339. return eu
  340. }
  341. // RemoveEmTutorial removes "em_tutorial" edges to Tutorial entities.
  342. func (eu *EmployeeUpdate) RemoveEmTutorial(t ...*Tutorial) *EmployeeUpdate {
  343. ids := make([]uint64, len(t))
  344. for i := range t {
  345. ids[i] = t[i].ID
  346. }
  347. return eu.RemoveEmTutorialIDs(ids...)
  348. }
  349. // Save executes the query and returns the number of nodes affected by the update operation.
  350. func (eu *EmployeeUpdate) Save(ctx context.Context) (int, error) {
  351. if err := eu.defaults(); err != nil {
  352. return 0, err
  353. }
  354. return withHooks(ctx, eu.sqlSave, eu.mutation, eu.hooks)
  355. }
  356. // SaveX is like Save, but panics if an error occurs.
  357. func (eu *EmployeeUpdate) SaveX(ctx context.Context) int {
  358. affected, err := eu.Save(ctx)
  359. if err != nil {
  360. panic(err)
  361. }
  362. return affected
  363. }
  364. // Exec executes the query.
  365. func (eu *EmployeeUpdate) Exec(ctx context.Context) error {
  366. _, err := eu.Save(ctx)
  367. return err
  368. }
  369. // ExecX is like Exec, but panics if an error occurs.
  370. func (eu *EmployeeUpdate) ExecX(ctx context.Context) {
  371. if err := eu.Exec(ctx); err != nil {
  372. panic(err)
  373. }
  374. }
  375. // defaults sets the default values of the builder before save.
  376. func (eu *EmployeeUpdate) defaults() error {
  377. if _, ok := eu.mutation.UpdatedAt(); !ok {
  378. if employee.UpdateDefaultUpdatedAt == nil {
  379. return fmt.Errorf("ent: uninitialized employee.UpdateDefaultUpdatedAt (forgotten import ent/runtime?)")
  380. }
  381. v := employee.UpdateDefaultUpdatedAt()
  382. eu.mutation.SetUpdatedAt(v)
  383. }
  384. return nil
  385. }
  386. // check runs all checks and user-defined validators on the builder.
  387. func (eu *EmployeeUpdate) check() error {
  388. if v, ok := eu.mutation.Title(); ok {
  389. if err := employee.TitleValidator(v); err != nil {
  390. return &ValidationError{Name: "title", err: fmt.Errorf(`ent: validator failed for field "Employee.title": %w`, err)}
  391. }
  392. }
  393. if v, ok := eu.mutation.Avatar(); ok {
  394. if err := employee.AvatarValidator(v); err != nil {
  395. return &ValidationError{Name: "avatar", err: fmt.Errorf(`ent: validator failed for field "Employee.avatar": %w`, err)}
  396. }
  397. }
  398. if v, ok := eu.mutation.Tags(); ok {
  399. if err := employee.TagsValidator(v); err != nil {
  400. return &ValidationError{Name: "tags", err: fmt.Errorf(`ent: validator failed for field "Employee.tags": %w`, err)}
  401. }
  402. }
  403. if v, ok := eu.mutation.HireCount(); ok {
  404. if err := employee.HireCountValidator(v); err != nil {
  405. return &ValidationError{Name: "hire_count", err: fmt.Errorf(`ent: validator failed for field "Employee.hire_count": %w`, err)}
  406. }
  407. }
  408. if v, ok := eu.mutation.ServiceCount(); ok {
  409. if err := employee.ServiceCountValidator(v); err != nil {
  410. return &ValidationError{Name: "service_count", err: fmt.Errorf(`ent: validator failed for field "Employee.service_count": %w`, err)}
  411. }
  412. }
  413. if v, ok := eu.mutation.AchievementCount(); ok {
  414. if err := employee.AchievementCountValidator(v); err != nil {
  415. return &ValidationError{Name: "achievement_count", err: fmt.Errorf(`ent: validator failed for field "Employee.achievement_count": %w`, err)}
  416. }
  417. }
  418. if v, ok := eu.mutation.Intro(); ok {
  419. if err := employee.IntroValidator(v); err != nil {
  420. return &ValidationError{Name: "intro", err: fmt.Errorf(`ent: validator failed for field "Employee.intro": %w`, err)}
  421. }
  422. }
  423. if v, ok := eu.mutation.Estimate(); ok {
  424. if err := employee.EstimateValidator(v); err != nil {
  425. return &ValidationError{Name: "estimate", err: fmt.Errorf(`ent: validator failed for field "Employee.estimate": %w`, err)}
  426. }
  427. }
  428. if v, ok := eu.mutation.Skill(); ok {
  429. if err := employee.SkillValidator(v); err != nil {
  430. return &ValidationError{Name: "skill", err: fmt.Errorf(`ent: validator failed for field "Employee.skill": %w`, err)}
  431. }
  432. }
  433. if v, ok := eu.mutation.VideoURL(); ok {
  434. if err := employee.VideoURLValidator(v); err != nil {
  435. return &ValidationError{Name: "video_url", err: fmt.Errorf(`ent: validator failed for field "Employee.video_url": %w`, err)}
  436. }
  437. }
  438. if v, ok := eu.mutation.OrganizationID(); ok {
  439. if err := employee.OrganizationIDValidator(v); err != nil {
  440. return &ValidationError{Name: "organization_id", err: fmt.Errorf(`ent: validator failed for field "Employee.organization_id": %w`, err)}
  441. }
  442. }
  443. if v, ok := eu.mutation.CategoryID(); ok {
  444. if err := employee.CategoryIDValidator(v); err != nil {
  445. return &ValidationError{Name: "category_id", err: fmt.Errorf(`ent: validator failed for field "Employee.category_id": %w`, err)}
  446. }
  447. }
  448. return nil
  449. }
  450. func (eu *EmployeeUpdate) sqlSave(ctx context.Context) (n int, err error) {
  451. if err := eu.check(); err != nil {
  452. return n, err
  453. }
  454. _spec := sqlgraph.NewUpdateSpec(employee.Table, employee.Columns, sqlgraph.NewFieldSpec(employee.FieldID, field.TypeUint64))
  455. if ps := eu.mutation.predicates; len(ps) > 0 {
  456. _spec.Predicate = func(selector *sql.Selector) {
  457. for i := range ps {
  458. ps[i](selector)
  459. }
  460. }
  461. }
  462. if value, ok := eu.mutation.UpdatedAt(); ok {
  463. _spec.SetField(employee.FieldUpdatedAt, field.TypeTime, value)
  464. }
  465. if value, ok := eu.mutation.DeletedAt(); ok {
  466. _spec.SetField(employee.FieldDeletedAt, field.TypeTime, value)
  467. }
  468. if eu.mutation.DeletedAtCleared() {
  469. _spec.ClearField(employee.FieldDeletedAt, field.TypeTime)
  470. }
  471. if value, ok := eu.mutation.Title(); ok {
  472. _spec.SetField(employee.FieldTitle, field.TypeString, value)
  473. }
  474. if value, ok := eu.mutation.Avatar(); ok {
  475. _spec.SetField(employee.FieldAvatar, field.TypeString, value)
  476. }
  477. if value, ok := eu.mutation.Tags(); ok {
  478. _spec.SetField(employee.FieldTags, field.TypeString, value)
  479. }
  480. if value, ok := eu.mutation.HireCount(); ok {
  481. _spec.SetField(employee.FieldHireCount, field.TypeInt, value)
  482. }
  483. if value, ok := eu.mutation.AddedHireCount(); ok {
  484. _spec.AddField(employee.FieldHireCount, field.TypeInt, value)
  485. }
  486. if value, ok := eu.mutation.ServiceCount(); ok {
  487. _spec.SetField(employee.FieldServiceCount, field.TypeInt, value)
  488. }
  489. if value, ok := eu.mutation.AddedServiceCount(); ok {
  490. _spec.AddField(employee.FieldServiceCount, field.TypeInt, value)
  491. }
  492. if value, ok := eu.mutation.AchievementCount(); ok {
  493. _spec.SetField(employee.FieldAchievementCount, field.TypeInt, value)
  494. }
  495. if value, ok := eu.mutation.AddedAchievementCount(); ok {
  496. _spec.AddField(employee.FieldAchievementCount, field.TypeInt, value)
  497. }
  498. if value, ok := eu.mutation.Intro(); ok {
  499. _spec.SetField(employee.FieldIntro, field.TypeString, value)
  500. }
  501. if value, ok := eu.mutation.Estimate(); ok {
  502. _spec.SetField(employee.FieldEstimate, field.TypeString, value)
  503. }
  504. if value, ok := eu.mutation.Skill(); ok {
  505. _spec.SetField(employee.FieldSkill, field.TypeString, value)
  506. }
  507. if value, ok := eu.mutation.AbilityType(); ok {
  508. _spec.SetField(employee.FieldAbilityType, field.TypeString, value)
  509. }
  510. if value, ok := eu.mutation.Scene(); ok {
  511. _spec.SetField(employee.FieldScene, field.TypeString, value)
  512. }
  513. if value, ok := eu.mutation.SwitchIn(); ok {
  514. _spec.SetField(employee.FieldSwitchIn, field.TypeString, value)
  515. }
  516. if value, ok := eu.mutation.VideoURL(); ok {
  517. _spec.SetField(employee.FieldVideoURL, field.TypeString, value)
  518. }
  519. if value, ok := eu.mutation.OrganizationID(); ok {
  520. _spec.SetField(employee.FieldOrganizationID, field.TypeUint64, value)
  521. }
  522. if value, ok := eu.mutation.AddedOrganizationID(); ok {
  523. _spec.AddField(employee.FieldOrganizationID, field.TypeUint64, value)
  524. }
  525. if value, ok := eu.mutation.CategoryID(); ok {
  526. _spec.SetField(employee.FieldCategoryID, field.TypeUint64, value)
  527. }
  528. if value, ok := eu.mutation.AddedCategoryID(); ok {
  529. _spec.AddField(employee.FieldCategoryID, field.TypeUint64, value)
  530. }
  531. if value, ok := eu.mutation.APIBase(); ok {
  532. _spec.SetField(employee.FieldAPIBase, field.TypeString, value)
  533. }
  534. if value, ok := eu.mutation.APIKey(); ok {
  535. _spec.SetField(employee.FieldAPIKey, field.TypeString, value)
  536. }
  537. if eu.mutation.EmWorkExperiencesCleared() {
  538. edge := &sqlgraph.EdgeSpec{
  539. Rel: sqlgraph.O2M,
  540. Inverse: false,
  541. Table: employee.EmWorkExperiencesTable,
  542. Columns: []string{employee.EmWorkExperiencesColumn},
  543. Bidi: false,
  544. Target: &sqlgraph.EdgeTarget{
  545. IDSpec: sqlgraph.NewFieldSpec(workexperience.FieldID, field.TypeUint64),
  546. },
  547. }
  548. _spec.Edges.Clear = append(_spec.Edges.Clear, edge)
  549. }
  550. if nodes := eu.mutation.RemovedEmWorkExperiencesIDs(); len(nodes) > 0 && !eu.mutation.EmWorkExperiencesCleared() {
  551. edge := &sqlgraph.EdgeSpec{
  552. Rel: sqlgraph.O2M,
  553. Inverse: false,
  554. Table: employee.EmWorkExperiencesTable,
  555. Columns: []string{employee.EmWorkExperiencesColumn},
  556. Bidi: false,
  557. Target: &sqlgraph.EdgeTarget{
  558. IDSpec: sqlgraph.NewFieldSpec(workexperience.FieldID, field.TypeUint64),
  559. },
  560. }
  561. for _, k := range nodes {
  562. edge.Target.Nodes = append(edge.Target.Nodes, k)
  563. }
  564. _spec.Edges.Clear = append(_spec.Edges.Clear, edge)
  565. }
  566. if nodes := eu.mutation.EmWorkExperiencesIDs(); len(nodes) > 0 {
  567. edge := &sqlgraph.EdgeSpec{
  568. Rel: sqlgraph.O2M,
  569. Inverse: false,
  570. Table: employee.EmWorkExperiencesTable,
  571. Columns: []string{employee.EmWorkExperiencesColumn},
  572. Bidi: false,
  573. Target: &sqlgraph.EdgeTarget{
  574. IDSpec: sqlgraph.NewFieldSpec(workexperience.FieldID, field.TypeUint64),
  575. },
  576. }
  577. for _, k := range nodes {
  578. edge.Target.Nodes = append(edge.Target.Nodes, k)
  579. }
  580. _spec.Edges.Add = append(_spec.Edges.Add, edge)
  581. }
  582. if eu.mutation.EmTutorialCleared() {
  583. edge := &sqlgraph.EdgeSpec{
  584. Rel: sqlgraph.O2M,
  585. Inverse: false,
  586. Table: employee.EmTutorialTable,
  587. Columns: []string{employee.EmTutorialColumn},
  588. Bidi: false,
  589. Target: &sqlgraph.EdgeTarget{
  590. IDSpec: sqlgraph.NewFieldSpec(tutorial.FieldID, field.TypeUint64),
  591. },
  592. }
  593. _spec.Edges.Clear = append(_spec.Edges.Clear, edge)
  594. }
  595. if nodes := eu.mutation.RemovedEmTutorialIDs(); len(nodes) > 0 && !eu.mutation.EmTutorialCleared() {
  596. edge := &sqlgraph.EdgeSpec{
  597. Rel: sqlgraph.O2M,
  598. Inverse: false,
  599. Table: employee.EmTutorialTable,
  600. Columns: []string{employee.EmTutorialColumn},
  601. Bidi: false,
  602. Target: &sqlgraph.EdgeTarget{
  603. IDSpec: sqlgraph.NewFieldSpec(tutorial.FieldID, field.TypeUint64),
  604. },
  605. }
  606. for _, k := range nodes {
  607. edge.Target.Nodes = append(edge.Target.Nodes, k)
  608. }
  609. _spec.Edges.Clear = append(_spec.Edges.Clear, edge)
  610. }
  611. if nodes := eu.mutation.EmTutorialIDs(); len(nodes) > 0 {
  612. edge := &sqlgraph.EdgeSpec{
  613. Rel: sqlgraph.O2M,
  614. Inverse: false,
  615. Table: employee.EmTutorialTable,
  616. Columns: []string{employee.EmTutorialColumn},
  617. Bidi: false,
  618. Target: &sqlgraph.EdgeTarget{
  619. IDSpec: sqlgraph.NewFieldSpec(tutorial.FieldID, field.TypeUint64),
  620. },
  621. }
  622. for _, k := range nodes {
  623. edge.Target.Nodes = append(edge.Target.Nodes, k)
  624. }
  625. _spec.Edges.Add = append(_spec.Edges.Add, edge)
  626. }
  627. if n, err = sqlgraph.UpdateNodes(ctx, eu.driver, _spec); err != nil {
  628. if _, ok := err.(*sqlgraph.NotFoundError); ok {
  629. err = &NotFoundError{employee.Label}
  630. } else if sqlgraph.IsConstraintError(err) {
  631. err = &ConstraintError{msg: err.Error(), wrap: err}
  632. }
  633. return 0, err
  634. }
  635. eu.mutation.done = true
  636. return n, nil
  637. }
  638. // EmployeeUpdateOne is the builder for updating a single Employee entity.
  639. type EmployeeUpdateOne struct {
  640. config
  641. fields []string
  642. hooks []Hook
  643. mutation *EmployeeMutation
  644. }
  645. // SetUpdatedAt sets the "updated_at" field.
  646. func (euo *EmployeeUpdateOne) SetUpdatedAt(t time.Time) *EmployeeUpdateOne {
  647. euo.mutation.SetUpdatedAt(t)
  648. return euo
  649. }
  650. // SetDeletedAt sets the "deleted_at" field.
  651. func (euo *EmployeeUpdateOne) SetDeletedAt(t time.Time) *EmployeeUpdateOne {
  652. euo.mutation.SetDeletedAt(t)
  653. return euo
  654. }
  655. // SetNillableDeletedAt sets the "deleted_at" field if the given value is not nil.
  656. func (euo *EmployeeUpdateOne) SetNillableDeletedAt(t *time.Time) *EmployeeUpdateOne {
  657. if t != nil {
  658. euo.SetDeletedAt(*t)
  659. }
  660. return euo
  661. }
  662. // ClearDeletedAt clears the value of the "deleted_at" field.
  663. func (euo *EmployeeUpdateOne) ClearDeletedAt() *EmployeeUpdateOne {
  664. euo.mutation.ClearDeletedAt()
  665. return euo
  666. }
  667. // SetTitle sets the "title" field.
  668. func (euo *EmployeeUpdateOne) SetTitle(s string) *EmployeeUpdateOne {
  669. euo.mutation.SetTitle(s)
  670. return euo
  671. }
  672. // SetNillableTitle sets the "title" field if the given value is not nil.
  673. func (euo *EmployeeUpdateOne) SetNillableTitle(s *string) *EmployeeUpdateOne {
  674. if s != nil {
  675. euo.SetTitle(*s)
  676. }
  677. return euo
  678. }
  679. // SetAvatar sets the "avatar" field.
  680. func (euo *EmployeeUpdateOne) SetAvatar(s string) *EmployeeUpdateOne {
  681. euo.mutation.SetAvatar(s)
  682. return euo
  683. }
  684. // SetNillableAvatar sets the "avatar" field if the given value is not nil.
  685. func (euo *EmployeeUpdateOne) SetNillableAvatar(s *string) *EmployeeUpdateOne {
  686. if s != nil {
  687. euo.SetAvatar(*s)
  688. }
  689. return euo
  690. }
  691. // SetTags sets the "tags" field.
  692. func (euo *EmployeeUpdateOne) SetTags(s string) *EmployeeUpdateOne {
  693. euo.mutation.SetTags(s)
  694. return euo
  695. }
  696. // SetNillableTags sets the "tags" field if the given value is not nil.
  697. func (euo *EmployeeUpdateOne) SetNillableTags(s *string) *EmployeeUpdateOne {
  698. if s != nil {
  699. euo.SetTags(*s)
  700. }
  701. return euo
  702. }
  703. // SetHireCount sets the "hire_count" field.
  704. func (euo *EmployeeUpdateOne) SetHireCount(i int) *EmployeeUpdateOne {
  705. euo.mutation.ResetHireCount()
  706. euo.mutation.SetHireCount(i)
  707. return euo
  708. }
  709. // SetNillableHireCount sets the "hire_count" field if the given value is not nil.
  710. func (euo *EmployeeUpdateOne) SetNillableHireCount(i *int) *EmployeeUpdateOne {
  711. if i != nil {
  712. euo.SetHireCount(*i)
  713. }
  714. return euo
  715. }
  716. // AddHireCount adds i to the "hire_count" field.
  717. func (euo *EmployeeUpdateOne) AddHireCount(i int) *EmployeeUpdateOne {
  718. euo.mutation.AddHireCount(i)
  719. return euo
  720. }
  721. // SetServiceCount sets the "service_count" field.
  722. func (euo *EmployeeUpdateOne) SetServiceCount(i int) *EmployeeUpdateOne {
  723. euo.mutation.ResetServiceCount()
  724. euo.mutation.SetServiceCount(i)
  725. return euo
  726. }
  727. // SetNillableServiceCount sets the "service_count" field if the given value is not nil.
  728. func (euo *EmployeeUpdateOne) SetNillableServiceCount(i *int) *EmployeeUpdateOne {
  729. if i != nil {
  730. euo.SetServiceCount(*i)
  731. }
  732. return euo
  733. }
  734. // AddServiceCount adds i to the "service_count" field.
  735. func (euo *EmployeeUpdateOne) AddServiceCount(i int) *EmployeeUpdateOne {
  736. euo.mutation.AddServiceCount(i)
  737. return euo
  738. }
  739. // SetAchievementCount sets the "achievement_count" field.
  740. func (euo *EmployeeUpdateOne) SetAchievementCount(i int) *EmployeeUpdateOne {
  741. euo.mutation.ResetAchievementCount()
  742. euo.mutation.SetAchievementCount(i)
  743. return euo
  744. }
  745. // SetNillableAchievementCount sets the "achievement_count" field if the given value is not nil.
  746. func (euo *EmployeeUpdateOne) SetNillableAchievementCount(i *int) *EmployeeUpdateOne {
  747. if i != nil {
  748. euo.SetAchievementCount(*i)
  749. }
  750. return euo
  751. }
  752. // AddAchievementCount adds i to the "achievement_count" field.
  753. func (euo *EmployeeUpdateOne) AddAchievementCount(i int) *EmployeeUpdateOne {
  754. euo.mutation.AddAchievementCount(i)
  755. return euo
  756. }
  757. // SetIntro sets the "intro" field.
  758. func (euo *EmployeeUpdateOne) SetIntro(s string) *EmployeeUpdateOne {
  759. euo.mutation.SetIntro(s)
  760. return euo
  761. }
  762. // SetNillableIntro sets the "intro" field if the given value is not nil.
  763. func (euo *EmployeeUpdateOne) SetNillableIntro(s *string) *EmployeeUpdateOne {
  764. if s != nil {
  765. euo.SetIntro(*s)
  766. }
  767. return euo
  768. }
  769. // SetEstimate sets the "estimate" field.
  770. func (euo *EmployeeUpdateOne) SetEstimate(s string) *EmployeeUpdateOne {
  771. euo.mutation.SetEstimate(s)
  772. return euo
  773. }
  774. // SetNillableEstimate sets the "estimate" field if the given value is not nil.
  775. func (euo *EmployeeUpdateOne) SetNillableEstimate(s *string) *EmployeeUpdateOne {
  776. if s != nil {
  777. euo.SetEstimate(*s)
  778. }
  779. return euo
  780. }
  781. // SetSkill sets the "skill" field.
  782. func (euo *EmployeeUpdateOne) SetSkill(s string) *EmployeeUpdateOne {
  783. euo.mutation.SetSkill(s)
  784. return euo
  785. }
  786. // SetNillableSkill sets the "skill" field if the given value is not nil.
  787. func (euo *EmployeeUpdateOne) SetNillableSkill(s *string) *EmployeeUpdateOne {
  788. if s != nil {
  789. euo.SetSkill(*s)
  790. }
  791. return euo
  792. }
  793. // SetAbilityType sets the "ability_type" field.
  794. func (euo *EmployeeUpdateOne) SetAbilityType(s string) *EmployeeUpdateOne {
  795. euo.mutation.SetAbilityType(s)
  796. return euo
  797. }
  798. // SetNillableAbilityType sets the "ability_type" field if the given value is not nil.
  799. func (euo *EmployeeUpdateOne) SetNillableAbilityType(s *string) *EmployeeUpdateOne {
  800. if s != nil {
  801. euo.SetAbilityType(*s)
  802. }
  803. return euo
  804. }
  805. // SetScene sets the "scene" field.
  806. func (euo *EmployeeUpdateOne) SetScene(s string) *EmployeeUpdateOne {
  807. euo.mutation.SetScene(s)
  808. return euo
  809. }
  810. // SetNillableScene sets the "scene" field if the given value is not nil.
  811. func (euo *EmployeeUpdateOne) SetNillableScene(s *string) *EmployeeUpdateOne {
  812. if s != nil {
  813. euo.SetScene(*s)
  814. }
  815. return euo
  816. }
  817. // SetSwitchIn sets the "switch_in" field.
  818. func (euo *EmployeeUpdateOne) SetSwitchIn(s string) *EmployeeUpdateOne {
  819. euo.mutation.SetSwitchIn(s)
  820. return euo
  821. }
  822. // SetNillableSwitchIn sets the "switch_in" field if the given value is not nil.
  823. func (euo *EmployeeUpdateOne) SetNillableSwitchIn(s *string) *EmployeeUpdateOne {
  824. if s != nil {
  825. euo.SetSwitchIn(*s)
  826. }
  827. return euo
  828. }
  829. // SetVideoURL sets the "video_url" field.
  830. func (euo *EmployeeUpdateOne) SetVideoURL(s string) *EmployeeUpdateOne {
  831. euo.mutation.SetVideoURL(s)
  832. return euo
  833. }
  834. // SetNillableVideoURL sets the "video_url" field if the given value is not nil.
  835. func (euo *EmployeeUpdateOne) SetNillableVideoURL(s *string) *EmployeeUpdateOne {
  836. if s != nil {
  837. euo.SetVideoURL(*s)
  838. }
  839. return euo
  840. }
  841. // SetOrganizationID sets the "organization_id" field.
  842. func (euo *EmployeeUpdateOne) SetOrganizationID(u uint64) *EmployeeUpdateOne {
  843. euo.mutation.ResetOrganizationID()
  844. euo.mutation.SetOrganizationID(u)
  845. return euo
  846. }
  847. // SetNillableOrganizationID sets the "organization_id" field if the given value is not nil.
  848. func (euo *EmployeeUpdateOne) SetNillableOrganizationID(u *uint64) *EmployeeUpdateOne {
  849. if u != nil {
  850. euo.SetOrganizationID(*u)
  851. }
  852. return euo
  853. }
  854. // AddOrganizationID adds u to the "organization_id" field.
  855. func (euo *EmployeeUpdateOne) AddOrganizationID(u int64) *EmployeeUpdateOne {
  856. euo.mutation.AddOrganizationID(u)
  857. return euo
  858. }
  859. // SetCategoryID sets the "category_id" field.
  860. func (euo *EmployeeUpdateOne) SetCategoryID(u uint64) *EmployeeUpdateOne {
  861. euo.mutation.ResetCategoryID()
  862. euo.mutation.SetCategoryID(u)
  863. return euo
  864. }
  865. // SetNillableCategoryID sets the "category_id" field if the given value is not nil.
  866. func (euo *EmployeeUpdateOne) SetNillableCategoryID(u *uint64) *EmployeeUpdateOne {
  867. if u != nil {
  868. euo.SetCategoryID(*u)
  869. }
  870. return euo
  871. }
  872. // AddCategoryID adds u to the "category_id" field.
  873. func (euo *EmployeeUpdateOne) AddCategoryID(u int64) *EmployeeUpdateOne {
  874. euo.mutation.AddCategoryID(u)
  875. return euo
  876. }
  877. // SetAPIBase sets the "api_base" field.
  878. func (euo *EmployeeUpdateOne) SetAPIBase(s string) *EmployeeUpdateOne {
  879. euo.mutation.SetAPIBase(s)
  880. return euo
  881. }
  882. // SetNillableAPIBase sets the "api_base" field if the given value is not nil.
  883. func (euo *EmployeeUpdateOne) SetNillableAPIBase(s *string) *EmployeeUpdateOne {
  884. if s != nil {
  885. euo.SetAPIBase(*s)
  886. }
  887. return euo
  888. }
  889. // SetAPIKey sets the "api_key" field.
  890. func (euo *EmployeeUpdateOne) SetAPIKey(s string) *EmployeeUpdateOne {
  891. euo.mutation.SetAPIKey(s)
  892. return euo
  893. }
  894. // SetNillableAPIKey sets the "api_key" field if the given value is not nil.
  895. func (euo *EmployeeUpdateOne) SetNillableAPIKey(s *string) *EmployeeUpdateOne {
  896. if s != nil {
  897. euo.SetAPIKey(*s)
  898. }
  899. return euo
  900. }
  901. // AddEmWorkExperienceIDs adds the "em_work_experiences" edge to the WorkExperience entity by IDs.
  902. func (euo *EmployeeUpdateOne) AddEmWorkExperienceIDs(ids ...uint64) *EmployeeUpdateOne {
  903. euo.mutation.AddEmWorkExperienceIDs(ids...)
  904. return euo
  905. }
  906. // AddEmWorkExperiences adds the "em_work_experiences" edges to the WorkExperience entity.
  907. func (euo *EmployeeUpdateOne) AddEmWorkExperiences(w ...*WorkExperience) *EmployeeUpdateOne {
  908. ids := make([]uint64, len(w))
  909. for i := range w {
  910. ids[i] = w[i].ID
  911. }
  912. return euo.AddEmWorkExperienceIDs(ids...)
  913. }
  914. // AddEmTutorialIDs adds the "em_tutorial" edge to the Tutorial entity by IDs.
  915. func (euo *EmployeeUpdateOne) AddEmTutorialIDs(ids ...uint64) *EmployeeUpdateOne {
  916. euo.mutation.AddEmTutorialIDs(ids...)
  917. return euo
  918. }
  919. // AddEmTutorial adds the "em_tutorial" edges to the Tutorial entity.
  920. func (euo *EmployeeUpdateOne) AddEmTutorial(t ...*Tutorial) *EmployeeUpdateOne {
  921. ids := make([]uint64, len(t))
  922. for i := range t {
  923. ids[i] = t[i].ID
  924. }
  925. return euo.AddEmTutorialIDs(ids...)
  926. }
  927. // Mutation returns the EmployeeMutation object of the builder.
  928. func (euo *EmployeeUpdateOne) Mutation() *EmployeeMutation {
  929. return euo.mutation
  930. }
  931. // ClearEmWorkExperiences clears all "em_work_experiences" edges to the WorkExperience entity.
  932. func (euo *EmployeeUpdateOne) ClearEmWorkExperiences() *EmployeeUpdateOne {
  933. euo.mutation.ClearEmWorkExperiences()
  934. return euo
  935. }
  936. // RemoveEmWorkExperienceIDs removes the "em_work_experiences" edge to WorkExperience entities by IDs.
  937. func (euo *EmployeeUpdateOne) RemoveEmWorkExperienceIDs(ids ...uint64) *EmployeeUpdateOne {
  938. euo.mutation.RemoveEmWorkExperienceIDs(ids...)
  939. return euo
  940. }
  941. // RemoveEmWorkExperiences removes "em_work_experiences" edges to WorkExperience entities.
  942. func (euo *EmployeeUpdateOne) RemoveEmWorkExperiences(w ...*WorkExperience) *EmployeeUpdateOne {
  943. ids := make([]uint64, len(w))
  944. for i := range w {
  945. ids[i] = w[i].ID
  946. }
  947. return euo.RemoveEmWorkExperienceIDs(ids...)
  948. }
  949. // ClearEmTutorial clears all "em_tutorial" edges to the Tutorial entity.
  950. func (euo *EmployeeUpdateOne) ClearEmTutorial() *EmployeeUpdateOne {
  951. euo.mutation.ClearEmTutorial()
  952. return euo
  953. }
  954. // RemoveEmTutorialIDs removes the "em_tutorial" edge to Tutorial entities by IDs.
  955. func (euo *EmployeeUpdateOne) RemoveEmTutorialIDs(ids ...uint64) *EmployeeUpdateOne {
  956. euo.mutation.RemoveEmTutorialIDs(ids...)
  957. return euo
  958. }
  959. // RemoveEmTutorial removes "em_tutorial" edges to Tutorial entities.
  960. func (euo *EmployeeUpdateOne) RemoveEmTutorial(t ...*Tutorial) *EmployeeUpdateOne {
  961. ids := make([]uint64, len(t))
  962. for i := range t {
  963. ids[i] = t[i].ID
  964. }
  965. return euo.RemoveEmTutorialIDs(ids...)
  966. }
  967. // Where appends a list predicates to the EmployeeUpdate builder.
  968. func (euo *EmployeeUpdateOne) Where(ps ...predicate.Employee) *EmployeeUpdateOne {
  969. euo.mutation.Where(ps...)
  970. return euo
  971. }
  972. // Select allows selecting one or more fields (columns) of the returned entity.
  973. // The default is selecting all fields defined in the entity schema.
  974. func (euo *EmployeeUpdateOne) Select(field string, fields ...string) *EmployeeUpdateOne {
  975. euo.fields = append([]string{field}, fields...)
  976. return euo
  977. }
  978. // Save executes the query and returns the updated Employee entity.
  979. func (euo *EmployeeUpdateOne) Save(ctx context.Context) (*Employee, error) {
  980. if err := euo.defaults(); err != nil {
  981. return nil, err
  982. }
  983. return withHooks(ctx, euo.sqlSave, euo.mutation, euo.hooks)
  984. }
  985. // SaveX is like Save, but panics if an error occurs.
  986. func (euo *EmployeeUpdateOne) SaveX(ctx context.Context) *Employee {
  987. node, err := euo.Save(ctx)
  988. if err != nil {
  989. panic(err)
  990. }
  991. return node
  992. }
  993. // Exec executes the query on the entity.
  994. func (euo *EmployeeUpdateOne) Exec(ctx context.Context) error {
  995. _, err := euo.Save(ctx)
  996. return err
  997. }
  998. // ExecX is like Exec, but panics if an error occurs.
  999. func (euo *EmployeeUpdateOne) ExecX(ctx context.Context) {
  1000. if err := euo.Exec(ctx); err != nil {
  1001. panic(err)
  1002. }
  1003. }
  1004. // defaults sets the default values of the builder before save.
  1005. func (euo *EmployeeUpdateOne) defaults() error {
  1006. if _, ok := euo.mutation.UpdatedAt(); !ok {
  1007. if employee.UpdateDefaultUpdatedAt == nil {
  1008. return fmt.Errorf("ent: uninitialized employee.UpdateDefaultUpdatedAt (forgotten import ent/runtime?)")
  1009. }
  1010. v := employee.UpdateDefaultUpdatedAt()
  1011. euo.mutation.SetUpdatedAt(v)
  1012. }
  1013. return nil
  1014. }
  1015. // check runs all checks and user-defined validators on the builder.
  1016. func (euo *EmployeeUpdateOne) check() error {
  1017. if v, ok := euo.mutation.Title(); ok {
  1018. if err := employee.TitleValidator(v); err != nil {
  1019. return &ValidationError{Name: "title", err: fmt.Errorf(`ent: validator failed for field "Employee.title": %w`, err)}
  1020. }
  1021. }
  1022. if v, ok := euo.mutation.Avatar(); ok {
  1023. if err := employee.AvatarValidator(v); err != nil {
  1024. return &ValidationError{Name: "avatar", err: fmt.Errorf(`ent: validator failed for field "Employee.avatar": %w`, err)}
  1025. }
  1026. }
  1027. if v, ok := euo.mutation.Tags(); ok {
  1028. if err := employee.TagsValidator(v); err != nil {
  1029. return &ValidationError{Name: "tags", err: fmt.Errorf(`ent: validator failed for field "Employee.tags": %w`, err)}
  1030. }
  1031. }
  1032. if v, ok := euo.mutation.HireCount(); ok {
  1033. if err := employee.HireCountValidator(v); err != nil {
  1034. return &ValidationError{Name: "hire_count", err: fmt.Errorf(`ent: validator failed for field "Employee.hire_count": %w`, err)}
  1035. }
  1036. }
  1037. if v, ok := euo.mutation.ServiceCount(); ok {
  1038. if err := employee.ServiceCountValidator(v); err != nil {
  1039. return &ValidationError{Name: "service_count", err: fmt.Errorf(`ent: validator failed for field "Employee.service_count": %w`, err)}
  1040. }
  1041. }
  1042. if v, ok := euo.mutation.AchievementCount(); ok {
  1043. if err := employee.AchievementCountValidator(v); err != nil {
  1044. return &ValidationError{Name: "achievement_count", err: fmt.Errorf(`ent: validator failed for field "Employee.achievement_count": %w`, err)}
  1045. }
  1046. }
  1047. if v, ok := euo.mutation.Intro(); ok {
  1048. if err := employee.IntroValidator(v); err != nil {
  1049. return &ValidationError{Name: "intro", err: fmt.Errorf(`ent: validator failed for field "Employee.intro": %w`, err)}
  1050. }
  1051. }
  1052. if v, ok := euo.mutation.Estimate(); ok {
  1053. if err := employee.EstimateValidator(v); err != nil {
  1054. return &ValidationError{Name: "estimate", err: fmt.Errorf(`ent: validator failed for field "Employee.estimate": %w`, err)}
  1055. }
  1056. }
  1057. if v, ok := euo.mutation.Skill(); ok {
  1058. if err := employee.SkillValidator(v); err != nil {
  1059. return &ValidationError{Name: "skill", err: fmt.Errorf(`ent: validator failed for field "Employee.skill": %w`, err)}
  1060. }
  1061. }
  1062. if v, ok := euo.mutation.VideoURL(); ok {
  1063. if err := employee.VideoURLValidator(v); err != nil {
  1064. return &ValidationError{Name: "video_url", err: fmt.Errorf(`ent: validator failed for field "Employee.video_url": %w`, err)}
  1065. }
  1066. }
  1067. if v, ok := euo.mutation.OrganizationID(); ok {
  1068. if err := employee.OrganizationIDValidator(v); err != nil {
  1069. return &ValidationError{Name: "organization_id", err: fmt.Errorf(`ent: validator failed for field "Employee.organization_id": %w`, err)}
  1070. }
  1071. }
  1072. if v, ok := euo.mutation.CategoryID(); ok {
  1073. if err := employee.CategoryIDValidator(v); err != nil {
  1074. return &ValidationError{Name: "category_id", err: fmt.Errorf(`ent: validator failed for field "Employee.category_id": %w`, err)}
  1075. }
  1076. }
  1077. return nil
  1078. }
  1079. func (euo *EmployeeUpdateOne) sqlSave(ctx context.Context) (_node *Employee, err error) {
  1080. if err := euo.check(); err != nil {
  1081. return _node, err
  1082. }
  1083. _spec := sqlgraph.NewUpdateSpec(employee.Table, employee.Columns, sqlgraph.NewFieldSpec(employee.FieldID, field.TypeUint64))
  1084. id, ok := euo.mutation.ID()
  1085. if !ok {
  1086. return nil, &ValidationError{Name: "id", err: errors.New(`ent: missing "Employee.id" for update`)}
  1087. }
  1088. _spec.Node.ID.Value = id
  1089. if fields := euo.fields; len(fields) > 0 {
  1090. _spec.Node.Columns = make([]string, 0, len(fields))
  1091. _spec.Node.Columns = append(_spec.Node.Columns, employee.FieldID)
  1092. for _, f := range fields {
  1093. if !employee.ValidColumn(f) {
  1094. return nil, &ValidationError{Name: f, err: fmt.Errorf("ent: invalid field %q for query", f)}
  1095. }
  1096. if f != employee.FieldID {
  1097. _spec.Node.Columns = append(_spec.Node.Columns, f)
  1098. }
  1099. }
  1100. }
  1101. if ps := euo.mutation.predicates; len(ps) > 0 {
  1102. _spec.Predicate = func(selector *sql.Selector) {
  1103. for i := range ps {
  1104. ps[i](selector)
  1105. }
  1106. }
  1107. }
  1108. if value, ok := euo.mutation.UpdatedAt(); ok {
  1109. _spec.SetField(employee.FieldUpdatedAt, field.TypeTime, value)
  1110. }
  1111. if value, ok := euo.mutation.DeletedAt(); ok {
  1112. _spec.SetField(employee.FieldDeletedAt, field.TypeTime, value)
  1113. }
  1114. if euo.mutation.DeletedAtCleared() {
  1115. _spec.ClearField(employee.FieldDeletedAt, field.TypeTime)
  1116. }
  1117. if value, ok := euo.mutation.Title(); ok {
  1118. _spec.SetField(employee.FieldTitle, field.TypeString, value)
  1119. }
  1120. if value, ok := euo.mutation.Avatar(); ok {
  1121. _spec.SetField(employee.FieldAvatar, field.TypeString, value)
  1122. }
  1123. if value, ok := euo.mutation.Tags(); ok {
  1124. _spec.SetField(employee.FieldTags, field.TypeString, value)
  1125. }
  1126. if value, ok := euo.mutation.HireCount(); ok {
  1127. _spec.SetField(employee.FieldHireCount, field.TypeInt, value)
  1128. }
  1129. if value, ok := euo.mutation.AddedHireCount(); ok {
  1130. _spec.AddField(employee.FieldHireCount, field.TypeInt, value)
  1131. }
  1132. if value, ok := euo.mutation.ServiceCount(); ok {
  1133. _spec.SetField(employee.FieldServiceCount, field.TypeInt, value)
  1134. }
  1135. if value, ok := euo.mutation.AddedServiceCount(); ok {
  1136. _spec.AddField(employee.FieldServiceCount, field.TypeInt, value)
  1137. }
  1138. if value, ok := euo.mutation.AchievementCount(); ok {
  1139. _spec.SetField(employee.FieldAchievementCount, field.TypeInt, value)
  1140. }
  1141. if value, ok := euo.mutation.AddedAchievementCount(); ok {
  1142. _spec.AddField(employee.FieldAchievementCount, field.TypeInt, value)
  1143. }
  1144. if value, ok := euo.mutation.Intro(); ok {
  1145. _spec.SetField(employee.FieldIntro, field.TypeString, value)
  1146. }
  1147. if value, ok := euo.mutation.Estimate(); ok {
  1148. _spec.SetField(employee.FieldEstimate, field.TypeString, value)
  1149. }
  1150. if value, ok := euo.mutation.Skill(); ok {
  1151. _spec.SetField(employee.FieldSkill, field.TypeString, value)
  1152. }
  1153. if value, ok := euo.mutation.AbilityType(); ok {
  1154. _spec.SetField(employee.FieldAbilityType, field.TypeString, value)
  1155. }
  1156. if value, ok := euo.mutation.Scene(); ok {
  1157. _spec.SetField(employee.FieldScene, field.TypeString, value)
  1158. }
  1159. if value, ok := euo.mutation.SwitchIn(); ok {
  1160. _spec.SetField(employee.FieldSwitchIn, field.TypeString, value)
  1161. }
  1162. if value, ok := euo.mutation.VideoURL(); ok {
  1163. _spec.SetField(employee.FieldVideoURL, field.TypeString, value)
  1164. }
  1165. if value, ok := euo.mutation.OrganizationID(); ok {
  1166. _spec.SetField(employee.FieldOrganizationID, field.TypeUint64, value)
  1167. }
  1168. if value, ok := euo.mutation.AddedOrganizationID(); ok {
  1169. _spec.AddField(employee.FieldOrganizationID, field.TypeUint64, value)
  1170. }
  1171. if value, ok := euo.mutation.CategoryID(); ok {
  1172. _spec.SetField(employee.FieldCategoryID, field.TypeUint64, value)
  1173. }
  1174. if value, ok := euo.mutation.AddedCategoryID(); ok {
  1175. _spec.AddField(employee.FieldCategoryID, field.TypeUint64, value)
  1176. }
  1177. if value, ok := euo.mutation.APIBase(); ok {
  1178. _spec.SetField(employee.FieldAPIBase, field.TypeString, value)
  1179. }
  1180. if value, ok := euo.mutation.APIKey(); ok {
  1181. _spec.SetField(employee.FieldAPIKey, field.TypeString, value)
  1182. }
  1183. if euo.mutation.EmWorkExperiencesCleared() {
  1184. edge := &sqlgraph.EdgeSpec{
  1185. Rel: sqlgraph.O2M,
  1186. Inverse: false,
  1187. Table: employee.EmWorkExperiencesTable,
  1188. Columns: []string{employee.EmWorkExperiencesColumn},
  1189. Bidi: false,
  1190. Target: &sqlgraph.EdgeTarget{
  1191. IDSpec: sqlgraph.NewFieldSpec(workexperience.FieldID, field.TypeUint64),
  1192. },
  1193. }
  1194. _spec.Edges.Clear = append(_spec.Edges.Clear, edge)
  1195. }
  1196. if nodes := euo.mutation.RemovedEmWorkExperiencesIDs(); len(nodes) > 0 && !euo.mutation.EmWorkExperiencesCleared() {
  1197. edge := &sqlgraph.EdgeSpec{
  1198. Rel: sqlgraph.O2M,
  1199. Inverse: false,
  1200. Table: employee.EmWorkExperiencesTable,
  1201. Columns: []string{employee.EmWorkExperiencesColumn},
  1202. Bidi: false,
  1203. Target: &sqlgraph.EdgeTarget{
  1204. IDSpec: sqlgraph.NewFieldSpec(workexperience.FieldID, field.TypeUint64),
  1205. },
  1206. }
  1207. for _, k := range nodes {
  1208. edge.Target.Nodes = append(edge.Target.Nodes, k)
  1209. }
  1210. _spec.Edges.Clear = append(_spec.Edges.Clear, edge)
  1211. }
  1212. if nodes := euo.mutation.EmWorkExperiencesIDs(); len(nodes) > 0 {
  1213. edge := &sqlgraph.EdgeSpec{
  1214. Rel: sqlgraph.O2M,
  1215. Inverse: false,
  1216. Table: employee.EmWorkExperiencesTable,
  1217. Columns: []string{employee.EmWorkExperiencesColumn},
  1218. Bidi: false,
  1219. Target: &sqlgraph.EdgeTarget{
  1220. IDSpec: sqlgraph.NewFieldSpec(workexperience.FieldID, field.TypeUint64),
  1221. },
  1222. }
  1223. for _, k := range nodes {
  1224. edge.Target.Nodes = append(edge.Target.Nodes, k)
  1225. }
  1226. _spec.Edges.Add = append(_spec.Edges.Add, edge)
  1227. }
  1228. if euo.mutation.EmTutorialCleared() {
  1229. edge := &sqlgraph.EdgeSpec{
  1230. Rel: sqlgraph.O2M,
  1231. Inverse: false,
  1232. Table: employee.EmTutorialTable,
  1233. Columns: []string{employee.EmTutorialColumn},
  1234. Bidi: false,
  1235. Target: &sqlgraph.EdgeTarget{
  1236. IDSpec: sqlgraph.NewFieldSpec(tutorial.FieldID, field.TypeUint64),
  1237. },
  1238. }
  1239. _spec.Edges.Clear = append(_spec.Edges.Clear, edge)
  1240. }
  1241. if nodes := euo.mutation.RemovedEmTutorialIDs(); len(nodes) > 0 && !euo.mutation.EmTutorialCleared() {
  1242. edge := &sqlgraph.EdgeSpec{
  1243. Rel: sqlgraph.O2M,
  1244. Inverse: false,
  1245. Table: employee.EmTutorialTable,
  1246. Columns: []string{employee.EmTutorialColumn},
  1247. Bidi: false,
  1248. Target: &sqlgraph.EdgeTarget{
  1249. IDSpec: sqlgraph.NewFieldSpec(tutorial.FieldID, field.TypeUint64),
  1250. },
  1251. }
  1252. for _, k := range nodes {
  1253. edge.Target.Nodes = append(edge.Target.Nodes, k)
  1254. }
  1255. _spec.Edges.Clear = append(_spec.Edges.Clear, edge)
  1256. }
  1257. if nodes := euo.mutation.EmTutorialIDs(); len(nodes) > 0 {
  1258. edge := &sqlgraph.EdgeSpec{
  1259. Rel: sqlgraph.O2M,
  1260. Inverse: false,
  1261. Table: employee.EmTutorialTable,
  1262. Columns: []string{employee.EmTutorialColumn},
  1263. Bidi: false,
  1264. Target: &sqlgraph.EdgeTarget{
  1265. IDSpec: sqlgraph.NewFieldSpec(tutorial.FieldID, field.TypeUint64),
  1266. },
  1267. }
  1268. for _, k := range nodes {
  1269. edge.Target.Nodes = append(edge.Target.Nodes, k)
  1270. }
  1271. _spec.Edges.Add = append(_spec.Edges.Add, edge)
  1272. }
  1273. _node = &Employee{config: euo.config}
  1274. _spec.Assign = _node.assignValues
  1275. _spec.ScanValues = _node.scanValues
  1276. if err = sqlgraph.UpdateNode(ctx, euo.driver, _spec); err != nil {
  1277. if _, ok := err.(*sqlgraph.NotFoundError); ok {
  1278. err = &NotFoundError{employee.Label}
  1279. } else if sqlgraph.IsConstraintError(err) {
  1280. err = &ConstraintError{msg: err.Error(), wrap: err}
  1281. }
  1282. return nil, err
  1283. }
  1284. euo.mutation.done = true
  1285. return _node, nil
  1286. }