// Code generated by ent, DO NOT EDIT. package ent import ( "context" "errors" "fmt" "time" "wechat-api/ent/agent" "wechat-api/ent/predicate" "wechat-api/ent/xunjiservice" "entgo.io/ent/dialect/sql" "entgo.io/ent/dialect/sql/sqlgraph" "entgo.io/ent/schema/field" ) // XunjiServiceUpdate is the builder for updating XunjiService entities. type XunjiServiceUpdate struct { config hooks []Hook mutation *XunjiServiceMutation } // Where appends a list predicates to the XunjiServiceUpdate builder. func (xsu *XunjiServiceUpdate) Where(ps ...predicate.XunjiService) *XunjiServiceUpdate { xsu.mutation.Where(ps...) return xsu } // SetUpdatedAt sets the "updated_at" field. func (xsu *XunjiServiceUpdate) SetUpdatedAt(t time.Time) *XunjiServiceUpdate { xsu.mutation.SetUpdatedAt(t) return xsu } // SetStatus sets the "status" field. func (xsu *XunjiServiceUpdate) SetStatus(u uint8) *XunjiServiceUpdate { xsu.mutation.ResetStatus() xsu.mutation.SetStatus(u) return xsu } // SetNillableStatus sets the "status" field if the given value is not nil. func (xsu *XunjiServiceUpdate) SetNillableStatus(u *uint8) *XunjiServiceUpdate { if u != nil { xsu.SetStatus(*u) } return xsu } // AddStatus adds u to the "status" field. func (xsu *XunjiServiceUpdate) AddStatus(u int8) *XunjiServiceUpdate { xsu.mutation.AddStatus(u) return xsu } // ClearStatus clears the value of the "status" field. func (xsu *XunjiServiceUpdate) ClearStatus() *XunjiServiceUpdate { xsu.mutation.ClearStatus() return xsu } // SetDeletedAt sets the "deleted_at" field. func (xsu *XunjiServiceUpdate) SetDeletedAt(t time.Time) *XunjiServiceUpdate { xsu.mutation.SetDeletedAt(t) return xsu } // SetNillableDeletedAt sets the "deleted_at" field if the given value is not nil. func (xsu *XunjiServiceUpdate) SetNillableDeletedAt(t *time.Time) *XunjiServiceUpdate { if t != nil { xsu.SetDeletedAt(*t) } return xsu } // ClearDeletedAt clears the value of the "deleted_at" field. func (xsu *XunjiServiceUpdate) ClearDeletedAt() *XunjiServiceUpdate { xsu.mutation.ClearDeletedAt() return xsu } // SetXunjiID sets the "xunji_id" field. func (xsu *XunjiServiceUpdate) SetXunjiID(u uint64) *XunjiServiceUpdate { xsu.mutation.ResetXunjiID() xsu.mutation.SetXunjiID(u) return xsu } // SetNillableXunjiID sets the "xunji_id" field if the given value is not nil. func (xsu *XunjiServiceUpdate) SetNillableXunjiID(u *uint64) *XunjiServiceUpdate { if u != nil { xsu.SetXunjiID(*u) } return xsu } // AddXunjiID adds u to the "xunji_id" field. func (xsu *XunjiServiceUpdate) AddXunjiID(u int64) *XunjiServiceUpdate { xsu.mutation.AddXunjiID(u) return xsu } // SetAgentID sets the "agent_id" field. func (xsu *XunjiServiceUpdate) SetAgentID(u uint64) *XunjiServiceUpdate { xsu.mutation.SetAgentID(u) return xsu } // SetNillableAgentID sets the "agent_id" field if the given value is not nil. func (xsu *XunjiServiceUpdate) SetNillableAgentID(u *uint64) *XunjiServiceUpdate { if u != nil { xsu.SetAgentID(*u) } return xsu } // SetOrganizationID sets the "organization_id" field. func (xsu *XunjiServiceUpdate) SetOrganizationID(u uint64) *XunjiServiceUpdate { xsu.mutation.ResetOrganizationID() xsu.mutation.SetOrganizationID(u) return xsu } // SetNillableOrganizationID sets the "organization_id" field if the given value is not nil. func (xsu *XunjiServiceUpdate) SetNillableOrganizationID(u *uint64) *XunjiServiceUpdate { if u != nil { xsu.SetOrganizationID(*u) } return xsu } // AddOrganizationID adds u to the "organization_id" field. func (xsu *XunjiServiceUpdate) AddOrganizationID(u int64) *XunjiServiceUpdate { xsu.mutation.AddOrganizationID(u) return xsu } // SetWxid sets the "wxid" field. func (xsu *XunjiServiceUpdate) SetWxid(s string) *XunjiServiceUpdate { xsu.mutation.SetWxid(s) return xsu } // SetNillableWxid sets the "wxid" field if the given value is not nil. func (xsu *XunjiServiceUpdate) SetNillableWxid(s *string) *XunjiServiceUpdate { if s != nil { xsu.SetWxid(*s) } return xsu } // SetAPIBase sets the "api_base" field. func (xsu *XunjiServiceUpdate) SetAPIBase(s string) *XunjiServiceUpdate { xsu.mutation.SetAPIBase(s) return xsu } // SetNillableAPIBase sets the "api_base" field if the given value is not nil. func (xsu *XunjiServiceUpdate) SetNillableAPIBase(s *string) *XunjiServiceUpdate { if s != nil { xsu.SetAPIBase(*s) } return xsu } // ClearAPIBase clears the value of the "api_base" field. func (xsu *XunjiServiceUpdate) ClearAPIBase() *XunjiServiceUpdate { xsu.mutation.ClearAPIBase() return xsu } // SetAPIKey sets the "api_key" field. func (xsu *XunjiServiceUpdate) SetAPIKey(s string) *XunjiServiceUpdate { xsu.mutation.SetAPIKey(s) return xsu } // SetNillableAPIKey sets the "api_key" field if the given value is not nil. func (xsu *XunjiServiceUpdate) SetNillableAPIKey(s *string) *XunjiServiceUpdate { if s != nil { xsu.SetAPIKey(*s) } return xsu } // ClearAPIKey clears the value of the "api_key" field. func (xsu *XunjiServiceUpdate) ClearAPIKey() *XunjiServiceUpdate { xsu.mutation.ClearAPIKey() return xsu } // SetAgent sets the "agent" edge to the Agent entity. func (xsu *XunjiServiceUpdate) SetAgent(a *Agent) *XunjiServiceUpdate { return xsu.SetAgentID(a.ID) } // Mutation returns the XunjiServiceMutation object of the builder. func (xsu *XunjiServiceUpdate) Mutation() *XunjiServiceMutation { return xsu.mutation } // ClearAgent clears the "agent" edge to the Agent entity. func (xsu *XunjiServiceUpdate) ClearAgent() *XunjiServiceUpdate { xsu.mutation.ClearAgent() return xsu } // Save executes the query and returns the number of nodes affected by the update operation. func (xsu *XunjiServiceUpdate) Save(ctx context.Context) (int, error) { if err := xsu.defaults(); err != nil { return 0, err } return withHooks(ctx, xsu.sqlSave, xsu.mutation, xsu.hooks) } // SaveX is like Save, but panics if an error occurs. func (xsu *XunjiServiceUpdate) SaveX(ctx context.Context) int { affected, err := xsu.Save(ctx) if err != nil { panic(err) } return affected } // Exec executes the query. func (xsu *XunjiServiceUpdate) Exec(ctx context.Context) error { _, err := xsu.Save(ctx) return err } // ExecX is like Exec, but panics if an error occurs. func (xsu *XunjiServiceUpdate) ExecX(ctx context.Context) { if err := xsu.Exec(ctx); err != nil { panic(err) } } // defaults sets the default values of the builder before save. func (xsu *XunjiServiceUpdate) defaults() error { if _, ok := xsu.mutation.UpdatedAt(); !ok { if xunjiservice.UpdateDefaultUpdatedAt == nil { return fmt.Errorf("ent: uninitialized xunjiservice.UpdateDefaultUpdatedAt (forgotten import ent/runtime?)") } v := xunjiservice.UpdateDefaultUpdatedAt() xsu.mutation.SetUpdatedAt(v) } return nil } // check runs all checks and user-defined validators on the builder. func (xsu *XunjiServiceUpdate) check() error { if v, ok := xsu.mutation.OrganizationID(); ok { if err := xunjiservice.OrganizationIDValidator(v); err != nil { return &ValidationError{Name: "organization_id", err: fmt.Errorf(`ent: validator failed for field "XunjiService.organization_id": %w`, err)} } } if _, ok := xsu.mutation.AgentID(); xsu.mutation.AgentCleared() && !ok { return errors.New(`ent: clearing a required unique edge "XunjiService.agent"`) } return nil } func (xsu *XunjiServiceUpdate) sqlSave(ctx context.Context) (n int, err error) { if err := xsu.check(); err != nil { return n, err } _spec := sqlgraph.NewUpdateSpec(xunjiservice.Table, xunjiservice.Columns, sqlgraph.NewFieldSpec(xunjiservice.FieldID, field.TypeUint64)) if ps := xsu.mutation.predicates; len(ps) > 0 { _spec.Predicate = func(selector *sql.Selector) { for i := range ps { ps[i](selector) } } } if value, ok := xsu.mutation.UpdatedAt(); ok { _spec.SetField(xunjiservice.FieldUpdatedAt, field.TypeTime, value) } if value, ok := xsu.mutation.Status(); ok { _spec.SetField(xunjiservice.FieldStatus, field.TypeUint8, value) } if value, ok := xsu.mutation.AddedStatus(); ok { _spec.AddField(xunjiservice.FieldStatus, field.TypeUint8, value) } if xsu.mutation.StatusCleared() { _spec.ClearField(xunjiservice.FieldStatus, field.TypeUint8) } if value, ok := xsu.mutation.DeletedAt(); ok { _spec.SetField(xunjiservice.FieldDeletedAt, field.TypeTime, value) } if xsu.mutation.DeletedAtCleared() { _spec.ClearField(xunjiservice.FieldDeletedAt, field.TypeTime) } if value, ok := xsu.mutation.XunjiID(); ok { _spec.SetField(xunjiservice.FieldXunjiID, field.TypeUint64, value) } if value, ok := xsu.mutation.AddedXunjiID(); ok { _spec.AddField(xunjiservice.FieldXunjiID, field.TypeUint64, value) } if value, ok := xsu.mutation.OrganizationID(); ok { _spec.SetField(xunjiservice.FieldOrganizationID, field.TypeUint64, value) } if value, ok := xsu.mutation.AddedOrganizationID(); ok { _spec.AddField(xunjiservice.FieldOrganizationID, field.TypeUint64, value) } if value, ok := xsu.mutation.Wxid(); ok { _spec.SetField(xunjiservice.FieldWxid, field.TypeString, value) } if value, ok := xsu.mutation.APIBase(); ok { _spec.SetField(xunjiservice.FieldAPIBase, field.TypeString, value) } if xsu.mutation.APIBaseCleared() { _spec.ClearField(xunjiservice.FieldAPIBase, field.TypeString) } if value, ok := xsu.mutation.APIKey(); ok { _spec.SetField(xunjiservice.FieldAPIKey, field.TypeString, value) } if xsu.mutation.APIKeyCleared() { _spec.ClearField(xunjiservice.FieldAPIKey, field.TypeString) } if xsu.mutation.AgentCleared() { edge := &sqlgraph.EdgeSpec{ Rel: sqlgraph.M2O, Inverse: true, Table: xunjiservice.AgentTable, Columns: []string{xunjiservice.AgentColumn}, Bidi: false, Target: &sqlgraph.EdgeTarget{ IDSpec: sqlgraph.NewFieldSpec(agent.FieldID, field.TypeUint64), }, } _spec.Edges.Clear = append(_spec.Edges.Clear, edge) } if nodes := xsu.mutation.AgentIDs(); len(nodes) > 0 { edge := &sqlgraph.EdgeSpec{ Rel: sqlgraph.M2O, Inverse: true, Table: xunjiservice.AgentTable, Columns: []string{xunjiservice.AgentColumn}, Bidi: false, Target: &sqlgraph.EdgeTarget{ IDSpec: sqlgraph.NewFieldSpec(agent.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, xsu.driver, _spec); err != nil { if _, ok := err.(*sqlgraph.NotFoundError); ok { err = &NotFoundError{xunjiservice.Label} } else if sqlgraph.IsConstraintError(err) { err = &ConstraintError{msg: err.Error(), wrap: err} } return 0, err } xsu.mutation.done = true return n, nil } // XunjiServiceUpdateOne is the builder for updating a single XunjiService entity. type XunjiServiceUpdateOne struct { config fields []string hooks []Hook mutation *XunjiServiceMutation } // SetUpdatedAt sets the "updated_at" field. func (xsuo *XunjiServiceUpdateOne) SetUpdatedAt(t time.Time) *XunjiServiceUpdateOne { xsuo.mutation.SetUpdatedAt(t) return xsuo } // SetStatus sets the "status" field. func (xsuo *XunjiServiceUpdateOne) SetStatus(u uint8) *XunjiServiceUpdateOne { xsuo.mutation.ResetStatus() xsuo.mutation.SetStatus(u) return xsuo } // SetNillableStatus sets the "status" field if the given value is not nil. func (xsuo *XunjiServiceUpdateOne) SetNillableStatus(u *uint8) *XunjiServiceUpdateOne { if u != nil { xsuo.SetStatus(*u) } return xsuo } // AddStatus adds u to the "status" field. func (xsuo *XunjiServiceUpdateOne) AddStatus(u int8) *XunjiServiceUpdateOne { xsuo.mutation.AddStatus(u) return xsuo } // ClearStatus clears the value of the "status" field. func (xsuo *XunjiServiceUpdateOne) ClearStatus() *XunjiServiceUpdateOne { xsuo.mutation.ClearStatus() return xsuo } // SetDeletedAt sets the "deleted_at" field. func (xsuo *XunjiServiceUpdateOne) SetDeletedAt(t time.Time) *XunjiServiceUpdateOne { xsuo.mutation.SetDeletedAt(t) return xsuo } // SetNillableDeletedAt sets the "deleted_at" field if the given value is not nil. func (xsuo *XunjiServiceUpdateOne) SetNillableDeletedAt(t *time.Time) *XunjiServiceUpdateOne { if t != nil { xsuo.SetDeletedAt(*t) } return xsuo } // ClearDeletedAt clears the value of the "deleted_at" field. func (xsuo *XunjiServiceUpdateOne) ClearDeletedAt() *XunjiServiceUpdateOne { xsuo.mutation.ClearDeletedAt() return xsuo } // SetXunjiID sets the "xunji_id" field. func (xsuo *XunjiServiceUpdateOne) SetXunjiID(u uint64) *XunjiServiceUpdateOne { xsuo.mutation.ResetXunjiID() xsuo.mutation.SetXunjiID(u) return xsuo } // SetNillableXunjiID sets the "xunji_id" field if the given value is not nil. func (xsuo *XunjiServiceUpdateOne) SetNillableXunjiID(u *uint64) *XunjiServiceUpdateOne { if u != nil { xsuo.SetXunjiID(*u) } return xsuo } // AddXunjiID adds u to the "xunji_id" field. func (xsuo *XunjiServiceUpdateOne) AddXunjiID(u int64) *XunjiServiceUpdateOne { xsuo.mutation.AddXunjiID(u) return xsuo } // SetAgentID sets the "agent_id" field. func (xsuo *XunjiServiceUpdateOne) SetAgentID(u uint64) *XunjiServiceUpdateOne { xsuo.mutation.SetAgentID(u) return xsuo } // SetNillableAgentID sets the "agent_id" field if the given value is not nil. func (xsuo *XunjiServiceUpdateOne) SetNillableAgentID(u *uint64) *XunjiServiceUpdateOne { if u != nil { xsuo.SetAgentID(*u) } return xsuo } // SetOrganizationID sets the "organization_id" field. func (xsuo *XunjiServiceUpdateOne) SetOrganizationID(u uint64) *XunjiServiceUpdateOne { xsuo.mutation.ResetOrganizationID() xsuo.mutation.SetOrganizationID(u) return xsuo } // SetNillableOrganizationID sets the "organization_id" field if the given value is not nil. func (xsuo *XunjiServiceUpdateOne) SetNillableOrganizationID(u *uint64) *XunjiServiceUpdateOne { if u != nil { xsuo.SetOrganizationID(*u) } return xsuo } // AddOrganizationID adds u to the "organization_id" field. func (xsuo *XunjiServiceUpdateOne) AddOrganizationID(u int64) *XunjiServiceUpdateOne { xsuo.mutation.AddOrganizationID(u) return xsuo } // SetWxid sets the "wxid" field. func (xsuo *XunjiServiceUpdateOne) SetWxid(s string) *XunjiServiceUpdateOne { xsuo.mutation.SetWxid(s) return xsuo } // SetNillableWxid sets the "wxid" field if the given value is not nil. func (xsuo *XunjiServiceUpdateOne) SetNillableWxid(s *string) *XunjiServiceUpdateOne { if s != nil { xsuo.SetWxid(*s) } return xsuo } // SetAPIBase sets the "api_base" field. func (xsuo *XunjiServiceUpdateOne) SetAPIBase(s string) *XunjiServiceUpdateOne { xsuo.mutation.SetAPIBase(s) return xsuo } // SetNillableAPIBase sets the "api_base" field if the given value is not nil. func (xsuo *XunjiServiceUpdateOne) SetNillableAPIBase(s *string) *XunjiServiceUpdateOne { if s != nil { xsuo.SetAPIBase(*s) } return xsuo } // ClearAPIBase clears the value of the "api_base" field. func (xsuo *XunjiServiceUpdateOne) ClearAPIBase() *XunjiServiceUpdateOne { xsuo.mutation.ClearAPIBase() return xsuo } // SetAPIKey sets the "api_key" field. func (xsuo *XunjiServiceUpdateOne) SetAPIKey(s string) *XunjiServiceUpdateOne { xsuo.mutation.SetAPIKey(s) return xsuo } // SetNillableAPIKey sets the "api_key" field if the given value is not nil. func (xsuo *XunjiServiceUpdateOne) SetNillableAPIKey(s *string) *XunjiServiceUpdateOne { if s != nil { xsuo.SetAPIKey(*s) } return xsuo } // ClearAPIKey clears the value of the "api_key" field. func (xsuo *XunjiServiceUpdateOne) ClearAPIKey() *XunjiServiceUpdateOne { xsuo.mutation.ClearAPIKey() return xsuo } // SetAgent sets the "agent" edge to the Agent entity. func (xsuo *XunjiServiceUpdateOne) SetAgent(a *Agent) *XunjiServiceUpdateOne { return xsuo.SetAgentID(a.ID) } // Mutation returns the XunjiServiceMutation object of the builder. func (xsuo *XunjiServiceUpdateOne) Mutation() *XunjiServiceMutation { return xsuo.mutation } // ClearAgent clears the "agent" edge to the Agent entity. func (xsuo *XunjiServiceUpdateOne) ClearAgent() *XunjiServiceUpdateOne { xsuo.mutation.ClearAgent() return xsuo } // Where appends a list predicates to the XunjiServiceUpdate builder. func (xsuo *XunjiServiceUpdateOne) Where(ps ...predicate.XunjiService) *XunjiServiceUpdateOne { xsuo.mutation.Where(ps...) return xsuo } // Select allows selecting one or more fields (columns) of the returned entity. // The default is selecting all fields defined in the entity schema. func (xsuo *XunjiServiceUpdateOne) Select(field string, fields ...string) *XunjiServiceUpdateOne { xsuo.fields = append([]string{field}, fields...) return xsuo } // Save executes the query and returns the updated XunjiService entity. func (xsuo *XunjiServiceUpdateOne) Save(ctx context.Context) (*XunjiService, error) { if err := xsuo.defaults(); err != nil { return nil, err } return withHooks(ctx, xsuo.sqlSave, xsuo.mutation, xsuo.hooks) } // SaveX is like Save, but panics if an error occurs. func (xsuo *XunjiServiceUpdateOne) SaveX(ctx context.Context) *XunjiService { node, err := xsuo.Save(ctx) if err != nil { panic(err) } return node } // Exec executes the query on the entity. func (xsuo *XunjiServiceUpdateOne) Exec(ctx context.Context) error { _, err := xsuo.Save(ctx) return err } // ExecX is like Exec, but panics if an error occurs. func (xsuo *XunjiServiceUpdateOne) ExecX(ctx context.Context) { if err := xsuo.Exec(ctx); err != nil { panic(err) } } // defaults sets the default values of the builder before save. func (xsuo *XunjiServiceUpdateOne) defaults() error { if _, ok := xsuo.mutation.UpdatedAt(); !ok { if xunjiservice.UpdateDefaultUpdatedAt == nil { return fmt.Errorf("ent: uninitialized xunjiservice.UpdateDefaultUpdatedAt (forgotten import ent/runtime?)") } v := xunjiservice.UpdateDefaultUpdatedAt() xsuo.mutation.SetUpdatedAt(v) } return nil } // check runs all checks and user-defined validators on the builder. func (xsuo *XunjiServiceUpdateOne) check() error { if v, ok := xsuo.mutation.OrganizationID(); ok { if err := xunjiservice.OrganizationIDValidator(v); err != nil { return &ValidationError{Name: "organization_id", err: fmt.Errorf(`ent: validator failed for field "XunjiService.organization_id": %w`, err)} } } if _, ok := xsuo.mutation.AgentID(); xsuo.mutation.AgentCleared() && !ok { return errors.New(`ent: clearing a required unique edge "XunjiService.agent"`) } return nil } func (xsuo *XunjiServiceUpdateOne) sqlSave(ctx context.Context) (_node *XunjiService, err error) { if err := xsuo.check(); err != nil { return _node, err } _spec := sqlgraph.NewUpdateSpec(xunjiservice.Table, xunjiservice.Columns, sqlgraph.NewFieldSpec(xunjiservice.FieldID, field.TypeUint64)) id, ok := xsuo.mutation.ID() if !ok { return nil, &ValidationError{Name: "id", err: errors.New(`ent: missing "XunjiService.id" for update`)} } _spec.Node.ID.Value = id if fields := xsuo.fields; len(fields) > 0 { _spec.Node.Columns = make([]string, 0, len(fields)) _spec.Node.Columns = append(_spec.Node.Columns, xunjiservice.FieldID) for _, f := range fields { if !xunjiservice.ValidColumn(f) { return nil, &ValidationError{Name: f, err: fmt.Errorf("ent: invalid field %q for query", f)} } if f != xunjiservice.FieldID { _spec.Node.Columns = append(_spec.Node.Columns, f) } } } if ps := xsuo.mutation.predicates; len(ps) > 0 { _spec.Predicate = func(selector *sql.Selector) { for i := range ps { ps[i](selector) } } } if value, ok := xsuo.mutation.UpdatedAt(); ok { _spec.SetField(xunjiservice.FieldUpdatedAt, field.TypeTime, value) } if value, ok := xsuo.mutation.Status(); ok { _spec.SetField(xunjiservice.FieldStatus, field.TypeUint8, value) } if value, ok := xsuo.mutation.AddedStatus(); ok { _spec.AddField(xunjiservice.FieldStatus, field.TypeUint8, value) } if xsuo.mutation.StatusCleared() { _spec.ClearField(xunjiservice.FieldStatus, field.TypeUint8) } if value, ok := xsuo.mutation.DeletedAt(); ok { _spec.SetField(xunjiservice.FieldDeletedAt, field.TypeTime, value) } if xsuo.mutation.DeletedAtCleared() { _spec.ClearField(xunjiservice.FieldDeletedAt, field.TypeTime) } if value, ok := xsuo.mutation.XunjiID(); ok { _spec.SetField(xunjiservice.FieldXunjiID, field.TypeUint64, value) } if value, ok := xsuo.mutation.AddedXunjiID(); ok { _spec.AddField(xunjiservice.FieldXunjiID, field.TypeUint64, value) } if value, ok := xsuo.mutation.OrganizationID(); ok { _spec.SetField(xunjiservice.FieldOrganizationID, field.TypeUint64, value) } if value, ok := xsuo.mutation.AddedOrganizationID(); ok { _spec.AddField(xunjiservice.FieldOrganizationID, field.TypeUint64, value) } if value, ok := xsuo.mutation.Wxid(); ok { _spec.SetField(xunjiservice.FieldWxid, field.TypeString, value) } if value, ok := xsuo.mutation.APIBase(); ok { _spec.SetField(xunjiservice.FieldAPIBase, field.TypeString, value) } if xsuo.mutation.APIBaseCleared() { _spec.ClearField(xunjiservice.FieldAPIBase, field.TypeString) } if value, ok := xsuo.mutation.APIKey(); ok { _spec.SetField(xunjiservice.FieldAPIKey, field.TypeString, value) } if xsuo.mutation.APIKeyCleared() { _spec.ClearField(xunjiservice.FieldAPIKey, field.TypeString) } if xsuo.mutation.AgentCleared() { edge := &sqlgraph.EdgeSpec{ Rel: sqlgraph.M2O, Inverse: true, Table: xunjiservice.AgentTable, Columns: []string{xunjiservice.AgentColumn}, Bidi: false, Target: &sqlgraph.EdgeTarget{ IDSpec: sqlgraph.NewFieldSpec(agent.FieldID, field.TypeUint64), }, } _spec.Edges.Clear = append(_spec.Edges.Clear, edge) } if nodes := xsuo.mutation.AgentIDs(); len(nodes) > 0 { edge := &sqlgraph.EdgeSpec{ Rel: sqlgraph.M2O, Inverse: true, Table: xunjiservice.AgentTable, Columns: []string{xunjiservice.AgentColumn}, Bidi: false, Target: &sqlgraph.EdgeTarget{ IDSpec: sqlgraph.NewFieldSpec(agent.FieldID, field.TypeUint64), }, } for _, k := range nodes { edge.Target.Nodes = append(edge.Target.Nodes, k) } _spec.Edges.Add = append(_spec.Edges.Add, edge) } _node = &XunjiService{config: xsuo.config} _spec.Assign = _node.assignValues _spec.ScanValues = _node.scanValues if err = sqlgraph.UpdateNode(ctx, xsuo.driver, _spec); err != nil { if _, ok := err.(*sqlgraph.NotFoundError); ok { err = &NotFoundError{xunjiservice.Label} } else if sqlgraph.IsConstraintError(err) { err = &ConstraintError{msg: err.Error(), wrap: err} } return nil, err } xsuo.mutation.done = true return _node, nil }