| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923 |
- // 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/schema/field"
- "github.com/Wei-Shaw/sub2api/ent/authidentity"
- "github.com/Wei-Shaw/sub2api/ent/authidentitychannel"
- "github.com/Wei-Shaw/sub2api/ent/identityadoptiondecision"
- "github.com/Wei-Shaw/sub2api/ent/predicate"
- "github.com/Wei-Shaw/sub2api/ent/user"
- )
- // AuthIdentityUpdate is the builder for updating AuthIdentity entities.
- type AuthIdentityUpdate struct {
- config
- hooks []Hook
- mutation *AuthIdentityMutation
- }
- // Where appends a list predicates to the AuthIdentityUpdate builder.
- func (_u *AuthIdentityUpdate) Where(ps ...predicate.AuthIdentity) *AuthIdentityUpdate {
- _u.mutation.Where(ps...)
- return _u
- }
- // SetUpdatedAt sets the "updated_at" field.
- func (_u *AuthIdentityUpdate) SetUpdatedAt(v time.Time) *AuthIdentityUpdate {
- _u.mutation.SetUpdatedAt(v)
- return _u
- }
- // SetUserID sets the "user_id" field.
- func (_u *AuthIdentityUpdate) SetUserID(v int64) *AuthIdentityUpdate {
- _u.mutation.SetUserID(v)
- return _u
- }
- // SetNillableUserID sets the "user_id" field if the given value is not nil.
- func (_u *AuthIdentityUpdate) SetNillableUserID(v *int64) *AuthIdentityUpdate {
- if v != nil {
- _u.SetUserID(*v)
- }
- return _u
- }
- // SetProviderType sets the "provider_type" field.
- func (_u *AuthIdentityUpdate) SetProviderType(v string) *AuthIdentityUpdate {
- _u.mutation.SetProviderType(v)
- return _u
- }
- // SetNillableProviderType sets the "provider_type" field if the given value is not nil.
- func (_u *AuthIdentityUpdate) SetNillableProviderType(v *string) *AuthIdentityUpdate {
- if v != nil {
- _u.SetProviderType(*v)
- }
- return _u
- }
- // SetProviderKey sets the "provider_key" field.
- func (_u *AuthIdentityUpdate) SetProviderKey(v string) *AuthIdentityUpdate {
- _u.mutation.SetProviderKey(v)
- return _u
- }
- // SetNillableProviderKey sets the "provider_key" field if the given value is not nil.
- func (_u *AuthIdentityUpdate) SetNillableProviderKey(v *string) *AuthIdentityUpdate {
- if v != nil {
- _u.SetProviderKey(*v)
- }
- return _u
- }
- // SetProviderSubject sets the "provider_subject" field.
- func (_u *AuthIdentityUpdate) SetProviderSubject(v string) *AuthIdentityUpdate {
- _u.mutation.SetProviderSubject(v)
- return _u
- }
- // SetNillableProviderSubject sets the "provider_subject" field if the given value is not nil.
- func (_u *AuthIdentityUpdate) SetNillableProviderSubject(v *string) *AuthIdentityUpdate {
- if v != nil {
- _u.SetProviderSubject(*v)
- }
- return _u
- }
- // SetVerifiedAt sets the "verified_at" field.
- func (_u *AuthIdentityUpdate) SetVerifiedAt(v time.Time) *AuthIdentityUpdate {
- _u.mutation.SetVerifiedAt(v)
- return _u
- }
- // SetNillableVerifiedAt sets the "verified_at" field if the given value is not nil.
- func (_u *AuthIdentityUpdate) SetNillableVerifiedAt(v *time.Time) *AuthIdentityUpdate {
- if v != nil {
- _u.SetVerifiedAt(*v)
- }
- return _u
- }
- // ClearVerifiedAt clears the value of the "verified_at" field.
- func (_u *AuthIdentityUpdate) ClearVerifiedAt() *AuthIdentityUpdate {
- _u.mutation.ClearVerifiedAt()
- return _u
- }
- // SetIssuer sets the "issuer" field.
- func (_u *AuthIdentityUpdate) SetIssuer(v string) *AuthIdentityUpdate {
- _u.mutation.SetIssuer(v)
- return _u
- }
- // SetNillableIssuer sets the "issuer" field if the given value is not nil.
- func (_u *AuthIdentityUpdate) SetNillableIssuer(v *string) *AuthIdentityUpdate {
- if v != nil {
- _u.SetIssuer(*v)
- }
- return _u
- }
- // ClearIssuer clears the value of the "issuer" field.
- func (_u *AuthIdentityUpdate) ClearIssuer() *AuthIdentityUpdate {
- _u.mutation.ClearIssuer()
- return _u
- }
- // SetMetadata sets the "metadata" field.
- func (_u *AuthIdentityUpdate) SetMetadata(v map[string]interface{}) *AuthIdentityUpdate {
- _u.mutation.SetMetadata(v)
- return _u
- }
- // SetUser sets the "user" edge to the User entity.
- func (_u *AuthIdentityUpdate) SetUser(v *User) *AuthIdentityUpdate {
- return _u.SetUserID(v.ID)
- }
- // AddChannelIDs adds the "channels" edge to the AuthIdentityChannel entity by IDs.
- func (_u *AuthIdentityUpdate) AddChannelIDs(ids ...int64) *AuthIdentityUpdate {
- _u.mutation.AddChannelIDs(ids...)
- return _u
- }
- // AddChannels adds the "channels" edges to the AuthIdentityChannel entity.
- func (_u *AuthIdentityUpdate) AddChannels(v ...*AuthIdentityChannel) *AuthIdentityUpdate {
- ids := make([]int64, len(v))
- for i := range v {
- ids[i] = v[i].ID
- }
- return _u.AddChannelIDs(ids...)
- }
- // AddAdoptionDecisionIDs adds the "adoption_decisions" edge to the IdentityAdoptionDecision entity by IDs.
- func (_u *AuthIdentityUpdate) AddAdoptionDecisionIDs(ids ...int64) *AuthIdentityUpdate {
- _u.mutation.AddAdoptionDecisionIDs(ids...)
- return _u
- }
- // AddAdoptionDecisions adds the "adoption_decisions" edges to the IdentityAdoptionDecision entity.
- func (_u *AuthIdentityUpdate) AddAdoptionDecisions(v ...*IdentityAdoptionDecision) *AuthIdentityUpdate {
- ids := make([]int64, len(v))
- for i := range v {
- ids[i] = v[i].ID
- }
- return _u.AddAdoptionDecisionIDs(ids...)
- }
- // Mutation returns the AuthIdentityMutation object of the builder.
- func (_u *AuthIdentityUpdate) Mutation() *AuthIdentityMutation {
- return _u.mutation
- }
- // ClearUser clears the "user" edge to the User entity.
- func (_u *AuthIdentityUpdate) ClearUser() *AuthIdentityUpdate {
- _u.mutation.ClearUser()
- return _u
- }
- // ClearChannels clears all "channels" edges to the AuthIdentityChannel entity.
- func (_u *AuthIdentityUpdate) ClearChannels() *AuthIdentityUpdate {
- _u.mutation.ClearChannels()
- return _u
- }
- // RemoveChannelIDs removes the "channels" edge to AuthIdentityChannel entities by IDs.
- func (_u *AuthIdentityUpdate) RemoveChannelIDs(ids ...int64) *AuthIdentityUpdate {
- _u.mutation.RemoveChannelIDs(ids...)
- return _u
- }
- // RemoveChannels removes "channels" edges to AuthIdentityChannel entities.
- func (_u *AuthIdentityUpdate) RemoveChannels(v ...*AuthIdentityChannel) *AuthIdentityUpdate {
- ids := make([]int64, len(v))
- for i := range v {
- ids[i] = v[i].ID
- }
- return _u.RemoveChannelIDs(ids...)
- }
- // ClearAdoptionDecisions clears all "adoption_decisions" edges to the IdentityAdoptionDecision entity.
- func (_u *AuthIdentityUpdate) ClearAdoptionDecisions() *AuthIdentityUpdate {
- _u.mutation.ClearAdoptionDecisions()
- return _u
- }
- // RemoveAdoptionDecisionIDs removes the "adoption_decisions" edge to IdentityAdoptionDecision entities by IDs.
- func (_u *AuthIdentityUpdate) RemoveAdoptionDecisionIDs(ids ...int64) *AuthIdentityUpdate {
- _u.mutation.RemoveAdoptionDecisionIDs(ids...)
- return _u
- }
- // RemoveAdoptionDecisions removes "adoption_decisions" edges to IdentityAdoptionDecision entities.
- func (_u *AuthIdentityUpdate) RemoveAdoptionDecisions(v ...*IdentityAdoptionDecision) *AuthIdentityUpdate {
- ids := make([]int64, len(v))
- for i := range v {
- ids[i] = v[i].ID
- }
- return _u.RemoveAdoptionDecisionIDs(ids...)
- }
- // Save executes the query and returns the number of nodes affected by the update operation.
- func (_u *AuthIdentityUpdate) Save(ctx context.Context) (int, error) {
- _u.defaults()
- return withHooks(ctx, _u.sqlSave, _u.mutation, _u.hooks)
- }
- // SaveX is like Save, but panics if an error occurs.
- func (_u *AuthIdentityUpdate) SaveX(ctx context.Context) int {
- affected, err := _u.Save(ctx)
- if err != nil {
- panic(err)
- }
- return affected
- }
- // Exec executes the query.
- func (_u *AuthIdentityUpdate) Exec(ctx context.Context) error {
- _, err := _u.Save(ctx)
- return err
- }
- // ExecX is like Exec, but panics if an error occurs.
- func (_u *AuthIdentityUpdate) ExecX(ctx context.Context) {
- if err := _u.Exec(ctx); err != nil {
- panic(err)
- }
- }
- // defaults sets the default values of the builder before save.
- func (_u *AuthIdentityUpdate) defaults() {
- if _, ok := _u.mutation.UpdatedAt(); !ok {
- v := authidentity.UpdateDefaultUpdatedAt()
- _u.mutation.SetUpdatedAt(v)
- }
- }
- // check runs all checks and user-defined validators on the builder.
- func (_u *AuthIdentityUpdate) check() error {
- if v, ok := _u.mutation.ProviderType(); ok {
- if err := authidentity.ProviderTypeValidator(v); err != nil {
- return &ValidationError{Name: "provider_type", err: fmt.Errorf(`ent: validator failed for field "AuthIdentity.provider_type": %w`, err)}
- }
- }
- if v, ok := _u.mutation.ProviderKey(); ok {
- if err := authidentity.ProviderKeyValidator(v); err != nil {
- return &ValidationError{Name: "provider_key", err: fmt.Errorf(`ent: validator failed for field "AuthIdentity.provider_key": %w`, err)}
- }
- }
- if v, ok := _u.mutation.ProviderSubject(); ok {
- if err := authidentity.ProviderSubjectValidator(v); err != nil {
- return &ValidationError{Name: "provider_subject", err: fmt.Errorf(`ent: validator failed for field "AuthIdentity.provider_subject": %w`, err)}
- }
- }
- if _u.mutation.UserCleared() && len(_u.mutation.UserIDs()) > 0 {
- return errors.New(`ent: clearing a required unique edge "AuthIdentity.user"`)
- }
- return nil
- }
- func (_u *AuthIdentityUpdate) sqlSave(ctx context.Context) (_node int, err error) {
- if err := _u.check(); err != nil {
- return _node, err
- }
- _spec := sqlgraph.NewUpdateSpec(authidentity.Table, authidentity.Columns, sqlgraph.NewFieldSpec(authidentity.FieldID, field.TypeInt64))
- if ps := _u.mutation.predicates; len(ps) > 0 {
- _spec.Predicate = func(selector *sql.Selector) {
- for i := range ps {
- ps[i](selector)
- }
- }
- }
- if value, ok := _u.mutation.UpdatedAt(); ok {
- _spec.SetField(authidentity.FieldUpdatedAt, field.TypeTime, value)
- }
- if value, ok := _u.mutation.ProviderType(); ok {
- _spec.SetField(authidentity.FieldProviderType, field.TypeString, value)
- }
- if value, ok := _u.mutation.ProviderKey(); ok {
- _spec.SetField(authidentity.FieldProviderKey, field.TypeString, value)
- }
- if value, ok := _u.mutation.ProviderSubject(); ok {
- _spec.SetField(authidentity.FieldProviderSubject, field.TypeString, value)
- }
- if value, ok := _u.mutation.VerifiedAt(); ok {
- _spec.SetField(authidentity.FieldVerifiedAt, field.TypeTime, value)
- }
- if _u.mutation.VerifiedAtCleared() {
- _spec.ClearField(authidentity.FieldVerifiedAt, field.TypeTime)
- }
- if value, ok := _u.mutation.Issuer(); ok {
- _spec.SetField(authidentity.FieldIssuer, field.TypeString, value)
- }
- if _u.mutation.IssuerCleared() {
- _spec.ClearField(authidentity.FieldIssuer, field.TypeString)
- }
- if value, ok := _u.mutation.Metadata(); ok {
- _spec.SetField(authidentity.FieldMetadata, field.TypeJSON, value)
- }
- if _u.mutation.UserCleared() {
- edge := &sqlgraph.EdgeSpec{
- Rel: sqlgraph.M2O,
- Inverse: true,
- Table: authidentity.UserTable,
- Columns: []string{authidentity.UserColumn},
- Bidi: false,
- Target: &sqlgraph.EdgeTarget{
- IDSpec: sqlgraph.NewFieldSpec(user.FieldID, field.TypeInt64),
- },
- }
- _spec.Edges.Clear = append(_spec.Edges.Clear, edge)
- }
- if nodes := _u.mutation.UserIDs(); len(nodes) > 0 {
- edge := &sqlgraph.EdgeSpec{
- Rel: sqlgraph.M2O,
- Inverse: true,
- Table: authidentity.UserTable,
- Columns: []string{authidentity.UserColumn},
- Bidi: false,
- Target: &sqlgraph.EdgeTarget{
- IDSpec: sqlgraph.NewFieldSpec(user.FieldID, field.TypeInt64),
- },
- }
- for _, k := range nodes {
- edge.Target.Nodes = append(edge.Target.Nodes, k)
- }
- _spec.Edges.Add = append(_spec.Edges.Add, edge)
- }
- if _u.mutation.ChannelsCleared() {
- edge := &sqlgraph.EdgeSpec{
- Rel: sqlgraph.O2M,
- Inverse: false,
- Table: authidentity.ChannelsTable,
- Columns: []string{authidentity.ChannelsColumn},
- Bidi: false,
- Target: &sqlgraph.EdgeTarget{
- IDSpec: sqlgraph.NewFieldSpec(authidentitychannel.FieldID, field.TypeInt64),
- },
- }
- _spec.Edges.Clear = append(_spec.Edges.Clear, edge)
- }
- if nodes := _u.mutation.RemovedChannelsIDs(); len(nodes) > 0 && !_u.mutation.ChannelsCleared() {
- edge := &sqlgraph.EdgeSpec{
- Rel: sqlgraph.O2M,
- Inverse: false,
- Table: authidentity.ChannelsTable,
- Columns: []string{authidentity.ChannelsColumn},
- Bidi: false,
- Target: &sqlgraph.EdgeTarget{
- IDSpec: sqlgraph.NewFieldSpec(authidentitychannel.FieldID, field.TypeInt64),
- },
- }
- for _, k := range nodes {
- edge.Target.Nodes = append(edge.Target.Nodes, k)
- }
- _spec.Edges.Clear = append(_spec.Edges.Clear, edge)
- }
- if nodes := _u.mutation.ChannelsIDs(); len(nodes) > 0 {
- edge := &sqlgraph.EdgeSpec{
- Rel: sqlgraph.O2M,
- Inverse: false,
- Table: authidentity.ChannelsTable,
- Columns: []string{authidentity.ChannelsColumn},
- Bidi: false,
- Target: &sqlgraph.EdgeTarget{
- IDSpec: sqlgraph.NewFieldSpec(authidentitychannel.FieldID, field.TypeInt64),
- },
- }
- for _, k := range nodes {
- edge.Target.Nodes = append(edge.Target.Nodes, k)
- }
- _spec.Edges.Add = append(_spec.Edges.Add, edge)
- }
- if _u.mutation.AdoptionDecisionsCleared() {
- edge := &sqlgraph.EdgeSpec{
- Rel: sqlgraph.O2M,
- Inverse: false,
- Table: authidentity.AdoptionDecisionsTable,
- Columns: []string{authidentity.AdoptionDecisionsColumn},
- Bidi: false,
- Target: &sqlgraph.EdgeTarget{
- IDSpec: sqlgraph.NewFieldSpec(identityadoptiondecision.FieldID, field.TypeInt64),
- },
- }
- _spec.Edges.Clear = append(_spec.Edges.Clear, edge)
- }
- if nodes := _u.mutation.RemovedAdoptionDecisionsIDs(); len(nodes) > 0 && !_u.mutation.AdoptionDecisionsCleared() {
- edge := &sqlgraph.EdgeSpec{
- Rel: sqlgraph.O2M,
- Inverse: false,
- Table: authidentity.AdoptionDecisionsTable,
- Columns: []string{authidentity.AdoptionDecisionsColumn},
- Bidi: false,
- Target: &sqlgraph.EdgeTarget{
- IDSpec: sqlgraph.NewFieldSpec(identityadoptiondecision.FieldID, field.TypeInt64),
- },
- }
- for _, k := range nodes {
- edge.Target.Nodes = append(edge.Target.Nodes, k)
- }
- _spec.Edges.Clear = append(_spec.Edges.Clear, edge)
- }
- if nodes := _u.mutation.AdoptionDecisionsIDs(); len(nodes) > 0 {
- edge := &sqlgraph.EdgeSpec{
- Rel: sqlgraph.O2M,
- Inverse: false,
- Table: authidentity.AdoptionDecisionsTable,
- Columns: []string{authidentity.AdoptionDecisionsColumn},
- Bidi: false,
- Target: &sqlgraph.EdgeTarget{
- IDSpec: sqlgraph.NewFieldSpec(identityadoptiondecision.FieldID, field.TypeInt64),
- },
- }
- for _, k := range nodes {
- edge.Target.Nodes = append(edge.Target.Nodes, k)
- }
- _spec.Edges.Add = append(_spec.Edges.Add, edge)
- }
- if _node, err = sqlgraph.UpdateNodes(ctx, _u.driver, _spec); err != nil {
- if _, ok := err.(*sqlgraph.NotFoundError); ok {
- err = &NotFoundError{authidentity.Label}
- } else if sqlgraph.IsConstraintError(err) {
- err = &ConstraintError{msg: err.Error(), wrap: err}
- }
- return 0, err
- }
- _u.mutation.done = true
- return _node, nil
- }
- // AuthIdentityUpdateOne is the builder for updating a single AuthIdentity entity.
- type AuthIdentityUpdateOne struct {
- config
- fields []string
- hooks []Hook
- mutation *AuthIdentityMutation
- }
- // SetUpdatedAt sets the "updated_at" field.
- func (_u *AuthIdentityUpdateOne) SetUpdatedAt(v time.Time) *AuthIdentityUpdateOne {
- _u.mutation.SetUpdatedAt(v)
- return _u
- }
- // SetUserID sets the "user_id" field.
- func (_u *AuthIdentityUpdateOne) SetUserID(v int64) *AuthIdentityUpdateOne {
- _u.mutation.SetUserID(v)
- return _u
- }
- // SetNillableUserID sets the "user_id" field if the given value is not nil.
- func (_u *AuthIdentityUpdateOne) SetNillableUserID(v *int64) *AuthIdentityUpdateOne {
- if v != nil {
- _u.SetUserID(*v)
- }
- return _u
- }
- // SetProviderType sets the "provider_type" field.
- func (_u *AuthIdentityUpdateOne) SetProviderType(v string) *AuthIdentityUpdateOne {
- _u.mutation.SetProviderType(v)
- return _u
- }
- // SetNillableProviderType sets the "provider_type" field if the given value is not nil.
- func (_u *AuthIdentityUpdateOne) SetNillableProviderType(v *string) *AuthIdentityUpdateOne {
- if v != nil {
- _u.SetProviderType(*v)
- }
- return _u
- }
- // SetProviderKey sets the "provider_key" field.
- func (_u *AuthIdentityUpdateOne) SetProviderKey(v string) *AuthIdentityUpdateOne {
- _u.mutation.SetProviderKey(v)
- return _u
- }
- // SetNillableProviderKey sets the "provider_key" field if the given value is not nil.
- func (_u *AuthIdentityUpdateOne) SetNillableProviderKey(v *string) *AuthIdentityUpdateOne {
- if v != nil {
- _u.SetProviderKey(*v)
- }
- return _u
- }
- // SetProviderSubject sets the "provider_subject" field.
- func (_u *AuthIdentityUpdateOne) SetProviderSubject(v string) *AuthIdentityUpdateOne {
- _u.mutation.SetProviderSubject(v)
- return _u
- }
- // SetNillableProviderSubject sets the "provider_subject" field if the given value is not nil.
- func (_u *AuthIdentityUpdateOne) SetNillableProviderSubject(v *string) *AuthIdentityUpdateOne {
- if v != nil {
- _u.SetProviderSubject(*v)
- }
- return _u
- }
- // SetVerifiedAt sets the "verified_at" field.
- func (_u *AuthIdentityUpdateOne) SetVerifiedAt(v time.Time) *AuthIdentityUpdateOne {
- _u.mutation.SetVerifiedAt(v)
- return _u
- }
- // SetNillableVerifiedAt sets the "verified_at" field if the given value is not nil.
- func (_u *AuthIdentityUpdateOne) SetNillableVerifiedAt(v *time.Time) *AuthIdentityUpdateOne {
- if v != nil {
- _u.SetVerifiedAt(*v)
- }
- return _u
- }
- // ClearVerifiedAt clears the value of the "verified_at" field.
- func (_u *AuthIdentityUpdateOne) ClearVerifiedAt() *AuthIdentityUpdateOne {
- _u.mutation.ClearVerifiedAt()
- return _u
- }
- // SetIssuer sets the "issuer" field.
- func (_u *AuthIdentityUpdateOne) SetIssuer(v string) *AuthIdentityUpdateOne {
- _u.mutation.SetIssuer(v)
- return _u
- }
- // SetNillableIssuer sets the "issuer" field if the given value is not nil.
- func (_u *AuthIdentityUpdateOne) SetNillableIssuer(v *string) *AuthIdentityUpdateOne {
- if v != nil {
- _u.SetIssuer(*v)
- }
- return _u
- }
- // ClearIssuer clears the value of the "issuer" field.
- func (_u *AuthIdentityUpdateOne) ClearIssuer() *AuthIdentityUpdateOne {
- _u.mutation.ClearIssuer()
- return _u
- }
- // SetMetadata sets the "metadata" field.
- func (_u *AuthIdentityUpdateOne) SetMetadata(v map[string]interface{}) *AuthIdentityUpdateOne {
- _u.mutation.SetMetadata(v)
- return _u
- }
- // SetUser sets the "user" edge to the User entity.
- func (_u *AuthIdentityUpdateOne) SetUser(v *User) *AuthIdentityUpdateOne {
- return _u.SetUserID(v.ID)
- }
- // AddChannelIDs adds the "channels" edge to the AuthIdentityChannel entity by IDs.
- func (_u *AuthIdentityUpdateOne) AddChannelIDs(ids ...int64) *AuthIdentityUpdateOne {
- _u.mutation.AddChannelIDs(ids...)
- return _u
- }
- // AddChannels adds the "channels" edges to the AuthIdentityChannel entity.
- func (_u *AuthIdentityUpdateOne) AddChannels(v ...*AuthIdentityChannel) *AuthIdentityUpdateOne {
- ids := make([]int64, len(v))
- for i := range v {
- ids[i] = v[i].ID
- }
- return _u.AddChannelIDs(ids...)
- }
- // AddAdoptionDecisionIDs adds the "adoption_decisions" edge to the IdentityAdoptionDecision entity by IDs.
- func (_u *AuthIdentityUpdateOne) AddAdoptionDecisionIDs(ids ...int64) *AuthIdentityUpdateOne {
- _u.mutation.AddAdoptionDecisionIDs(ids...)
- return _u
- }
- // AddAdoptionDecisions adds the "adoption_decisions" edges to the IdentityAdoptionDecision entity.
- func (_u *AuthIdentityUpdateOne) AddAdoptionDecisions(v ...*IdentityAdoptionDecision) *AuthIdentityUpdateOne {
- ids := make([]int64, len(v))
- for i := range v {
- ids[i] = v[i].ID
- }
- return _u.AddAdoptionDecisionIDs(ids...)
- }
- // Mutation returns the AuthIdentityMutation object of the builder.
- func (_u *AuthIdentityUpdateOne) Mutation() *AuthIdentityMutation {
- return _u.mutation
- }
- // ClearUser clears the "user" edge to the User entity.
- func (_u *AuthIdentityUpdateOne) ClearUser() *AuthIdentityUpdateOne {
- _u.mutation.ClearUser()
- return _u
- }
- // ClearChannels clears all "channels" edges to the AuthIdentityChannel entity.
- func (_u *AuthIdentityUpdateOne) ClearChannels() *AuthIdentityUpdateOne {
- _u.mutation.ClearChannels()
- return _u
- }
- // RemoveChannelIDs removes the "channels" edge to AuthIdentityChannel entities by IDs.
- func (_u *AuthIdentityUpdateOne) RemoveChannelIDs(ids ...int64) *AuthIdentityUpdateOne {
- _u.mutation.RemoveChannelIDs(ids...)
- return _u
- }
- // RemoveChannels removes "channels" edges to AuthIdentityChannel entities.
- func (_u *AuthIdentityUpdateOne) RemoveChannels(v ...*AuthIdentityChannel) *AuthIdentityUpdateOne {
- ids := make([]int64, len(v))
- for i := range v {
- ids[i] = v[i].ID
- }
- return _u.RemoveChannelIDs(ids...)
- }
- // ClearAdoptionDecisions clears all "adoption_decisions" edges to the IdentityAdoptionDecision entity.
- func (_u *AuthIdentityUpdateOne) ClearAdoptionDecisions() *AuthIdentityUpdateOne {
- _u.mutation.ClearAdoptionDecisions()
- return _u
- }
- // RemoveAdoptionDecisionIDs removes the "adoption_decisions" edge to IdentityAdoptionDecision entities by IDs.
- func (_u *AuthIdentityUpdateOne) RemoveAdoptionDecisionIDs(ids ...int64) *AuthIdentityUpdateOne {
- _u.mutation.RemoveAdoptionDecisionIDs(ids...)
- return _u
- }
- // RemoveAdoptionDecisions removes "adoption_decisions" edges to IdentityAdoptionDecision entities.
- func (_u *AuthIdentityUpdateOne) RemoveAdoptionDecisions(v ...*IdentityAdoptionDecision) *AuthIdentityUpdateOne {
- ids := make([]int64, len(v))
- for i := range v {
- ids[i] = v[i].ID
- }
- return _u.RemoveAdoptionDecisionIDs(ids...)
- }
- // Where appends a list predicates to the AuthIdentityUpdate builder.
- func (_u *AuthIdentityUpdateOne) Where(ps ...predicate.AuthIdentity) *AuthIdentityUpdateOne {
- _u.mutation.Where(ps...)
- return _u
- }
- // Select allows selecting one or more fields (columns) of the returned entity.
- // The default is selecting all fields defined in the entity schema.
- func (_u *AuthIdentityUpdateOne) Select(field string, fields ...string) *AuthIdentityUpdateOne {
- _u.fields = append([]string{field}, fields...)
- return _u
- }
- // Save executes the query and returns the updated AuthIdentity entity.
- func (_u *AuthIdentityUpdateOne) Save(ctx context.Context) (*AuthIdentity, error) {
- _u.defaults()
- return withHooks(ctx, _u.sqlSave, _u.mutation, _u.hooks)
- }
- // SaveX is like Save, but panics if an error occurs.
- func (_u *AuthIdentityUpdateOne) SaveX(ctx context.Context) *AuthIdentity {
- node, err := _u.Save(ctx)
- if err != nil {
- panic(err)
- }
- return node
- }
- // Exec executes the query on the entity.
- func (_u *AuthIdentityUpdateOne) Exec(ctx context.Context) error {
- _, err := _u.Save(ctx)
- return err
- }
- // ExecX is like Exec, but panics if an error occurs.
- func (_u *AuthIdentityUpdateOne) ExecX(ctx context.Context) {
- if err := _u.Exec(ctx); err != nil {
- panic(err)
- }
- }
- // defaults sets the default values of the builder before save.
- func (_u *AuthIdentityUpdateOne) defaults() {
- if _, ok := _u.mutation.UpdatedAt(); !ok {
- v := authidentity.UpdateDefaultUpdatedAt()
- _u.mutation.SetUpdatedAt(v)
- }
- }
- // check runs all checks and user-defined validators on the builder.
- func (_u *AuthIdentityUpdateOne) check() error {
- if v, ok := _u.mutation.ProviderType(); ok {
- if err := authidentity.ProviderTypeValidator(v); err != nil {
- return &ValidationError{Name: "provider_type", err: fmt.Errorf(`ent: validator failed for field "AuthIdentity.provider_type": %w`, err)}
- }
- }
- if v, ok := _u.mutation.ProviderKey(); ok {
- if err := authidentity.ProviderKeyValidator(v); err != nil {
- return &ValidationError{Name: "provider_key", err: fmt.Errorf(`ent: validator failed for field "AuthIdentity.provider_key": %w`, err)}
- }
- }
- if v, ok := _u.mutation.ProviderSubject(); ok {
- if err := authidentity.ProviderSubjectValidator(v); err != nil {
- return &ValidationError{Name: "provider_subject", err: fmt.Errorf(`ent: validator failed for field "AuthIdentity.provider_subject": %w`, err)}
- }
- }
- if _u.mutation.UserCleared() && len(_u.mutation.UserIDs()) > 0 {
- return errors.New(`ent: clearing a required unique edge "AuthIdentity.user"`)
- }
- return nil
- }
- func (_u *AuthIdentityUpdateOne) sqlSave(ctx context.Context) (_node *AuthIdentity, err error) {
- if err := _u.check(); err != nil {
- return _node, err
- }
- _spec := sqlgraph.NewUpdateSpec(authidentity.Table, authidentity.Columns, sqlgraph.NewFieldSpec(authidentity.FieldID, field.TypeInt64))
- id, ok := _u.mutation.ID()
- if !ok {
- return nil, &ValidationError{Name: "id", err: errors.New(`ent: missing "AuthIdentity.id" for update`)}
- }
- _spec.Node.ID.Value = id
- if fields := _u.fields; len(fields) > 0 {
- _spec.Node.Columns = make([]string, 0, len(fields))
- _spec.Node.Columns = append(_spec.Node.Columns, authidentity.FieldID)
- for _, f := range fields {
- if !authidentity.ValidColumn(f) {
- return nil, &ValidationError{Name: f, err: fmt.Errorf("ent: invalid field %q for query", f)}
- }
- if f != authidentity.FieldID {
- _spec.Node.Columns = append(_spec.Node.Columns, f)
- }
- }
- }
- if ps := _u.mutation.predicates; len(ps) > 0 {
- _spec.Predicate = func(selector *sql.Selector) {
- for i := range ps {
- ps[i](selector)
- }
- }
- }
- if value, ok := _u.mutation.UpdatedAt(); ok {
- _spec.SetField(authidentity.FieldUpdatedAt, field.TypeTime, value)
- }
- if value, ok := _u.mutation.ProviderType(); ok {
- _spec.SetField(authidentity.FieldProviderType, field.TypeString, value)
- }
- if value, ok := _u.mutation.ProviderKey(); ok {
- _spec.SetField(authidentity.FieldProviderKey, field.TypeString, value)
- }
- if value, ok := _u.mutation.ProviderSubject(); ok {
- _spec.SetField(authidentity.FieldProviderSubject, field.TypeString, value)
- }
- if value, ok := _u.mutation.VerifiedAt(); ok {
- _spec.SetField(authidentity.FieldVerifiedAt, field.TypeTime, value)
- }
- if _u.mutation.VerifiedAtCleared() {
- _spec.ClearField(authidentity.FieldVerifiedAt, field.TypeTime)
- }
- if value, ok := _u.mutation.Issuer(); ok {
- _spec.SetField(authidentity.FieldIssuer, field.TypeString, value)
- }
- if _u.mutation.IssuerCleared() {
- _spec.ClearField(authidentity.FieldIssuer, field.TypeString)
- }
- if value, ok := _u.mutation.Metadata(); ok {
- _spec.SetField(authidentity.FieldMetadata, field.TypeJSON, value)
- }
- if _u.mutation.UserCleared() {
- edge := &sqlgraph.EdgeSpec{
- Rel: sqlgraph.M2O,
- Inverse: true,
- Table: authidentity.UserTable,
- Columns: []string{authidentity.UserColumn},
- Bidi: false,
- Target: &sqlgraph.EdgeTarget{
- IDSpec: sqlgraph.NewFieldSpec(user.FieldID, field.TypeInt64),
- },
- }
- _spec.Edges.Clear = append(_spec.Edges.Clear, edge)
- }
- if nodes := _u.mutation.UserIDs(); len(nodes) > 0 {
- edge := &sqlgraph.EdgeSpec{
- Rel: sqlgraph.M2O,
- Inverse: true,
- Table: authidentity.UserTable,
- Columns: []string{authidentity.UserColumn},
- Bidi: false,
- Target: &sqlgraph.EdgeTarget{
- IDSpec: sqlgraph.NewFieldSpec(user.FieldID, field.TypeInt64),
- },
- }
- for _, k := range nodes {
- edge.Target.Nodes = append(edge.Target.Nodes, k)
- }
- _spec.Edges.Add = append(_spec.Edges.Add, edge)
- }
- if _u.mutation.ChannelsCleared() {
- edge := &sqlgraph.EdgeSpec{
- Rel: sqlgraph.O2M,
- Inverse: false,
- Table: authidentity.ChannelsTable,
- Columns: []string{authidentity.ChannelsColumn},
- Bidi: false,
- Target: &sqlgraph.EdgeTarget{
- IDSpec: sqlgraph.NewFieldSpec(authidentitychannel.FieldID, field.TypeInt64),
- },
- }
- _spec.Edges.Clear = append(_spec.Edges.Clear, edge)
- }
- if nodes := _u.mutation.RemovedChannelsIDs(); len(nodes) > 0 && !_u.mutation.ChannelsCleared() {
- edge := &sqlgraph.EdgeSpec{
- Rel: sqlgraph.O2M,
- Inverse: false,
- Table: authidentity.ChannelsTable,
- Columns: []string{authidentity.ChannelsColumn},
- Bidi: false,
- Target: &sqlgraph.EdgeTarget{
- IDSpec: sqlgraph.NewFieldSpec(authidentitychannel.FieldID, field.TypeInt64),
- },
- }
- for _, k := range nodes {
- edge.Target.Nodes = append(edge.Target.Nodes, k)
- }
- _spec.Edges.Clear = append(_spec.Edges.Clear, edge)
- }
- if nodes := _u.mutation.ChannelsIDs(); len(nodes) > 0 {
- edge := &sqlgraph.EdgeSpec{
- Rel: sqlgraph.O2M,
- Inverse: false,
- Table: authidentity.ChannelsTable,
- Columns: []string{authidentity.ChannelsColumn},
- Bidi: false,
- Target: &sqlgraph.EdgeTarget{
- IDSpec: sqlgraph.NewFieldSpec(authidentitychannel.FieldID, field.TypeInt64),
- },
- }
- for _, k := range nodes {
- edge.Target.Nodes = append(edge.Target.Nodes, k)
- }
- _spec.Edges.Add = append(_spec.Edges.Add, edge)
- }
- if _u.mutation.AdoptionDecisionsCleared() {
- edge := &sqlgraph.EdgeSpec{
- Rel: sqlgraph.O2M,
- Inverse: false,
- Table: authidentity.AdoptionDecisionsTable,
- Columns: []string{authidentity.AdoptionDecisionsColumn},
- Bidi: false,
- Target: &sqlgraph.EdgeTarget{
- IDSpec: sqlgraph.NewFieldSpec(identityadoptiondecision.FieldID, field.TypeInt64),
- },
- }
- _spec.Edges.Clear = append(_spec.Edges.Clear, edge)
- }
- if nodes := _u.mutation.RemovedAdoptionDecisionsIDs(); len(nodes) > 0 && !_u.mutation.AdoptionDecisionsCleared() {
- edge := &sqlgraph.EdgeSpec{
- Rel: sqlgraph.O2M,
- Inverse: false,
- Table: authidentity.AdoptionDecisionsTable,
- Columns: []string{authidentity.AdoptionDecisionsColumn},
- Bidi: false,
- Target: &sqlgraph.EdgeTarget{
- IDSpec: sqlgraph.NewFieldSpec(identityadoptiondecision.FieldID, field.TypeInt64),
- },
- }
- for _, k := range nodes {
- edge.Target.Nodes = append(edge.Target.Nodes, k)
- }
- _spec.Edges.Clear = append(_spec.Edges.Clear, edge)
- }
- if nodes := _u.mutation.AdoptionDecisionsIDs(); len(nodes) > 0 {
- edge := &sqlgraph.EdgeSpec{
- Rel: sqlgraph.O2M,
- Inverse: false,
- Table: authidentity.AdoptionDecisionsTable,
- Columns: []string{authidentity.AdoptionDecisionsColumn},
- Bidi: false,
- Target: &sqlgraph.EdgeTarget{
- IDSpec: sqlgraph.NewFieldSpec(identityadoptiondecision.FieldID, field.TypeInt64),
- },
- }
- for _, k := range nodes {
- edge.Target.Nodes = append(edge.Target.Nodes, k)
- }
- _spec.Edges.Add = append(_spec.Edges.Add, edge)
- }
- _node = &AuthIdentity{config: _u.config}
- _spec.Assign = _node.assignValues
- _spec.ScanValues = _node.scanValues
- if err = sqlgraph.UpdateNode(ctx, _u.driver, _spec); err != nil {
- if _, ok := err.(*sqlgraph.NotFoundError); ok {
- err = &NotFoundError{authidentity.Label}
- } else if sqlgraph.IsConstraintError(err) {
- err = &ConstraintError{msg: err.Error(), wrap: err}
- }
- return nil, err
- }
- _u.mutation.done = true
- return _node, nil
- }
|