// 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" "git.noahlan.cn/n-admin/n-admin-server/rpc/core/ent/user" "git.noahlan.cn/n-admin/n-admin-server/rpc/core/ent/usersocial" ) // UserSocialCreate is the builder for creating a UserSocial entity. type UserSocialCreate struct { config mutation *UserSocialMutation hooks []Hook conflict []sql.ConflictOption } // SetCreatedAt sets the "created_at" field. func (usc *UserSocialCreate) SetCreatedAt(t time.Time) *UserSocialCreate { usc.mutation.SetCreatedAt(t) return usc } // SetNillableCreatedAt sets the "created_at" field if the given value is not nil. func (usc *UserSocialCreate) SetNillableCreatedAt(t *time.Time) *UserSocialCreate { if t != nil { usc.SetCreatedAt(*t) } return usc } // SetUpdatedAt sets the "updated_at" field. func (usc *UserSocialCreate) SetUpdatedAt(t time.Time) *UserSocialCreate { usc.mutation.SetUpdatedAt(t) return usc } // SetNillableUpdatedAt sets the "updated_at" field if the given value is not nil. func (usc *UserSocialCreate) SetNillableUpdatedAt(t *time.Time) *UserSocialCreate { if t != nil { usc.SetUpdatedAt(*t) } return usc } // SetUserID sets the "user_id" field. func (usc *UserSocialCreate) SetUserID(i int64) *UserSocialCreate { usc.mutation.SetUserID(i) return usc } // SetProvider sets the "provider" field. func (usc *UserSocialCreate) SetProvider(s string) *UserSocialCreate { usc.mutation.SetProvider(s) return usc } // SetAccessToken sets the "access_token" field. func (usc *UserSocialCreate) SetAccessToken(s string) *UserSocialCreate { usc.mutation.SetAccessToken(s) return usc } // SetRefreshToken sets the "refresh_token" field. func (usc *UserSocialCreate) SetRefreshToken(s string) *UserSocialCreate { usc.mutation.SetRefreshToken(s) return usc } // SetUID sets the "uid" field. func (usc *UserSocialCreate) SetUID(s string) *UserSocialCreate { usc.mutation.SetUID(s) return usc } // SetOpenID sets the "open_id" field. func (usc *UserSocialCreate) SetOpenID(s string) *UserSocialCreate { usc.mutation.SetOpenID(s) return usc } // SetUnionID sets the "union_id" field. func (usc *UserSocialCreate) SetUnionID(s string) *UserSocialCreate { usc.mutation.SetUnionID(s) return usc } // SetKey sets the "key" field. func (usc *UserSocialCreate) SetKey(s string) *UserSocialCreate { usc.mutation.SetKey(s) return usc } // SetExpiresIn sets the "expires_in" field. func (usc *UserSocialCreate) SetExpiresIn(u uint64) *UserSocialCreate { usc.mutation.SetExpiresIn(u) return usc } // SetUserProfile sets the "user_profile" field. func (usc *UserSocialCreate) SetUserProfile(s string) *UserSocialCreate { usc.mutation.SetUserProfile(s) return usc } // SetID sets the "id" field. func (usc *UserSocialCreate) SetID(i int64) *UserSocialCreate { usc.mutation.SetID(i) return usc } // SetNillableID sets the "id" field if the given value is not nil. func (usc *UserSocialCreate) SetNillableID(i *int64) *UserSocialCreate { if i != nil { usc.SetID(*i) } return usc } // SetUser sets the "user" edge to the User entity. func (usc *UserSocialCreate) SetUser(u *User) *UserSocialCreate { return usc.SetUserID(u.ID) } // Mutation returns the UserSocialMutation object of the builder. func (usc *UserSocialCreate) Mutation() *UserSocialMutation { return usc.mutation } // Save creates the UserSocial in the database. func (usc *UserSocialCreate) Save(ctx context.Context) (*UserSocial, error) { usc.defaults() return withHooks(ctx, usc.sqlSave, usc.mutation, usc.hooks) } // SaveX calls Save and panics if Save returns an error. func (usc *UserSocialCreate) SaveX(ctx context.Context) *UserSocial { v, err := usc.Save(ctx) if err != nil { panic(err) } return v } // Exec executes the query. func (usc *UserSocialCreate) Exec(ctx context.Context) error { _, err := usc.Save(ctx) return err } // ExecX is like Exec, but panics if an error occurs. func (usc *UserSocialCreate) ExecX(ctx context.Context) { if err := usc.Exec(ctx); err != nil { panic(err) } } // defaults sets the default values of the builder before save. func (usc *UserSocialCreate) defaults() { if _, ok := usc.mutation.CreatedAt(); !ok { v := usersocial.DefaultCreatedAt() usc.mutation.SetCreatedAt(v) } if _, ok := usc.mutation.UpdatedAt(); !ok { v := usersocial.DefaultUpdatedAt() usc.mutation.SetUpdatedAt(v) } if _, ok := usc.mutation.ID(); !ok { v := usersocial.DefaultID() usc.mutation.SetID(v) } } // check runs all checks and user-defined validators on the builder. func (usc *UserSocialCreate) check() error { if _, ok := usc.mutation.CreatedAt(); !ok { return &ValidationError{Name: "created_at", err: errors.New(`ent: missing required field "UserSocial.created_at"`)} } if _, ok := usc.mutation.UpdatedAt(); !ok { return &ValidationError{Name: "updated_at", err: errors.New(`ent: missing required field "UserSocial.updated_at"`)} } if _, ok := usc.mutation.UserID(); !ok { return &ValidationError{Name: "user_id", err: errors.New(`ent: missing required field "UserSocial.user_id"`)} } if _, ok := usc.mutation.Provider(); !ok { return &ValidationError{Name: "provider", err: errors.New(`ent: missing required field "UserSocial.provider"`)} } if _, ok := usc.mutation.AccessToken(); !ok { return &ValidationError{Name: "access_token", err: errors.New(`ent: missing required field "UserSocial.access_token"`)} } if _, ok := usc.mutation.RefreshToken(); !ok { return &ValidationError{Name: "refresh_token", err: errors.New(`ent: missing required field "UserSocial.refresh_token"`)} } if _, ok := usc.mutation.UID(); !ok { return &ValidationError{Name: "uid", err: errors.New(`ent: missing required field "UserSocial.uid"`)} } if _, ok := usc.mutation.OpenID(); !ok { return &ValidationError{Name: "open_id", err: errors.New(`ent: missing required field "UserSocial.open_id"`)} } if _, ok := usc.mutation.UnionID(); !ok { return &ValidationError{Name: "union_id", err: errors.New(`ent: missing required field "UserSocial.union_id"`)} } if _, ok := usc.mutation.Key(); !ok { return &ValidationError{Name: "key", err: errors.New(`ent: missing required field "UserSocial.key"`)} } if _, ok := usc.mutation.ExpiresIn(); !ok { return &ValidationError{Name: "expires_in", err: errors.New(`ent: missing required field "UserSocial.expires_in"`)} } if _, ok := usc.mutation.UserProfile(); !ok { return &ValidationError{Name: "user_profile", err: errors.New(`ent: missing required field "UserSocial.user_profile"`)} } if _, ok := usc.mutation.UserID(); !ok { return &ValidationError{Name: "user", err: errors.New(`ent: missing required edge "UserSocial.user"`)} } return nil } func (usc *UserSocialCreate) sqlSave(ctx context.Context) (*UserSocial, error) { if err := usc.check(); err != nil { return nil, err } _node, _spec := usc.createSpec() if err := sqlgraph.CreateNode(ctx, usc.driver, _spec); err != nil { if sqlgraph.IsConstraintError(err) { err = &ConstraintError{msg: err.Error(), wrap: err} } return nil, err } if _spec.ID.Value != _node.ID { id := _spec.ID.Value.(int64) _node.ID = int64(id) } usc.mutation.id = &_node.ID usc.mutation.done = true return _node, nil } func (usc *UserSocialCreate) createSpec() (*UserSocial, *sqlgraph.CreateSpec) { var ( _node = &UserSocial{config: usc.config} _spec = sqlgraph.NewCreateSpec(usersocial.Table, sqlgraph.NewFieldSpec(usersocial.FieldID, field.TypeInt64)) ) _spec.OnConflict = usc.conflict if id, ok := usc.mutation.ID(); ok { _node.ID = id _spec.ID.Value = id } if value, ok := usc.mutation.CreatedAt(); ok { _spec.SetField(usersocial.FieldCreatedAt, field.TypeTime, value) _node.CreatedAt = value } if value, ok := usc.mutation.UpdatedAt(); ok { _spec.SetField(usersocial.FieldUpdatedAt, field.TypeTime, value) _node.UpdatedAt = value } if value, ok := usc.mutation.Provider(); ok { _spec.SetField(usersocial.FieldProvider, field.TypeString, value) _node.Provider = value } if value, ok := usc.mutation.AccessToken(); ok { _spec.SetField(usersocial.FieldAccessToken, field.TypeString, value) _node.AccessToken = value } if value, ok := usc.mutation.RefreshToken(); ok { _spec.SetField(usersocial.FieldRefreshToken, field.TypeString, value) _node.RefreshToken = value } if value, ok := usc.mutation.UID(); ok { _spec.SetField(usersocial.FieldUID, field.TypeString, value) _node.UID = value } if value, ok := usc.mutation.OpenID(); ok { _spec.SetField(usersocial.FieldOpenID, field.TypeString, value) _node.OpenID = value } if value, ok := usc.mutation.UnionID(); ok { _spec.SetField(usersocial.FieldUnionID, field.TypeString, value) _node.UnionID = value } if value, ok := usc.mutation.Key(); ok { _spec.SetField(usersocial.FieldKey, field.TypeString, value) _node.Key = value } if value, ok := usc.mutation.ExpiresIn(); ok { _spec.SetField(usersocial.FieldExpiresIn, field.TypeUint64, value) _node.ExpiresIn = value } if value, ok := usc.mutation.UserProfile(); ok { _spec.SetField(usersocial.FieldUserProfile, field.TypeString, value) _node.UserProfile = value } if nodes := usc.mutation.UserIDs(); len(nodes) > 0 { edge := &sqlgraph.EdgeSpec{ Rel: sqlgraph.M2O, Inverse: true, Table: usersocial.UserTable, Columns: []string{usersocial.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) } return _node, _spec } // OnConflict allows configuring the `ON CONFLICT` / `ON DUPLICATE KEY` clause // of the `INSERT` statement. For example: // // client.UserSocial.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.UserSocialUpsert) { // SetCreatedAt(v+v). // }). // Exec(ctx) func (usc *UserSocialCreate) OnConflict(opts ...sql.ConflictOption) *UserSocialUpsertOne { usc.conflict = opts return &UserSocialUpsertOne{ create: usc, } } // OnConflictColumns calls `OnConflict` and configures the columns // as conflict target. Using this option is equivalent to using: // // client.UserSocial.Create(). // OnConflict(sql.ConflictColumns(columns...)). // Exec(ctx) func (usc *UserSocialCreate) OnConflictColumns(columns ...string) *UserSocialUpsertOne { usc.conflict = append(usc.conflict, sql.ConflictColumns(columns...)) return &UserSocialUpsertOne{ create: usc, } } type ( // UserSocialUpsertOne is the builder for "upsert"-ing // one UserSocial node. UserSocialUpsertOne struct { create *UserSocialCreate } // UserSocialUpsert is the "OnConflict" setter. UserSocialUpsert struct { *sql.UpdateSet } ) // SetUpdatedAt sets the "updated_at" field. func (u *UserSocialUpsert) SetUpdatedAt(v time.Time) *UserSocialUpsert { u.Set(usersocial.FieldUpdatedAt, v) return u } // UpdateUpdatedAt sets the "updated_at" field to the value that was provided on create. func (u *UserSocialUpsert) UpdateUpdatedAt() *UserSocialUpsert { u.SetExcluded(usersocial.FieldUpdatedAt) return u } // SetUserID sets the "user_id" field. func (u *UserSocialUpsert) SetUserID(v int64) *UserSocialUpsert { u.Set(usersocial.FieldUserID, v) return u } // UpdateUserID sets the "user_id" field to the value that was provided on create. func (u *UserSocialUpsert) UpdateUserID() *UserSocialUpsert { u.SetExcluded(usersocial.FieldUserID) return u } // SetProvider sets the "provider" field. func (u *UserSocialUpsert) SetProvider(v string) *UserSocialUpsert { u.Set(usersocial.FieldProvider, v) return u } // UpdateProvider sets the "provider" field to the value that was provided on create. func (u *UserSocialUpsert) UpdateProvider() *UserSocialUpsert { u.SetExcluded(usersocial.FieldProvider) return u } // SetAccessToken sets the "access_token" field. func (u *UserSocialUpsert) SetAccessToken(v string) *UserSocialUpsert { u.Set(usersocial.FieldAccessToken, v) return u } // UpdateAccessToken sets the "access_token" field to the value that was provided on create. func (u *UserSocialUpsert) UpdateAccessToken() *UserSocialUpsert { u.SetExcluded(usersocial.FieldAccessToken) return u } // SetRefreshToken sets the "refresh_token" field. func (u *UserSocialUpsert) SetRefreshToken(v string) *UserSocialUpsert { u.Set(usersocial.FieldRefreshToken, v) return u } // UpdateRefreshToken sets the "refresh_token" field to the value that was provided on create. func (u *UserSocialUpsert) UpdateRefreshToken() *UserSocialUpsert { u.SetExcluded(usersocial.FieldRefreshToken) return u } // SetUID sets the "uid" field. func (u *UserSocialUpsert) SetUID(v string) *UserSocialUpsert { u.Set(usersocial.FieldUID, v) return u } // UpdateUID sets the "uid" field to the value that was provided on create. func (u *UserSocialUpsert) UpdateUID() *UserSocialUpsert { u.SetExcluded(usersocial.FieldUID) return u } // SetOpenID sets the "open_id" field. func (u *UserSocialUpsert) SetOpenID(v string) *UserSocialUpsert { u.Set(usersocial.FieldOpenID, v) return u } // UpdateOpenID sets the "open_id" field to the value that was provided on create. func (u *UserSocialUpsert) UpdateOpenID() *UserSocialUpsert { u.SetExcluded(usersocial.FieldOpenID) return u } // SetUnionID sets the "union_id" field. func (u *UserSocialUpsert) SetUnionID(v string) *UserSocialUpsert { u.Set(usersocial.FieldUnionID, v) return u } // UpdateUnionID sets the "union_id" field to the value that was provided on create. func (u *UserSocialUpsert) UpdateUnionID() *UserSocialUpsert { u.SetExcluded(usersocial.FieldUnionID) return u } // SetKey sets the "key" field. func (u *UserSocialUpsert) SetKey(v string) *UserSocialUpsert { u.Set(usersocial.FieldKey, v) return u } // UpdateKey sets the "key" field to the value that was provided on create. func (u *UserSocialUpsert) UpdateKey() *UserSocialUpsert { u.SetExcluded(usersocial.FieldKey) return u } // SetExpiresIn sets the "expires_in" field. func (u *UserSocialUpsert) SetExpiresIn(v uint64) *UserSocialUpsert { u.Set(usersocial.FieldExpiresIn, v) return u } // UpdateExpiresIn sets the "expires_in" field to the value that was provided on create. func (u *UserSocialUpsert) UpdateExpiresIn() *UserSocialUpsert { u.SetExcluded(usersocial.FieldExpiresIn) return u } // AddExpiresIn adds v to the "expires_in" field. func (u *UserSocialUpsert) AddExpiresIn(v uint64) *UserSocialUpsert { u.Add(usersocial.FieldExpiresIn, v) return u } // SetUserProfile sets the "user_profile" field. func (u *UserSocialUpsert) SetUserProfile(v string) *UserSocialUpsert { u.Set(usersocial.FieldUserProfile, v) return u } // UpdateUserProfile sets the "user_profile" field to the value that was provided on create. func (u *UserSocialUpsert) UpdateUserProfile() *UserSocialUpsert { u.SetExcluded(usersocial.FieldUserProfile) return u } // UpdateNewValues updates the mutable fields using the new values that were set on create except the ID field. // Using this option is equivalent to using: // // client.UserSocial.Create(). // OnConflict( // sql.ResolveWithNewValues(), // sql.ResolveWith(func(u *sql.UpdateSet) { // u.SetIgnore(usersocial.FieldID) // }), // ). // Exec(ctx) func (u *UserSocialUpsertOne) UpdateNewValues() *UserSocialUpsertOne { 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.ID(); exists { s.SetIgnore(usersocial.FieldID) } if _, exists := u.create.mutation.CreatedAt(); exists { s.SetIgnore(usersocial.FieldCreatedAt) } })) return u } // Ignore sets each column to itself in case of conflict. // Using this option is equivalent to using: // // client.UserSocial.Create(). // OnConflict(sql.ResolveWithIgnore()). // Exec(ctx) func (u *UserSocialUpsertOne) Ignore() *UserSocialUpsertOne { 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 *UserSocialUpsertOne) DoNothing() *UserSocialUpsertOne { u.create.conflict = append(u.create.conflict, sql.DoNothing()) return u } // Update allows overriding fields `UPDATE` values. See the UserSocialCreate.OnConflict // documentation for more info. func (u *UserSocialUpsertOne) Update(set func(*UserSocialUpsert)) *UserSocialUpsertOne { u.create.conflict = append(u.create.conflict, sql.ResolveWith(func(update *sql.UpdateSet) { set(&UserSocialUpsert{UpdateSet: update}) })) return u } // SetUpdatedAt sets the "updated_at" field. func (u *UserSocialUpsertOne) SetUpdatedAt(v time.Time) *UserSocialUpsertOne { return u.Update(func(s *UserSocialUpsert) { s.SetUpdatedAt(v) }) } // UpdateUpdatedAt sets the "updated_at" field to the value that was provided on create. func (u *UserSocialUpsertOne) UpdateUpdatedAt() *UserSocialUpsertOne { return u.Update(func(s *UserSocialUpsert) { s.UpdateUpdatedAt() }) } // SetUserID sets the "user_id" field. func (u *UserSocialUpsertOne) SetUserID(v int64) *UserSocialUpsertOne { return u.Update(func(s *UserSocialUpsert) { s.SetUserID(v) }) } // UpdateUserID sets the "user_id" field to the value that was provided on create. func (u *UserSocialUpsertOne) UpdateUserID() *UserSocialUpsertOne { return u.Update(func(s *UserSocialUpsert) { s.UpdateUserID() }) } // SetProvider sets the "provider" field. func (u *UserSocialUpsertOne) SetProvider(v string) *UserSocialUpsertOne { return u.Update(func(s *UserSocialUpsert) { s.SetProvider(v) }) } // UpdateProvider sets the "provider" field to the value that was provided on create. func (u *UserSocialUpsertOne) UpdateProvider() *UserSocialUpsertOne { return u.Update(func(s *UserSocialUpsert) { s.UpdateProvider() }) } // SetAccessToken sets the "access_token" field. func (u *UserSocialUpsertOne) SetAccessToken(v string) *UserSocialUpsertOne { return u.Update(func(s *UserSocialUpsert) { s.SetAccessToken(v) }) } // UpdateAccessToken sets the "access_token" field to the value that was provided on create. func (u *UserSocialUpsertOne) UpdateAccessToken() *UserSocialUpsertOne { return u.Update(func(s *UserSocialUpsert) { s.UpdateAccessToken() }) } // SetRefreshToken sets the "refresh_token" field. func (u *UserSocialUpsertOne) SetRefreshToken(v string) *UserSocialUpsertOne { return u.Update(func(s *UserSocialUpsert) { s.SetRefreshToken(v) }) } // UpdateRefreshToken sets the "refresh_token" field to the value that was provided on create. func (u *UserSocialUpsertOne) UpdateRefreshToken() *UserSocialUpsertOne { return u.Update(func(s *UserSocialUpsert) { s.UpdateRefreshToken() }) } // SetUID sets the "uid" field. func (u *UserSocialUpsertOne) SetUID(v string) *UserSocialUpsertOne { return u.Update(func(s *UserSocialUpsert) { s.SetUID(v) }) } // UpdateUID sets the "uid" field to the value that was provided on create. func (u *UserSocialUpsertOne) UpdateUID() *UserSocialUpsertOne { return u.Update(func(s *UserSocialUpsert) { s.UpdateUID() }) } // SetOpenID sets the "open_id" field. func (u *UserSocialUpsertOne) SetOpenID(v string) *UserSocialUpsertOne { return u.Update(func(s *UserSocialUpsert) { s.SetOpenID(v) }) } // UpdateOpenID sets the "open_id" field to the value that was provided on create. func (u *UserSocialUpsertOne) UpdateOpenID() *UserSocialUpsertOne { return u.Update(func(s *UserSocialUpsert) { s.UpdateOpenID() }) } // SetUnionID sets the "union_id" field. func (u *UserSocialUpsertOne) SetUnionID(v string) *UserSocialUpsertOne { return u.Update(func(s *UserSocialUpsert) { s.SetUnionID(v) }) } // UpdateUnionID sets the "union_id" field to the value that was provided on create. func (u *UserSocialUpsertOne) UpdateUnionID() *UserSocialUpsertOne { return u.Update(func(s *UserSocialUpsert) { s.UpdateUnionID() }) } // SetKey sets the "key" field. func (u *UserSocialUpsertOne) SetKey(v string) *UserSocialUpsertOne { return u.Update(func(s *UserSocialUpsert) { s.SetKey(v) }) } // UpdateKey sets the "key" field to the value that was provided on create. func (u *UserSocialUpsertOne) UpdateKey() *UserSocialUpsertOne { return u.Update(func(s *UserSocialUpsert) { s.UpdateKey() }) } // SetExpiresIn sets the "expires_in" field. func (u *UserSocialUpsertOne) SetExpiresIn(v uint64) *UserSocialUpsertOne { return u.Update(func(s *UserSocialUpsert) { s.SetExpiresIn(v) }) } // AddExpiresIn adds v to the "expires_in" field. func (u *UserSocialUpsertOne) AddExpiresIn(v uint64) *UserSocialUpsertOne { return u.Update(func(s *UserSocialUpsert) { s.AddExpiresIn(v) }) } // UpdateExpiresIn sets the "expires_in" field to the value that was provided on create. func (u *UserSocialUpsertOne) UpdateExpiresIn() *UserSocialUpsertOne { return u.Update(func(s *UserSocialUpsert) { s.UpdateExpiresIn() }) } // SetUserProfile sets the "user_profile" field. func (u *UserSocialUpsertOne) SetUserProfile(v string) *UserSocialUpsertOne { return u.Update(func(s *UserSocialUpsert) { s.SetUserProfile(v) }) } // UpdateUserProfile sets the "user_profile" field to the value that was provided on create. func (u *UserSocialUpsertOne) UpdateUserProfile() *UserSocialUpsertOne { return u.Update(func(s *UserSocialUpsert) { s.UpdateUserProfile() }) } // Exec executes the query. func (u *UserSocialUpsertOne) Exec(ctx context.Context) error { if len(u.create.conflict) == 0 { return errors.New("ent: missing options for UserSocialCreate.OnConflict") } return u.create.Exec(ctx) } // ExecX is like Exec, but panics if an error occurs. func (u *UserSocialUpsertOne) 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 *UserSocialUpsertOne) 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 *UserSocialUpsertOne) IDX(ctx context.Context) int64 { id, err := u.ID(ctx) if err != nil { panic(err) } return id } // UserSocialCreateBulk is the builder for creating many UserSocial entities in bulk. type UserSocialCreateBulk struct { config builders []*UserSocialCreate conflict []sql.ConflictOption } // Save creates the UserSocial entities in the database. func (uscb *UserSocialCreateBulk) Save(ctx context.Context) ([]*UserSocial, error) { specs := make([]*sqlgraph.CreateSpec, len(uscb.builders)) nodes := make([]*UserSocial, len(uscb.builders)) mutators := make([]Mutator, len(uscb.builders)) for i := range uscb.builders { func(i int, root context.Context) { builder := uscb.builders[i] builder.defaults() var mut Mutator = MutateFunc(func(ctx context.Context, m Mutation) (Value, error) { mutation, ok := m.(*UserSocialMutation) 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, uscb.builders[i+1].mutation) } else { spec := &sqlgraph.BatchCreateSpec{Nodes: specs} spec.OnConflict = uscb.conflict // Invoke the actual operation on the latest mutation in the chain. if err = sqlgraph.BatchCreate(ctx, uscb.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 && nodes[i].ID == 0 { 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, uscb.builders[0].mutation); err != nil { return nil, err } } return nodes, nil } // SaveX is like Save, but panics if an error occurs. func (uscb *UserSocialCreateBulk) SaveX(ctx context.Context) []*UserSocial { v, err := uscb.Save(ctx) if err != nil { panic(err) } return v } // Exec executes the query. func (uscb *UserSocialCreateBulk) Exec(ctx context.Context) error { _, err := uscb.Save(ctx) return err } // ExecX is like Exec, but panics if an error occurs. func (uscb *UserSocialCreateBulk) ExecX(ctx context.Context) { if err := uscb.Exec(ctx); err != nil { panic(err) } } // OnConflict allows configuring the `ON CONFLICT` / `ON DUPLICATE KEY` clause // of the `INSERT` statement. For example: // // client.UserSocial.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.UserSocialUpsert) { // SetCreatedAt(v+v). // }). // Exec(ctx) func (uscb *UserSocialCreateBulk) OnConflict(opts ...sql.ConflictOption) *UserSocialUpsertBulk { uscb.conflict = opts return &UserSocialUpsertBulk{ create: uscb, } } // OnConflictColumns calls `OnConflict` and configures the columns // as conflict target. Using this option is equivalent to using: // // client.UserSocial.Create(). // OnConflict(sql.ConflictColumns(columns...)). // Exec(ctx) func (uscb *UserSocialCreateBulk) OnConflictColumns(columns ...string) *UserSocialUpsertBulk { uscb.conflict = append(uscb.conflict, sql.ConflictColumns(columns...)) return &UserSocialUpsertBulk{ create: uscb, } } // UserSocialUpsertBulk is the builder for "upsert"-ing // a bulk of UserSocial nodes. type UserSocialUpsertBulk struct { create *UserSocialCreateBulk } // UpdateNewValues updates the mutable fields using the new values that // were set on create. Using this option is equivalent to using: // // client.UserSocial.Create(). // OnConflict( // sql.ResolveWithNewValues(), // sql.ResolveWith(func(u *sql.UpdateSet) { // u.SetIgnore(usersocial.FieldID) // }), // ). // Exec(ctx) func (u *UserSocialUpsertBulk) UpdateNewValues() *UserSocialUpsertBulk { 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.ID(); exists { s.SetIgnore(usersocial.FieldID) } if _, exists := b.mutation.CreatedAt(); exists { s.SetIgnore(usersocial.FieldCreatedAt) } } })) return u } // Ignore sets each column to itself in case of conflict. // Using this option is equivalent to using: // // client.UserSocial.Create(). // OnConflict(sql.ResolveWithIgnore()). // Exec(ctx) func (u *UserSocialUpsertBulk) Ignore() *UserSocialUpsertBulk { 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 *UserSocialUpsertBulk) DoNothing() *UserSocialUpsertBulk { u.create.conflict = append(u.create.conflict, sql.DoNothing()) return u } // Update allows overriding fields `UPDATE` values. See the UserSocialCreateBulk.OnConflict // documentation for more info. func (u *UserSocialUpsertBulk) Update(set func(*UserSocialUpsert)) *UserSocialUpsertBulk { u.create.conflict = append(u.create.conflict, sql.ResolveWith(func(update *sql.UpdateSet) { set(&UserSocialUpsert{UpdateSet: update}) })) return u } // SetUpdatedAt sets the "updated_at" field. func (u *UserSocialUpsertBulk) SetUpdatedAt(v time.Time) *UserSocialUpsertBulk { return u.Update(func(s *UserSocialUpsert) { s.SetUpdatedAt(v) }) } // UpdateUpdatedAt sets the "updated_at" field to the value that was provided on create. func (u *UserSocialUpsertBulk) UpdateUpdatedAt() *UserSocialUpsertBulk { return u.Update(func(s *UserSocialUpsert) { s.UpdateUpdatedAt() }) } // SetUserID sets the "user_id" field. func (u *UserSocialUpsertBulk) SetUserID(v int64) *UserSocialUpsertBulk { return u.Update(func(s *UserSocialUpsert) { s.SetUserID(v) }) } // UpdateUserID sets the "user_id" field to the value that was provided on create. func (u *UserSocialUpsertBulk) UpdateUserID() *UserSocialUpsertBulk { return u.Update(func(s *UserSocialUpsert) { s.UpdateUserID() }) } // SetProvider sets the "provider" field. func (u *UserSocialUpsertBulk) SetProvider(v string) *UserSocialUpsertBulk { return u.Update(func(s *UserSocialUpsert) { s.SetProvider(v) }) } // UpdateProvider sets the "provider" field to the value that was provided on create. func (u *UserSocialUpsertBulk) UpdateProvider() *UserSocialUpsertBulk { return u.Update(func(s *UserSocialUpsert) { s.UpdateProvider() }) } // SetAccessToken sets the "access_token" field. func (u *UserSocialUpsertBulk) SetAccessToken(v string) *UserSocialUpsertBulk { return u.Update(func(s *UserSocialUpsert) { s.SetAccessToken(v) }) } // UpdateAccessToken sets the "access_token" field to the value that was provided on create. func (u *UserSocialUpsertBulk) UpdateAccessToken() *UserSocialUpsertBulk { return u.Update(func(s *UserSocialUpsert) { s.UpdateAccessToken() }) } // SetRefreshToken sets the "refresh_token" field. func (u *UserSocialUpsertBulk) SetRefreshToken(v string) *UserSocialUpsertBulk { return u.Update(func(s *UserSocialUpsert) { s.SetRefreshToken(v) }) } // UpdateRefreshToken sets the "refresh_token" field to the value that was provided on create. func (u *UserSocialUpsertBulk) UpdateRefreshToken() *UserSocialUpsertBulk { return u.Update(func(s *UserSocialUpsert) { s.UpdateRefreshToken() }) } // SetUID sets the "uid" field. func (u *UserSocialUpsertBulk) SetUID(v string) *UserSocialUpsertBulk { return u.Update(func(s *UserSocialUpsert) { s.SetUID(v) }) } // UpdateUID sets the "uid" field to the value that was provided on create. func (u *UserSocialUpsertBulk) UpdateUID() *UserSocialUpsertBulk { return u.Update(func(s *UserSocialUpsert) { s.UpdateUID() }) } // SetOpenID sets the "open_id" field. func (u *UserSocialUpsertBulk) SetOpenID(v string) *UserSocialUpsertBulk { return u.Update(func(s *UserSocialUpsert) { s.SetOpenID(v) }) } // UpdateOpenID sets the "open_id" field to the value that was provided on create. func (u *UserSocialUpsertBulk) UpdateOpenID() *UserSocialUpsertBulk { return u.Update(func(s *UserSocialUpsert) { s.UpdateOpenID() }) } // SetUnionID sets the "union_id" field. func (u *UserSocialUpsertBulk) SetUnionID(v string) *UserSocialUpsertBulk { return u.Update(func(s *UserSocialUpsert) { s.SetUnionID(v) }) } // UpdateUnionID sets the "union_id" field to the value that was provided on create. func (u *UserSocialUpsertBulk) UpdateUnionID() *UserSocialUpsertBulk { return u.Update(func(s *UserSocialUpsert) { s.UpdateUnionID() }) } // SetKey sets the "key" field. func (u *UserSocialUpsertBulk) SetKey(v string) *UserSocialUpsertBulk { return u.Update(func(s *UserSocialUpsert) { s.SetKey(v) }) } // UpdateKey sets the "key" field to the value that was provided on create. func (u *UserSocialUpsertBulk) UpdateKey() *UserSocialUpsertBulk { return u.Update(func(s *UserSocialUpsert) { s.UpdateKey() }) } // SetExpiresIn sets the "expires_in" field. func (u *UserSocialUpsertBulk) SetExpiresIn(v uint64) *UserSocialUpsertBulk { return u.Update(func(s *UserSocialUpsert) { s.SetExpiresIn(v) }) } // AddExpiresIn adds v to the "expires_in" field. func (u *UserSocialUpsertBulk) AddExpiresIn(v uint64) *UserSocialUpsertBulk { return u.Update(func(s *UserSocialUpsert) { s.AddExpiresIn(v) }) } // UpdateExpiresIn sets the "expires_in" field to the value that was provided on create. func (u *UserSocialUpsertBulk) UpdateExpiresIn() *UserSocialUpsertBulk { return u.Update(func(s *UserSocialUpsert) { s.UpdateExpiresIn() }) } // SetUserProfile sets the "user_profile" field. func (u *UserSocialUpsertBulk) SetUserProfile(v string) *UserSocialUpsertBulk { return u.Update(func(s *UserSocialUpsert) { s.SetUserProfile(v) }) } // UpdateUserProfile sets the "user_profile" field to the value that was provided on create. func (u *UserSocialUpsertBulk) UpdateUserProfile() *UserSocialUpsertBulk { return u.Update(func(s *UserSocialUpsert) { s.UpdateUserProfile() }) } // Exec executes the query. func (u *UserSocialUpsertBulk) Exec(ctx context.Context) error { 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 UserSocialCreateBulk instead", i) } } if len(u.create.conflict) == 0 { return errors.New("ent: missing options for UserSocialCreateBulk.OnConflict") } return u.create.Exec(ctx) } // ExecX is like Exec, but panics if an error occurs. func (u *UserSocialUpsertBulk) ExecX(ctx context.Context) { if err := u.create.Exec(ctx); err != nil { panic(err) } }