// Code generated by ent, DO NOT EDIT. package ent import ( "context" "errors" "fmt" "time" "entgo.io/ent/dialect/sql" "entgo.io/ent/dialect/sql/sqlgraph" "entgo.io/ent/dialect/sql/sqljson" "entgo.io/ent/schema/field" "github.com/cloudreve/Cloudreve/v4/ent/oauthclient" "github.com/cloudreve/Cloudreve/v4/ent/oauthgrant" "github.com/cloudreve/Cloudreve/v4/ent/predicate" "github.com/cloudreve/Cloudreve/v4/inventory/types" ) // OAuthClientUpdate is the builder for updating OAuthClient entities. type OAuthClientUpdate struct { config hooks []Hook mutation *OAuthClientMutation } // Where appends a list predicates to the OAuthClientUpdate builder. func (ocu *OAuthClientUpdate) Where(ps ...predicate.OAuthClient) *OAuthClientUpdate { ocu.mutation.Where(ps...) return ocu } // SetUpdatedAt sets the "updated_at" field. func (ocu *OAuthClientUpdate) SetUpdatedAt(t time.Time) *OAuthClientUpdate { ocu.mutation.SetUpdatedAt(t) return ocu } // SetDeletedAt sets the "deleted_at" field. func (ocu *OAuthClientUpdate) SetDeletedAt(t time.Time) *OAuthClientUpdate { ocu.mutation.SetDeletedAt(t) return ocu } // SetNillableDeletedAt sets the "deleted_at" field if the given value is not nil. func (ocu *OAuthClientUpdate) SetNillableDeletedAt(t *time.Time) *OAuthClientUpdate { if t != nil { ocu.SetDeletedAt(*t) } return ocu } // ClearDeletedAt clears the value of the "deleted_at" field. func (ocu *OAuthClientUpdate) ClearDeletedAt() *OAuthClientUpdate { ocu.mutation.ClearDeletedAt() return ocu } // SetGUID sets the "guid" field. func (ocu *OAuthClientUpdate) SetGUID(s string) *OAuthClientUpdate { ocu.mutation.SetGUID(s) return ocu } // SetNillableGUID sets the "guid" field if the given value is not nil. func (ocu *OAuthClientUpdate) SetNillableGUID(s *string) *OAuthClientUpdate { if s != nil { ocu.SetGUID(*s) } return ocu } // SetSecret sets the "secret" field. func (ocu *OAuthClientUpdate) SetSecret(s string) *OAuthClientUpdate { ocu.mutation.SetSecret(s) return ocu } // SetNillableSecret sets the "secret" field if the given value is not nil. func (ocu *OAuthClientUpdate) SetNillableSecret(s *string) *OAuthClientUpdate { if s != nil { ocu.SetSecret(*s) } return ocu } // SetName sets the "name" field. func (ocu *OAuthClientUpdate) SetName(s string) *OAuthClientUpdate { ocu.mutation.SetName(s) return ocu } // SetNillableName sets the "name" field if the given value is not nil. func (ocu *OAuthClientUpdate) SetNillableName(s *string) *OAuthClientUpdate { if s != nil { ocu.SetName(*s) } return ocu } // SetHomepageURL sets the "homepage_url" field. func (ocu *OAuthClientUpdate) SetHomepageURL(s string) *OAuthClientUpdate { ocu.mutation.SetHomepageURL(s) return ocu } // SetNillableHomepageURL sets the "homepage_url" field if the given value is not nil. func (ocu *OAuthClientUpdate) SetNillableHomepageURL(s *string) *OAuthClientUpdate { if s != nil { ocu.SetHomepageURL(*s) } return ocu } // ClearHomepageURL clears the value of the "homepage_url" field. func (ocu *OAuthClientUpdate) ClearHomepageURL() *OAuthClientUpdate { ocu.mutation.ClearHomepageURL() return ocu } // SetRedirectUris sets the "redirect_uris" field. func (ocu *OAuthClientUpdate) SetRedirectUris(s []string) *OAuthClientUpdate { ocu.mutation.SetRedirectUris(s) return ocu } // AppendRedirectUris appends s to the "redirect_uris" field. func (ocu *OAuthClientUpdate) AppendRedirectUris(s []string) *OAuthClientUpdate { ocu.mutation.AppendRedirectUris(s) return ocu } // SetScopes sets the "scopes" field. func (ocu *OAuthClientUpdate) SetScopes(s []string) *OAuthClientUpdate { ocu.mutation.SetScopes(s) return ocu } // AppendScopes appends s to the "scopes" field. func (ocu *OAuthClientUpdate) AppendScopes(s []string) *OAuthClientUpdate { ocu.mutation.AppendScopes(s) return ocu } // SetProps sets the "props" field. func (ocu *OAuthClientUpdate) SetProps(tacp *types.OAuthClientProps) *OAuthClientUpdate { ocu.mutation.SetProps(tacp) return ocu } // SetIsEnabled sets the "is_enabled" field. func (ocu *OAuthClientUpdate) SetIsEnabled(b bool) *OAuthClientUpdate { ocu.mutation.SetIsEnabled(b) return ocu } // SetNillableIsEnabled sets the "is_enabled" field if the given value is not nil. func (ocu *OAuthClientUpdate) SetNillableIsEnabled(b *bool) *OAuthClientUpdate { if b != nil { ocu.SetIsEnabled(*b) } return ocu } // AddGrantIDs adds the "grants" edge to the OAuthGrant entity by IDs. func (ocu *OAuthClientUpdate) AddGrantIDs(ids ...int) *OAuthClientUpdate { ocu.mutation.AddGrantIDs(ids...) return ocu } // AddGrants adds the "grants" edges to the OAuthGrant entity. func (ocu *OAuthClientUpdate) AddGrants(o ...*OAuthGrant) *OAuthClientUpdate { ids := make([]int, len(o)) for i := range o { ids[i] = o[i].ID } return ocu.AddGrantIDs(ids...) } // Mutation returns the OAuthClientMutation object of the builder. func (ocu *OAuthClientUpdate) Mutation() *OAuthClientMutation { return ocu.mutation } // ClearGrants clears all "grants" edges to the OAuthGrant entity. func (ocu *OAuthClientUpdate) ClearGrants() *OAuthClientUpdate { ocu.mutation.ClearGrants() return ocu } // RemoveGrantIDs removes the "grants" edge to OAuthGrant entities by IDs. func (ocu *OAuthClientUpdate) RemoveGrantIDs(ids ...int) *OAuthClientUpdate { ocu.mutation.RemoveGrantIDs(ids...) return ocu } // RemoveGrants removes "grants" edges to OAuthGrant entities. func (ocu *OAuthClientUpdate) RemoveGrants(o ...*OAuthGrant) *OAuthClientUpdate { ids := make([]int, len(o)) for i := range o { ids[i] = o[i].ID } return ocu.RemoveGrantIDs(ids...) } // Save executes the query and returns the number of nodes affected by the update operation. func (ocu *OAuthClientUpdate) Save(ctx context.Context) (int, error) { if err := ocu.defaults(); err != nil { return 0, err } return withHooks(ctx, ocu.sqlSave, ocu.mutation, ocu.hooks) } // SaveX is like Save, but panics if an error occurs. func (ocu *OAuthClientUpdate) SaveX(ctx context.Context) int { affected, err := ocu.Save(ctx) if err != nil { panic(err) } return affected } // Exec executes the query. func (ocu *OAuthClientUpdate) Exec(ctx context.Context) error { _, err := ocu.Save(ctx) return err } // ExecX is like Exec, but panics if an error occurs. func (ocu *OAuthClientUpdate) ExecX(ctx context.Context) { if err := ocu.Exec(ctx); err != nil { panic(err) } } // defaults sets the default values of the builder before save. func (ocu *OAuthClientUpdate) defaults() error { if _, ok := ocu.mutation.UpdatedAt(); !ok { if oauthclient.UpdateDefaultUpdatedAt == nil { return fmt.Errorf("ent: uninitialized oauthclient.UpdateDefaultUpdatedAt (forgotten import ent/runtime?)") } v := oauthclient.UpdateDefaultUpdatedAt() ocu.mutation.SetUpdatedAt(v) } return nil } // check runs all checks and user-defined validators on the builder. func (ocu *OAuthClientUpdate) check() error { if v, ok := ocu.mutation.GUID(); ok { if err := oauthclient.GUIDValidator(v); err != nil { return &ValidationError{Name: "guid", err: fmt.Errorf(`ent: validator failed for field "OAuthClient.guid": %w`, err)} } } if v, ok := ocu.mutation.Secret(); ok { if err := oauthclient.SecretValidator(v); err != nil { return &ValidationError{Name: "secret", err: fmt.Errorf(`ent: validator failed for field "OAuthClient.secret": %w`, err)} } } if v, ok := ocu.mutation.Name(); ok { if err := oauthclient.NameValidator(v); err != nil { return &ValidationError{Name: "name", err: fmt.Errorf(`ent: validator failed for field "OAuthClient.name": %w`, err)} } } if v, ok := ocu.mutation.HomepageURL(); ok { if err := oauthclient.HomepageURLValidator(v); err != nil { return &ValidationError{Name: "homepage_url", err: fmt.Errorf(`ent: validator failed for field "OAuthClient.homepage_url": %w`, err)} } } return nil } func (ocu *OAuthClientUpdate) sqlSave(ctx context.Context) (n int, err error) { if err := ocu.check(); err != nil { return n, err } _spec := sqlgraph.NewUpdateSpec(oauthclient.Table, oauthclient.Columns, sqlgraph.NewFieldSpec(oauthclient.FieldID, field.TypeInt)) if ps := ocu.mutation.predicates; len(ps) > 0 { _spec.Predicate = func(selector *sql.Selector) { for i := range ps { ps[i](selector) } } } if value, ok := ocu.mutation.UpdatedAt(); ok { _spec.SetField(oauthclient.FieldUpdatedAt, field.TypeTime, value) } if value, ok := ocu.mutation.DeletedAt(); ok { _spec.SetField(oauthclient.FieldDeletedAt, field.TypeTime, value) } if ocu.mutation.DeletedAtCleared() { _spec.ClearField(oauthclient.FieldDeletedAt, field.TypeTime) } if value, ok := ocu.mutation.GUID(); ok { _spec.SetField(oauthclient.FieldGUID, field.TypeString, value) } if value, ok := ocu.mutation.Secret(); ok { _spec.SetField(oauthclient.FieldSecret, field.TypeString, value) } if value, ok := ocu.mutation.Name(); ok { _spec.SetField(oauthclient.FieldName, field.TypeString, value) } if value, ok := ocu.mutation.HomepageURL(); ok { _spec.SetField(oauthclient.FieldHomepageURL, field.TypeString, value) } if ocu.mutation.HomepageURLCleared() { _spec.ClearField(oauthclient.FieldHomepageURL, field.TypeString) } if value, ok := ocu.mutation.RedirectUris(); ok { _spec.SetField(oauthclient.FieldRedirectUris, field.TypeJSON, value) } if value, ok := ocu.mutation.AppendedRedirectUris(); ok { _spec.AddModifier(func(u *sql.UpdateBuilder) { sqljson.Append(u, oauthclient.FieldRedirectUris, value) }) } if value, ok := ocu.mutation.Scopes(); ok { _spec.SetField(oauthclient.FieldScopes, field.TypeJSON, value) } if value, ok := ocu.mutation.AppendedScopes(); ok { _spec.AddModifier(func(u *sql.UpdateBuilder) { sqljson.Append(u, oauthclient.FieldScopes, value) }) } if value, ok := ocu.mutation.Props(); ok { _spec.SetField(oauthclient.FieldProps, field.TypeJSON, value) } if value, ok := ocu.mutation.IsEnabled(); ok { _spec.SetField(oauthclient.FieldIsEnabled, field.TypeBool, value) } if ocu.mutation.GrantsCleared() { edge := &sqlgraph.EdgeSpec{ Rel: sqlgraph.O2M, Inverse: false, Table: oauthclient.GrantsTable, Columns: []string{oauthclient.GrantsColumn}, Bidi: false, Target: &sqlgraph.EdgeTarget{ IDSpec: sqlgraph.NewFieldSpec(oauthgrant.FieldID, field.TypeInt), }, } _spec.Edges.Clear = append(_spec.Edges.Clear, edge) } if nodes := ocu.mutation.RemovedGrantsIDs(); len(nodes) > 0 && !ocu.mutation.GrantsCleared() { edge := &sqlgraph.EdgeSpec{ Rel: sqlgraph.O2M, Inverse: false, Table: oauthclient.GrantsTable, Columns: []string{oauthclient.GrantsColumn}, Bidi: false, Target: &sqlgraph.EdgeTarget{ IDSpec: sqlgraph.NewFieldSpec(oauthgrant.FieldID, field.TypeInt), }, } for _, k := range nodes { edge.Target.Nodes = append(edge.Target.Nodes, k) } _spec.Edges.Clear = append(_spec.Edges.Clear, edge) } if nodes := ocu.mutation.GrantsIDs(); len(nodes) > 0 { edge := &sqlgraph.EdgeSpec{ Rel: sqlgraph.O2M, Inverse: false, Table: oauthclient.GrantsTable, Columns: []string{oauthclient.GrantsColumn}, Bidi: false, Target: &sqlgraph.EdgeTarget{ IDSpec: sqlgraph.NewFieldSpec(oauthgrant.FieldID, field.TypeInt), }, } 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, ocu.driver, _spec); err != nil { if _, ok := err.(*sqlgraph.NotFoundError); ok { err = &NotFoundError{oauthclient.Label} } else if sqlgraph.IsConstraintError(err) { err = &ConstraintError{msg: err.Error(), wrap: err} } return 0, err } ocu.mutation.done = true return n, nil } // OAuthClientUpdateOne is the builder for updating a single OAuthClient entity. type OAuthClientUpdateOne struct { config fields []string hooks []Hook mutation *OAuthClientMutation } // SetUpdatedAt sets the "updated_at" field. func (ocuo *OAuthClientUpdateOne) SetUpdatedAt(t time.Time) *OAuthClientUpdateOne { ocuo.mutation.SetUpdatedAt(t) return ocuo } // SetDeletedAt sets the "deleted_at" field. func (ocuo *OAuthClientUpdateOne) SetDeletedAt(t time.Time) *OAuthClientUpdateOne { ocuo.mutation.SetDeletedAt(t) return ocuo } // SetNillableDeletedAt sets the "deleted_at" field if the given value is not nil. func (ocuo *OAuthClientUpdateOne) SetNillableDeletedAt(t *time.Time) *OAuthClientUpdateOne { if t != nil { ocuo.SetDeletedAt(*t) } return ocuo } // ClearDeletedAt clears the value of the "deleted_at" field. func (ocuo *OAuthClientUpdateOne) ClearDeletedAt() *OAuthClientUpdateOne { ocuo.mutation.ClearDeletedAt() return ocuo } // SetGUID sets the "guid" field. func (ocuo *OAuthClientUpdateOne) SetGUID(s string) *OAuthClientUpdateOne { ocuo.mutation.SetGUID(s) return ocuo } // SetNillableGUID sets the "guid" field if the given value is not nil. func (ocuo *OAuthClientUpdateOne) SetNillableGUID(s *string) *OAuthClientUpdateOne { if s != nil { ocuo.SetGUID(*s) } return ocuo } // SetSecret sets the "secret" field. func (ocuo *OAuthClientUpdateOne) SetSecret(s string) *OAuthClientUpdateOne { ocuo.mutation.SetSecret(s) return ocuo } // SetNillableSecret sets the "secret" field if the given value is not nil. func (ocuo *OAuthClientUpdateOne) SetNillableSecret(s *string) *OAuthClientUpdateOne { if s != nil { ocuo.SetSecret(*s) } return ocuo } // SetName sets the "name" field. func (ocuo *OAuthClientUpdateOne) SetName(s string) *OAuthClientUpdateOne { ocuo.mutation.SetName(s) return ocuo } // SetNillableName sets the "name" field if the given value is not nil. func (ocuo *OAuthClientUpdateOne) SetNillableName(s *string) *OAuthClientUpdateOne { if s != nil { ocuo.SetName(*s) } return ocuo } // SetHomepageURL sets the "homepage_url" field. func (ocuo *OAuthClientUpdateOne) SetHomepageURL(s string) *OAuthClientUpdateOne { ocuo.mutation.SetHomepageURL(s) return ocuo } // SetNillableHomepageURL sets the "homepage_url" field if the given value is not nil. func (ocuo *OAuthClientUpdateOne) SetNillableHomepageURL(s *string) *OAuthClientUpdateOne { if s != nil { ocuo.SetHomepageURL(*s) } return ocuo } // ClearHomepageURL clears the value of the "homepage_url" field. func (ocuo *OAuthClientUpdateOne) ClearHomepageURL() *OAuthClientUpdateOne { ocuo.mutation.ClearHomepageURL() return ocuo } // SetRedirectUris sets the "redirect_uris" field. func (ocuo *OAuthClientUpdateOne) SetRedirectUris(s []string) *OAuthClientUpdateOne { ocuo.mutation.SetRedirectUris(s) return ocuo } // AppendRedirectUris appends s to the "redirect_uris" field. func (ocuo *OAuthClientUpdateOne) AppendRedirectUris(s []string) *OAuthClientUpdateOne { ocuo.mutation.AppendRedirectUris(s) return ocuo } // SetScopes sets the "scopes" field. func (ocuo *OAuthClientUpdateOne) SetScopes(s []string) *OAuthClientUpdateOne { ocuo.mutation.SetScopes(s) return ocuo } // AppendScopes appends s to the "scopes" field. func (ocuo *OAuthClientUpdateOne) AppendScopes(s []string) *OAuthClientUpdateOne { ocuo.mutation.AppendScopes(s) return ocuo } // SetProps sets the "props" field. func (ocuo *OAuthClientUpdateOne) SetProps(tacp *types.OAuthClientProps) *OAuthClientUpdateOne { ocuo.mutation.SetProps(tacp) return ocuo } // SetIsEnabled sets the "is_enabled" field. func (ocuo *OAuthClientUpdateOne) SetIsEnabled(b bool) *OAuthClientUpdateOne { ocuo.mutation.SetIsEnabled(b) return ocuo } // SetNillableIsEnabled sets the "is_enabled" field if the given value is not nil. func (ocuo *OAuthClientUpdateOne) SetNillableIsEnabled(b *bool) *OAuthClientUpdateOne { if b != nil { ocuo.SetIsEnabled(*b) } return ocuo } // AddGrantIDs adds the "grants" edge to the OAuthGrant entity by IDs. func (ocuo *OAuthClientUpdateOne) AddGrantIDs(ids ...int) *OAuthClientUpdateOne { ocuo.mutation.AddGrantIDs(ids...) return ocuo } // AddGrants adds the "grants" edges to the OAuthGrant entity. func (ocuo *OAuthClientUpdateOne) AddGrants(o ...*OAuthGrant) *OAuthClientUpdateOne { ids := make([]int, len(o)) for i := range o { ids[i] = o[i].ID } return ocuo.AddGrantIDs(ids...) } // Mutation returns the OAuthClientMutation object of the builder. func (ocuo *OAuthClientUpdateOne) Mutation() *OAuthClientMutation { return ocuo.mutation } // ClearGrants clears all "grants" edges to the OAuthGrant entity. func (ocuo *OAuthClientUpdateOne) ClearGrants() *OAuthClientUpdateOne { ocuo.mutation.ClearGrants() return ocuo } // RemoveGrantIDs removes the "grants" edge to OAuthGrant entities by IDs. func (ocuo *OAuthClientUpdateOne) RemoveGrantIDs(ids ...int) *OAuthClientUpdateOne { ocuo.mutation.RemoveGrantIDs(ids...) return ocuo } // RemoveGrants removes "grants" edges to OAuthGrant entities. func (ocuo *OAuthClientUpdateOne) RemoveGrants(o ...*OAuthGrant) *OAuthClientUpdateOne { ids := make([]int, len(o)) for i := range o { ids[i] = o[i].ID } return ocuo.RemoveGrantIDs(ids...) } // Where appends a list predicates to the OAuthClientUpdate builder. func (ocuo *OAuthClientUpdateOne) Where(ps ...predicate.OAuthClient) *OAuthClientUpdateOne { ocuo.mutation.Where(ps...) return ocuo } // Select allows selecting one or more fields (columns) of the returned entity. // The default is selecting all fields defined in the entity schema. func (ocuo *OAuthClientUpdateOne) Select(field string, fields ...string) *OAuthClientUpdateOne { ocuo.fields = append([]string{field}, fields...) return ocuo } // Save executes the query and returns the updated OAuthClient entity. func (ocuo *OAuthClientUpdateOne) Save(ctx context.Context) (*OAuthClient, error) { if err := ocuo.defaults(); err != nil { return nil, err } return withHooks(ctx, ocuo.sqlSave, ocuo.mutation, ocuo.hooks) } // SaveX is like Save, but panics if an error occurs. func (ocuo *OAuthClientUpdateOne) SaveX(ctx context.Context) *OAuthClient { node, err := ocuo.Save(ctx) if err != nil { panic(err) } return node } // Exec executes the query on the entity. func (ocuo *OAuthClientUpdateOne) Exec(ctx context.Context) error { _, err := ocuo.Save(ctx) return err } // ExecX is like Exec, but panics if an error occurs. func (ocuo *OAuthClientUpdateOne) ExecX(ctx context.Context) { if err := ocuo.Exec(ctx); err != nil { panic(err) } } // defaults sets the default values of the builder before save. func (ocuo *OAuthClientUpdateOne) defaults() error { if _, ok := ocuo.mutation.UpdatedAt(); !ok { if oauthclient.UpdateDefaultUpdatedAt == nil { return fmt.Errorf("ent: uninitialized oauthclient.UpdateDefaultUpdatedAt (forgotten import ent/runtime?)") } v := oauthclient.UpdateDefaultUpdatedAt() ocuo.mutation.SetUpdatedAt(v) } return nil } // check runs all checks and user-defined validators on the builder. func (ocuo *OAuthClientUpdateOne) check() error { if v, ok := ocuo.mutation.GUID(); ok { if err := oauthclient.GUIDValidator(v); err != nil { return &ValidationError{Name: "guid", err: fmt.Errorf(`ent: validator failed for field "OAuthClient.guid": %w`, err)} } } if v, ok := ocuo.mutation.Secret(); ok { if err := oauthclient.SecretValidator(v); err != nil { return &ValidationError{Name: "secret", err: fmt.Errorf(`ent: validator failed for field "OAuthClient.secret": %w`, err)} } } if v, ok := ocuo.mutation.Name(); ok { if err := oauthclient.NameValidator(v); err != nil { return &ValidationError{Name: "name", err: fmt.Errorf(`ent: validator failed for field "OAuthClient.name": %w`, err)} } } if v, ok := ocuo.mutation.HomepageURL(); ok { if err := oauthclient.HomepageURLValidator(v); err != nil { return &ValidationError{Name: "homepage_url", err: fmt.Errorf(`ent: validator failed for field "OAuthClient.homepage_url": %w`, err)} } } return nil } func (ocuo *OAuthClientUpdateOne) sqlSave(ctx context.Context) (_node *OAuthClient, err error) { if err := ocuo.check(); err != nil { return _node, err } _spec := sqlgraph.NewUpdateSpec(oauthclient.Table, oauthclient.Columns, sqlgraph.NewFieldSpec(oauthclient.FieldID, field.TypeInt)) id, ok := ocuo.mutation.ID() if !ok { return nil, &ValidationError{Name: "id", err: errors.New(`ent: missing "OAuthClient.id" for update`)} } _spec.Node.ID.Value = id if fields := ocuo.fields; len(fields) > 0 { _spec.Node.Columns = make([]string, 0, len(fields)) _spec.Node.Columns = append(_spec.Node.Columns, oauthclient.FieldID) for _, f := range fields { if !oauthclient.ValidColumn(f) { return nil, &ValidationError{Name: f, err: fmt.Errorf("ent: invalid field %q for query", f)} } if f != oauthclient.FieldID { _spec.Node.Columns = append(_spec.Node.Columns, f) } } } if ps := ocuo.mutation.predicates; len(ps) > 0 { _spec.Predicate = func(selector *sql.Selector) { for i := range ps { ps[i](selector) } } } if value, ok := ocuo.mutation.UpdatedAt(); ok { _spec.SetField(oauthclient.FieldUpdatedAt, field.TypeTime, value) } if value, ok := ocuo.mutation.DeletedAt(); ok { _spec.SetField(oauthclient.FieldDeletedAt, field.TypeTime, value) } if ocuo.mutation.DeletedAtCleared() { _spec.ClearField(oauthclient.FieldDeletedAt, field.TypeTime) } if value, ok := ocuo.mutation.GUID(); ok { _spec.SetField(oauthclient.FieldGUID, field.TypeString, value) } if value, ok := ocuo.mutation.Secret(); ok { _spec.SetField(oauthclient.FieldSecret, field.TypeString, value) } if value, ok := ocuo.mutation.Name(); ok { _spec.SetField(oauthclient.FieldName, field.TypeString, value) } if value, ok := ocuo.mutation.HomepageURL(); ok { _spec.SetField(oauthclient.FieldHomepageURL, field.TypeString, value) } if ocuo.mutation.HomepageURLCleared() { _spec.ClearField(oauthclient.FieldHomepageURL, field.TypeString) } if value, ok := ocuo.mutation.RedirectUris(); ok { _spec.SetField(oauthclient.FieldRedirectUris, field.TypeJSON, value) } if value, ok := ocuo.mutation.AppendedRedirectUris(); ok { _spec.AddModifier(func(u *sql.UpdateBuilder) { sqljson.Append(u, oauthclient.FieldRedirectUris, value) }) } if value, ok := ocuo.mutation.Scopes(); ok { _spec.SetField(oauthclient.FieldScopes, field.TypeJSON, value) } if value, ok := ocuo.mutation.AppendedScopes(); ok { _spec.AddModifier(func(u *sql.UpdateBuilder) { sqljson.Append(u, oauthclient.FieldScopes, value) }) } if value, ok := ocuo.mutation.Props(); ok { _spec.SetField(oauthclient.FieldProps, field.TypeJSON, value) } if value, ok := ocuo.mutation.IsEnabled(); ok { _spec.SetField(oauthclient.FieldIsEnabled, field.TypeBool, value) } if ocuo.mutation.GrantsCleared() { edge := &sqlgraph.EdgeSpec{ Rel: sqlgraph.O2M, Inverse: false, Table: oauthclient.GrantsTable, Columns: []string{oauthclient.GrantsColumn}, Bidi: false, Target: &sqlgraph.EdgeTarget{ IDSpec: sqlgraph.NewFieldSpec(oauthgrant.FieldID, field.TypeInt), }, } _spec.Edges.Clear = append(_spec.Edges.Clear, edge) } if nodes := ocuo.mutation.RemovedGrantsIDs(); len(nodes) > 0 && !ocuo.mutation.GrantsCleared() { edge := &sqlgraph.EdgeSpec{ Rel: sqlgraph.O2M, Inverse: false, Table: oauthclient.GrantsTable, Columns: []string{oauthclient.GrantsColumn}, Bidi: false, Target: &sqlgraph.EdgeTarget{ IDSpec: sqlgraph.NewFieldSpec(oauthgrant.FieldID, field.TypeInt), }, } for _, k := range nodes { edge.Target.Nodes = append(edge.Target.Nodes, k) } _spec.Edges.Clear = append(_spec.Edges.Clear, edge) } if nodes := ocuo.mutation.GrantsIDs(); len(nodes) > 0 { edge := &sqlgraph.EdgeSpec{ Rel: sqlgraph.O2M, Inverse: false, Table: oauthclient.GrantsTable, Columns: []string{oauthclient.GrantsColumn}, Bidi: false, Target: &sqlgraph.EdgeTarget{ IDSpec: sqlgraph.NewFieldSpec(oauthgrant.FieldID, field.TypeInt), }, } for _, k := range nodes { edge.Target.Nodes = append(edge.Target.Nodes, k) } _spec.Edges.Add = append(_spec.Edges.Add, edge) } _node = &OAuthClient{config: ocuo.config} _spec.Assign = _node.assignValues _spec.ScanValues = _node.scanValues if err = sqlgraph.UpdateNode(ctx, ocuo.driver, _spec); err != nil { if _, ok := err.(*sqlgraph.NotFoundError); ok { err = &NotFoundError{oauthclient.Label} } else if sqlgraph.IsConstraintError(err) { err = &ConstraintError{msg: err.Error(), wrap: err} } return nil, err } ocuo.mutation.done = true return _node, nil }