613 lines
18 KiB
Go
613 lines
18 KiB
Go
// Code generated by ent, DO NOT EDIT.
|
|
|
|
package ent
|
|
|
|
import (
|
|
"context"
|
|
"errors"
|
|
"fmt"
|
|
"mingyang-admin-app-rpc/ent/userthirdauth"
|
|
"time"
|
|
|
|
"entgo.io/ent/dialect/sql/sqlgraph"
|
|
"entgo.io/ent/schema/field"
|
|
)
|
|
|
|
// UserThirdAuthCreate is the builder for creating a UserThirdAuth entity.
|
|
type UserThirdAuthCreate struct {
|
|
config
|
|
mutation *UserThirdAuthMutation
|
|
hooks []Hook
|
|
}
|
|
|
|
// SetCreatedAt sets the "created_at" field.
|
|
func (_c *UserThirdAuthCreate) SetCreatedAt(v time.Time) *UserThirdAuthCreate {
|
|
_c.mutation.SetCreatedAt(v)
|
|
return _c
|
|
}
|
|
|
|
// SetNillableCreatedAt sets the "created_at" field if the given value is not nil.
|
|
func (_c *UserThirdAuthCreate) SetNillableCreatedAt(v *time.Time) *UserThirdAuthCreate {
|
|
if v != nil {
|
|
_c.SetCreatedAt(*v)
|
|
}
|
|
return _c
|
|
}
|
|
|
|
// SetUpdatedAt sets the "updated_at" field.
|
|
func (_c *UserThirdAuthCreate) SetUpdatedAt(v time.Time) *UserThirdAuthCreate {
|
|
_c.mutation.SetUpdatedAt(v)
|
|
return _c
|
|
}
|
|
|
|
// SetNillableUpdatedAt sets the "updated_at" field if the given value is not nil.
|
|
func (_c *UserThirdAuthCreate) SetNillableUpdatedAt(v *time.Time) *UserThirdAuthCreate {
|
|
if v != nil {
|
|
_c.SetUpdatedAt(*v)
|
|
}
|
|
return _c
|
|
}
|
|
|
|
// SetStatus sets the "status" field.
|
|
func (_c *UserThirdAuthCreate) SetStatus(v uint8) *UserThirdAuthCreate {
|
|
_c.mutation.SetStatus(v)
|
|
return _c
|
|
}
|
|
|
|
// SetNillableStatus sets the "status" field if the given value is not nil.
|
|
func (_c *UserThirdAuthCreate) SetNillableStatus(v *uint8) *UserThirdAuthCreate {
|
|
if v != nil {
|
|
_c.SetStatus(*v)
|
|
}
|
|
return _c
|
|
}
|
|
|
|
// SetTenantID sets the "tenant_id" field.
|
|
func (_c *UserThirdAuthCreate) SetTenantID(v uint64) *UserThirdAuthCreate {
|
|
_c.mutation.SetTenantID(v)
|
|
return _c
|
|
}
|
|
|
|
// SetNillableTenantID sets the "tenant_id" field if the given value is not nil.
|
|
func (_c *UserThirdAuthCreate) SetNillableTenantID(v *uint64) *UserThirdAuthCreate {
|
|
if v != nil {
|
|
_c.SetTenantID(*v)
|
|
}
|
|
return _c
|
|
}
|
|
|
|
// SetDeletedAt sets the "deleted_at" field.
|
|
func (_c *UserThirdAuthCreate) SetDeletedAt(v time.Time) *UserThirdAuthCreate {
|
|
_c.mutation.SetDeletedAt(v)
|
|
return _c
|
|
}
|
|
|
|
// SetNillableDeletedAt sets the "deleted_at" field if the given value is not nil.
|
|
func (_c *UserThirdAuthCreate) SetNillableDeletedAt(v *time.Time) *UserThirdAuthCreate {
|
|
if v != nil {
|
|
_c.SetDeletedAt(*v)
|
|
}
|
|
return _c
|
|
}
|
|
|
|
// SetUserID sets the "user_id" field.
|
|
func (_c *UserThirdAuthCreate) SetUserID(v uint64) *UserThirdAuthCreate {
|
|
_c.mutation.SetUserID(v)
|
|
return _c
|
|
}
|
|
|
|
// SetOpenid sets the "openid" field.
|
|
func (_c *UserThirdAuthCreate) SetOpenid(v string) *UserThirdAuthCreate {
|
|
_c.mutation.SetOpenid(v)
|
|
return _c
|
|
}
|
|
|
|
// SetNillableOpenid sets the "openid" field if the given value is not nil.
|
|
func (_c *UserThirdAuthCreate) SetNillableOpenid(v *string) *UserThirdAuthCreate {
|
|
if v != nil {
|
|
_c.SetOpenid(*v)
|
|
}
|
|
return _c
|
|
}
|
|
|
|
// SetUnionid sets the "unionid" field.
|
|
func (_c *UserThirdAuthCreate) SetUnionid(v string) *UserThirdAuthCreate {
|
|
_c.mutation.SetUnionid(v)
|
|
return _c
|
|
}
|
|
|
|
// SetNillableUnionid sets the "unionid" field if the given value is not nil.
|
|
func (_c *UserThirdAuthCreate) SetNillableUnionid(v *string) *UserThirdAuthCreate {
|
|
if v != nil {
|
|
_c.SetUnionid(*v)
|
|
}
|
|
return _c
|
|
}
|
|
|
|
// SetAccessToken sets the "access_token" field.
|
|
func (_c *UserThirdAuthCreate) SetAccessToken(v string) *UserThirdAuthCreate {
|
|
_c.mutation.SetAccessToken(v)
|
|
return _c
|
|
}
|
|
|
|
// SetNillableAccessToken sets the "access_token" field if the given value is not nil.
|
|
func (_c *UserThirdAuthCreate) SetNillableAccessToken(v *string) *UserThirdAuthCreate {
|
|
if v != nil {
|
|
_c.SetAccessToken(*v)
|
|
}
|
|
return _c
|
|
}
|
|
|
|
// SetRefreshToken sets the "refresh_token" field.
|
|
func (_c *UserThirdAuthCreate) SetRefreshToken(v string) *UserThirdAuthCreate {
|
|
_c.mutation.SetRefreshToken(v)
|
|
return _c
|
|
}
|
|
|
|
// SetNillableRefreshToken sets the "refresh_token" field if the given value is not nil.
|
|
func (_c *UserThirdAuthCreate) SetNillableRefreshToken(v *string) *UserThirdAuthCreate {
|
|
if v != nil {
|
|
_c.SetRefreshToken(*v)
|
|
}
|
|
return _c
|
|
}
|
|
|
|
// SetAccessTokenExpiry sets the "access_token_expiry" field.
|
|
func (_c *UserThirdAuthCreate) SetAccessTokenExpiry(v time.Time) *UserThirdAuthCreate {
|
|
_c.mutation.SetAccessTokenExpiry(v)
|
|
return _c
|
|
}
|
|
|
|
// SetNillableAccessTokenExpiry sets the "access_token_expiry" field if the given value is not nil.
|
|
func (_c *UserThirdAuthCreate) SetNillableAccessTokenExpiry(v *time.Time) *UserThirdAuthCreate {
|
|
if v != nil {
|
|
_c.SetAccessTokenExpiry(*v)
|
|
}
|
|
return _c
|
|
}
|
|
|
|
// SetUserInfo sets the "user_info" field.
|
|
func (_c *UserThirdAuthCreate) SetUserInfo(v map[string]interface{}) *UserThirdAuthCreate {
|
|
_c.mutation.SetUserInfo(v)
|
|
return _c
|
|
}
|
|
|
|
// SetPlatformUserID sets the "platform_user_id" field.
|
|
func (_c *UserThirdAuthCreate) SetPlatformUserID(v string) *UserThirdAuthCreate {
|
|
_c.mutation.SetPlatformUserID(v)
|
|
return _c
|
|
}
|
|
|
|
// SetNillablePlatformUserID sets the "platform_user_id" field if the given value is not nil.
|
|
func (_c *UserThirdAuthCreate) SetNillablePlatformUserID(v *string) *UserThirdAuthCreate {
|
|
if v != nil {
|
|
_c.SetPlatformUserID(*v)
|
|
}
|
|
return _c
|
|
}
|
|
|
|
// SetNickname sets the "nickname" field.
|
|
func (_c *UserThirdAuthCreate) SetNickname(v string) *UserThirdAuthCreate {
|
|
_c.mutation.SetNickname(v)
|
|
return _c
|
|
}
|
|
|
|
// SetNillableNickname sets the "nickname" field if the given value is not nil.
|
|
func (_c *UserThirdAuthCreate) SetNillableNickname(v *string) *UserThirdAuthCreate {
|
|
if v != nil {
|
|
_c.SetNickname(*v)
|
|
}
|
|
return _c
|
|
}
|
|
|
|
// SetAvatar sets the "avatar" field.
|
|
func (_c *UserThirdAuthCreate) SetAvatar(v string) *UserThirdAuthCreate {
|
|
_c.mutation.SetAvatar(v)
|
|
return _c
|
|
}
|
|
|
|
// SetNillableAvatar sets the "avatar" field if the given value is not nil.
|
|
func (_c *UserThirdAuthCreate) SetNillableAvatar(v *string) *UserThirdAuthCreate {
|
|
if v != nil {
|
|
_c.SetAvatar(*v)
|
|
}
|
|
return _c
|
|
}
|
|
|
|
// SetEmail sets the "email" field.
|
|
func (_c *UserThirdAuthCreate) SetEmail(v string) *UserThirdAuthCreate {
|
|
_c.mutation.SetEmail(v)
|
|
return _c
|
|
}
|
|
|
|
// SetNillableEmail sets the "email" field if the given value is not nil.
|
|
func (_c *UserThirdAuthCreate) SetNillableEmail(v *string) *UserThirdAuthCreate {
|
|
if v != nil {
|
|
_c.SetEmail(*v)
|
|
}
|
|
return _c
|
|
}
|
|
|
|
// SetMobile sets the "mobile" field.
|
|
func (_c *UserThirdAuthCreate) SetMobile(v string) *UserThirdAuthCreate {
|
|
_c.mutation.SetMobile(v)
|
|
return _c
|
|
}
|
|
|
|
// SetNillableMobile sets the "mobile" field if the given value is not nil.
|
|
func (_c *UserThirdAuthCreate) SetNillableMobile(v *string) *UserThirdAuthCreate {
|
|
if v != nil {
|
|
_c.SetMobile(*v)
|
|
}
|
|
return _c
|
|
}
|
|
|
|
// SetIsBound sets the "is_bound" field.
|
|
func (_c *UserThirdAuthCreate) SetIsBound(v bool) *UserThirdAuthCreate {
|
|
_c.mutation.SetIsBound(v)
|
|
return _c
|
|
}
|
|
|
|
// SetNillableIsBound sets the "is_bound" field if the given value is not nil.
|
|
func (_c *UserThirdAuthCreate) SetNillableIsBound(v *bool) *UserThirdAuthCreate {
|
|
if v != nil {
|
|
_c.SetIsBound(*v)
|
|
}
|
|
return _c
|
|
}
|
|
|
|
// SetBoundAt sets the "bound_at" field.
|
|
func (_c *UserThirdAuthCreate) SetBoundAt(v time.Time) *UserThirdAuthCreate {
|
|
_c.mutation.SetBoundAt(v)
|
|
return _c
|
|
}
|
|
|
|
// SetNillableBoundAt sets the "bound_at" field if the given value is not nil.
|
|
func (_c *UserThirdAuthCreate) SetNillableBoundAt(v *time.Time) *UserThirdAuthCreate {
|
|
if v != nil {
|
|
_c.SetBoundAt(*v)
|
|
}
|
|
return _c
|
|
}
|
|
|
|
// SetExtraData sets the "extra_data" field.
|
|
func (_c *UserThirdAuthCreate) SetExtraData(v map[string]interface{}) *UserThirdAuthCreate {
|
|
_c.mutation.SetExtraData(v)
|
|
return _c
|
|
}
|
|
|
|
// SetID sets the "id" field.
|
|
func (_c *UserThirdAuthCreate) SetID(v uint64) *UserThirdAuthCreate {
|
|
_c.mutation.SetID(v)
|
|
return _c
|
|
}
|
|
|
|
// Mutation returns the UserThirdAuthMutation object of the builder.
|
|
func (_c *UserThirdAuthCreate) Mutation() *UserThirdAuthMutation {
|
|
return _c.mutation
|
|
}
|
|
|
|
// Save creates the UserThirdAuth in the database.
|
|
func (_c *UserThirdAuthCreate) Save(ctx context.Context) (*UserThirdAuth, error) {
|
|
_c.defaults()
|
|
return withHooks(ctx, _c.sqlSave, _c.mutation, _c.hooks)
|
|
}
|
|
|
|
// SaveX calls Save and panics if Save returns an error.
|
|
func (_c *UserThirdAuthCreate) SaveX(ctx context.Context) *UserThirdAuth {
|
|
v, err := _c.Save(ctx)
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
return v
|
|
}
|
|
|
|
// Exec executes the query.
|
|
func (_c *UserThirdAuthCreate) Exec(ctx context.Context) error {
|
|
_, err := _c.Save(ctx)
|
|
return err
|
|
}
|
|
|
|
// ExecX is like Exec, but panics if an error occurs.
|
|
func (_c *UserThirdAuthCreate) 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 *UserThirdAuthCreate) defaults() {
|
|
if _, ok := _c.mutation.CreatedAt(); !ok {
|
|
v := userthirdauth.DefaultCreatedAt()
|
|
_c.mutation.SetCreatedAt(v)
|
|
}
|
|
if _, ok := _c.mutation.UpdatedAt(); !ok {
|
|
v := userthirdauth.DefaultUpdatedAt()
|
|
_c.mutation.SetUpdatedAt(v)
|
|
}
|
|
if _, ok := _c.mutation.Status(); !ok {
|
|
v := userthirdauth.DefaultStatus
|
|
_c.mutation.SetStatus(v)
|
|
}
|
|
if _, ok := _c.mutation.TenantID(); !ok {
|
|
v := userthirdauth.DefaultTenantID
|
|
_c.mutation.SetTenantID(v)
|
|
}
|
|
if _, ok := _c.mutation.IsBound(); !ok {
|
|
v := userthirdauth.DefaultIsBound
|
|
_c.mutation.SetIsBound(v)
|
|
}
|
|
if _, ok := _c.mutation.BoundAt(); !ok {
|
|
v := userthirdauth.DefaultBoundAt()
|
|
_c.mutation.SetBoundAt(v)
|
|
}
|
|
}
|
|
|
|
// check runs all checks and user-defined validators on the builder.
|
|
func (_c *UserThirdAuthCreate) check() error {
|
|
if _, ok := _c.mutation.CreatedAt(); !ok {
|
|
return &ValidationError{Name: "created_at", err: errors.New(`ent: missing required field "UserThirdAuth.created_at"`)}
|
|
}
|
|
if _, ok := _c.mutation.UpdatedAt(); !ok {
|
|
return &ValidationError{Name: "updated_at", err: errors.New(`ent: missing required field "UserThirdAuth.updated_at"`)}
|
|
}
|
|
if _, ok := _c.mutation.TenantID(); !ok {
|
|
return &ValidationError{Name: "tenant_id", err: errors.New(`ent: missing required field "UserThirdAuth.tenant_id"`)}
|
|
}
|
|
if _, ok := _c.mutation.UserID(); !ok {
|
|
return &ValidationError{Name: "user_id", err: errors.New(`ent: missing required field "UserThirdAuth.user_id"`)}
|
|
}
|
|
if v, ok := _c.mutation.Openid(); ok {
|
|
if err := userthirdauth.OpenidValidator(v); err != nil {
|
|
return &ValidationError{Name: "openid", err: fmt.Errorf(`ent: validator failed for field "UserThirdAuth.openid": %w`, err)}
|
|
}
|
|
}
|
|
if v, ok := _c.mutation.Unionid(); ok {
|
|
if err := userthirdauth.UnionidValidator(v); err != nil {
|
|
return &ValidationError{Name: "unionid", err: fmt.Errorf(`ent: validator failed for field "UserThirdAuth.unionid": %w`, err)}
|
|
}
|
|
}
|
|
if v, ok := _c.mutation.AccessToken(); ok {
|
|
if err := userthirdauth.AccessTokenValidator(v); err != nil {
|
|
return &ValidationError{Name: "access_token", err: fmt.Errorf(`ent: validator failed for field "UserThirdAuth.access_token": %w`, err)}
|
|
}
|
|
}
|
|
if v, ok := _c.mutation.RefreshToken(); ok {
|
|
if err := userthirdauth.RefreshTokenValidator(v); err != nil {
|
|
return &ValidationError{Name: "refresh_token", err: fmt.Errorf(`ent: validator failed for field "UserThirdAuth.refresh_token": %w`, err)}
|
|
}
|
|
}
|
|
if v, ok := _c.mutation.PlatformUserID(); ok {
|
|
if err := userthirdauth.PlatformUserIDValidator(v); err != nil {
|
|
return &ValidationError{Name: "platform_user_id", err: fmt.Errorf(`ent: validator failed for field "UserThirdAuth.platform_user_id": %w`, err)}
|
|
}
|
|
}
|
|
if v, ok := _c.mutation.Nickname(); ok {
|
|
if err := userthirdauth.NicknameValidator(v); err != nil {
|
|
return &ValidationError{Name: "nickname", err: fmt.Errorf(`ent: validator failed for field "UserThirdAuth.nickname": %w`, err)}
|
|
}
|
|
}
|
|
if v, ok := _c.mutation.Avatar(); ok {
|
|
if err := userthirdauth.AvatarValidator(v); err != nil {
|
|
return &ValidationError{Name: "avatar", err: fmt.Errorf(`ent: validator failed for field "UserThirdAuth.avatar": %w`, err)}
|
|
}
|
|
}
|
|
if v, ok := _c.mutation.Email(); ok {
|
|
if err := userthirdauth.EmailValidator(v); err != nil {
|
|
return &ValidationError{Name: "email", err: fmt.Errorf(`ent: validator failed for field "UserThirdAuth.email": %w`, err)}
|
|
}
|
|
}
|
|
if v, ok := _c.mutation.Mobile(); ok {
|
|
if err := userthirdauth.MobileValidator(v); err != nil {
|
|
return &ValidationError{Name: "mobile", err: fmt.Errorf(`ent: validator failed for field "UserThirdAuth.mobile": %w`, err)}
|
|
}
|
|
}
|
|
if _, ok := _c.mutation.IsBound(); !ok {
|
|
return &ValidationError{Name: "is_bound", err: errors.New(`ent: missing required field "UserThirdAuth.is_bound"`)}
|
|
}
|
|
if _, ok := _c.mutation.BoundAt(); !ok {
|
|
return &ValidationError{Name: "bound_at", err: errors.New(`ent: missing required field "UserThirdAuth.bound_at"`)}
|
|
}
|
|
return nil
|
|
}
|
|
|
|
func (_c *UserThirdAuthCreate) sqlSave(ctx context.Context) (*UserThirdAuth, 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
|
|
}
|
|
if _spec.ID.Value != _node.ID {
|
|
id := _spec.ID.Value.(int64)
|
|
_node.ID = uint64(id)
|
|
}
|
|
_c.mutation.id = &_node.ID
|
|
_c.mutation.done = true
|
|
return _node, nil
|
|
}
|
|
|
|
func (_c *UserThirdAuthCreate) createSpec() (*UserThirdAuth, *sqlgraph.CreateSpec) {
|
|
var (
|
|
_node = &UserThirdAuth{config: _c.config}
|
|
_spec = sqlgraph.NewCreateSpec(userthirdauth.Table, sqlgraph.NewFieldSpec(userthirdauth.FieldID, field.TypeUint64))
|
|
)
|
|
if id, ok := _c.mutation.ID(); ok {
|
|
_node.ID = id
|
|
_spec.ID.Value = id
|
|
}
|
|
if value, ok := _c.mutation.CreatedAt(); ok {
|
|
_spec.SetField(userthirdauth.FieldCreatedAt, field.TypeTime, value)
|
|
_node.CreatedAt = value
|
|
}
|
|
if value, ok := _c.mutation.UpdatedAt(); ok {
|
|
_spec.SetField(userthirdauth.FieldUpdatedAt, field.TypeTime, value)
|
|
_node.UpdatedAt = value
|
|
}
|
|
if value, ok := _c.mutation.Status(); ok {
|
|
_spec.SetField(userthirdauth.FieldStatus, field.TypeUint8, value)
|
|
_node.Status = value
|
|
}
|
|
if value, ok := _c.mutation.TenantID(); ok {
|
|
_spec.SetField(userthirdauth.FieldTenantID, field.TypeUint64, value)
|
|
_node.TenantID = value
|
|
}
|
|
if value, ok := _c.mutation.DeletedAt(); ok {
|
|
_spec.SetField(userthirdauth.FieldDeletedAt, field.TypeTime, value)
|
|
_node.DeletedAt = value
|
|
}
|
|
if value, ok := _c.mutation.UserID(); ok {
|
|
_spec.SetField(userthirdauth.FieldUserID, field.TypeUint64, value)
|
|
_node.UserID = value
|
|
}
|
|
if value, ok := _c.mutation.Openid(); ok {
|
|
_spec.SetField(userthirdauth.FieldOpenid, field.TypeString, value)
|
|
_node.Openid = value
|
|
}
|
|
if value, ok := _c.mutation.Unionid(); ok {
|
|
_spec.SetField(userthirdauth.FieldUnionid, field.TypeString, value)
|
|
_node.Unionid = value
|
|
}
|
|
if value, ok := _c.mutation.AccessToken(); ok {
|
|
_spec.SetField(userthirdauth.FieldAccessToken, field.TypeString, value)
|
|
_node.AccessToken = value
|
|
}
|
|
if value, ok := _c.mutation.RefreshToken(); ok {
|
|
_spec.SetField(userthirdauth.FieldRefreshToken, field.TypeString, value)
|
|
_node.RefreshToken = value
|
|
}
|
|
if value, ok := _c.mutation.AccessTokenExpiry(); ok {
|
|
_spec.SetField(userthirdauth.FieldAccessTokenExpiry, field.TypeTime, value)
|
|
_node.AccessTokenExpiry = &value
|
|
}
|
|
if value, ok := _c.mutation.UserInfo(); ok {
|
|
_spec.SetField(userthirdauth.FieldUserInfo, field.TypeJSON, value)
|
|
_node.UserInfo = value
|
|
}
|
|
if value, ok := _c.mutation.PlatformUserID(); ok {
|
|
_spec.SetField(userthirdauth.FieldPlatformUserID, field.TypeString, value)
|
|
_node.PlatformUserID = value
|
|
}
|
|
if value, ok := _c.mutation.Nickname(); ok {
|
|
_spec.SetField(userthirdauth.FieldNickname, field.TypeString, value)
|
|
_node.Nickname = value
|
|
}
|
|
if value, ok := _c.mutation.Avatar(); ok {
|
|
_spec.SetField(userthirdauth.FieldAvatar, field.TypeString, value)
|
|
_node.Avatar = value
|
|
}
|
|
if value, ok := _c.mutation.Email(); ok {
|
|
_spec.SetField(userthirdauth.FieldEmail, field.TypeString, value)
|
|
_node.Email = value
|
|
}
|
|
if value, ok := _c.mutation.Mobile(); ok {
|
|
_spec.SetField(userthirdauth.FieldMobile, field.TypeString, value)
|
|
_node.Mobile = value
|
|
}
|
|
if value, ok := _c.mutation.IsBound(); ok {
|
|
_spec.SetField(userthirdauth.FieldIsBound, field.TypeBool, value)
|
|
_node.IsBound = value
|
|
}
|
|
if value, ok := _c.mutation.BoundAt(); ok {
|
|
_spec.SetField(userthirdauth.FieldBoundAt, field.TypeTime, value)
|
|
_node.BoundAt = value
|
|
}
|
|
if value, ok := _c.mutation.ExtraData(); ok {
|
|
_spec.SetField(userthirdauth.FieldExtraData, field.TypeJSON, value)
|
|
_node.ExtraData = value
|
|
}
|
|
return _node, _spec
|
|
}
|
|
|
|
// UserThirdAuthCreateBulk is the builder for creating many UserThirdAuth entities in bulk.
|
|
type UserThirdAuthCreateBulk struct {
|
|
config
|
|
err error
|
|
builders []*UserThirdAuthCreate
|
|
}
|
|
|
|
// Save creates the UserThirdAuth entities in the database.
|
|
func (_c *UserThirdAuthCreateBulk) Save(ctx context.Context) ([]*UserThirdAuth, error) {
|
|
if _c.err != nil {
|
|
return nil, _c.err
|
|
}
|
|
specs := make([]*sqlgraph.CreateSpec, len(_c.builders))
|
|
nodes := make([]*UserThirdAuth, 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.(*UserThirdAuthMutation)
|
|
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}
|
|
// 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 && nodes[i].ID == 0 {
|
|
id := specs[i].ID.Value.(int64)
|
|
nodes[i].ID = uint64(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 *UserThirdAuthCreateBulk) SaveX(ctx context.Context) []*UserThirdAuth {
|
|
v, err := _c.Save(ctx)
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
return v
|
|
}
|
|
|
|
// Exec executes the query.
|
|
func (_c *UserThirdAuthCreateBulk) Exec(ctx context.Context) error {
|
|
_, err := _c.Save(ctx)
|
|
return err
|
|
}
|
|
|
|
// ExecX is like Exec, but panics if an error occurs.
|
|
func (_c *UserThirdAuthCreateBulk) ExecX(ctx context.Context) {
|
|
if err := _c.Exec(ctx); err != nil {
|
|
panic(err)
|
|
}
|
|
}
|