employee_update.go 42 KB

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