12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616 |
- // Code generated by ent, DO NOT EDIT.
- package ent
- import (
- "context"
- "errors"
- "fmt"
- "time"
- "wechat-api/ent/agent"
- "wechat-api/ent/apikey"
- "wechat-api/ent/predicate"
- "wechat-api/ent/token"
- "wechat-api/ent/whatsapp"
- "wechat-api/ent/wx"
- "entgo.io/ent/dialect/sql"
- "entgo.io/ent/dialect/sql/sqlgraph"
- "entgo.io/ent/schema/field"
- )
- // AgentUpdate is the builder for updating Agent entities.
- type AgentUpdate struct {
- config
- hooks []Hook
- mutation *AgentMutation
- }
- // Where appends a list predicates to the AgentUpdate builder.
- func (au *AgentUpdate) Where(ps ...predicate.Agent) *AgentUpdate {
- au.mutation.Where(ps...)
- return au
- }
- // SetUpdatedAt sets the "updated_at" field.
- func (au *AgentUpdate) SetUpdatedAt(t time.Time) *AgentUpdate {
- au.mutation.SetUpdatedAt(t)
- return au
- }
- // SetDeletedAt sets the "deleted_at" field.
- func (au *AgentUpdate) SetDeletedAt(t time.Time) *AgentUpdate {
- au.mutation.SetDeletedAt(t)
- return au
- }
- // SetNillableDeletedAt sets the "deleted_at" field if the given value is not nil.
- func (au *AgentUpdate) SetNillableDeletedAt(t *time.Time) *AgentUpdate {
- if t != nil {
- au.SetDeletedAt(*t)
- }
- return au
- }
- // ClearDeletedAt clears the value of the "deleted_at" field.
- func (au *AgentUpdate) ClearDeletedAt() *AgentUpdate {
- au.mutation.ClearDeletedAt()
- return au
- }
- // SetName sets the "name" field.
- func (au *AgentUpdate) SetName(s string) *AgentUpdate {
- au.mutation.SetName(s)
- return au
- }
- // SetNillableName sets the "name" field if the given value is not nil.
- func (au *AgentUpdate) SetNillableName(s *string) *AgentUpdate {
- if s != nil {
- au.SetName(*s)
- }
- return au
- }
- // SetRole sets the "role" field.
- func (au *AgentUpdate) SetRole(s string) *AgentUpdate {
- au.mutation.SetRole(s)
- return au
- }
- // SetNillableRole sets the "role" field if the given value is not nil.
- func (au *AgentUpdate) SetNillableRole(s *string) *AgentUpdate {
- if s != nil {
- au.SetRole(*s)
- }
- return au
- }
- // ClearRole clears the value of the "role" field.
- func (au *AgentUpdate) ClearRole() *AgentUpdate {
- au.mutation.ClearRole()
- return au
- }
- // SetStatus sets the "status" field.
- func (au *AgentUpdate) SetStatus(i int) *AgentUpdate {
- au.mutation.ResetStatus()
- au.mutation.SetStatus(i)
- return au
- }
- // SetNillableStatus sets the "status" field if the given value is not nil.
- func (au *AgentUpdate) SetNillableStatus(i *int) *AgentUpdate {
- if i != nil {
- au.SetStatus(*i)
- }
- return au
- }
- // AddStatus adds i to the "status" field.
- func (au *AgentUpdate) AddStatus(i int) *AgentUpdate {
- au.mutation.AddStatus(i)
- return au
- }
- // ClearStatus clears the value of the "status" field.
- func (au *AgentUpdate) ClearStatus() *AgentUpdate {
- au.mutation.ClearStatus()
- return au
- }
- // SetBackground sets the "background" field.
- func (au *AgentUpdate) SetBackground(s string) *AgentUpdate {
- au.mutation.SetBackground(s)
- return au
- }
- // SetNillableBackground sets the "background" field if the given value is not nil.
- func (au *AgentUpdate) SetNillableBackground(s *string) *AgentUpdate {
- if s != nil {
- au.SetBackground(*s)
- }
- return au
- }
- // ClearBackground clears the value of the "background" field.
- func (au *AgentUpdate) ClearBackground() *AgentUpdate {
- au.mutation.ClearBackground()
- return au
- }
- // SetExamples sets the "examples" field.
- func (au *AgentUpdate) SetExamples(s string) *AgentUpdate {
- au.mutation.SetExamples(s)
- return au
- }
- // SetNillableExamples sets the "examples" field if the given value is not nil.
- func (au *AgentUpdate) SetNillableExamples(s *string) *AgentUpdate {
- if s != nil {
- au.SetExamples(*s)
- }
- return au
- }
- // ClearExamples clears the value of the "examples" field.
- func (au *AgentUpdate) ClearExamples() *AgentUpdate {
- au.mutation.ClearExamples()
- return au
- }
- // SetOrganizationID sets the "organization_id" field.
- func (au *AgentUpdate) SetOrganizationID(u uint64) *AgentUpdate {
- au.mutation.ResetOrganizationID()
- au.mutation.SetOrganizationID(u)
- return au
- }
- // SetNillableOrganizationID sets the "organization_id" field if the given value is not nil.
- func (au *AgentUpdate) SetNillableOrganizationID(u *uint64) *AgentUpdate {
- if u != nil {
- au.SetOrganizationID(*u)
- }
- return au
- }
- // AddOrganizationID adds u to the "organization_id" field.
- func (au *AgentUpdate) AddOrganizationID(u int64) *AgentUpdate {
- au.mutation.AddOrganizationID(u)
- return au
- }
- // SetDatasetID sets the "dataset_id" field.
- func (au *AgentUpdate) SetDatasetID(s string) *AgentUpdate {
- au.mutation.SetDatasetID(s)
- return au
- }
- // SetNillableDatasetID sets the "dataset_id" field if the given value is not nil.
- func (au *AgentUpdate) SetNillableDatasetID(s *string) *AgentUpdate {
- if s != nil {
- au.SetDatasetID(*s)
- }
- return au
- }
- // SetCollectionID sets the "collection_id" field.
- func (au *AgentUpdate) SetCollectionID(s string) *AgentUpdate {
- au.mutation.SetCollectionID(s)
- return au
- }
- // SetNillableCollectionID sets the "collection_id" field if the given value is not nil.
- func (au *AgentUpdate) SetNillableCollectionID(s *string) *AgentUpdate {
- if s != nil {
- au.SetCollectionID(*s)
- }
- return au
- }
- // SetModel sets the "model" field.
- func (au *AgentUpdate) SetModel(s string) *AgentUpdate {
- au.mutation.SetModel(s)
- return au
- }
- // SetNillableModel sets the "model" field if the given value is not nil.
- func (au *AgentUpdate) SetNillableModel(s *string) *AgentUpdate {
- if s != nil {
- au.SetModel(*s)
- }
- return au
- }
- // ClearModel clears the value of the "model" field.
- func (au *AgentUpdate) ClearModel() *AgentUpdate {
- au.mutation.ClearModel()
- return au
- }
- // SetAPIBase sets the "api_base" field.
- func (au *AgentUpdate) SetAPIBase(s string) *AgentUpdate {
- au.mutation.SetAPIBase(s)
- return au
- }
- // SetNillableAPIBase sets the "api_base" field if the given value is not nil.
- func (au *AgentUpdate) SetNillableAPIBase(s *string) *AgentUpdate {
- if s != nil {
- au.SetAPIBase(*s)
- }
- return au
- }
- // ClearAPIBase clears the value of the "api_base" field.
- func (au *AgentUpdate) ClearAPIBase() *AgentUpdate {
- au.mutation.ClearAPIBase()
- return au
- }
- // SetAPIKey sets the "api_key" field.
- func (au *AgentUpdate) SetAPIKey(s string) *AgentUpdate {
- au.mutation.SetAPIKey(s)
- return au
- }
- // SetNillableAPIKey sets the "api_key" field if the given value is not nil.
- func (au *AgentUpdate) SetNillableAPIKey(s *string) *AgentUpdate {
- if s != nil {
- au.SetAPIKey(*s)
- }
- return au
- }
- // ClearAPIKey clears the value of the "api_key" field.
- func (au *AgentUpdate) ClearAPIKey() *AgentUpdate {
- au.mutation.ClearAPIKey()
- return au
- }
- // SetType sets the "type" field.
- func (au *AgentUpdate) SetType(i int) *AgentUpdate {
- au.mutation.ResetType()
- au.mutation.SetType(i)
- return au
- }
- // SetNillableType sets the "type" field if the given value is not nil.
- func (au *AgentUpdate) SetNillableType(i *int) *AgentUpdate {
- if i != nil {
- au.SetType(*i)
- }
- return au
- }
- // AddType adds i to the "type" field.
- func (au *AgentUpdate) AddType(i int) *AgentUpdate {
- au.mutation.AddType(i)
- return au
- }
- // ClearType clears the value of the "type" field.
- func (au *AgentUpdate) ClearType() *AgentUpdate {
- au.mutation.ClearType()
- return au
- }
- // AddWxAgentIDs adds the "wx_agent" edge to the Wx entity by IDs.
- func (au *AgentUpdate) AddWxAgentIDs(ids ...uint64) *AgentUpdate {
- au.mutation.AddWxAgentIDs(ids...)
- return au
- }
- // AddWxAgent adds the "wx_agent" edges to the Wx entity.
- func (au *AgentUpdate) AddWxAgent(w ...*Wx) *AgentUpdate {
- ids := make([]uint64, len(w))
- for i := range w {
- ids[i] = w[i].ID
- }
- return au.AddWxAgentIDs(ids...)
- }
- // AddTokenAgentIDs adds the "token_agent" edge to the Token entity by IDs.
- func (au *AgentUpdate) AddTokenAgentIDs(ids ...uint64) *AgentUpdate {
- au.mutation.AddTokenAgentIDs(ids...)
- return au
- }
- // AddTokenAgent adds the "token_agent" edges to the Token entity.
- func (au *AgentUpdate) AddTokenAgent(t ...*Token) *AgentUpdate {
- ids := make([]uint64, len(t))
- for i := range t {
- ids[i] = t[i].ID
- }
- return au.AddTokenAgentIDs(ids...)
- }
- // AddWaAgentIDs adds the "wa_agent" edge to the Whatsapp entity by IDs.
- func (au *AgentUpdate) AddWaAgentIDs(ids ...uint64) *AgentUpdate {
- au.mutation.AddWaAgentIDs(ids...)
- return au
- }
- // AddWaAgent adds the "wa_agent" edges to the Whatsapp entity.
- func (au *AgentUpdate) AddWaAgent(w ...*Whatsapp) *AgentUpdate {
- ids := make([]uint64, len(w))
- for i := range w {
- ids[i] = w[i].ID
- }
- return au.AddWaAgentIDs(ids...)
- }
- // AddKeyAgentIDs adds the "key_agent" edge to the ApiKey entity by IDs.
- func (au *AgentUpdate) AddKeyAgentIDs(ids ...uint64) *AgentUpdate {
- au.mutation.AddKeyAgentIDs(ids...)
- return au
- }
- // AddKeyAgent adds the "key_agent" edges to the ApiKey entity.
- func (au *AgentUpdate) AddKeyAgent(a ...*ApiKey) *AgentUpdate {
- ids := make([]uint64, len(a))
- for i := range a {
- ids[i] = a[i].ID
- }
- return au.AddKeyAgentIDs(ids...)
- }
- // Mutation returns the AgentMutation object of the builder.
- func (au *AgentUpdate) Mutation() *AgentMutation {
- return au.mutation
- }
- // ClearWxAgent clears all "wx_agent" edges to the Wx entity.
- func (au *AgentUpdate) ClearWxAgent() *AgentUpdate {
- au.mutation.ClearWxAgent()
- return au
- }
- // RemoveWxAgentIDs removes the "wx_agent" edge to Wx entities by IDs.
- func (au *AgentUpdate) RemoveWxAgentIDs(ids ...uint64) *AgentUpdate {
- au.mutation.RemoveWxAgentIDs(ids...)
- return au
- }
- // RemoveWxAgent removes "wx_agent" edges to Wx entities.
- func (au *AgentUpdate) RemoveWxAgent(w ...*Wx) *AgentUpdate {
- ids := make([]uint64, len(w))
- for i := range w {
- ids[i] = w[i].ID
- }
- return au.RemoveWxAgentIDs(ids...)
- }
- // ClearTokenAgent clears all "token_agent" edges to the Token entity.
- func (au *AgentUpdate) ClearTokenAgent() *AgentUpdate {
- au.mutation.ClearTokenAgent()
- return au
- }
- // RemoveTokenAgentIDs removes the "token_agent" edge to Token entities by IDs.
- func (au *AgentUpdate) RemoveTokenAgentIDs(ids ...uint64) *AgentUpdate {
- au.mutation.RemoveTokenAgentIDs(ids...)
- return au
- }
- // RemoveTokenAgent removes "token_agent" edges to Token entities.
- func (au *AgentUpdate) RemoveTokenAgent(t ...*Token) *AgentUpdate {
- ids := make([]uint64, len(t))
- for i := range t {
- ids[i] = t[i].ID
- }
- return au.RemoveTokenAgentIDs(ids...)
- }
- // ClearWaAgent clears all "wa_agent" edges to the Whatsapp entity.
- func (au *AgentUpdate) ClearWaAgent() *AgentUpdate {
- au.mutation.ClearWaAgent()
- return au
- }
- // RemoveWaAgentIDs removes the "wa_agent" edge to Whatsapp entities by IDs.
- func (au *AgentUpdate) RemoveWaAgentIDs(ids ...uint64) *AgentUpdate {
- au.mutation.RemoveWaAgentIDs(ids...)
- return au
- }
- // RemoveWaAgent removes "wa_agent" edges to Whatsapp entities.
- func (au *AgentUpdate) RemoveWaAgent(w ...*Whatsapp) *AgentUpdate {
- ids := make([]uint64, len(w))
- for i := range w {
- ids[i] = w[i].ID
- }
- return au.RemoveWaAgentIDs(ids...)
- }
- // ClearKeyAgent clears all "key_agent" edges to the ApiKey entity.
- func (au *AgentUpdate) ClearKeyAgent() *AgentUpdate {
- au.mutation.ClearKeyAgent()
- return au
- }
- // RemoveKeyAgentIDs removes the "key_agent" edge to ApiKey entities by IDs.
- func (au *AgentUpdate) RemoveKeyAgentIDs(ids ...uint64) *AgentUpdate {
- au.mutation.RemoveKeyAgentIDs(ids...)
- return au
- }
- // RemoveKeyAgent removes "key_agent" edges to ApiKey entities.
- func (au *AgentUpdate) RemoveKeyAgent(a ...*ApiKey) *AgentUpdate {
- ids := make([]uint64, len(a))
- for i := range a {
- ids[i] = a[i].ID
- }
- return au.RemoveKeyAgentIDs(ids...)
- }
- // Save executes the query and returns the number of nodes affected by the update operation.
- func (au *AgentUpdate) Save(ctx context.Context) (int, error) {
- if err := au.defaults(); err != nil {
- return 0, err
- }
- return withHooks(ctx, au.sqlSave, au.mutation, au.hooks)
- }
- // SaveX is like Save, but panics if an error occurs.
- func (au *AgentUpdate) SaveX(ctx context.Context) int {
- affected, err := au.Save(ctx)
- if err != nil {
- panic(err)
- }
- return affected
- }
- // Exec executes the query.
- func (au *AgentUpdate) Exec(ctx context.Context) error {
- _, err := au.Save(ctx)
- return err
- }
- // ExecX is like Exec, but panics if an error occurs.
- func (au *AgentUpdate) ExecX(ctx context.Context) {
- if err := au.Exec(ctx); err != nil {
- panic(err)
- }
- }
- // defaults sets the default values of the builder before save.
- func (au *AgentUpdate) defaults() error {
- if _, ok := au.mutation.UpdatedAt(); !ok {
- if agent.UpdateDefaultUpdatedAt == nil {
- return fmt.Errorf("ent: uninitialized agent.UpdateDefaultUpdatedAt (forgotten import ent/runtime?)")
- }
- v := agent.UpdateDefaultUpdatedAt()
- au.mutation.SetUpdatedAt(v)
- }
- return nil
- }
- // check runs all checks and user-defined validators on the builder.
- func (au *AgentUpdate) check() error {
- if v, ok := au.mutation.Name(); ok {
- if err := agent.NameValidator(v); err != nil {
- return &ValidationError{Name: "name", err: fmt.Errorf(`ent: validator failed for field "Agent.name": %w`, err)}
- }
- }
- if v, ok := au.mutation.Status(); ok {
- if err := agent.StatusValidator(v); err != nil {
- return &ValidationError{Name: "status", err: fmt.Errorf(`ent: validator failed for field "Agent.status": %w`, err)}
- }
- }
- if v, ok := au.mutation.OrganizationID(); ok {
- if err := agent.OrganizationIDValidator(v); err != nil {
- return &ValidationError{Name: "organization_id", err: fmt.Errorf(`ent: validator failed for field "Agent.organization_id": %w`, err)}
- }
- }
- if v, ok := au.mutation.DatasetID(); ok {
- if err := agent.DatasetIDValidator(v); err != nil {
- return &ValidationError{Name: "dataset_id", err: fmt.Errorf(`ent: validator failed for field "Agent.dataset_id": %w`, err)}
- }
- }
- if v, ok := au.mutation.CollectionID(); ok {
- if err := agent.CollectionIDValidator(v); err != nil {
- return &ValidationError{Name: "collection_id", err: fmt.Errorf(`ent: validator failed for field "Agent.collection_id": %w`, err)}
- }
- }
- if v, ok := au.mutation.GetType(); ok {
- if err := agent.TypeValidator(v); err != nil {
- return &ValidationError{Name: "type", err: fmt.Errorf(`ent: validator failed for field "Agent.type": %w`, err)}
- }
- }
- return nil
- }
- func (au *AgentUpdate) sqlSave(ctx context.Context) (n int, err error) {
- if err := au.check(); err != nil {
- return n, err
- }
- _spec := sqlgraph.NewUpdateSpec(agent.Table, agent.Columns, sqlgraph.NewFieldSpec(agent.FieldID, field.TypeUint64))
- if ps := au.mutation.predicates; len(ps) > 0 {
- _spec.Predicate = func(selector *sql.Selector) {
- for i := range ps {
- ps[i](selector)
- }
- }
- }
- if value, ok := au.mutation.UpdatedAt(); ok {
- _spec.SetField(agent.FieldUpdatedAt, field.TypeTime, value)
- }
- if value, ok := au.mutation.DeletedAt(); ok {
- _spec.SetField(agent.FieldDeletedAt, field.TypeTime, value)
- }
- if au.mutation.DeletedAtCleared() {
- _spec.ClearField(agent.FieldDeletedAt, field.TypeTime)
- }
- if value, ok := au.mutation.Name(); ok {
- _spec.SetField(agent.FieldName, field.TypeString, value)
- }
- if value, ok := au.mutation.Role(); ok {
- _spec.SetField(agent.FieldRole, field.TypeString, value)
- }
- if au.mutation.RoleCleared() {
- _spec.ClearField(agent.FieldRole, field.TypeString)
- }
- if value, ok := au.mutation.Status(); ok {
- _spec.SetField(agent.FieldStatus, field.TypeInt, value)
- }
- if value, ok := au.mutation.AddedStatus(); ok {
- _spec.AddField(agent.FieldStatus, field.TypeInt, value)
- }
- if au.mutation.StatusCleared() {
- _spec.ClearField(agent.FieldStatus, field.TypeInt)
- }
- if value, ok := au.mutation.Background(); ok {
- _spec.SetField(agent.FieldBackground, field.TypeString, value)
- }
- if au.mutation.BackgroundCleared() {
- _spec.ClearField(agent.FieldBackground, field.TypeString)
- }
- if value, ok := au.mutation.Examples(); ok {
- _spec.SetField(agent.FieldExamples, field.TypeString, value)
- }
- if au.mutation.ExamplesCleared() {
- _spec.ClearField(agent.FieldExamples, field.TypeString)
- }
- if value, ok := au.mutation.OrganizationID(); ok {
- _spec.SetField(agent.FieldOrganizationID, field.TypeUint64, value)
- }
- if value, ok := au.mutation.AddedOrganizationID(); ok {
- _spec.AddField(agent.FieldOrganizationID, field.TypeUint64, value)
- }
- if value, ok := au.mutation.DatasetID(); ok {
- _spec.SetField(agent.FieldDatasetID, field.TypeString, value)
- }
- if value, ok := au.mutation.CollectionID(); ok {
- _spec.SetField(agent.FieldCollectionID, field.TypeString, value)
- }
- if value, ok := au.mutation.Model(); ok {
- _spec.SetField(agent.FieldModel, field.TypeString, value)
- }
- if au.mutation.ModelCleared() {
- _spec.ClearField(agent.FieldModel, field.TypeString)
- }
- if value, ok := au.mutation.APIBase(); ok {
- _spec.SetField(agent.FieldAPIBase, field.TypeString, value)
- }
- if au.mutation.APIBaseCleared() {
- _spec.ClearField(agent.FieldAPIBase, field.TypeString)
- }
- if value, ok := au.mutation.APIKey(); ok {
- _spec.SetField(agent.FieldAPIKey, field.TypeString, value)
- }
- if au.mutation.APIKeyCleared() {
- _spec.ClearField(agent.FieldAPIKey, field.TypeString)
- }
- if value, ok := au.mutation.GetType(); ok {
- _spec.SetField(agent.FieldType, field.TypeInt, value)
- }
- if value, ok := au.mutation.AddedType(); ok {
- _spec.AddField(agent.FieldType, field.TypeInt, value)
- }
- if au.mutation.TypeCleared() {
- _spec.ClearField(agent.FieldType, field.TypeInt)
- }
- if au.mutation.WxAgentCleared() {
- edge := &sqlgraph.EdgeSpec{
- Rel: sqlgraph.O2M,
- Inverse: false,
- Table: agent.WxAgentTable,
- Columns: []string{agent.WxAgentColumn},
- Bidi: false,
- Target: &sqlgraph.EdgeTarget{
- IDSpec: sqlgraph.NewFieldSpec(wx.FieldID, field.TypeUint64),
- },
- }
- _spec.Edges.Clear = append(_spec.Edges.Clear, edge)
- }
- if nodes := au.mutation.RemovedWxAgentIDs(); len(nodes) > 0 && !au.mutation.WxAgentCleared() {
- edge := &sqlgraph.EdgeSpec{
- Rel: sqlgraph.O2M,
- Inverse: false,
- Table: agent.WxAgentTable,
- Columns: []string{agent.WxAgentColumn},
- Bidi: false,
- Target: &sqlgraph.EdgeTarget{
- IDSpec: sqlgraph.NewFieldSpec(wx.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 := au.mutation.WxAgentIDs(); len(nodes) > 0 {
- edge := &sqlgraph.EdgeSpec{
- Rel: sqlgraph.O2M,
- Inverse: false,
- Table: agent.WxAgentTable,
- Columns: []string{agent.WxAgentColumn},
- Bidi: false,
- Target: &sqlgraph.EdgeTarget{
- IDSpec: sqlgraph.NewFieldSpec(wx.FieldID, field.TypeUint64),
- },
- }
- for _, k := range nodes {
- edge.Target.Nodes = append(edge.Target.Nodes, k)
- }
- _spec.Edges.Add = append(_spec.Edges.Add, edge)
- }
- if au.mutation.TokenAgentCleared() {
- edge := &sqlgraph.EdgeSpec{
- Rel: sqlgraph.O2M,
- Inverse: false,
- Table: agent.TokenAgentTable,
- Columns: []string{agent.TokenAgentColumn},
- Bidi: false,
- Target: &sqlgraph.EdgeTarget{
- IDSpec: sqlgraph.NewFieldSpec(token.FieldID, field.TypeUint64),
- },
- }
- _spec.Edges.Clear = append(_spec.Edges.Clear, edge)
- }
- if nodes := au.mutation.RemovedTokenAgentIDs(); len(nodes) > 0 && !au.mutation.TokenAgentCleared() {
- edge := &sqlgraph.EdgeSpec{
- Rel: sqlgraph.O2M,
- Inverse: false,
- Table: agent.TokenAgentTable,
- Columns: []string{agent.TokenAgentColumn},
- Bidi: false,
- Target: &sqlgraph.EdgeTarget{
- IDSpec: sqlgraph.NewFieldSpec(token.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 := au.mutation.TokenAgentIDs(); len(nodes) > 0 {
- edge := &sqlgraph.EdgeSpec{
- Rel: sqlgraph.O2M,
- Inverse: false,
- Table: agent.TokenAgentTable,
- Columns: []string{agent.TokenAgentColumn},
- Bidi: false,
- Target: &sqlgraph.EdgeTarget{
- IDSpec: sqlgraph.NewFieldSpec(token.FieldID, field.TypeUint64),
- },
- }
- for _, k := range nodes {
- edge.Target.Nodes = append(edge.Target.Nodes, k)
- }
- _spec.Edges.Add = append(_spec.Edges.Add, edge)
- }
- if au.mutation.WaAgentCleared() {
- edge := &sqlgraph.EdgeSpec{
- Rel: sqlgraph.O2M,
- Inverse: false,
- Table: agent.WaAgentTable,
- Columns: []string{agent.WaAgentColumn},
- Bidi: false,
- Target: &sqlgraph.EdgeTarget{
- IDSpec: sqlgraph.NewFieldSpec(whatsapp.FieldID, field.TypeUint64),
- },
- }
- _spec.Edges.Clear = append(_spec.Edges.Clear, edge)
- }
- if nodes := au.mutation.RemovedWaAgentIDs(); len(nodes) > 0 && !au.mutation.WaAgentCleared() {
- edge := &sqlgraph.EdgeSpec{
- Rel: sqlgraph.O2M,
- Inverse: false,
- Table: agent.WaAgentTable,
- Columns: []string{agent.WaAgentColumn},
- Bidi: false,
- Target: &sqlgraph.EdgeTarget{
- IDSpec: sqlgraph.NewFieldSpec(whatsapp.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 := au.mutation.WaAgentIDs(); len(nodes) > 0 {
- edge := &sqlgraph.EdgeSpec{
- Rel: sqlgraph.O2M,
- Inverse: false,
- Table: agent.WaAgentTable,
- Columns: []string{agent.WaAgentColumn},
- Bidi: false,
- Target: &sqlgraph.EdgeTarget{
- IDSpec: sqlgraph.NewFieldSpec(whatsapp.FieldID, field.TypeUint64),
- },
- }
- for _, k := range nodes {
- edge.Target.Nodes = append(edge.Target.Nodes, k)
- }
- _spec.Edges.Add = append(_spec.Edges.Add, edge)
- }
- if au.mutation.KeyAgentCleared() {
- edge := &sqlgraph.EdgeSpec{
- Rel: sqlgraph.O2M,
- Inverse: false,
- Table: agent.KeyAgentTable,
- Columns: []string{agent.KeyAgentColumn},
- Bidi: false,
- Target: &sqlgraph.EdgeTarget{
- IDSpec: sqlgraph.NewFieldSpec(apikey.FieldID, field.TypeUint64),
- },
- }
- _spec.Edges.Clear = append(_spec.Edges.Clear, edge)
- }
- if nodes := au.mutation.RemovedKeyAgentIDs(); len(nodes) > 0 && !au.mutation.KeyAgentCleared() {
- edge := &sqlgraph.EdgeSpec{
- Rel: sqlgraph.O2M,
- Inverse: false,
- Table: agent.KeyAgentTable,
- Columns: []string{agent.KeyAgentColumn},
- Bidi: false,
- Target: &sqlgraph.EdgeTarget{
- IDSpec: sqlgraph.NewFieldSpec(apikey.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 := au.mutation.KeyAgentIDs(); len(nodes) > 0 {
- edge := &sqlgraph.EdgeSpec{
- Rel: sqlgraph.O2M,
- Inverse: false,
- Table: agent.KeyAgentTable,
- Columns: []string{agent.KeyAgentColumn},
- Bidi: false,
- Target: &sqlgraph.EdgeTarget{
- IDSpec: sqlgraph.NewFieldSpec(apikey.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, au.driver, _spec); err != nil {
- if _, ok := err.(*sqlgraph.NotFoundError); ok {
- err = &NotFoundError{agent.Label}
- } else if sqlgraph.IsConstraintError(err) {
- err = &ConstraintError{msg: err.Error(), wrap: err}
- }
- return 0, err
- }
- au.mutation.done = true
- return n, nil
- }
- // AgentUpdateOne is the builder for updating a single Agent entity.
- type AgentUpdateOne struct {
- config
- fields []string
- hooks []Hook
- mutation *AgentMutation
- }
- // SetUpdatedAt sets the "updated_at" field.
- func (auo *AgentUpdateOne) SetUpdatedAt(t time.Time) *AgentUpdateOne {
- auo.mutation.SetUpdatedAt(t)
- return auo
- }
- // SetDeletedAt sets the "deleted_at" field.
- func (auo *AgentUpdateOne) SetDeletedAt(t time.Time) *AgentUpdateOne {
- auo.mutation.SetDeletedAt(t)
- return auo
- }
- // SetNillableDeletedAt sets the "deleted_at" field if the given value is not nil.
- func (auo *AgentUpdateOne) SetNillableDeletedAt(t *time.Time) *AgentUpdateOne {
- if t != nil {
- auo.SetDeletedAt(*t)
- }
- return auo
- }
- // ClearDeletedAt clears the value of the "deleted_at" field.
- func (auo *AgentUpdateOne) ClearDeletedAt() *AgentUpdateOne {
- auo.mutation.ClearDeletedAt()
- return auo
- }
- // SetName sets the "name" field.
- func (auo *AgentUpdateOne) SetName(s string) *AgentUpdateOne {
- auo.mutation.SetName(s)
- return auo
- }
- // SetNillableName sets the "name" field if the given value is not nil.
- func (auo *AgentUpdateOne) SetNillableName(s *string) *AgentUpdateOne {
- if s != nil {
- auo.SetName(*s)
- }
- return auo
- }
- // SetRole sets the "role" field.
- func (auo *AgentUpdateOne) SetRole(s string) *AgentUpdateOne {
- auo.mutation.SetRole(s)
- return auo
- }
- // SetNillableRole sets the "role" field if the given value is not nil.
- func (auo *AgentUpdateOne) SetNillableRole(s *string) *AgentUpdateOne {
- if s != nil {
- auo.SetRole(*s)
- }
- return auo
- }
- // ClearRole clears the value of the "role" field.
- func (auo *AgentUpdateOne) ClearRole() *AgentUpdateOne {
- auo.mutation.ClearRole()
- return auo
- }
- // SetStatus sets the "status" field.
- func (auo *AgentUpdateOne) SetStatus(i int) *AgentUpdateOne {
- auo.mutation.ResetStatus()
- auo.mutation.SetStatus(i)
- return auo
- }
- // SetNillableStatus sets the "status" field if the given value is not nil.
- func (auo *AgentUpdateOne) SetNillableStatus(i *int) *AgentUpdateOne {
- if i != nil {
- auo.SetStatus(*i)
- }
- return auo
- }
- // AddStatus adds i to the "status" field.
- func (auo *AgentUpdateOne) AddStatus(i int) *AgentUpdateOne {
- auo.mutation.AddStatus(i)
- return auo
- }
- // ClearStatus clears the value of the "status" field.
- func (auo *AgentUpdateOne) ClearStatus() *AgentUpdateOne {
- auo.mutation.ClearStatus()
- return auo
- }
- // SetBackground sets the "background" field.
- func (auo *AgentUpdateOne) SetBackground(s string) *AgentUpdateOne {
- auo.mutation.SetBackground(s)
- return auo
- }
- // SetNillableBackground sets the "background" field if the given value is not nil.
- func (auo *AgentUpdateOne) SetNillableBackground(s *string) *AgentUpdateOne {
- if s != nil {
- auo.SetBackground(*s)
- }
- return auo
- }
- // ClearBackground clears the value of the "background" field.
- func (auo *AgentUpdateOne) ClearBackground() *AgentUpdateOne {
- auo.mutation.ClearBackground()
- return auo
- }
- // SetExamples sets the "examples" field.
- func (auo *AgentUpdateOne) SetExamples(s string) *AgentUpdateOne {
- auo.mutation.SetExamples(s)
- return auo
- }
- // SetNillableExamples sets the "examples" field if the given value is not nil.
- func (auo *AgentUpdateOne) SetNillableExamples(s *string) *AgentUpdateOne {
- if s != nil {
- auo.SetExamples(*s)
- }
- return auo
- }
- // ClearExamples clears the value of the "examples" field.
- func (auo *AgentUpdateOne) ClearExamples() *AgentUpdateOne {
- auo.mutation.ClearExamples()
- return auo
- }
- // SetOrganizationID sets the "organization_id" field.
- func (auo *AgentUpdateOne) SetOrganizationID(u uint64) *AgentUpdateOne {
- auo.mutation.ResetOrganizationID()
- auo.mutation.SetOrganizationID(u)
- return auo
- }
- // SetNillableOrganizationID sets the "organization_id" field if the given value is not nil.
- func (auo *AgentUpdateOne) SetNillableOrganizationID(u *uint64) *AgentUpdateOne {
- if u != nil {
- auo.SetOrganizationID(*u)
- }
- return auo
- }
- // AddOrganizationID adds u to the "organization_id" field.
- func (auo *AgentUpdateOne) AddOrganizationID(u int64) *AgentUpdateOne {
- auo.mutation.AddOrganizationID(u)
- return auo
- }
- // SetDatasetID sets the "dataset_id" field.
- func (auo *AgentUpdateOne) SetDatasetID(s string) *AgentUpdateOne {
- auo.mutation.SetDatasetID(s)
- return auo
- }
- // SetNillableDatasetID sets the "dataset_id" field if the given value is not nil.
- func (auo *AgentUpdateOne) SetNillableDatasetID(s *string) *AgentUpdateOne {
- if s != nil {
- auo.SetDatasetID(*s)
- }
- return auo
- }
- // SetCollectionID sets the "collection_id" field.
- func (auo *AgentUpdateOne) SetCollectionID(s string) *AgentUpdateOne {
- auo.mutation.SetCollectionID(s)
- return auo
- }
- // SetNillableCollectionID sets the "collection_id" field if the given value is not nil.
- func (auo *AgentUpdateOne) SetNillableCollectionID(s *string) *AgentUpdateOne {
- if s != nil {
- auo.SetCollectionID(*s)
- }
- return auo
- }
- // SetModel sets the "model" field.
- func (auo *AgentUpdateOne) SetModel(s string) *AgentUpdateOne {
- auo.mutation.SetModel(s)
- return auo
- }
- // SetNillableModel sets the "model" field if the given value is not nil.
- func (auo *AgentUpdateOne) SetNillableModel(s *string) *AgentUpdateOne {
- if s != nil {
- auo.SetModel(*s)
- }
- return auo
- }
- // ClearModel clears the value of the "model" field.
- func (auo *AgentUpdateOne) ClearModel() *AgentUpdateOne {
- auo.mutation.ClearModel()
- return auo
- }
- // SetAPIBase sets the "api_base" field.
- func (auo *AgentUpdateOne) SetAPIBase(s string) *AgentUpdateOne {
- auo.mutation.SetAPIBase(s)
- return auo
- }
- // SetNillableAPIBase sets the "api_base" field if the given value is not nil.
- func (auo *AgentUpdateOne) SetNillableAPIBase(s *string) *AgentUpdateOne {
- if s != nil {
- auo.SetAPIBase(*s)
- }
- return auo
- }
- // ClearAPIBase clears the value of the "api_base" field.
- func (auo *AgentUpdateOne) ClearAPIBase() *AgentUpdateOne {
- auo.mutation.ClearAPIBase()
- return auo
- }
- // SetAPIKey sets the "api_key" field.
- func (auo *AgentUpdateOne) SetAPIKey(s string) *AgentUpdateOne {
- auo.mutation.SetAPIKey(s)
- return auo
- }
- // SetNillableAPIKey sets the "api_key" field if the given value is not nil.
- func (auo *AgentUpdateOne) SetNillableAPIKey(s *string) *AgentUpdateOne {
- if s != nil {
- auo.SetAPIKey(*s)
- }
- return auo
- }
- // ClearAPIKey clears the value of the "api_key" field.
- func (auo *AgentUpdateOne) ClearAPIKey() *AgentUpdateOne {
- auo.mutation.ClearAPIKey()
- return auo
- }
- // SetType sets the "type" field.
- func (auo *AgentUpdateOne) SetType(i int) *AgentUpdateOne {
- auo.mutation.ResetType()
- auo.mutation.SetType(i)
- return auo
- }
- // SetNillableType sets the "type" field if the given value is not nil.
- func (auo *AgentUpdateOne) SetNillableType(i *int) *AgentUpdateOne {
- if i != nil {
- auo.SetType(*i)
- }
- return auo
- }
- // AddType adds i to the "type" field.
- func (auo *AgentUpdateOne) AddType(i int) *AgentUpdateOne {
- auo.mutation.AddType(i)
- return auo
- }
- // ClearType clears the value of the "type" field.
- func (auo *AgentUpdateOne) ClearType() *AgentUpdateOne {
- auo.mutation.ClearType()
- return auo
- }
- // AddWxAgentIDs adds the "wx_agent" edge to the Wx entity by IDs.
- func (auo *AgentUpdateOne) AddWxAgentIDs(ids ...uint64) *AgentUpdateOne {
- auo.mutation.AddWxAgentIDs(ids...)
- return auo
- }
- // AddWxAgent adds the "wx_agent" edges to the Wx entity.
- func (auo *AgentUpdateOne) AddWxAgent(w ...*Wx) *AgentUpdateOne {
- ids := make([]uint64, len(w))
- for i := range w {
- ids[i] = w[i].ID
- }
- return auo.AddWxAgentIDs(ids...)
- }
- // AddTokenAgentIDs adds the "token_agent" edge to the Token entity by IDs.
- func (auo *AgentUpdateOne) AddTokenAgentIDs(ids ...uint64) *AgentUpdateOne {
- auo.mutation.AddTokenAgentIDs(ids...)
- return auo
- }
- // AddTokenAgent adds the "token_agent" edges to the Token entity.
- func (auo *AgentUpdateOne) AddTokenAgent(t ...*Token) *AgentUpdateOne {
- ids := make([]uint64, len(t))
- for i := range t {
- ids[i] = t[i].ID
- }
- return auo.AddTokenAgentIDs(ids...)
- }
- // AddWaAgentIDs adds the "wa_agent" edge to the Whatsapp entity by IDs.
- func (auo *AgentUpdateOne) AddWaAgentIDs(ids ...uint64) *AgentUpdateOne {
- auo.mutation.AddWaAgentIDs(ids...)
- return auo
- }
- // AddWaAgent adds the "wa_agent" edges to the Whatsapp entity.
- func (auo *AgentUpdateOne) AddWaAgent(w ...*Whatsapp) *AgentUpdateOne {
- ids := make([]uint64, len(w))
- for i := range w {
- ids[i] = w[i].ID
- }
- return auo.AddWaAgentIDs(ids...)
- }
- // AddKeyAgentIDs adds the "key_agent" edge to the ApiKey entity by IDs.
- func (auo *AgentUpdateOne) AddKeyAgentIDs(ids ...uint64) *AgentUpdateOne {
- auo.mutation.AddKeyAgentIDs(ids...)
- return auo
- }
- // AddKeyAgent adds the "key_agent" edges to the ApiKey entity.
- func (auo *AgentUpdateOne) AddKeyAgent(a ...*ApiKey) *AgentUpdateOne {
- ids := make([]uint64, len(a))
- for i := range a {
- ids[i] = a[i].ID
- }
- return auo.AddKeyAgentIDs(ids...)
- }
- // Mutation returns the AgentMutation object of the builder.
- func (auo *AgentUpdateOne) Mutation() *AgentMutation {
- return auo.mutation
- }
- // ClearWxAgent clears all "wx_agent" edges to the Wx entity.
- func (auo *AgentUpdateOne) ClearWxAgent() *AgentUpdateOne {
- auo.mutation.ClearWxAgent()
- return auo
- }
- // RemoveWxAgentIDs removes the "wx_agent" edge to Wx entities by IDs.
- func (auo *AgentUpdateOne) RemoveWxAgentIDs(ids ...uint64) *AgentUpdateOne {
- auo.mutation.RemoveWxAgentIDs(ids...)
- return auo
- }
- // RemoveWxAgent removes "wx_agent" edges to Wx entities.
- func (auo *AgentUpdateOne) RemoveWxAgent(w ...*Wx) *AgentUpdateOne {
- ids := make([]uint64, len(w))
- for i := range w {
- ids[i] = w[i].ID
- }
- return auo.RemoveWxAgentIDs(ids...)
- }
- // ClearTokenAgent clears all "token_agent" edges to the Token entity.
- func (auo *AgentUpdateOne) ClearTokenAgent() *AgentUpdateOne {
- auo.mutation.ClearTokenAgent()
- return auo
- }
- // RemoveTokenAgentIDs removes the "token_agent" edge to Token entities by IDs.
- func (auo *AgentUpdateOne) RemoveTokenAgentIDs(ids ...uint64) *AgentUpdateOne {
- auo.mutation.RemoveTokenAgentIDs(ids...)
- return auo
- }
- // RemoveTokenAgent removes "token_agent" edges to Token entities.
- func (auo *AgentUpdateOne) RemoveTokenAgent(t ...*Token) *AgentUpdateOne {
- ids := make([]uint64, len(t))
- for i := range t {
- ids[i] = t[i].ID
- }
- return auo.RemoveTokenAgentIDs(ids...)
- }
- // ClearWaAgent clears all "wa_agent" edges to the Whatsapp entity.
- func (auo *AgentUpdateOne) ClearWaAgent() *AgentUpdateOne {
- auo.mutation.ClearWaAgent()
- return auo
- }
- // RemoveWaAgentIDs removes the "wa_agent" edge to Whatsapp entities by IDs.
- func (auo *AgentUpdateOne) RemoveWaAgentIDs(ids ...uint64) *AgentUpdateOne {
- auo.mutation.RemoveWaAgentIDs(ids...)
- return auo
- }
- // RemoveWaAgent removes "wa_agent" edges to Whatsapp entities.
- func (auo *AgentUpdateOne) RemoveWaAgent(w ...*Whatsapp) *AgentUpdateOne {
- ids := make([]uint64, len(w))
- for i := range w {
- ids[i] = w[i].ID
- }
- return auo.RemoveWaAgentIDs(ids...)
- }
- // ClearKeyAgent clears all "key_agent" edges to the ApiKey entity.
- func (auo *AgentUpdateOne) ClearKeyAgent() *AgentUpdateOne {
- auo.mutation.ClearKeyAgent()
- return auo
- }
- // RemoveKeyAgentIDs removes the "key_agent" edge to ApiKey entities by IDs.
- func (auo *AgentUpdateOne) RemoveKeyAgentIDs(ids ...uint64) *AgentUpdateOne {
- auo.mutation.RemoveKeyAgentIDs(ids...)
- return auo
- }
- // RemoveKeyAgent removes "key_agent" edges to ApiKey entities.
- func (auo *AgentUpdateOne) RemoveKeyAgent(a ...*ApiKey) *AgentUpdateOne {
- ids := make([]uint64, len(a))
- for i := range a {
- ids[i] = a[i].ID
- }
- return auo.RemoveKeyAgentIDs(ids...)
- }
- // Where appends a list predicates to the AgentUpdate builder.
- func (auo *AgentUpdateOne) Where(ps ...predicate.Agent) *AgentUpdateOne {
- auo.mutation.Where(ps...)
- return auo
- }
- // Select allows selecting one or more fields (columns) of the returned entity.
- // The default is selecting all fields defined in the entity schema.
- func (auo *AgentUpdateOne) Select(field string, fields ...string) *AgentUpdateOne {
- auo.fields = append([]string{field}, fields...)
- return auo
- }
- // Save executes the query and returns the updated Agent entity.
- func (auo *AgentUpdateOne) Save(ctx context.Context) (*Agent, error) {
- if err := auo.defaults(); err != nil {
- return nil, err
- }
- return withHooks(ctx, auo.sqlSave, auo.mutation, auo.hooks)
- }
- // SaveX is like Save, but panics if an error occurs.
- func (auo *AgentUpdateOne) SaveX(ctx context.Context) *Agent {
- node, err := auo.Save(ctx)
- if err != nil {
- panic(err)
- }
- return node
- }
- // Exec executes the query on the entity.
- func (auo *AgentUpdateOne) Exec(ctx context.Context) error {
- _, err := auo.Save(ctx)
- return err
- }
- // ExecX is like Exec, but panics if an error occurs.
- func (auo *AgentUpdateOne) ExecX(ctx context.Context) {
- if err := auo.Exec(ctx); err != nil {
- panic(err)
- }
- }
- // defaults sets the default values of the builder before save.
- func (auo *AgentUpdateOne) defaults() error {
- if _, ok := auo.mutation.UpdatedAt(); !ok {
- if agent.UpdateDefaultUpdatedAt == nil {
- return fmt.Errorf("ent: uninitialized agent.UpdateDefaultUpdatedAt (forgotten import ent/runtime?)")
- }
- v := agent.UpdateDefaultUpdatedAt()
- auo.mutation.SetUpdatedAt(v)
- }
- return nil
- }
- // check runs all checks and user-defined validators on the builder.
- func (auo *AgentUpdateOne) check() error {
- if v, ok := auo.mutation.Name(); ok {
- if err := agent.NameValidator(v); err != nil {
- return &ValidationError{Name: "name", err: fmt.Errorf(`ent: validator failed for field "Agent.name": %w`, err)}
- }
- }
- if v, ok := auo.mutation.Status(); ok {
- if err := agent.StatusValidator(v); err != nil {
- return &ValidationError{Name: "status", err: fmt.Errorf(`ent: validator failed for field "Agent.status": %w`, err)}
- }
- }
- if v, ok := auo.mutation.OrganizationID(); ok {
- if err := agent.OrganizationIDValidator(v); err != nil {
- return &ValidationError{Name: "organization_id", err: fmt.Errorf(`ent: validator failed for field "Agent.organization_id": %w`, err)}
- }
- }
- if v, ok := auo.mutation.DatasetID(); ok {
- if err := agent.DatasetIDValidator(v); err != nil {
- return &ValidationError{Name: "dataset_id", err: fmt.Errorf(`ent: validator failed for field "Agent.dataset_id": %w`, err)}
- }
- }
- if v, ok := auo.mutation.CollectionID(); ok {
- if err := agent.CollectionIDValidator(v); err != nil {
- return &ValidationError{Name: "collection_id", err: fmt.Errorf(`ent: validator failed for field "Agent.collection_id": %w`, err)}
- }
- }
- if v, ok := auo.mutation.GetType(); ok {
- if err := agent.TypeValidator(v); err != nil {
- return &ValidationError{Name: "type", err: fmt.Errorf(`ent: validator failed for field "Agent.type": %w`, err)}
- }
- }
- return nil
- }
- func (auo *AgentUpdateOne) sqlSave(ctx context.Context) (_node *Agent, err error) {
- if err := auo.check(); err != nil {
- return _node, err
- }
- _spec := sqlgraph.NewUpdateSpec(agent.Table, agent.Columns, sqlgraph.NewFieldSpec(agent.FieldID, field.TypeUint64))
- id, ok := auo.mutation.ID()
- if !ok {
- return nil, &ValidationError{Name: "id", err: errors.New(`ent: missing "Agent.id" for update`)}
- }
- _spec.Node.ID.Value = id
- if fields := auo.fields; len(fields) > 0 {
- _spec.Node.Columns = make([]string, 0, len(fields))
- _spec.Node.Columns = append(_spec.Node.Columns, agent.FieldID)
- for _, f := range fields {
- if !agent.ValidColumn(f) {
- return nil, &ValidationError{Name: f, err: fmt.Errorf("ent: invalid field %q for query", f)}
- }
- if f != agent.FieldID {
- _spec.Node.Columns = append(_spec.Node.Columns, f)
- }
- }
- }
- if ps := auo.mutation.predicates; len(ps) > 0 {
- _spec.Predicate = func(selector *sql.Selector) {
- for i := range ps {
- ps[i](selector)
- }
- }
- }
- if value, ok := auo.mutation.UpdatedAt(); ok {
- _spec.SetField(agent.FieldUpdatedAt, field.TypeTime, value)
- }
- if value, ok := auo.mutation.DeletedAt(); ok {
- _spec.SetField(agent.FieldDeletedAt, field.TypeTime, value)
- }
- if auo.mutation.DeletedAtCleared() {
- _spec.ClearField(agent.FieldDeletedAt, field.TypeTime)
- }
- if value, ok := auo.mutation.Name(); ok {
- _spec.SetField(agent.FieldName, field.TypeString, value)
- }
- if value, ok := auo.mutation.Role(); ok {
- _spec.SetField(agent.FieldRole, field.TypeString, value)
- }
- if auo.mutation.RoleCleared() {
- _spec.ClearField(agent.FieldRole, field.TypeString)
- }
- if value, ok := auo.mutation.Status(); ok {
- _spec.SetField(agent.FieldStatus, field.TypeInt, value)
- }
- if value, ok := auo.mutation.AddedStatus(); ok {
- _spec.AddField(agent.FieldStatus, field.TypeInt, value)
- }
- if auo.mutation.StatusCleared() {
- _spec.ClearField(agent.FieldStatus, field.TypeInt)
- }
- if value, ok := auo.mutation.Background(); ok {
- _spec.SetField(agent.FieldBackground, field.TypeString, value)
- }
- if auo.mutation.BackgroundCleared() {
- _spec.ClearField(agent.FieldBackground, field.TypeString)
- }
- if value, ok := auo.mutation.Examples(); ok {
- _spec.SetField(agent.FieldExamples, field.TypeString, value)
- }
- if auo.mutation.ExamplesCleared() {
- _spec.ClearField(agent.FieldExamples, field.TypeString)
- }
- if value, ok := auo.mutation.OrganizationID(); ok {
- _spec.SetField(agent.FieldOrganizationID, field.TypeUint64, value)
- }
- if value, ok := auo.mutation.AddedOrganizationID(); ok {
- _spec.AddField(agent.FieldOrganizationID, field.TypeUint64, value)
- }
- if value, ok := auo.mutation.DatasetID(); ok {
- _spec.SetField(agent.FieldDatasetID, field.TypeString, value)
- }
- if value, ok := auo.mutation.CollectionID(); ok {
- _spec.SetField(agent.FieldCollectionID, field.TypeString, value)
- }
- if value, ok := auo.mutation.Model(); ok {
- _spec.SetField(agent.FieldModel, field.TypeString, value)
- }
- if auo.mutation.ModelCleared() {
- _spec.ClearField(agent.FieldModel, field.TypeString)
- }
- if value, ok := auo.mutation.APIBase(); ok {
- _spec.SetField(agent.FieldAPIBase, field.TypeString, value)
- }
- if auo.mutation.APIBaseCleared() {
- _spec.ClearField(agent.FieldAPIBase, field.TypeString)
- }
- if value, ok := auo.mutation.APIKey(); ok {
- _spec.SetField(agent.FieldAPIKey, field.TypeString, value)
- }
- if auo.mutation.APIKeyCleared() {
- _spec.ClearField(agent.FieldAPIKey, field.TypeString)
- }
- if value, ok := auo.mutation.GetType(); ok {
- _spec.SetField(agent.FieldType, field.TypeInt, value)
- }
- if value, ok := auo.mutation.AddedType(); ok {
- _spec.AddField(agent.FieldType, field.TypeInt, value)
- }
- if auo.mutation.TypeCleared() {
- _spec.ClearField(agent.FieldType, field.TypeInt)
- }
- if auo.mutation.WxAgentCleared() {
- edge := &sqlgraph.EdgeSpec{
- Rel: sqlgraph.O2M,
- Inverse: false,
- Table: agent.WxAgentTable,
- Columns: []string{agent.WxAgentColumn},
- Bidi: false,
- Target: &sqlgraph.EdgeTarget{
- IDSpec: sqlgraph.NewFieldSpec(wx.FieldID, field.TypeUint64),
- },
- }
- _spec.Edges.Clear = append(_spec.Edges.Clear, edge)
- }
- if nodes := auo.mutation.RemovedWxAgentIDs(); len(nodes) > 0 && !auo.mutation.WxAgentCleared() {
- edge := &sqlgraph.EdgeSpec{
- Rel: sqlgraph.O2M,
- Inverse: false,
- Table: agent.WxAgentTable,
- Columns: []string{agent.WxAgentColumn},
- Bidi: false,
- Target: &sqlgraph.EdgeTarget{
- IDSpec: sqlgraph.NewFieldSpec(wx.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 := auo.mutation.WxAgentIDs(); len(nodes) > 0 {
- edge := &sqlgraph.EdgeSpec{
- Rel: sqlgraph.O2M,
- Inverse: false,
- Table: agent.WxAgentTable,
- Columns: []string{agent.WxAgentColumn},
- Bidi: false,
- Target: &sqlgraph.EdgeTarget{
- IDSpec: sqlgraph.NewFieldSpec(wx.FieldID, field.TypeUint64),
- },
- }
- for _, k := range nodes {
- edge.Target.Nodes = append(edge.Target.Nodes, k)
- }
- _spec.Edges.Add = append(_spec.Edges.Add, edge)
- }
- if auo.mutation.TokenAgentCleared() {
- edge := &sqlgraph.EdgeSpec{
- Rel: sqlgraph.O2M,
- Inverse: false,
- Table: agent.TokenAgentTable,
- Columns: []string{agent.TokenAgentColumn},
- Bidi: false,
- Target: &sqlgraph.EdgeTarget{
- IDSpec: sqlgraph.NewFieldSpec(token.FieldID, field.TypeUint64),
- },
- }
- _spec.Edges.Clear = append(_spec.Edges.Clear, edge)
- }
- if nodes := auo.mutation.RemovedTokenAgentIDs(); len(nodes) > 0 && !auo.mutation.TokenAgentCleared() {
- edge := &sqlgraph.EdgeSpec{
- Rel: sqlgraph.O2M,
- Inverse: false,
- Table: agent.TokenAgentTable,
- Columns: []string{agent.TokenAgentColumn},
- Bidi: false,
- Target: &sqlgraph.EdgeTarget{
- IDSpec: sqlgraph.NewFieldSpec(token.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 := auo.mutation.TokenAgentIDs(); len(nodes) > 0 {
- edge := &sqlgraph.EdgeSpec{
- Rel: sqlgraph.O2M,
- Inverse: false,
- Table: agent.TokenAgentTable,
- Columns: []string{agent.TokenAgentColumn},
- Bidi: false,
- Target: &sqlgraph.EdgeTarget{
- IDSpec: sqlgraph.NewFieldSpec(token.FieldID, field.TypeUint64),
- },
- }
- for _, k := range nodes {
- edge.Target.Nodes = append(edge.Target.Nodes, k)
- }
- _spec.Edges.Add = append(_spec.Edges.Add, edge)
- }
- if auo.mutation.WaAgentCleared() {
- edge := &sqlgraph.EdgeSpec{
- Rel: sqlgraph.O2M,
- Inverse: false,
- Table: agent.WaAgentTable,
- Columns: []string{agent.WaAgentColumn},
- Bidi: false,
- Target: &sqlgraph.EdgeTarget{
- IDSpec: sqlgraph.NewFieldSpec(whatsapp.FieldID, field.TypeUint64),
- },
- }
- _spec.Edges.Clear = append(_spec.Edges.Clear, edge)
- }
- if nodes := auo.mutation.RemovedWaAgentIDs(); len(nodes) > 0 && !auo.mutation.WaAgentCleared() {
- edge := &sqlgraph.EdgeSpec{
- Rel: sqlgraph.O2M,
- Inverse: false,
- Table: agent.WaAgentTable,
- Columns: []string{agent.WaAgentColumn},
- Bidi: false,
- Target: &sqlgraph.EdgeTarget{
- IDSpec: sqlgraph.NewFieldSpec(whatsapp.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 := auo.mutation.WaAgentIDs(); len(nodes) > 0 {
- edge := &sqlgraph.EdgeSpec{
- Rel: sqlgraph.O2M,
- Inverse: false,
- Table: agent.WaAgentTable,
- Columns: []string{agent.WaAgentColumn},
- Bidi: false,
- Target: &sqlgraph.EdgeTarget{
- IDSpec: sqlgraph.NewFieldSpec(whatsapp.FieldID, field.TypeUint64),
- },
- }
- for _, k := range nodes {
- edge.Target.Nodes = append(edge.Target.Nodes, k)
- }
- _spec.Edges.Add = append(_spec.Edges.Add, edge)
- }
- if auo.mutation.KeyAgentCleared() {
- edge := &sqlgraph.EdgeSpec{
- Rel: sqlgraph.O2M,
- Inverse: false,
- Table: agent.KeyAgentTable,
- Columns: []string{agent.KeyAgentColumn},
- Bidi: false,
- Target: &sqlgraph.EdgeTarget{
- IDSpec: sqlgraph.NewFieldSpec(apikey.FieldID, field.TypeUint64),
- },
- }
- _spec.Edges.Clear = append(_spec.Edges.Clear, edge)
- }
- if nodes := auo.mutation.RemovedKeyAgentIDs(); len(nodes) > 0 && !auo.mutation.KeyAgentCleared() {
- edge := &sqlgraph.EdgeSpec{
- Rel: sqlgraph.O2M,
- Inverse: false,
- Table: agent.KeyAgentTable,
- Columns: []string{agent.KeyAgentColumn},
- Bidi: false,
- Target: &sqlgraph.EdgeTarget{
- IDSpec: sqlgraph.NewFieldSpec(apikey.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 := auo.mutation.KeyAgentIDs(); len(nodes) > 0 {
- edge := &sqlgraph.EdgeSpec{
- Rel: sqlgraph.O2M,
- Inverse: false,
- Table: agent.KeyAgentTable,
- Columns: []string{agent.KeyAgentColumn},
- Bidi: false,
- Target: &sqlgraph.EdgeTarget{
- IDSpec: sqlgraph.NewFieldSpec(apikey.FieldID, field.TypeUint64),
- },
- }
- for _, k := range nodes {
- edge.Target.Nodes = append(edge.Target.Nodes, k)
- }
- _spec.Edges.Add = append(_spec.Edges.Add, edge)
- }
- _node = &Agent{config: auo.config}
- _spec.Assign = _node.assignValues
- _spec.ScanValues = _node.scanValues
- if err = sqlgraph.UpdateNode(ctx, auo.driver, _spec); err != nil {
- if _, ok := err.(*sqlgraph.NotFoundError); ok {
- err = &NotFoundError{agent.Label}
- } else if sqlgraph.IsConstraintError(err) {
- err = &ConstraintError{msg: err.Error(), wrap: err}
- }
- return nil, err
- }
- auo.mutation.done = true
- return _node, nil
- }
|