// 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/user" ) // AuthIdentityCreate is the builder for creating a AuthIdentity entity. type AuthIdentityCreate struct { config mutation *AuthIdentityMutation hooks []Hook conflict []sql.ConflictOption } // SetCreatedAt sets the "created_at" field. func (_c *AuthIdentityCreate) SetCreatedAt(v time.Time) *AuthIdentityCreate { _c.mutation.SetCreatedAt(v) return _c } // SetNillableCreatedAt sets the "created_at" field if the given value is not nil. func (_c *AuthIdentityCreate) SetNillableCreatedAt(v *time.Time) *AuthIdentityCreate { if v != nil { _c.SetCreatedAt(*v) } return _c } // SetUpdatedAt sets the "updated_at" field. func (_c *AuthIdentityCreate) SetUpdatedAt(v time.Time) *AuthIdentityCreate { _c.mutation.SetUpdatedAt(v) return _c } // SetNillableUpdatedAt sets the "updated_at" field if the given value is not nil. func (_c *AuthIdentityCreate) SetNillableUpdatedAt(v *time.Time) *AuthIdentityCreate { if v != nil { _c.SetUpdatedAt(*v) } return _c } // SetUserID sets the "user_id" field. func (_c *AuthIdentityCreate) SetUserID(v int64) *AuthIdentityCreate { _c.mutation.SetUserID(v) return _c } // SetProviderType sets the "provider_type" field. func (_c *AuthIdentityCreate) SetProviderType(v string) *AuthIdentityCreate { _c.mutation.SetProviderType(v) return _c } // SetProviderKey sets the "provider_key" field. func (_c *AuthIdentityCreate) SetProviderKey(v string) *AuthIdentityCreate { _c.mutation.SetProviderKey(v) return _c } // SetProviderSubject sets the "provider_subject" field. func (_c *AuthIdentityCreate) SetProviderSubject(v string) *AuthIdentityCreate { _c.mutation.SetProviderSubject(v) return _c } // SetVerifiedAt sets the "verified_at" field. func (_c *AuthIdentityCreate) SetVerifiedAt(v time.Time) *AuthIdentityCreate { _c.mutation.SetVerifiedAt(v) return _c } // SetNillableVerifiedAt sets the "verified_at" field if the given value is not nil. func (_c *AuthIdentityCreate) SetNillableVerifiedAt(v *time.Time) *AuthIdentityCreate { if v != nil { _c.SetVerifiedAt(*v) } return _c } // SetIssuer sets the "issuer" field. func (_c *AuthIdentityCreate) SetIssuer(v string) *AuthIdentityCreate { _c.mutation.SetIssuer(v) return _c } // SetNillableIssuer sets the "issuer" field if the given value is not nil. func (_c *AuthIdentityCreate) SetNillableIssuer(v *string) *AuthIdentityCreate { if v != nil { _c.SetIssuer(*v) } return _c } // SetMetadata sets the "metadata" field. func (_c *AuthIdentityCreate) SetMetadata(v map[string]interface{}) *AuthIdentityCreate { _c.mutation.SetMetadata(v) return _c } // SetUser sets the "user" edge to the User entity. func (_c *AuthIdentityCreate) SetUser(v *User) *AuthIdentityCreate { return _c.SetUserID(v.ID) } // AddChannelIDs adds the "channels" edge to the AuthIdentityChannel entity by IDs. func (_c *AuthIdentityCreate) AddChannelIDs(ids ...int64) *AuthIdentityCreate { _c.mutation.AddChannelIDs(ids...) return _c } // AddChannels adds the "channels" edges to the AuthIdentityChannel entity. func (_c *AuthIdentityCreate) AddChannels(v ...*AuthIdentityChannel) *AuthIdentityCreate { ids := make([]int64, len(v)) for i := range v { ids[i] = v[i].ID } return _c.AddChannelIDs(ids...) } // AddAdoptionDecisionIDs adds the "adoption_decisions" edge to the IdentityAdoptionDecision entity by IDs. func (_c *AuthIdentityCreate) AddAdoptionDecisionIDs(ids ...int64) *AuthIdentityCreate { _c.mutation.AddAdoptionDecisionIDs(ids...) return _c } // AddAdoptionDecisions adds the "adoption_decisions" edges to the IdentityAdoptionDecision entity. func (_c *AuthIdentityCreate) AddAdoptionDecisions(v ...*IdentityAdoptionDecision) *AuthIdentityCreate { ids := make([]int64, len(v)) for i := range v { ids[i] = v[i].ID } return _c.AddAdoptionDecisionIDs(ids...) } // Mutation returns the AuthIdentityMutation object of the builder. func (_c *AuthIdentityCreate) Mutation() *AuthIdentityMutation { return _c.mutation } // Save creates the AuthIdentity in the database. func (_c *AuthIdentityCreate) Save(ctx context.Context) (*AuthIdentity, error) { _c.defaults() return withHooks(ctx, _c.sqlSave, _c.mutation, _c.hooks) } // SaveX calls Save and panics if Save returns an error. func (_c *AuthIdentityCreate) SaveX(ctx context.Context) *AuthIdentity { v, err := _c.Save(ctx) if err != nil { panic(err) } return v } // Exec executes the query. func (_c *AuthIdentityCreate) Exec(ctx context.Context) error { _, err := _c.Save(ctx) return err } // ExecX is like Exec, but panics if an error occurs. func (_c *AuthIdentityCreate) ExecX(ctx context.Context) { if err := _c.Exec(ctx); err != nil { panic(err) } } // defaults sets the default values of the builder before save. func (_c *AuthIdentityCreate) defaults() { if _, ok := _c.mutation.CreatedAt(); !ok { v := authidentity.DefaultCreatedAt() _c.mutation.SetCreatedAt(v) } if _, ok := _c.mutation.UpdatedAt(); !ok { v := authidentity.DefaultUpdatedAt() _c.mutation.SetUpdatedAt(v) } if _, ok := _c.mutation.Metadata(); !ok { v := authidentity.DefaultMetadata() _c.mutation.SetMetadata(v) } } // check runs all checks and user-defined validators on the builder. func (_c *AuthIdentityCreate) check() error { if _, ok := _c.mutation.CreatedAt(); !ok { return &ValidationError{Name: "created_at", err: errors.New(`ent: missing required field "AuthIdentity.created_at"`)} } if _, ok := _c.mutation.UpdatedAt(); !ok { return &ValidationError{Name: "updated_at", err: errors.New(`ent: missing required field "AuthIdentity.updated_at"`)} } if _, ok := _c.mutation.UserID(); !ok { return &ValidationError{Name: "user_id", err: errors.New(`ent: missing required field "AuthIdentity.user_id"`)} } if _, ok := _c.mutation.ProviderType(); !ok { return &ValidationError{Name: "provider_type", err: errors.New(`ent: missing required field "AuthIdentity.provider_type"`)} } if v, ok := _c.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 _, ok := _c.mutation.ProviderKey(); !ok { return &ValidationError{Name: "provider_key", err: errors.New(`ent: missing required field "AuthIdentity.provider_key"`)} } if v, ok := _c.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 _, ok := _c.mutation.ProviderSubject(); !ok { return &ValidationError{Name: "provider_subject", err: errors.New(`ent: missing required field "AuthIdentity.provider_subject"`)} } if v, ok := _c.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 _, ok := _c.mutation.Metadata(); !ok { return &ValidationError{Name: "metadata", err: errors.New(`ent: missing required field "AuthIdentity.metadata"`)} } if len(_c.mutation.UserIDs()) == 0 { return &ValidationError{Name: "user", err: errors.New(`ent: missing required edge "AuthIdentity.user"`)} } return nil } func (_c *AuthIdentityCreate) sqlSave(ctx context.Context) (*AuthIdentity, error) { if err := _c.check(); err != nil { return nil, err } _node, _spec := _c.createSpec() if err := sqlgraph.CreateNode(ctx, _c.driver, _spec); err != nil { if sqlgraph.IsConstraintError(err) { err = &ConstraintError{msg: err.Error(), wrap: err} } return nil, err } id := _spec.ID.Value.(int64) _node.ID = int64(id) _c.mutation.id = &_node.ID _c.mutation.done = true return _node, nil } func (_c *AuthIdentityCreate) createSpec() (*AuthIdentity, *sqlgraph.CreateSpec) { var ( _node = &AuthIdentity{config: _c.config} _spec = sqlgraph.NewCreateSpec(authidentity.Table, sqlgraph.NewFieldSpec(authidentity.FieldID, field.TypeInt64)) ) _spec.OnConflict = _c.conflict if value, ok := _c.mutation.CreatedAt(); ok { _spec.SetField(authidentity.FieldCreatedAt, field.TypeTime, value) _node.CreatedAt = value } if value, ok := _c.mutation.UpdatedAt(); ok { _spec.SetField(authidentity.FieldUpdatedAt, field.TypeTime, value) _node.UpdatedAt = value } if value, ok := _c.mutation.ProviderType(); ok { _spec.SetField(authidentity.FieldProviderType, field.TypeString, value) _node.ProviderType = value } if value, ok := _c.mutation.ProviderKey(); ok { _spec.SetField(authidentity.FieldProviderKey, field.TypeString, value) _node.ProviderKey = value } if value, ok := _c.mutation.ProviderSubject(); ok { _spec.SetField(authidentity.FieldProviderSubject, field.TypeString, value) _node.ProviderSubject = value } if value, ok := _c.mutation.VerifiedAt(); ok { _spec.SetField(authidentity.FieldVerifiedAt, field.TypeTime, value) _node.VerifiedAt = &value } if value, ok := _c.mutation.Issuer(); ok { _spec.SetField(authidentity.FieldIssuer, field.TypeString, value) _node.Issuer = &value } if value, ok := _c.mutation.Metadata(); ok { _spec.SetField(authidentity.FieldMetadata, field.TypeJSON, value) _node.Metadata = value } if nodes := _c.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) } _node.UserID = nodes[0] _spec.Edges = append(_spec.Edges, edge) } if nodes := _c.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 = append(_spec.Edges, edge) } if nodes := _c.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 = append(_spec.Edges, edge) } return _node, _spec } // OnConflict allows configuring the `ON CONFLICT` / `ON DUPLICATE KEY` clause // of the `INSERT` statement. For example: // // client.AuthIdentity.Create(). // SetCreatedAt(v). // OnConflict( // // Update the row with the new values // // the was proposed for insertion. // sql.ResolveWithNewValues(), // ). // // Override some of the fields with custom // // update values. // Update(func(u *ent.AuthIdentityUpsert) { // SetCreatedAt(v+v). // }). // Exec(ctx) func (_c *AuthIdentityCreate) OnConflict(opts ...sql.ConflictOption) *AuthIdentityUpsertOne { _c.conflict = opts return &AuthIdentityUpsertOne{ create: _c, } } // OnConflictColumns calls `OnConflict` and configures the columns // as conflict target. Using this option is equivalent to using: // // client.AuthIdentity.Create(). // OnConflict(sql.ConflictColumns(columns...)). // Exec(ctx) func (_c *AuthIdentityCreate) OnConflictColumns(columns ...string) *AuthIdentityUpsertOne { _c.conflict = append(_c.conflict, sql.ConflictColumns(columns...)) return &AuthIdentityUpsertOne{ create: _c, } } type ( // AuthIdentityUpsertOne is the builder for "upsert"-ing // one AuthIdentity node. AuthIdentityUpsertOne struct { create *AuthIdentityCreate } // AuthIdentityUpsert is the "OnConflict" setter. AuthIdentityUpsert struct { *sql.UpdateSet } ) // SetUpdatedAt sets the "updated_at" field. func (u *AuthIdentityUpsert) SetUpdatedAt(v time.Time) *AuthIdentityUpsert { u.Set(authidentity.FieldUpdatedAt, v) return u } // UpdateUpdatedAt sets the "updated_at" field to the value that was provided on create. func (u *AuthIdentityUpsert) UpdateUpdatedAt() *AuthIdentityUpsert { u.SetExcluded(authidentity.FieldUpdatedAt) return u } // SetUserID sets the "user_id" field. func (u *AuthIdentityUpsert) SetUserID(v int64) *AuthIdentityUpsert { u.Set(authidentity.FieldUserID, v) return u } // UpdateUserID sets the "user_id" field to the value that was provided on create. func (u *AuthIdentityUpsert) UpdateUserID() *AuthIdentityUpsert { u.SetExcluded(authidentity.FieldUserID) return u } // SetProviderType sets the "provider_type" field. func (u *AuthIdentityUpsert) SetProviderType(v string) *AuthIdentityUpsert { u.Set(authidentity.FieldProviderType, v) return u } // UpdateProviderType sets the "provider_type" field to the value that was provided on create. func (u *AuthIdentityUpsert) UpdateProviderType() *AuthIdentityUpsert { u.SetExcluded(authidentity.FieldProviderType) return u } // SetProviderKey sets the "provider_key" field. func (u *AuthIdentityUpsert) SetProviderKey(v string) *AuthIdentityUpsert { u.Set(authidentity.FieldProviderKey, v) return u } // UpdateProviderKey sets the "provider_key" field to the value that was provided on create. func (u *AuthIdentityUpsert) UpdateProviderKey() *AuthIdentityUpsert { u.SetExcluded(authidentity.FieldProviderKey) return u } // SetProviderSubject sets the "provider_subject" field. func (u *AuthIdentityUpsert) SetProviderSubject(v string) *AuthIdentityUpsert { u.Set(authidentity.FieldProviderSubject, v) return u } // UpdateProviderSubject sets the "provider_subject" field to the value that was provided on create. func (u *AuthIdentityUpsert) UpdateProviderSubject() *AuthIdentityUpsert { u.SetExcluded(authidentity.FieldProviderSubject) return u } // SetVerifiedAt sets the "verified_at" field. func (u *AuthIdentityUpsert) SetVerifiedAt(v time.Time) *AuthIdentityUpsert { u.Set(authidentity.FieldVerifiedAt, v) return u } // UpdateVerifiedAt sets the "verified_at" field to the value that was provided on create. func (u *AuthIdentityUpsert) UpdateVerifiedAt() *AuthIdentityUpsert { u.SetExcluded(authidentity.FieldVerifiedAt) return u } // ClearVerifiedAt clears the value of the "verified_at" field. func (u *AuthIdentityUpsert) ClearVerifiedAt() *AuthIdentityUpsert { u.SetNull(authidentity.FieldVerifiedAt) return u } // SetIssuer sets the "issuer" field. func (u *AuthIdentityUpsert) SetIssuer(v string) *AuthIdentityUpsert { u.Set(authidentity.FieldIssuer, v) return u } // UpdateIssuer sets the "issuer" field to the value that was provided on create. func (u *AuthIdentityUpsert) UpdateIssuer() *AuthIdentityUpsert { u.SetExcluded(authidentity.FieldIssuer) return u } // ClearIssuer clears the value of the "issuer" field. func (u *AuthIdentityUpsert) ClearIssuer() *AuthIdentityUpsert { u.SetNull(authidentity.FieldIssuer) return u } // SetMetadata sets the "metadata" field. func (u *AuthIdentityUpsert) SetMetadata(v map[string]interface{}) *AuthIdentityUpsert { u.Set(authidentity.FieldMetadata, v) return u } // UpdateMetadata sets the "metadata" field to the value that was provided on create. func (u *AuthIdentityUpsert) UpdateMetadata() *AuthIdentityUpsert { u.SetExcluded(authidentity.FieldMetadata) return u } // UpdateNewValues updates the mutable fields using the new values that were set on create. // Using this option is equivalent to using: // // client.AuthIdentity.Create(). // OnConflict( // sql.ResolveWithNewValues(), // ). // Exec(ctx) func (u *AuthIdentityUpsertOne) UpdateNewValues() *AuthIdentityUpsertOne { u.create.conflict = append(u.create.conflict, sql.ResolveWithNewValues()) u.create.conflict = append(u.create.conflict, sql.ResolveWith(func(s *sql.UpdateSet) { if _, exists := u.create.mutation.CreatedAt(); exists { s.SetIgnore(authidentity.FieldCreatedAt) } })) return u } // Ignore sets each column to itself in case of conflict. // Using this option is equivalent to using: // // client.AuthIdentity.Create(). // OnConflict(sql.ResolveWithIgnore()). // Exec(ctx) func (u *AuthIdentityUpsertOne) Ignore() *AuthIdentityUpsertOne { u.create.conflict = append(u.create.conflict, sql.ResolveWithIgnore()) return u } // DoNothing configures the conflict_action to `DO NOTHING`. // Supported only by SQLite and PostgreSQL. func (u *AuthIdentityUpsertOne) DoNothing() *AuthIdentityUpsertOne { u.create.conflict = append(u.create.conflict, sql.DoNothing()) return u } // Update allows overriding fields `UPDATE` values. See the AuthIdentityCreate.OnConflict // documentation for more info. func (u *AuthIdentityUpsertOne) Update(set func(*AuthIdentityUpsert)) *AuthIdentityUpsertOne { u.create.conflict = append(u.create.conflict, sql.ResolveWith(func(update *sql.UpdateSet) { set(&AuthIdentityUpsert{UpdateSet: update}) })) return u } // SetUpdatedAt sets the "updated_at" field. func (u *AuthIdentityUpsertOne) SetUpdatedAt(v time.Time) *AuthIdentityUpsertOne { return u.Update(func(s *AuthIdentityUpsert) { s.SetUpdatedAt(v) }) } // UpdateUpdatedAt sets the "updated_at" field to the value that was provided on create. func (u *AuthIdentityUpsertOne) UpdateUpdatedAt() *AuthIdentityUpsertOne { return u.Update(func(s *AuthIdentityUpsert) { s.UpdateUpdatedAt() }) } // SetUserID sets the "user_id" field. func (u *AuthIdentityUpsertOne) SetUserID(v int64) *AuthIdentityUpsertOne { return u.Update(func(s *AuthIdentityUpsert) { s.SetUserID(v) }) } // UpdateUserID sets the "user_id" field to the value that was provided on create. func (u *AuthIdentityUpsertOne) UpdateUserID() *AuthIdentityUpsertOne { return u.Update(func(s *AuthIdentityUpsert) { s.UpdateUserID() }) } // SetProviderType sets the "provider_type" field. func (u *AuthIdentityUpsertOne) SetProviderType(v string) *AuthIdentityUpsertOne { return u.Update(func(s *AuthIdentityUpsert) { s.SetProviderType(v) }) } // UpdateProviderType sets the "provider_type" field to the value that was provided on create. func (u *AuthIdentityUpsertOne) UpdateProviderType() *AuthIdentityUpsertOne { return u.Update(func(s *AuthIdentityUpsert) { s.UpdateProviderType() }) } // SetProviderKey sets the "provider_key" field. func (u *AuthIdentityUpsertOne) SetProviderKey(v string) *AuthIdentityUpsertOne { return u.Update(func(s *AuthIdentityUpsert) { s.SetProviderKey(v) }) } // UpdateProviderKey sets the "provider_key" field to the value that was provided on create. func (u *AuthIdentityUpsertOne) UpdateProviderKey() *AuthIdentityUpsertOne { return u.Update(func(s *AuthIdentityUpsert) { s.UpdateProviderKey() }) } // SetProviderSubject sets the "provider_subject" field. func (u *AuthIdentityUpsertOne) SetProviderSubject(v string) *AuthIdentityUpsertOne { return u.Update(func(s *AuthIdentityUpsert) { s.SetProviderSubject(v) }) } // UpdateProviderSubject sets the "provider_subject" field to the value that was provided on create. func (u *AuthIdentityUpsertOne) UpdateProviderSubject() *AuthIdentityUpsertOne { return u.Update(func(s *AuthIdentityUpsert) { s.UpdateProviderSubject() }) } // SetVerifiedAt sets the "verified_at" field. func (u *AuthIdentityUpsertOne) SetVerifiedAt(v time.Time) *AuthIdentityUpsertOne { return u.Update(func(s *AuthIdentityUpsert) { s.SetVerifiedAt(v) }) } // UpdateVerifiedAt sets the "verified_at" field to the value that was provided on create. func (u *AuthIdentityUpsertOne) UpdateVerifiedAt() *AuthIdentityUpsertOne { return u.Update(func(s *AuthIdentityUpsert) { s.UpdateVerifiedAt() }) } // ClearVerifiedAt clears the value of the "verified_at" field. func (u *AuthIdentityUpsertOne) ClearVerifiedAt() *AuthIdentityUpsertOne { return u.Update(func(s *AuthIdentityUpsert) { s.ClearVerifiedAt() }) } // SetIssuer sets the "issuer" field. func (u *AuthIdentityUpsertOne) SetIssuer(v string) *AuthIdentityUpsertOne { return u.Update(func(s *AuthIdentityUpsert) { s.SetIssuer(v) }) } // UpdateIssuer sets the "issuer" field to the value that was provided on create. func (u *AuthIdentityUpsertOne) UpdateIssuer() *AuthIdentityUpsertOne { return u.Update(func(s *AuthIdentityUpsert) { s.UpdateIssuer() }) } // ClearIssuer clears the value of the "issuer" field. func (u *AuthIdentityUpsertOne) ClearIssuer() *AuthIdentityUpsertOne { return u.Update(func(s *AuthIdentityUpsert) { s.ClearIssuer() }) } // SetMetadata sets the "metadata" field. func (u *AuthIdentityUpsertOne) SetMetadata(v map[string]interface{}) *AuthIdentityUpsertOne { return u.Update(func(s *AuthIdentityUpsert) { s.SetMetadata(v) }) } // UpdateMetadata sets the "metadata" field to the value that was provided on create. func (u *AuthIdentityUpsertOne) UpdateMetadata() *AuthIdentityUpsertOne { return u.Update(func(s *AuthIdentityUpsert) { s.UpdateMetadata() }) } // Exec executes the query. func (u *AuthIdentityUpsertOne) Exec(ctx context.Context) error { if len(u.create.conflict) == 0 { return errors.New("ent: missing options for AuthIdentityCreate.OnConflict") } return u.create.Exec(ctx) } // ExecX is like Exec, but panics if an error occurs. func (u *AuthIdentityUpsertOne) ExecX(ctx context.Context) { if err := u.create.Exec(ctx); err != nil { panic(err) } } // Exec executes the UPSERT query and returns the inserted/updated ID. func (u *AuthIdentityUpsertOne) ID(ctx context.Context) (id int64, err error) { node, err := u.create.Save(ctx) if err != nil { return id, err } return node.ID, nil } // IDX is like ID, but panics if an error occurs. func (u *AuthIdentityUpsertOne) IDX(ctx context.Context) int64 { id, err := u.ID(ctx) if err != nil { panic(err) } return id } // AuthIdentityCreateBulk is the builder for creating many AuthIdentity entities in bulk. type AuthIdentityCreateBulk struct { config err error builders []*AuthIdentityCreate conflict []sql.ConflictOption } // Save creates the AuthIdentity entities in the database. func (_c *AuthIdentityCreateBulk) Save(ctx context.Context) ([]*AuthIdentity, error) { if _c.err != nil { return nil, _c.err } specs := make([]*sqlgraph.CreateSpec, len(_c.builders)) nodes := make([]*AuthIdentity, len(_c.builders)) mutators := make([]Mutator, len(_c.builders)) for i := range _c.builders { func(i int, root context.Context) { builder := _c.builders[i] builder.defaults() var mut Mutator = MutateFunc(func(ctx context.Context, m Mutation) (Value, error) { mutation, ok := m.(*AuthIdentityMutation) if !ok { return nil, fmt.Errorf("unexpected mutation type %T", m) } if err := builder.check(); err != nil { return nil, err } builder.mutation = mutation var err error nodes[i], specs[i] = builder.createSpec() if i < len(mutators)-1 { _, err = mutators[i+1].Mutate(root, _c.builders[i+1].mutation) } else { spec := &sqlgraph.BatchCreateSpec{Nodes: specs} spec.OnConflict = _c.conflict // Invoke the actual operation on the latest mutation in the chain. if err = sqlgraph.BatchCreate(ctx, _c.driver, spec); err != nil { if sqlgraph.IsConstraintError(err) { err = &ConstraintError{msg: err.Error(), wrap: err} } } } if err != nil { return nil, err } mutation.id = &nodes[i].ID if specs[i].ID.Value != nil { id := specs[i].ID.Value.(int64) nodes[i].ID = int64(id) } mutation.done = true return nodes[i], nil }) for i := len(builder.hooks) - 1; i >= 0; i-- { mut = builder.hooks[i](mut) } mutators[i] = mut }(i, ctx) } if len(mutators) > 0 { if _, err := mutators[0].Mutate(ctx, _c.builders[0].mutation); err != nil { return nil, err } } return nodes, nil } // SaveX is like Save, but panics if an error occurs. func (_c *AuthIdentityCreateBulk) SaveX(ctx context.Context) []*AuthIdentity { v, err := _c.Save(ctx) if err != nil { panic(err) } return v } // Exec executes the query. func (_c *AuthIdentityCreateBulk) Exec(ctx context.Context) error { _, err := _c.Save(ctx) return err } // ExecX is like Exec, but panics if an error occurs. func (_c *AuthIdentityCreateBulk) ExecX(ctx context.Context) { if err := _c.Exec(ctx); err != nil { panic(err) } } // OnConflict allows configuring the `ON CONFLICT` / `ON DUPLICATE KEY` clause // of the `INSERT` statement. For example: // // client.AuthIdentity.CreateBulk(builders...). // OnConflict( // // Update the row with the new values // // the was proposed for insertion. // sql.ResolveWithNewValues(), // ). // // Override some of the fields with custom // // update values. // Update(func(u *ent.AuthIdentityUpsert) { // SetCreatedAt(v+v). // }). // Exec(ctx) func (_c *AuthIdentityCreateBulk) OnConflict(opts ...sql.ConflictOption) *AuthIdentityUpsertBulk { _c.conflict = opts return &AuthIdentityUpsertBulk{ create: _c, } } // OnConflictColumns calls `OnConflict` and configures the columns // as conflict target. Using this option is equivalent to using: // // client.AuthIdentity.Create(). // OnConflict(sql.ConflictColumns(columns...)). // Exec(ctx) func (_c *AuthIdentityCreateBulk) OnConflictColumns(columns ...string) *AuthIdentityUpsertBulk { _c.conflict = append(_c.conflict, sql.ConflictColumns(columns...)) return &AuthIdentityUpsertBulk{ create: _c, } } // AuthIdentityUpsertBulk is the builder for "upsert"-ing // a bulk of AuthIdentity nodes. type AuthIdentityUpsertBulk struct { create *AuthIdentityCreateBulk } // UpdateNewValues updates the mutable fields using the new values that // were set on create. Using this option is equivalent to using: // // client.AuthIdentity.Create(). // OnConflict( // sql.ResolveWithNewValues(), // ). // Exec(ctx) func (u *AuthIdentityUpsertBulk) UpdateNewValues() *AuthIdentityUpsertBulk { u.create.conflict = append(u.create.conflict, sql.ResolveWithNewValues()) u.create.conflict = append(u.create.conflict, sql.ResolveWith(func(s *sql.UpdateSet) { for _, b := range u.create.builders { if _, exists := b.mutation.CreatedAt(); exists { s.SetIgnore(authidentity.FieldCreatedAt) } } })) return u } // Ignore sets each column to itself in case of conflict. // Using this option is equivalent to using: // // client.AuthIdentity.Create(). // OnConflict(sql.ResolveWithIgnore()). // Exec(ctx) func (u *AuthIdentityUpsertBulk) Ignore() *AuthIdentityUpsertBulk { u.create.conflict = append(u.create.conflict, sql.ResolveWithIgnore()) return u } // DoNothing configures the conflict_action to `DO NOTHING`. // Supported only by SQLite and PostgreSQL. func (u *AuthIdentityUpsertBulk) DoNothing() *AuthIdentityUpsertBulk { u.create.conflict = append(u.create.conflict, sql.DoNothing()) return u } // Update allows overriding fields `UPDATE` values. See the AuthIdentityCreateBulk.OnConflict // documentation for more info. func (u *AuthIdentityUpsertBulk) Update(set func(*AuthIdentityUpsert)) *AuthIdentityUpsertBulk { u.create.conflict = append(u.create.conflict, sql.ResolveWith(func(update *sql.UpdateSet) { set(&AuthIdentityUpsert{UpdateSet: update}) })) return u } // SetUpdatedAt sets the "updated_at" field. func (u *AuthIdentityUpsertBulk) SetUpdatedAt(v time.Time) *AuthIdentityUpsertBulk { return u.Update(func(s *AuthIdentityUpsert) { s.SetUpdatedAt(v) }) } // UpdateUpdatedAt sets the "updated_at" field to the value that was provided on create. func (u *AuthIdentityUpsertBulk) UpdateUpdatedAt() *AuthIdentityUpsertBulk { return u.Update(func(s *AuthIdentityUpsert) { s.UpdateUpdatedAt() }) } // SetUserID sets the "user_id" field. func (u *AuthIdentityUpsertBulk) SetUserID(v int64) *AuthIdentityUpsertBulk { return u.Update(func(s *AuthIdentityUpsert) { s.SetUserID(v) }) } // UpdateUserID sets the "user_id" field to the value that was provided on create. func (u *AuthIdentityUpsertBulk) UpdateUserID() *AuthIdentityUpsertBulk { return u.Update(func(s *AuthIdentityUpsert) { s.UpdateUserID() }) } // SetProviderType sets the "provider_type" field. func (u *AuthIdentityUpsertBulk) SetProviderType(v string) *AuthIdentityUpsertBulk { return u.Update(func(s *AuthIdentityUpsert) { s.SetProviderType(v) }) } // UpdateProviderType sets the "provider_type" field to the value that was provided on create. func (u *AuthIdentityUpsertBulk) UpdateProviderType() *AuthIdentityUpsertBulk { return u.Update(func(s *AuthIdentityUpsert) { s.UpdateProviderType() }) } // SetProviderKey sets the "provider_key" field. func (u *AuthIdentityUpsertBulk) SetProviderKey(v string) *AuthIdentityUpsertBulk { return u.Update(func(s *AuthIdentityUpsert) { s.SetProviderKey(v) }) } // UpdateProviderKey sets the "provider_key" field to the value that was provided on create. func (u *AuthIdentityUpsertBulk) UpdateProviderKey() *AuthIdentityUpsertBulk { return u.Update(func(s *AuthIdentityUpsert) { s.UpdateProviderKey() }) } // SetProviderSubject sets the "provider_subject" field. func (u *AuthIdentityUpsertBulk) SetProviderSubject(v string) *AuthIdentityUpsertBulk { return u.Update(func(s *AuthIdentityUpsert) { s.SetProviderSubject(v) }) } // UpdateProviderSubject sets the "provider_subject" field to the value that was provided on create. func (u *AuthIdentityUpsertBulk) UpdateProviderSubject() *AuthIdentityUpsertBulk { return u.Update(func(s *AuthIdentityUpsert) { s.UpdateProviderSubject() }) } // SetVerifiedAt sets the "verified_at" field. func (u *AuthIdentityUpsertBulk) SetVerifiedAt(v time.Time) *AuthIdentityUpsertBulk { return u.Update(func(s *AuthIdentityUpsert) { s.SetVerifiedAt(v) }) } // UpdateVerifiedAt sets the "verified_at" field to the value that was provided on create. func (u *AuthIdentityUpsertBulk) UpdateVerifiedAt() *AuthIdentityUpsertBulk { return u.Update(func(s *AuthIdentityUpsert) { s.UpdateVerifiedAt() }) } // ClearVerifiedAt clears the value of the "verified_at" field. func (u *AuthIdentityUpsertBulk) ClearVerifiedAt() *AuthIdentityUpsertBulk { return u.Update(func(s *AuthIdentityUpsert) { s.ClearVerifiedAt() }) } // SetIssuer sets the "issuer" field. func (u *AuthIdentityUpsertBulk) SetIssuer(v string) *AuthIdentityUpsertBulk { return u.Update(func(s *AuthIdentityUpsert) { s.SetIssuer(v) }) } // UpdateIssuer sets the "issuer" field to the value that was provided on create. func (u *AuthIdentityUpsertBulk) UpdateIssuer() *AuthIdentityUpsertBulk { return u.Update(func(s *AuthIdentityUpsert) { s.UpdateIssuer() }) } // ClearIssuer clears the value of the "issuer" field. func (u *AuthIdentityUpsertBulk) ClearIssuer() *AuthIdentityUpsertBulk { return u.Update(func(s *AuthIdentityUpsert) { s.ClearIssuer() }) } // SetMetadata sets the "metadata" field. func (u *AuthIdentityUpsertBulk) SetMetadata(v map[string]interface{}) *AuthIdentityUpsertBulk { return u.Update(func(s *AuthIdentityUpsert) { s.SetMetadata(v) }) } // UpdateMetadata sets the "metadata" field to the value that was provided on create. func (u *AuthIdentityUpsertBulk) UpdateMetadata() *AuthIdentityUpsertBulk { return u.Update(func(s *AuthIdentityUpsert) { s.UpdateMetadata() }) } // Exec executes the query. func (u *AuthIdentityUpsertBulk) Exec(ctx context.Context) error { if u.create.err != nil { return u.create.err } for i, b := range u.create.builders { if len(b.conflict) != 0 { return fmt.Errorf("ent: OnConflict was set for builder %d. Set it on the AuthIdentityCreateBulk instead", i) } } if len(u.create.conflict) == 0 { return errors.New("ent: missing options for AuthIdentityCreateBulk.OnConflict") } return u.create.Exec(ctx) } // ExecX is like Exec, but panics if an error occurs. func (u *AuthIdentityUpsertBulk) ExecX(ctx context.Context) { if err := u.create.Exec(ctx); err != nil { panic(err) } }