12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556 |
- // 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
- }
- // SetAiInfo sets the "ai_info" field.
- func (eu *EmployeeUpdate) SetAiInfo(s string) *EmployeeUpdate {
- eu.mutation.SetAiInfo(s)
- return eu
- }
- // SetNillableAiInfo sets the "ai_info" field if the given value is not nil.
- func (eu *EmployeeUpdate) SetNillableAiInfo(s *string) *EmployeeUpdate {
- if s != nil {
- eu.SetAiInfo(*s)
- }
- return eu
- }
- // ClearAiInfo clears the value of the "ai_info" field.
- func (eu *EmployeeUpdate) ClearAiInfo() *EmployeeUpdate {
- eu.mutation.ClearAiInfo()
- return eu
- }
- // SetIsVip sets the "is_vip" field.
- func (eu *EmployeeUpdate) SetIsVip(i int) *EmployeeUpdate {
- eu.mutation.ResetIsVip()
- eu.mutation.SetIsVip(i)
- return eu
- }
- // SetNillableIsVip sets the "is_vip" field if the given value is not nil.
- func (eu *EmployeeUpdate) SetNillableIsVip(i *int) *EmployeeUpdate {
- if i != nil {
- eu.SetIsVip(*i)
- }
- return eu
- }
- // AddIsVip adds i to the "is_vip" field.
- func (eu *EmployeeUpdate) AddIsVip(i int) *EmployeeUpdate {
- eu.mutation.AddIsVip(i)
- return eu
- }
- // SetChatURL sets the "chat_url" field.
- func (eu *EmployeeUpdate) SetChatURL(s string) *EmployeeUpdate {
- eu.mutation.SetChatURL(s)
- return eu
- }
- // SetNillableChatURL sets the "chat_url" field if the given value is not nil.
- func (eu *EmployeeUpdate) SetNillableChatURL(s *string) *EmployeeUpdate {
- if s != nil {
- eu.SetChatURL(*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 value, ok := eu.mutation.AiInfo(); ok {
- _spec.SetField(employee.FieldAiInfo, field.TypeString, value)
- }
- if eu.mutation.AiInfoCleared() {
- _spec.ClearField(employee.FieldAiInfo, field.TypeString)
- }
- if value, ok := eu.mutation.IsVip(); ok {
- _spec.SetField(employee.FieldIsVip, field.TypeInt, value)
- }
- if value, ok := eu.mutation.AddedIsVip(); ok {
- _spec.AddField(employee.FieldIsVip, field.TypeInt, value)
- }
- if value, ok := eu.mutation.ChatURL(); ok {
- _spec.SetField(employee.FieldChatURL, 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
- }
- // SetAiInfo sets the "ai_info" field.
- func (euo *EmployeeUpdateOne) SetAiInfo(s string) *EmployeeUpdateOne {
- euo.mutation.SetAiInfo(s)
- return euo
- }
- // SetNillableAiInfo sets the "ai_info" field if the given value is not nil.
- func (euo *EmployeeUpdateOne) SetNillableAiInfo(s *string) *EmployeeUpdateOne {
- if s != nil {
- euo.SetAiInfo(*s)
- }
- return euo
- }
- // ClearAiInfo clears the value of the "ai_info" field.
- func (euo *EmployeeUpdateOne) ClearAiInfo() *EmployeeUpdateOne {
- euo.mutation.ClearAiInfo()
- return euo
- }
- // SetIsVip sets the "is_vip" field.
- func (euo *EmployeeUpdateOne) SetIsVip(i int) *EmployeeUpdateOne {
- euo.mutation.ResetIsVip()
- euo.mutation.SetIsVip(i)
- return euo
- }
- // SetNillableIsVip sets the "is_vip" field if the given value is not nil.
- func (euo *EmployeeUpdateOne) SetNillableIsVip(i *int) *EmployeeUpdateOne {
- if i != nil {
- euo.SetIsVip(*i)
- }
- return euo
- }
- // AddIsVip adds i to the "is_vip" field.
- func (euo *EmployeeUpdateOne) AddIsVip(i int) *EmployeeUpdateOne {
- euo.mutation.AddIsVip(i)
- return euo
- }
- // SetChatURL sets the "chat_url" field.
- func (euo *EmployeeUpdateOne) SetChatURL(s string) *EmployeeUpdateOne {
- euo.mutation.SetChatURL(s)
- return euo
- }
- // SetNillableChatURL sets the "chat_url" field if the given value is not nil.
- func (euo *EmployeeUpdateOne) SetNillableChatURL(s *string) *EmployeeUpdateOne {
- if s != nil {
- euo.SetChatURL(*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 value, ok := euo.mutation.AiInfo(); ok {
- _spec.SetField(employee.FieldAiInfo, field.TypeString, value)
- }
- if euo.mutation.AiInfoCleared() {
- _spec.ClearField(employee.FieldAiInfo, field.TypeString)
- }
- if value, ok := euo.mutation.IsVip(); ok {
- _spec.SetField(employee.FieldIsVip, field.TypeInt, value)
- }
- if value, ok := euo.mutation.AddedIsVip(); ok {
- _spec.AddField(employee.FieldIsVip, field.TypeInt, value)
- }
- if value, ok := euo.mutation.ChatURL(); ok {
- _spec.SetField(employee.FieldChatURL, 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
- }
|