123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416 |
- // Code generated by ent, DO NOT EDIT.
- package ent
- import (
- "context"
- "errors"
- "fmt"
- "time"
- "wechat-api/ent/employee"
- "wechat-api/ent/predicate"
- "wechat-api/ent/tutorial"
- "wechat-api/ent/workexperience"
- "entgo.io/ent/dialect/sql"
- "entgo.io/ent/dialect/sql/sqlgraph"
- "entgo.io/ent/schema/field"
- )
- // EmployeeUpdate is the builder for updating Employee entities.
- type EmployeeUpdate struct {
- config
- hooks []Hook
- mutation *EmployeeMutation
- }
- // Where appends a list predicates to the EmployeeUpdate builder.
- func (eu *EmployeeUpdate) Where(ps ...predicate.Employee) *EmployeeUpdate {
- eu.mutation.Where(ps...)
- return eu
- }
- // SetUpdatedAt sets the "updated_at" field.
- func (eu *EmployeeUpdate) SetUpdatedAt(t time.Time) *EmployeeUpdate {
- eu.mutation.SetUpdatedAt(t)
- return eu
- }
- // SetDeletedAt sets the "deleted_at" field.
- func (eu *EmployeeUpdate) SetDeletedAt(t time.Time) *EmployeeUpdate {
- eu.mutation.SetDeletedAt(t)
- return eu
- }
- // SetNillableDeletedAt sets the "deleted_at" field if the given value is not nil.
- func (eu *EmployeeUpdate) SetNillableDeletedAt(t *time.Time) *EmployeeUpdate {
- if t != nil {
- eu.SetDeletedAt(*t)
- }
- return eu
- }
- // ClearDeletedAt clears the value of the "deleted_at" field.
- func (eu *EmployeeUpdate) ClearDeletedAt() *EmployeeUpdate {
- eu.mutation.ClearDeletedAt()
- return eu
- }
- // SetTitle sets the "title" field.
- func (eu *EmployeeUpdate) SetTitle(s string) *EmployeeUpdate {
- eu.mutation.SetTitle(s)
- return eu
- }
- // SetNillableTitle sets the "title" field if the given value is not nil.
- func (eu *EmployeeUpdate) SetNillableTitle(s *string) *EmployeeUpdate {
- if s != nil {
- eu.SetTitle(*s)
- }
- return eu
- }
- // SetAvatar sets the "avatar" field.
- func (eu *EmployeeUpdate) SetAvatar(s string) *EmployeeUpdate {
- eu.mutation.SetAvatar(s)
- return eu
- }
- // SetNillableAvatar sets the "avatar" field if the given value is not nil.
- func (eu *EmployeeUpdate) SetNillableAvatar(s *string) *EmployeeUpdate {
- if s != nil {
- eu.SetAvatar(*s)
- }
- return eu
- }
- // SetTags sets the "tags" field.
- func (eu *EmployeeUpdate) SetTags(s string) *EmployeeUpdate {
- eu.mutation.SetTags(s)
- return eu
- }
- // SetNillableTags sets the "tags" field if the given value is not nil.
- func (eu *EmployeeUpdate) SetNillableTags(s *string) *EmployeeUpdate {
- if s != nil {
- eu.SetTags(*s)
- }
- return eu
- }
- // SetHireCount sets the "hire_count" field.
- func (eu *EmployeeUpdate) SetHireCount(i int) *EmployeeUpdate {
- eu.mutation.ResetHireCount()
- eu.mutation.SetHireCount(i)
- return eu
- }
- // SetNillableHireCount sets the "hire_count" field if the given value is not nil.
- func (eu *EmployeeUpdate) SetNillableHireCount(i *int) *EmployeeUpdate {
- if i != nil {
- eu.SetHireCount(*i)
- }
- return eu
- }
- // AddHireCount adds i to the "hire_count" field.
- func (eu *EmployeeUpdate) AddHireCount(i int) *EmployeeUpdate {
- eu.mutation.AddHireCount(i)
- return eu
- }
- // SetServiceCount sets the "service_count" field.
- func (eu *EmployeeUpdate) SetServiceCount(i int) *EmployeeUpdate {
- eu.mutation.ResetServiceCount()
- eu.mutation.SetServiceCount(i)
- return eu
- }
- // SetNillableServiceCount sets the "service_count" field if the given value is not nil.
- func (eu *EmployeeUpdate) SetNillableServiceCount(i *int) *EmployeeUpdate {
- if i != nil {
- eu.SetServiceCount(*i)
- }
- return eu
- }
- // AddServiceCount adds i to the "service_count" field.
- func (eu *EmployeeUpdate) AddServiceCount(i int) *EmployeeUpdate {
- eu.mutation.AddServiceCount(i)
- return eu
- }
- // SetAchievementCount sets the "achievement_count" field.
- func (eu *EmployeeUpdate) SetAchievementCount(i int) *EmployeeUpdate {
- eu.mutation.ResetAchievementCount()
- eu.mutation.SetAchievementCount(i)
- return eu
- }
- // SetNillableAchievementCount sets the "achievement_count" field if the given value is not nil.
- func (eu *EmployeeUpdate) SetNillableAchievementCount(i *int) *EmployeeUpdate {
- if i != nil {
- eu.SetAchievementCount(*i)
- }
- return eu
- }
- // AddAchievementCount adds i to the "achievement_count" field.
- func (eu *EmployeeUpdate) AddAchievementCount(i int) *EmployeeUpdate {
- eu.mutation.AddAchievementCount(i)
- return eu
- }
- // SetIntro sets the "intro" field.
- func (eu *EmployeeUpdate) SetIntro(s string) *EmployeeUpdate {
- eu.mutation.SetIntro(s)
- return eu
- }
- // SetNillableIntro sets the "intro" field if the given value is not nil.
- func (eu *EmployeeUpdate) SetNillableIntro(s *string) *EmployeeUpdate {
- if s != nil {
- eu.SetIntro(*s)
- }
- return eu
- }
- // SetEstimate sets the "estimate" field.
- func (eu *EmployeeUpdate) SetEstimate(s string) *EmployeeUpdate {
- eu.mutation.SetEstimate(s)
- return eu
- }
- // SetNillableEstimate sets the "estimate" field if the given value is not nil.
- func (eu *EmployeeUpdate) SetNillableEstimate(s *string) *EmployeeUpdate {
- if s != nil {
- eu.SetEstimate(*s)
- }
- return eu
- }
- // SetSkill sets the "skill" field.
- func (eu *EmployeeUpdate) SetSkill(s string) *EmployeeUpdate {
- eu.mutation.SetSkill(s)
- return eu
- }
- // SetNillableSkill sets the "skill" field if the given value is not nil.
- func (eu *EmployeeUpdate) SetNillableSkill(s *string) *EmployeeUpdate {
- if s != nil {
- eu.SetSkill(*s)
- }
- return eu
- }
- // SetAbilityType sets the "ability_type" field.
- func (eu *EmployeeUpdate) SetAbilityType(s string) *EmployeeUpdate {
- eu.mutation.SetAbilityType(s)
- return eu
- }
- // SetNillableAbilityType sets the "ability_type" field if the given value is not nil.
- func (eu *EmployeeUpdate) SetNillableAbilityType(s *string) *EmployeeUpdate {
- if s != nil {
- eu.SetAbilityType(*s)
- }
- return eu
- }
- // SetScene sets the "scene" field.
- func (eu *EmployeeUpdate) SetScene(s string) *EmployeeUpdate {
- eu.mutation.SetScene(s)
- return eu
- }
- // SetNillableScene sets the "scene" field if the given value is not nil.
- func (eu *EmployeeUpdate) SetNillableScene(s *string) *EmployeeUpdate {
- if s != nil {
- eu.SetScene(*s)
- }
- return eu
- }
- // SetSwitchIn sets the "switch_in" field.
- func (eu *EmployeeUpdate) SetSwitchIn(s string) *EmployeeUpdate {
- eu.mutation.SetSwitchIn(s)
- return eu
- }
- // SetNillableSwitchIn sets the "switch_in" field if the given value is not nil.
- func (eu *EmployeeUpdate) SetNillableSwitchIn(s *string) *EmployeeUpdate {
- if s != nil {
- eu.SetSwitchIn(*s)
- }
- return eu
- }
- // SetVideoURL sets the "video_url" field.
- func (eu *EmployeeUpdate) SetVideoURL(s string) *EmployeeUpdate {
- eu.mutation.SetVideoURL(s)
- return eu
- }
- // SetNillableVideoURL sets the "video_url" field if the given value is not nil.
- func (eu *EmployeeUpdate) SetNillableVideoURL(s *string) *EmployeeUpdate {
- if s != nil {
- eu.SetVideoURL(*s)
- }
- return eu
- }
- // SetOrganizationID sets the "organization_id" field.
- func (eu *EmployeeUpdate) SetOrganizationID(u uint64) *EmployeeUpdate {
- eu.mutation.ResetOrganizationID()
- eu.mutation.SetOrganizationID(u)
- return eu
- }
- // SetNillableOrganizationID sets the "organization_id" field if the given value is not nil.
- func (eu *EmployeeUpdate) SetNillableOrganizationID(u *uint64) *EmployeeUpdate {
- if u != nil {
- eu.SetOrganizationID(*u)
- }
- return eu
- }
- // AddOrganizationID adds u to the "organization_id" field.
- func (eu *EmployeeUpdate) AddOrganizationID(u int64) *EmployeeUpdate {
- eu.mutation.AddOrganizationID(u)
- return eu
- }
- // SetCategoryID sets the "category_id" field.
- func (eu *EmployeeUpdate) SetCategoryID(u uint64) *EmployeeUpdate {
- eu.mutation.ResetCategoryID()
- eu.mutation.SetCategoryID(u)
- return eu
- }
- // SetNillableCategoryID sets the "category_id" field if the given value is not nil.
- func (eu *EmployeeUpdate) SetNillableCategoryID(u *uint64) *EmployeeUpdate {
- if u != nil {
- eu.SetCategoryID(*u)
- }
- return eu
- }
- // AddCategoryID adds u to the "category_id" field.
- func (eu *EmployeeUpdate) AddCategoryID(u int64) *EmployeeUpdate {
- eu.mutation.AddCategoryID(u)
- return eu
- }
- // SetAPIBase sets the "api_base" field.
- func (eu *EmployeeUpdate) SetAPIBase(s string) *EmployeeUpdate {
- eu.mutation.SetAPIBase(s)
- return eu
- }
- // SetNillableAPIBase sets the "api_base" field if the given value is not nil.
- func (eu *EmployeeUpdate) SetNillableAPIBase(s *string) *EmployeeUpdate {
- if s != nil {
- eu.SetAPIBase(*s)
- }
- return eu
- }
- // SetAPIKey sets the "api_key" field.
- func (eu *EmployeeUpdate) SetAPIKey(s string) *EmployeeUpdate {
- eu.mutation.SetAPIKey(s)
- return eu
- }
- // SetNillableAPIKey sets the "api_key" field if the given value is not nil.
- func (eu *EmployeeUpdate) SetNillableAPIKey(s *string) *EmployeeUpdate {
- if s != nil {
- eu.SetAPIKey(*s)
- }
- return eu
- }
- // AddEmWorkExperienceIDs adds the "em_work_experiences" edge to the WorkExperience entity by IDs.
- func (eu *EmployeeUpdate) AddEmWorkExperienceIDs(ids ...uint64) *EmployeeUpdate {
- eu.mutation.AddEmWorkExperienceIDs(ids...)
- return eu
- }
- // AddEmWorkExperiences adds the "em_work_experiences" edges to the WorkExperience entity.
- func (eu *EmployeeUpdate) AddEmWorkExperiences(w ...*WorkExperience) *EmployeeUpdate {
- ids := make([]uint64, len(w))
- for i := range w {
- ids[i] = w[i].ID
- }
- return eu.AddEmWorkExperienceIDs(ids...)
- }
- // AddEmTutorialIDs adds the "em_tutorial" edge to the Tutorial entity by IDs.
- func (eu *EmployeeUpdate) AddEmTutorialIDs(ids ...uint64) *EmployeeUpdate {
- eu.mutation.AddEmTutorialIDs(ids...)
- return eu
- }
- // AddEmTutorial adds the "em_tutorial" edges to the Tutorial entity.
- func (eu *EmployeeUpdate) AddEmTutorial(t ...*Tutorial) *EmployeeUpdate {
- ids := make([]uint64, len(t))
- for i := range t {
- ids[i] = t[i].ID
- }
- return eu.AddEmTutorialIDs(ids...)
- }
- // Mutation returns the EmployeeMutation object of the builder.
- func (eu *EmployeeUpdate) Mutation() *EmployeeMutation {
- return eu.mutation
- }
- // ClearEmWorkExperiences clears all "em_work_experiences" edges to the WorkExperience entity.
- func (eu *EmployeeUpdate) ClearEmWorkExperiences() *EmployeeUpdate {
- eu.mutation.ClearEmWorkExperiences()
- return eu
- }
- // RemoveEmWorkExperienceIDs removes the "em_work_experiences" edge to WorkExperience entities by IDs.
- func (eu *EmployeeUpdate) RemoveEmWorkExperienceIDs(ids ...uint64) *EmployeeUpdate {
- eu.mutation.RemoveEmWorkExperienceIDs(ids...)
- return eu
- }
- // RemoveEmWorkExperiences removes "em_work_experiences" edges to WorkExperience entities.
- func (eu *EmployeeUpdate) RemoveEmWorkExperiences(w ...*WorkExperience) *EmployeeUpdate {
- ids := make([]uint64, len(w))
- for i := range w {
- ids[i] = w[i].ID
- }
- return eu.RemoveEmWorkExperienceIDs(ids...)
- }
- // ClearEmTutorial clears all "em_tutorial" edges to the Tutorial entity.
- func (eu *EmployeeUpdate) ClearEmTutorial() *EmployeeUpdate {
- eu.mutation.ClearEmTutorial()
- return eu
- }
- // RemoveEmTutorialIDs removes the "em_tutorial" edge to Tutorial entities by IDs.
- func (eu *EmployeeUpdate) RemoveEmTutorialIDs(ids ...uint64) *EmployeeUpdate {
- eu.mutation.RemoveEmTutorialIDs(ids...)
- return eu
- }
- // RemoveEmTutorial removes "em_tutorial" edges to Tutorial entities.
- func (eu *EmployeeUpdate) RemoveEmTutorial(t ...*Tutorial) *EmployeeUpdate {
- ids := make([]uint64, len(t))
- for i := range t {
- ids[i] = t[i].ID
- }
- return eu.RemoveEmTutorialIDs(ids...)
- }
- // Save executes the query and returns the number of nodes affected by the update operation.
- func (eu *EmployeeUpdate) Save(ctx context.Context) (int, error) {
- if err := eu.defaults(); err != nil {
- return 0, err
- }
- return withHooks(ctx, eu.sqlSave, eu.mutation, eu.hooks)
- }
- // SaveX is like Save, but panics if an error occurs.
- func (eu *EmployeeUpdate) SaveX(ctx context.Context) int {
- affected, err := eu.Save(ctx)
- if err != nil {
- panic(err)
- }
- return affected
- }
- // Exec executes the query.
- func (eu *EmployeeUpdate) Exec(ctx context.Context) error {
- _, err := eu.Save(ctx)
- return err
- }
- // ExecX is like Exec, but panics if an error occurs.
- func (eu *EmployeeUpdate) ExecX(ctx context.Context) {
- if err := eu.Exec(ctx); err != nil {
- panic(err)
- }
- }
- // defaults sets the default values of the builder before save.
- func (eu *EmployeeUpdate) defaults() error {
- if _, ok := eu.mutation.UpdatedAt(); !ok {
- if employee.UpdateDefaultUpdatedAt == nil {
- return fmt.Errorf("ent: uninitialized employee.UpdateDefaultUpdatedAt (forgotten import ent/runtime?)")
- }
- v := employee.UpdateDefaultUpdatedAt()
- eu.mutation.SetUpdatedAt(v)
- }
- return nil
- }
- // check runs all checks and user-defined validators on the builder.
- func (eu *EmployeeUpdate) check() error {
- if v, ok := eu.mutation.Title(); ok {
- if err := employee.TitleValidator(v); err != nil {
- return &ValidationError{Name: "title", err: fmt.Errorf(`ent: validator failed for field "Employee.title": %w`, err)}
- }
- }
- if v, ok := eu.mutation.Avatar(); ok {
- if err := employee.AvatarValidator(v); err != nil {
- return &ValidationError{Name: "avatar", err: fmt.Errorf(`ent: validator failed for field "Employee.avatar": %w`, err)}
- }
- }
- if v, ok := eu.mutation.Tags(); ok {
- if err := employee.TagsValidator(v); err != nil {
- return &ValidationError{Name: "tags", err: fmt.Errorf(`ent: validator failed for field "Employee.tags": %w`, err)}
- }
- }
- if v, ok := eu.mutation.HireCount(); ok {
- if err := employee.HireCountValidator(v); err != nil {
- return &ValidationError{Name: "hire_count", err: fmt.Errorf(`ent: validator failed for field "Employee.hire_count": %w`, err)}
- }
- }
- if v, ok := eu.mutation.ServiceCount(); ok {
- if err := employee.ServiceCountValidator(v); err != nil {
- return &ValidationError{Name: "service_count", err: fmt.Errorf(`ent: validator failed for field "Employee.service_count": %w`, err)}
- }
- }
- if v, ok := eu.mutation.AchievementCount(); ok {
- if err := employee.AchievementCountValidator(v); err != nil {
- return &ValidationError{Name: "achievement_count", err: fmt.Errorf(`ent: validator failed for field "Employee.achievement_count": %w`, err)}
- }
- }
- if v, ok := eu.mutation.Intro(); ok {
- if err := employee.IntroValidator(v); err != nil {
- return &ValidationError{Name: "intro", err: fmt.Errorf(`ent: validator failed for field "Employee.intro": %w`, err)}
- }
- }
- if v, ok := eu.mutation.Estimate(); ok {
- if err := employee.EstimateValidator(v); err != nil {
- return &ValidationError{Name: "estimate", err: fmt.Errorf(`ent: validator failed for field "Employee.estimate": %w`, err)}
- }
- }
- if v, ok := eu.mutation.Skill(); ok {
- if err := employee.SkillValidator(v); err != nil {
- return &ValidationError{Name: "skill", err: fmt.Errorf(`ent: validator failed for field "Employee.skill": %w`, err)}
- }
- }
- if v, ok := eu.mutation.VideoURL(); ok {
- if err := employee.VideoURLValidator(v); err != nil {
- return &ValidationError{Name: "video_url", err: fmt.Errorf(`ent: validator failed for field "Employee.video_url": %w`, err)}
- }
- }
- if v, ok := eu.mutation.OrganizationID(); ok {
- if err := employee.OrganizationIDValidator(v); err != nil {
- return &ValidationError{Name: "organization_id", err: fmt.Errorf(`ent: validator failed for field "Employee.organization_id": %w`, err)}
- }
- }
- if v, ok := eu.mutation.CategoryID(); ok {
- if err := employee.CategoryIDValidator(v); err != nil {
- return &ValidationError{Name: "category_id", err: fmt.Errorf(`ent: validator failed for field "Employee.category_id": %w`, err)}
- }
- }
- return nil
- }
- func (eu *EmployeeUpdate) sqlSave(ctx context.Context) (n int, err error) {
- if err := eu.check(); err != nil {
- return n, err
- }
- _spec := sqlgraph.NewUpdateSpec(employee.Table, employee.Columns, sqlgraph.NewFieldSpec(employee.FieldID, field.TypeUint64))
- if ps := eu.mutation.predicates; len(ps) > 0 {
- _spec.Predicate = func(selector *sql.Selector) {
- for i := range ps {
- ps[i](selector)
- }
- }
- }
- if value, ok := eu.mutation.UpdatedAt(); ok {
- _spec.SetField(employee.FieldUpdatedAt, field.TypeTime, value)
- }
- if value, ok := eu.mutation.DeletedAt(); ok {
- _spec.SetField(employee.FieldDeletedAt, field.TypeTime, value)
- }
- if eu.mutation.DeletedAtCleared() {
- _spec.ClearField(employee.FieldDeletedAt, field.TypeTime)
- }
- if value, ok := eu.mutation.Title(); ok {
- _spec.SetField(employee.FieldTitle, field.TypeString, value)
- }
- if value, ok := eu.mutation.Avatar(); ok {
- _spec.SetField(employee.FieldAvatar, field.TypeString, value)
- }
- if value, ok := eu.mutation.Tags(); ok {
- _spec.SetField(employee.FieldTags, field.TypeString, value)
- }
- if value, ok := eu.mutation.HireCount(); ok {
- _spec.SetField(employee.FieldHireCount, field.TypeInt, value)
- }
- if value, ok := eu.mutation.AddedHireCount(); ok {
- _spec.AddField(employee.FieldHireCount, field.TypeInt, value)
- }
- if value, ok := eu.mutation.ServiceCount(); ok {
- _spec.SetField(employee.FieldServiceCount, field.TypeInt, value)
- }
- if value, ok := eu.mutation.AddedServiceCount(); ok {
- _spec.AddField(employee.FieldServiceCount, field.TypeInt, value)
- }
- if value, ok := eu.mutation.AchievementCount(); ok {
- _spec.SetField(employee.FieldAchievementCount, field.TypeInt, value)
- }
- if value, ok := eu.mutation.AddedAchievementCount(); ok {
- _spec.AddField(employee.FieldAchievementCount, field.TypeInt, value)
- }
- if value, ok := eu.mutation.Intro(); ok {
- _spec.SetField(employee.FieldIntro, field.TypeString, value)
- }
- if value, ok := eu.mutation.Estimate(); ok {
- _spec.SetField(employee.FieldEstimate, field.TypeString, value)
- }
- if value, ok := eu.mutation.Skill(); ok {
- _spec.SetField(employee.FieldSkill, field.TypeString, value)
- }
- if value, ok := eu.mutation.AbilityType(); ok {
- _spec.SetField(employee.FieldAbilityType, field.TypeString, value)
- }
- if value, ok := eu.mutation.Scene(); ok {
- _spec.SetField(employee.FieldScene, field.TypeString, value)
- }
- if value, ok := eu.mutation.SwitchIn(); ok {
- _spec.SetField(employee.FieldSwitchIn, field.TypeString, value)
- }
- if value, ok := eu.mutation.VideoURL(); ok {
- _spec.SetField(employee.FieldVideoURL, field.TypeString, value)
- }
- if value, ok := eu.mutation.OrganizationID(); ok {
- _spec.SetField(employee.FieldOrganizationID, field.TypeUint64, value)
- }
- if value, ok := eu.mutation.AddedOrganizationID(); ok {
- _spec.AddField(employee.FieldOrganizationID, field.TypeUint64, value)
- }
- if value, ok := eu.mutation.CategoryID(); ok {
- _spec.SetField(employee.FieldCategoryID, field.TypeUint64, value)
- }
- if value, ok := eu.mutation.AddedCategoryID(); ok {
- _spec.AddField(employee.FieldCategoryID, field.TypeUint64, value)
- }
- if value, ok := eu.mutation.APIBase(); ok {
- _spec.SetField(employee.FieldAPIBase, field.TypeString, value)
- }
- if value, ok := eu.mutation.APIKey(); ok {
- _spec.SetField(employee.FieldAPIKey, field.TypeString, value)
- }
- if eu.mutation.EmWorkExperiencesCleared() {
- edge := &sqlgraph.EdgeSpec{
- Rel: sqlgraph.O2M,
- Inverse: false,
- Table: employee.EmWorkExperiencesTable,
- Columns: []string{employee.EmWorkExperiencesColumn},
- Bidi: false,
- Target: &sqlgraph.EdgeTarget{
- IDSpec: sqlgraph.NewFieldSpec(workexperience.FieldID, field.TypeUint64),
- },
- }
- _spec.Edges.Clear = append(_spec.Edges.Clear, edge)
- }
- if nodes := eu.mutation.RemovedEmWorkExperiencesIDs(); len(nodes) > 0 && !eu.mutation.EmWorkExperiencesCleared() {
- edge := &sqlgraph.EdgeSpec{
- Rel: sqlgraph.O2M,
- Inverse: false,
- Table: employee.EmWorkExperiencesTable,
- Columns: []string{employee.EmWorkExperiencesColumn},
- Bidi: false,
- Target: &sqlgraph.EdgeTarget{
- IDSpec: sqlgraph.NewFieldSpec(workexperience.FieldID, field.TypeUint64),
- },
- }
- for _, k := range nodes {
- edge.Target.Nodes = append(edge.Target.Nodes, k)
- }
- _spec.Edges.Clear = append(_spec.Edges.Clear, edge)
- }
- if nodes := eu.mutation.EmWorkExperiencesIDs(); len(nodes) > 0 {
- edge := &sqlgraph.EdgeSpec{
- Rel: sqlgraph.O2M,
- Inverse: false,
- Table: employee.EmWorkExperiencesTable,
- Columns: []string{employee.EmWorkExperiencesColumn},
- Bidi: false,
- Target: &sqlgraph.EdgeTarget{
- IDSpec: sqlgraph.NewFieldSpec(workexperience.FieldID, field.TypeUint64),
- },
- }
- for _, k := range nodes {
- edge.Target.Nodes = append(edge.Target.Nodes, k)
- }
- _spec.Edges.Add = append(_spec.Edges.Add, edge)
- }
- if eu.mutation.EmTutorialCleared() {
- edge := &sqlgraph.EdgeSpec{
- Rel: sqlgraph.O2M,
- Inverse: false,
- Table: employee.EmTutorialTable,
- Columns: []string{employee.EmTutorialColumn},
- Bidi: false,
- Target: &sqlgraph.EdgeTarget{
- IDSpec: sqlgraph.NewFieldSpec(tutorial.FieldID, field.TypeUint64),
- },
- }
- _spec.Edges.Clear = append(_spec.Edges.Clear, edge)
- }
- if nodes := eu.mutation.RemovedEmTutorialIDs(); len(nodes) > 0 && !eu.mutation.EmTutorialCleared() {
- edge := &sqlgraph.EdgeSpec{
- Rel: sqlgraph.O2M,
- Inverse: false,
- Table: employee.EmTutorialTable,
- Columns: []string{employee.EmTutorialColumn},
- Bidi: false,
- Target: &sqlgraph.EdgeTarget{
- IDSpec: sqlgraph.NewFieldSpec(tutorial.FieldID, field.TypeUint64),
- },
- }
- for _, k := range nodes {
- edge.Target.Nodes = append(edge.Target.Nodes, k)
- }
- _spec.Edges.Clear = append(_spec.Edges.Clear, edge)
- }
- if nodes := eu.mutation.EmTutorialIDs(); len(nodes) > 0 {
- edge := &sqlgraph.EdgeSpec{
- Rel: sqlgraph.O2M,
- Inverse: false,
- Table: employee.EmTutorialTable,
- Columns: []string{employee.EmTutorialColumn},
- Bidi: false,
- Target: &sqlgraph.EdgeTarget{
- IDSpec: sqlgraph.NewFieldSpec(tutorial.FieldID, field.TypeUint64),
- },
- }
- for _, k := range nodes {
- edge.Target.Nodes = append(edge.Target.Nodes, k)
- }
- _spec.Edges.Add = append(_spec.Edges.Add, edge)
- }
- if n, err = sqlgraph.UpdateNodes(ctx, eu.driver, _spec); err != nil {
- if _, ok := err.(*sqlgraph.NotFoundError); ok {
- err = &NotFoundError{employee.Label}
- } else if sqlgraph.IsConstraintError(err) {
- err = &ConstraintError{msg: err.Error(), wrap: err}
- }
- return 0, err
- }
- eu.mutation.done = true
- return n, nil
- }
- // EmployeeUpdateOne is the builder for updating a single Employee entity.
- type EmployeeUpdateOne struct {
- config
- fields []string
- hooks []Hook
- mutation *EmployeeMutation
- }
- // SetUpdatedAt sets the "updated_at" field.
- func (euo *EmployeeUpdateOne) SetUpdatedAt(t time.Time) *EmployeeUpdateOne {
- euo.mutation.SetUpdatedAt(t)
- return euo
- }
- // SetDeletedAt sets the "deleted_at" field.
- func (euo *EmployeeUpdateOne) SetDeletedAt(t time.Time) *EmployeeUpdateOne {
- euo.mutation.SetDeletedAt(t)
- return euo
- }
- // SetNillableDeletedAt sets the "deleted_at" field if the given value is not nil.
- func (euo *EmployeeUpdateOne) SetNillableDeletedAt(t *time.Time) *EmployeeUpdateOne {
- if t != nil {
- euo.SetDeletedAt(*t)
- }
- return euo
- }
- // ClearDeletedAt clears the value of the "deleted_at" field.
- func (euo *EmployeeUpdateOne) ClearDeletedAt() *EmployeeUpdateOne {
- euo.mutation.ClearDeletedAt()
- return euo
- }
- // SetTitle sets the "title" field.
- func (euo *EmployeeUpdateOne) SetTitle(s string) *EmployeeUpdateOne {
- euo.mutation.SetTitle(s)
- return euo
- }
- // SetNillableTitle sets the "title" field if the given value is not nil.
- func (euo *EmployeeUpdateOne) SetNillableTitle(s *string) *EmployeeUpdateOne {
- if s != nil {
- euo.SetTitle(*s)
- }
- return euo
- }
- // SetAvatar sets the "avatar" field.
- func (euo *EmployeeUpdateOne) SetAvatar(s string) *EmployeeUpdateOne {
- euo.mutation.SetAvatar(s)
- return euo
- }
- // SetNillableAvatar sets the "avatar" field if the given value is not nil.
- func (euo *EmployeeUpdateOne) SetNillableAvatar(s *string) *EmployeeUpdateOne {
- if s != nil {
- euo.SetAvatar(*s)
- }
- return euo
- }
- // SetTags sets the "tags" field.
- func (euo *EmployeeUpdateOne) SetTags(s string) *EmployeeUpdateOne {
- euo.mutation.SetTags(s)
- return euo
- }
- // SetNillableTags sets the "tags" field if the given value is not nil.
- func (euo *EmployeeUpdateOne) SetNillableTags(s *string) *EmployeeUpdateOne {
- if s != nil {
- euo.SetTags(*s)
- }
- return euo
- }
- // SetHireCount sets the "hire_count" field.
- func (euo *EmployeeUpdateOne) SetHireCount(i int) *EmployeeUpdateOne {
- euo.mutation.ResetHireCount()
- euo.mutation.SetHireCount(i)
- return euo
- }
- // SetNillableHireCount sets the "hire_count" field if the given value is not nil.
- func (euo *EmployeeUpdateOne) SetNillableHireCount(i *int) *EmployeeUpdateOne {
- if i != nil {
- euo.SetHireCount(*i)
- }
- return euo
- }
- // AddHireCount adds i to the "hire_count" field.
- func (euo *EmployeeUpdateOne) AddHireCount(i int) *EmployeeUpdateOne {
- euo.mutation.AddHireCount(i)
- return euo
- }
- // SetServiceCount sets the "service_count" field.
- func (euo *EmployeeUpdateOne) SetServiceCount(i int) *EmployeeUpdateOne {
- euo.mutation.ResetServiceCount()
- euo.mutation.SetServiceCount(i)
- return euo
- }
- // SetNillableServiceCount sets the "service_count" field if the given value is not nil.
- func (euo *EmployeeUpdateOne) SetNillableServiceCount(i *int) *EmployeeUpdateOne {
- if i != nil {
- euo.SetServiceCount(*i)
- }
- return euo
- }
- // AddServiceCount adds i to the "service_count" field.
- func (euo *EmployeeUpdateOne) AddServiceCount(i int) *EmployeeUpdateOne {
- euo.mutation.AddServiceCount(i)
- return euo
- }
- // SetAchievementCount sets the "achievement_count" field.
- func (euo *EmployeeUpdateOne) SetAchievementCount(i int) *EmployeeUpdateOne {
- euo.mutation.ResetAchievementCount()
- euo.mutation.SetAchievementCount(i)
- return euo
- }
- // SetNillableAchievementCount sets the "achievement_count" field if the given value is not nil.
- func (euo *EmployeeUpdateOne) SetNillableAchievementCount(i *int) *EmployeeUpdateOne {
- if i != nil {
- euo.SetAchievementCount(*i)
- }
- return euo
- }
- // AddAchievementCount adds i to the "achievement_count" field.
- func (euo *EmployeeUpdateOne) AddAchievementCount(i int) *EmployeeUpdateOne {
- euo.mutation.AddAchievementCount(i)
- return euo
- }
- // SetIntro sets the "intro" field.
- func (euo *EmployeeUpdateOne) SetIntro(s string) *EmployeeUpdateOne {
- euo.mutation.SetIntro(s)
- return euo
- }
- // SetNillableIntro sets the "intro" field if the given value is not nil.
- func (euo *EmployeeUpdateOne) SetNillableIntro(s *string) *EmployeeUpdateOne {
- if s != nil {
- euo.SetIntro(*s)
- }
- return euo
- }
- // SetEstimate sets the "estimate" field.
- func (euo *EmployeeUpdateOne) SetEstimate(s string) *EmployeeUpdateOne {
- euo.mutation.SetEstimate(s)
- return euo
- }
- // SetNillableEstimate sets the "estimate" field if the given value is not nil.
- func (euo *EmployeeUpdateOne) SetNillableEstimate(s *string) *EmployeeUpdateOne {
- if s != nil {
- euo.SetEstimate(*s)
- }
- return euo
- }
- // SetSkill sets the "skill" field.
- func (euo *EmployeeUpdateOne) SetSkill(s string) *EmployeeUpdateOne {
- euo.mutation.SetSkill(s)
- return euo
- }
- // SetNillableSkill sets the "skill" field if the given value is not nil.
- func (euo *EmployeeUpdateOne) SetNillableSkill(s *string) *EmployeeUpdateOne {
- if s != nil {
- euo.SetSkill(*s)
- }
- return euo
- }
- // SetAbilityType sets the "ability_type" field.
- func (euo *EmployeeUpdateOne) SetAbilityType(s string) *EmployeeUpdateOne {
- euo.mutation.SetAbilityType(s)
- return euo
- }
- // SetNillableAbilityType sets the "ability_type" field if the given value is not nil.
- func (euo *EmployeeUpdateOne) SetNillableAbilityType(s *string) *EmployeeUpdateOne {
- if s != nil {
- euo.SetAbilityType(*s)
- }
- return euo
- }
- // SetScene sets the "scene" field.
- func (euo *EmployeeUpdateOne) SetScene(s string) *EmployeeUpdateOne {
- euo.mutation.SetScene(s)
- return euo
- }
- // SetNillableScene sets the "scene" field if the given value is not nil.
- func (euo *EmployeeUpdateOne) SetNillableScene(s *string) *EmployeeUpdateOne {
- if s != nil {
- euo.SetScene(*s)
- }
- return euo
- }
- // SetSwitchIn sets the "switch_in" field.
- func (euo *EmployeeUpdateOne) SetSwitchIn(s string) *EmployeeUpdateOne {
- euo.mutation.SetSwitchIn(s)
- return euo
- }
- // SetNillableSwitchIn sets the "switch_in" field if the given value is not nil.
- func (euo *EmployeeUpdateOne) SetNillableSwitchIn(s *string) *EmployeeUpdateOne {
- if s != nil {
- euo.SetSwitchIn(*s)
- }
- return euo
- }
- // SetVideoURL sets the "video_url" field.
- func (euo *EmployeeUpdateOne) SetVideoURL(s string) *EmployeeUpdateOne {
- euo.mutation.SetVideoURL(s)
- return euo
- }
- // SetNillableVideoURL sets the "video_url" field if the given value is not nil.
- func (euo *EmployeeUpdateOne) SetNillableVideoURL(s *string) *EmployeeUpdateOne {
- if s != nil {
- euo.SetVideoURL(*s)
- }
- return euo
- }
- // SetOrganizationID sets the "organization_id" field.
- func (euo *EmployeeUpdateOne) SetOrganizationID(u uint64) *EmployeeUpdateOne {
- euo.mutation.ResetOrganizationID()
- euo.mutation.SetOrganizationID(u)
- return euo
- }
- // SetNillableOrganizationID sets the "organization_id" field if the given value is not nil.
- func (euo *EmployeeUpdateOne) SetNillableOrganizationID(u *uint64) *EmployeeUpdateOne {
- if u != nil {
- euo.SetOrganizationID(*u)
- }
- return euo
- }
- // AddOrganizationID adds u to the "organization_id" field.
- func (euo *EmployeeUpdateOne) AddOrganizationID(u int64) *EmployeeUpdateOne {
- euo.mutation.AddOrganizationID(u)
- return euo
- }
- // SetCategoryID sets the "category_id" field.
- func (euo *EmployeeUpdateOne) SetCategoryID(u uint64) *EmployeeUpdateOne {
- euo.mutation.ResetCategoryID()
- euo.mutation.SetCategoryID(u)
- return euo
- }
- // SetNillableCategoryID sets the "category_id" field if the given value is not nil.
- func (euo *EmployeeUpdateOne) SetNillableCategoryID(u *uint64) *EmployeeUpdateOne {
- if u != nil {
- euo.SetCategoryID(*u)
- }
- return euo
- }
- // AddCategoryID adds u to the "category_id" field.
- func (euo *EmployeeUpdateOne) AddCategoryID(u int64) *EmployeeUpdateOne {
- euo.mutation.AddCategoryID(u)
- return euo
- }
- // SetAPIBase sets the "api_base" field.
- func (euo *EmployeeUpdateOne) SetAPIBase(s string) *EmployeeUpdateOne {
- euo.mutation.SetAPIBase(s)
- return euo
- }
- // SetNillableAPIBase sets the "api_base" field if the given value is not nil.
- func (euo *EmployeeUpdateOne) SetNillableAPIBase(s *string) *EmployeeUpdateOne {
- if s != nil {
- euo.SetAPIBase(*s)
- }
- return euo
- }
- // SetAPIKey sets the "api_key" field.
- func (euo *EmployeeUpdateOne) SetAPIKey(s string) *EmployeeUpdateOne {
- euo.mutation.SetAPIKey(s)
- return euo
- }
- // SetNillableAPIKey sets the "api_key" field if the given value is not nil.
- func (euo *EmployeeUpdateOne) SetNillableAPIKey(s *string) *EmployeeUpdateOne {
- if s != nil {
- euo.SetAPIKey(*s)
- }
- return euo
- }
- // AddEmWorkExperienceIDs adds the "em_work_experiences" edge to the WorkExperience entity by IDs.
- func (euo *EmployeeUpdateOne) AddEmWorkExperienceIDs(ids ...uint64) *EmployeeUpdateOne {
- euo.mutation.AddEmWorkExperienceIDs(ids...)
- return euo
- }
- // AddEmWorkExperiences adds the "em_work_experiences" edges to the WorkExperience entity.
- func (euo *EmployeeUpdateOne) AddEmWorkExperiences(w ...*WorkExperience) *EmployeeUpdateOne {
- ids := make([]uint64, len(w))
- for i := range w {
- ids[i] = w[i].ID
- }
- return euo.AddEmWorkExperienceIDs(ids...)
- }
- // AddEmTutorialIDs adds the "em_tutorial" edge to the Tutorial entity by IDs.
- func (euo *EmployeeUpdateOne) AddEmTutorialIDs(ids ...uint64) *EmployeeUpdateOne {
- euo.mutation.AddEmTutorialIDs(ids...)
- return euo
- }
- // AddEmTutorial adds the "em_tutorial" edges to the Tutorial entity.
- func (euo *EmployeeUpdateOne) AddEmTutorial(t ...*Tutorial) *EmployeeUpdateOne {
- ids := make([]uint64, len(t))
- for i := range t {
- ids[i] = t[i].ID
- }
- return euo.AddEmTutorialIDs(ids...)
- }
- // Mutation returns the EmployeeMutation object of the builder.
- func (euo *EmployeeUpdateOne) Mutation() *EmployeeMutation {
- return euo.mutation
- }
- // ClearEmWorkExperiences clears all "em_work_experiences" edges to the WorkExperience entity.
- func (euo *EmployeeUpdateOne) ClearEmWorkExperiences() *EmployeeUpdateOne {
- euo.mutation.ClearEmWorkExperiences()
- return euo
- }
- // RemoveEmWorkExperienceIDs removes the "em_work_experiences" edge to WorkExperience entities by IDs.
- func (euo *EmployeeUpdateOne) RemoveEmWorkExperienceIDs(ids ...uint64) *EmployeeUpdateOne {
- euo.mutation.RemoveEmWorkExperienceIDs(ids...)
- return euo
- }
- // RemoveEmWorkExperiences removes "em_work_experiences" edges to WorkExperience entities.
- func (euo *EmployeeUpdateOne) RemoveEmWorkExperiences(w ...*WorkExperience) *EmployeeUpdateOne {
- ids := make([]uint64, len(w))
- for i := range w {
- ids[i] = w[i].ID
- }
- return euo.RemoveEmWorkExperienceIDs(ids...)
- }
- // ClearEmTutorial clears all "em_tutorial" edges to the Tutorial entity.
- func (euo *EmployeeUpdateOne) ClearEmTutorial() *EmployeeUpdateOne {
- euo.mutation.ClearEmTutorial()
- return euo
- }
- // RemoveEmTutorialIDs removes the "em_tutorial" edge to Tutorial entities by IDs.
- func (euo *EmployeeUpdateOne) RemoveEmTutorialIDs(ids ...uint64) *EmployeeUpdateOne {
- euo.mutation.RemoveEmTutorialIDs(ids...)
- return euo
- }
- // RemoveEmTutorial removes "em_tutorial" edges to Tutorial entities.
- func (euo *EmployeeUpdateOne) RemoveEmTutorial(t ...*Tutorial) *EmployeeUpdateOne {
- ids := make([]uint64, len(t))
- for i := range t {
- ids[i] = t[i].ID
- }
- return euo.RemoveEmTutorialIDs(ids...)
- }
- // Where appends a list predicates to the EmployeeUpdate builder.
- func (euo *EmployeeUpdateOne) Where(ps ...predicate.Employee) *EmployeeUpdateOne {
- euo.mutation.Where(ps...)
- return euo
- }
- // Select allows selecting one or more fields (columns) of the returned entity.
- // The default is selecting all fields defined in the entity schema.
- func (euo *EmployeeUpdateOne) Select(field string, fields ...string) *EmployeeUpdateOne {
- euo.fields = append([]string{field}, fields...)
- return euo
- }
- // Save executes the query and returns the updated Employee entity.
- func (euo *EmployeeUpdateOne) Save(ctx context.Context) (*Employee, error) {
- if err := euo.defaults(); err != nil {
- return nil, err
- }
- return withHooks(ctx, euo.sqlSave, euo.mutation, euo.hooks)
- }
- // SaveX is like Save, but panics if an error occurs.
- func (euo *EmployeeUpdateOne) SaveX(ctx context.Context) *Employee {
- node, err := euo.Save(ctx)
- if err != nil {
- panic(err)
- }
- return node
- }
- // Exec executes the query on the entity.
- func (euo *EmployeeUpdateOne) Exec(ctx context.Context) error {
- _, err := euo.Save(ctx)
- return err
- }
- // ExecX is like Exec, but panics if an error occurs.
- func (euo *EmployeeUpdateOne) ExecX(ctx context.Context) {
- if err := euo.Exec(ctx); err != nil {
- panic(err)
- }
- }
- // defaults sets the default values of the builder before save.
- func (euo *EmployeeUpdateOne) defaults() error {
- if _, ok := euo.mutation.UpdatedAt(); !ok {
- if employee.UpdateDefaultUpdatedAt == nil {
- return fmt.Errorf("ent: uninitialized employee.UpdateDefaultUpdatedAt (forgotten import ent/runtime?)")
- }
- v := employee.UpdateDefaultUpdatedAt()
- euo.mutation.SetUpdatedAt(v)
- }
- return nil
- }
- // check runs all checks and user-defined validators on the builder.
- func (euo *EmployeeUpdateOne) check() error {
- if v, ok := euo.mutation.Title(); ok {
- if err := employee.TitleValidator(v); err != nil {
- return &ValidationError{Name: "title", err: fmt.Errorf(`ent: validator failed for field "Employee.title": %w`, err)}
- }
- }
- if v, ok := euo.mutation.Avatar(); ok {
- if err := employee.AvatarValidator(v); err != nil {
- return &ValidationError{Name: "avatar", err: fmt.Errorf(`ent: validator failed for field "Employee.avatar": %w`, err)}
- }
- }
- if v, ok := euo.mutation.Tags(); ok {
- if err := employee.TagsValidator(v); err != nil {
- return &ValidationError{Name: "tags", err: fmt.Errorf(`ent: validator failed for field "Employee.tags": %w`, err)}
- }
- }
- if v, ok := euo.mutation.HireCount(); ok {
- if err := employee.HireCountValidator(v); err != nil {
- return &ValidationError{Name: "hire_count", err: fmt.Errorf(`ent: validator failed for field "Employee.hire_count": %w`, err)}
- }
- }
- if v, ok := euo.mutation.ServiceCount(); ok {
- if err := employee.ServiceCountValidator(v); err != nil {
- return &ValidationError{Name: "service_count", err: fmt.Errorf(`ent: validator failed for field "Employee.service_count": %w`, err)}
- }
- }
- if v, ok := euo.mutation.AchievementCount(); ok {
- if err := employee.AchievementCountValidator(v); err != nil {
- return &ValidationError{Name: "achievement_count", err: fmt.Errorf(`ent: validator failed for field "Employee.achievement_count": %w`, err)}
- }
- }
- if v, ok := euo.mutation.Intro(); ok {
- if err := employee.IntroValidator(v); err != nil {
- return &ValidationError{Name: "intro", err: fmt.Errorf(`ent: validator failed for field "Employee.intro": %w`, err)}
- }
- }
- if v, ok := euo.mutation.Estimate(); ok {
- if err := employee.EstimateValidator(v); err != nil {
- return &ValidationError{Name: "estimate", err: fmt.Errorf(`ent: validator failed for field "Employee.estimate": %w`, err)}
- }
- }
- if v, ok := euo.mutation.Skill(); ok {
- if err := employee.SkillValidator(v); err != nil {
- return &ValidationError{Name: "skill", err: fmt.Errorf(`ent: validator failed for field "Employee.skill": %w`, err)}
- }
- }
- if v, ok := euo.mutation.VideoURL(); ok {
- if err := employee.VideoURLValidator(v); err != nil {
- return &ValidationError{Name: "video_url", err: fmt.Errorf(`ent: validator failed for field "Employee.video_url": %w`, err)}
- }
- }
- if v, ok := euo.mutation.OrganizationID(); ok {
- if err := employee.OrganizationIDValidator(v); err != nil {
- return &ValidationError{Name: "organization_id", err: fmt.Errorf(`ent: validator failed for field "Employee.organization_id": %w`, err)}
- }
- }
- if v, ok := euo.mutation.CategoryID(); ok {
- if err := employee.CategoryIDValidator(v); err != nil {
- return &ValidationError{Name: "category_id", err: fmt.Errorf(`ent: validator failed for field "Employee.category_id": %w`, err)}
- }
- }
- return nil
- }
- func (euo *EmployeeUpdateOne) sqlSave(ctx context.Context) (_node *Employee, err error) {
- if err := euo.check(); err != nil {
- return _node, err
- }
- _spec := sqlgraph.NewUpdateSpec(employee.Table, employee.Columns, sqlgraph.NewFieldSpec(employee.FieldID, field.TypeUint64))
- id, ok := euo.mutation.ID()
- if !ok {
- return nil, &ValidationError{Name: "id", err: errors.New(`ent: missing "Employee.id" for update`)}
- }
- _spec.Node.ID.Value = id
- if fields := euo.fields; len(fields) > 0 {
- _spec.Node.Columns = make([]string, 0, len(fields))
- _spec.Node.Columns = append(_spec.Node.Columns, employee.FieldID)
- for _, f := range fields {
- if !employee.ValidColumn(f) {
- return nil, &ValidationError{Name: f, err: fmt.Errorf("ent: invalid field %q for query", f)}
- }
- if f != employee.FieldID {
- _spec.Node.Columns = append(_spec.Node.Columns, f)
- }
- }
- }
- if ps := euo.mutation.predicates; len(ps) > 0 {
- _spec.Predicate = func(selector *sql.Selector) {
- for i := range ps {
- ps[i](selector)
- }
- }
- }
- if value, ok := euo.mutation.UpdatedAt(); ok {
- _spec.SetField(employee.FieldUpdatedAt, field.TypeTime, value)
- }
- if value, ok := euo.mutation.DeletedAt(); ok {
- _spec.SetField(employee.FieldDeletedAt, field.TypeTime, value)
- }
- if euo.mutation.DeletedAtCleared() {
- _spec.ClearField(employee.FieldDeletedAt, field.TypeTime)
- }
- if value, ok := euo.mutation.Title(); ok {
- _spec.SetField(employee.FieldTitle, field.TypeString, value)
- }
- if value, ok := euo.mutation.Avatar(); ok {
- _spec.SetField(employee.FieldAvatar, field.TypeString, value)
- }
- if value, ok := euo.mutation.Tags(); ok {
- _spec.SetField(employee.FieldTags, field.TypeString, value)
- }
- if value, ok := euo.mutation.HireCount(); ok {
- _spec.SetField(employee.FieldHireCount, field.TypeInt, value)
- }
- if value, ok := euo.mutation.AddedHireCount(); ok {
- _spec.AddField(employee.FieldHireCount, field.TypeInt, value)
- }
- if value, ok := euo.mutation.ServiceCount(); ok {
- _spec.SetField(employee.FieldServiceCount, field.TypeInt, value)
- }
- if value, ok := euo.mutation.AddedServiceCount(); ok {
- _spec.AddField(employee.FieldServiceCount, field.TypeInt, value)
- }
- if value, ok := euo.mutation.AchievementCount(); ok {
- _spec.SetField(employee.FieldAchievementCount, field.TypeInt, value)
- }
- if value, ok := euo.mutation.AddedAchievementCount(); ok {
- _spec.AddField(employee.FieldAchievementCount, field.TypeInt, value)
- }
- if value, ok := euo.mutation.Intro(); ok {
- _spec.SetField(employee.FieldIntro, field.TypeString, value)
- }
- if value, ok := euo.mutation.Estimate(); ok {
- _spec.SetField(employee.FieldEstimate, field.TypeString, value)
- }
- if value, ok := euo.mutation.Skill(); ok {
- _spec.SetField(employee.FieldSkill, field.TypeString, value)
- }
- if value, ok := euo.mutation.AbilityType(); ok {
- _spec.SetField(employee.FieldAbilityType, field.TypeString, value)
- }
- if value, ok := euo.mutation.Scene(); ok {
- _spec.SetField(employee.FieldScene, field.TypeString, value)
- }
- if value, ok := euo.mutation.SwitchIn(); ok {
- _spec.SetField(employee.FieldSwitchIn, field.TypeString, value)
- }
- if value, ok := euo.mutation.VideoURL(); ok {
- _spec.SetField(employee.FieldVideoURL, field.TypeString, value)
- }
- if value, ok := euo.mutation.OrganizationID(); ok {
- _spec.SetField(employee.FieldOrganizationID, field.TypeUint64, value)
- }
- if value, ok := euo.mutation.AddedOrganizationID(); ok {
- _spec.AddField(employee.FieldOrganizationID, field.TypeUint64, value)
- }
- if value, ok := euo.mutation.CategoryID(); ok {
- _spec.SetField(employee.FieldCategoryID, field.TypeUint64, value)
- }
- if value, ok := euo.mutation.AddedCategoryID(); ok {
- _spec.AddField(employee.FieldCategoryID, field.TypeUint64, value)
- }
- if value, ok := euo.mutation.APIBase(); ok {
- _spec.SetField(employee.FieldAPIBase, field.TypeString, value)
- }
- if value, ok := euo.mutation.APIKey(); ok {
- _spec.SetField(employee.FieldAPIKey, field.TypeString, value)
- }
- if euo.mutation.EmWorkExperiencesCleared() {
- edge := &sqlgraph.EdgeSpec{
- Rel: sqlgraph.O2M,
- Inverse: false,
- Table: employee.EmWorkExperiencesTable,
- Columns: []string{employee.EmWorkExperiencesColumn},
- Bidi: false,
- Target: &sqlgraph.EdgeTarget{
- IDSpec: sqlgraph.NewFieldSpec(workexperience.FieldID, field.TypeUint64),
- },
- }
- _spec.Edges.Clear = append(_spec.Edges.Clear, edge)
- }
- if nodes := euo.mutation.RemovedEmWorkExperiencesIDs(); len(nodes) > 0 && !euo.mutation.EmWorkExperiencesCleared() {
- edge := &sqlgraph.EdgeSpec{
- Rel: sqlgraph.O2M,
- Inverse: false,
- Table: employee.EmWorkExperiencesTable,
- Columns: []string{employee.EmWorkExperiencesColumn},
- Bidi: false,
- Target: &sqlgraph.EdgeTarget{
- IDSpec: sqlgraph.NewFieldSpec(workexperience.FieldID, field.TypeUint64),
- },
- }
- for _, k := range nodes {
- edge.Target.Nodes = append(edge.Target.Nodes, k)
- }
- _spec.Edges.Clear = append(_spec.Edges.Clear, edge)
- }
- if nodes := euo.mutation.EmWorkExperiencesIDs(); len(nodes) > 0 {
- edge := &sqlgraph.EdgeSpec{
- Rel: sqlgraph.O2M,
- Inverse: false,
- Table: employee.EmWorkExperiencesTable,
- Columns: []string{employee.EmWorkExperiencesColumn},
- Bidi: false,
- Target: &sqlgraph.EdgeTarget{
- IDSpec: sqlgraph.NewFieldSpec(workexperience.FieldID, field.TypeUint64),
- },
- }
- for _, k := range nodes {
- edge.Target.Nodes = append(edge.Target.Nodes, k)
- }
- _spec.Edges.Add = append(_spec.Edges.Add, edge)
- }
- if euo.mutation.EmTutorialCleared() {
- edge := &sqlgraph.EdgeSpec{
- Rel: sqlgraph.O2M,
- Inverse: false,
- Table: employee.EmTutorialTable,
- Columns: []string{employee.EmTutorialColumn},
- Bidi: false,
- Target: &sqlgraph.EdgeTarget{
- IDSpec: sqlgraph.NewFieldSpec(tutorial.FieldID, field.TypeUint64),
- },
- }
- _spec.Edges.Clear = append(_spec.Edges.Clear, edge)
- }
- if nodes := euo.mutation.RemovedEmTutorialIDs(); len(nodes) > 0 && !euo.mutation.EmTutorialCleared() {
- edge := &sqlgraph.EdgeSpec{
- Rel: sqlgraph.O2M,
- Inverse: false,
- Table: employee.EmTutorialTable,
- Columns: []string{employee.EmTutorialColumn},
- Bidi: false,
- Target: &sqlgraph.EdgeTarget{
- IDSpec: sqlgraph.NewFieldSpec(tutorial.FieldID, field.TypeUint64),
- },
- }
- for _, k := range nodes {
- edge.Target.Nodes = append(edge.Target.Nodes, k)
- }
- _spec.Edges.Clear = append(_spec.Edges.Clear, edge)
- }
- if nodes := euo.mutation.EmTutorialIDs(); len(nodes) > 0 {
- edge := &sqlgraph.EdgeSpec{
- Rel: sqlgraph.O2M,
- Inverse: false,
- Table: employee.EmTutorialTable,
- Columns: []string{employee.EmTutorialColumn},
- Bidi: false,
- Target: &sqlgraph.EdgeTarget{
- IDSpec: sqlgraph.NewFieldSpec(tutorial.FieldID, field.TypeUint64),
- },
- }
- for _, k := range nodes {
- edge.Target.Nodes = append(edge.Target.Nodes, k)
- }
- _spec.Edges.Add = append(_spec.Edges.Add, edge)
- }
- _node = &Employee{config: euo.config}
- _spec.Assign = _node.assignValues
- _spec.ScanValues = _node.scanValues
- if err = sqlgraph.UpdateNode(ctx, euo.driver, _spec); err != nil {
- if _, ok := err.(*sqlgraph.NotFoundError); ok {
- err = &NotFoundError{employee.Label}
- } else if sqlgraph.IsConstraintError(err) {
- err = &ConstraintError{msg: err.Error(), wrap: err}
- }
- return nil, err
- }
- euo.mutation.done = true
- return _node, nil
- }
|