1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360 |
- // 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
- }
- // 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
- }
- // 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)}
- }
- }
- 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 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 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
- }
- // 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
- }
- // 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)}
- }
- }
- 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 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 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
- }
|