614 lines
18 KiB
Go
614 lines
18 KiB
Go
// Code generated by ent, DO NOT EDIT.
|
|
|
|
package ent
|
|
|
|
import (
|
|
"context"
|
|
"errors"
|
|
"fmt"
|
|
"schisandra-album-cloud-microservices/common/ent/scaauthuser"
|
|
"schisandra-album-cloud-microservices/common/ent/scaauthuserdevice"
|
|
"schisandra-album-cloud-microservices/common/ent/scaauthusersocial"
|
|
"time"
|
|
|
|
"entgo.io/ent/dialect/sql/sqlgraph"
|
|
"entgo.io/ent/schema/field"
|
|
)
|
|
|
|
// ScaAuthUserCreate is the builder for creating a ScaAuthUser entity.
|
|
type ScaAuthUserCreate struct {
|
|
config
|
|
mutation *ScaAuthUserMutation
|
|
hooks []Hook
|
|
}
|
|
|
|
// SetUID sets the "uid" field.
|
|
func (sauc *ScaAuthUserCreate) SetUID(s string) *ScaAuthUserCreate {
|
|
sauc.mutation.SetUID(s)
|
|
return sauc
|
|
}
|
|
|
|
// SetUsername sets the "username" field.
|
|
func (sauc *ScaAuthUserCreate) SetUsername(s string) *ScaAuthUserCreate {
|
|
sauc.mutation.SetUsername(s)
|
|
return sauc
|
|
}
|
|
|
|
// SetNillableUsername sets the "username" field if the given value is not nil.
|
|
func (sauc *ScaAuthUserCreate) SetNillableUsername(s *string) *ScaAuthUserCreate {
|
|
if s != nil {
|
|
sauc.SetUsername(*s)
|
|
}
|
|
return sauc
|
|
}
|
|
|
|
// SetNickname sets the "nickname" field.
|
|
func (sauc *ScaAuthUserCreate) SetNickname(s string) *ScaAuthUserCreate {
|
|
sauc.mutation.SetNickname(s)
|
|
return sauc
|
|
}
|
|
|
|
// SetNillableNickname sets the "nickname" field if the given value is not nil.
|
|
func (sauc *ScaAuthUserCreate) SetNillableNickname(s *string) *ScaAuthUserCreate {
|
|
if s != nil {
|
|
sauc.SetNickname(*s)
|
|
}
|
|
return sauc
|
|
}
|
|
|
|
// SetEmail sets the "email" field.
|
|
func (sauc *ScaAuthUserCreate) SetEmail(s string) *ScaAuthUserCreate {
|
|
sauc.mutation.SetEmail(s)
|
|
return sauc
|
|
}
|
|
|
|
// SetNillableEmail sets the "email" field if the given value is not nil.
|
|
func (sauc *ScaAuthUserCreate) SetNillableEmail(s *string) *ScaAuthUserCreate {
|
|
if s != nil {
|
|
sauc.SetEmail(*s)
|
|
}
|
|
return sauc
|
|
}
|
|
|
|
// SetPhone sets the "phone" field.
|
|
func (sauc *ScaAuthUserCreate) SetPhone(s string) *ScaAuthUserCreate {
|
|
sauc.mutation.SetPhone(s)
|
|
return sauc
|
|
}
|
|
|
|
// SetNillablePhone sets the "phone" field if the given value is not nil.
|
|
func (sauc *ScaAuthUserCreate) SetNillablePhone(s *string) *ScaAuthUserCreate {
|
|
if s != nil {
|
|
sauc.SetPhone(*s)
|
|
}
|
|
return sauc
|
|
}
|
|
|
|
// SetPassword sets the "password" field.
|
|
func (sauc *ScaAuthUserCreate) SetPassword(s string) *ScaAuthUserCreate {
|
|
sauc.mutation.SetPassword(s)
|
|
return sauc
|
|
}
|
|
|
|
// SetNillablePassword sets the "password" field if the given value is not nil.
|
|
func (sauc *ScaAuthUserCreate) SetNillablePassword(s *string) *ScaAuthUserCreate {
|
|
if s != nil {
|
|
sauc.SetPassword(*s)
|
|
}
|
|
return sauc
|
|
}
|
|
|
|
// SetGender sets the "gender" field.
|
|
func (sauc *ScaAuthUserCreate) SetGender(s string) *ScaAuthUserCreate {
|
|
sauc.mutation.SetGender(s)
|
|
return sauc
|
|
}
|
|
|
|
// SetNillableGender sets the "gender" field if the given value is not nil.
|
|
func (sauc *ScaAuthUserCreate) SetNillableGender(s *string) *ScaAuthUserCreate {
|
|
if s != nil {
|
|
sauc.SetGender(*s)
|
|
}
|
|
return sauc
|
|
}
|
|
|
|
// SetAvatar sets the "avatar" field.
|
|
func (sauc *ScaAuthUserCreate) SetAvatar(s string) *ScaAuthUserCreate {
|
|
sauc.mutation.SetAvatar(s)
|
|
return sauc
|
|
}
|
|
|
|
// SetNillableAvatar sets the "avatar" field if the given value is not nil.
|
|
func (sauc *ScaAuthUserCreate) SetNillableAvatar(s *string) *ScaAuthUserCreate {
|
|
if s != nil {
|
|
sauc.SetAvatar(*s)
|
|
}
|
|
return sauc
|
|
}
|
|
|
|
// SetStatus sets the "status" field.
|
|
func (sauc *ScaAuthUserCreate) SetStatus(i int8) *ScaAuthUserCreate {
|
|
sauc.mutation.SetStatus(i)
|
|
return sauc
|
|
}
|
|
|
|
// SetNillableStatus sets the "status" field if the given value is not nil.
|
|
func (sauc *ScaAuthUserCreate) SetNillableStatus(i *int8) *ScaAuthUserCreate {
|
|
if i != nil {
|
|
sauc.SetStatus(*i)
|
|
}
|
|
return sauc
|
|
}
|
|
|
|
// SetIntroduce sets the "introduce" field.
|
|
func (sauc *ScaAuthUserCreate) SetIntroduce(s string) *ScaAuthUserCreate {
|
|
sauc.mutation.SetIntroduce(s)
|
|
return sauc
|
|
}
|
|
|
|
// SetNillableIntroduce sets the "introduce" field if the given value is not nil.
|
|
func (sauc *ScaAuthUserCreate) SetNillableIntroduce(s *string) *ScaAuthUserCreate {
|
|
if s != nil {
|
|
sauc.SetIntroduce(*s)
|
|
}
|
|
return sauc
|
|
}
|
|
|
|
// SetCreatedAt sets the "created_at" field.
|
|
func (sauc *ScaAuthUserCreate) SetCreatedAt(t time.Time) *ScaAuthUserCreate {
|
|
sauc.mutation.SetCreatedAt(t)
|
|
return sauc
|
|
}
|
|
|
|
// SetNillableCreatedAt sets the "created_at" field if the given value is not nil.
|
|
func (sauc *ScaAuthUserCreate) SetNillableCreatedAt(t *time.Time) *ScaAuthUserCreate {
|
|
if t != nil {
|
|
sauc.SetCreatedAt(*t)
|
|
}
|
|
return sauc
|
|
}
|
|
|
|
// SetUpdateAt sets the "update_at" field.
|
|
func (sauc *ScaAuthUserCreate) SetUpdateAt(t time.Time) *ScaAuthUserCreate {
|
|
sauc.mutation.SetUpdateAt(t)
|
|
return sauc
|
|
}
|
|
|
|
// SetNillableUpdateAt sets the "update_at" field if the given value is not nil.
|
|
func (sauc *ScaAuthUserCreate) SetNillableUpdateAt(t *time.Time) *ScaAuthUserCreate {
|
|
if t != nil {
|
|
sauc.SetUpdateAt(*t)
|
|
}
|
|
return sauc
|
|
}
|
|
|
|
// SetDeleted sets the "deleted" field.
|
|
func (sauc *ScaAuthUserCreate) SetDeleted(i int8) *ScaAuthUserCreate {
|
|
sauc.mutation.SetDeleted(i)
|
|
return sauc
|
|
}
|
|
|
|
// SetNillableDeleted sets the "deleted" field if the given value is not nil.
|
|
func (sauc *ScaAuthUserCreate) SetNillableDeleted(i *int8) *ScaAuthUserCreate {
|
|
if i != nil {
|
|
sauc.SetDeleted(*i)
|
|
}
|
|
return sauc
|
|
}
|
|
|
|
// SetBlog sets the "blog" field.
|
|
func (sauc *ScaAuthUserCreate) SetBlog(s string) *ScaAuthUserCreate {
|
|
sauc.mutation.SetBlog(s)
|
|
return sauc
|
|
}
|
|
|
|
// SetNillableBlog sets the "blog" field if the given value is not nil.
|
|
func (sauc *ScaAuthUserCreate) SetNillableBlog(s *string) *ScaAuthUserCreate {
|
|
if s != nil {
|
|
sauc.SetBlog(*s)
|
|
}
|
|
return sauc
|
|
}
|
|
|
|
// SetLocation sets the "location" field.
|
|
func (sauc *ScaAuthUserCreate) SetLocation(s string) *ScaAuthUserCreate {
|
|
sauc.mutation.SetLocation(s)
|
|
return sauc
|
|
}
|
|
|
|
// SetNillableLocation sets the "location" field if the given value is not nil.
|
|
func (sauc *ScaAuthUserCreate) SetNillableLocation(s *string) *ScaAuthUserCreate {
|
|
if s != nil {
|
|
sauc.SetLocation(*s)
|
|
}
|
|
return sauc
|
|
}
|
|
|
|
// SetCompany sets the "company" field.
|
|
func (sauc *ScaAuthUserCreate) SetCompany(s string) *ScaAuthUserCreate {
|
|
sauc.mutation.SetCompany(s)
|
|
return sauc
|
|
}
|
|
|
|
// SetNillableCompany sets the "company" field if the given value is not nil.
|
|
func (sauc *ScaAuthUserCreate) SetNillableCompany(s *string) *ScaAuthUserCreate {
|
|
if s != nil {
|
|
sauc.SetCompany(*s)
|
|
}
|
|
return sauc
|
|
}
|
|
|
|
// SetID sets the "id" field.
|
|
func (sauc *ScaAuthUserCreate) SetID(i int64) *ScaAuthUserCreate {
|
|
sauc.mutation.SetID(i)
|
|
return sauc
|
|
}
|
|
|
|
// AddScaAuthUserSocialIDs adds the "sca_auth_user_social" edge to the ScaAuthUserSocial entity by IDs.
|
|
func (sauc *ScaAuthUserCreate) AddScaAuthUserSocialIDs(ids ...int64) *ScaAuthUserCreate {
|
|
sauc.mutation.AddScaAuthUserSocialIDs(ids...)
|
|
return sauc
|
|
}
|
|
|
|
// AddScaAuthUserSocial adds the "sca_auth_user_social" edges to the ScaAuthUserSocial entity.
|
|
func (sauc *ScaAuthUserCreate) AddScaAuthUserSocial(s ...*ScaAuthUserSocial) *ScaAuthUserCreate {
|
|
ids := make([]int64, len(s))
|
|
for i := range s {
|
|
ids[i] = s[i].ID
|
|
}
|
|
return sauc.AddScaAuthUserSocialIDs(ids...)
|
|
}
|
|
|
|
// AddScaAuthUserDeviceIDs adds the "sca_auth_user_device" edge to the ScaAuthUserDevice entity by IDs.
|
|
func (sauc *ScaAuthUserCreate) AddScaAuthUserDeviceIDs(ids ...int64) *ScaAuthUserCreate {
|
|
sauc.mutation.AddScaAuthUserDeviceIDs(ids...)
|
|
return sauc
|
|
}
|
|
|
|
// AddScaAuthUserDevice adds the "sca_auth_user_device" edges to the ScaAuthUserDevice entity.
|
|
func (sauc *ScaAuthUserCreate) AddScaAuthUserDevice(s ...*ScaAuthUserDevice) *ScaAuthUserCreate {
|
|
ids := make([]int64, len(s))
|
|
for i := range s {
|
|
ids[i] = s[i].ID
|
|
}
|
|
return sauc.AddScaAuthUserDeviceIDs(ids...)
|
|
}
|
|
|
|
// Mutation returns the ScaAuthUserMutation object of the builder.
|
|
func (sauc *ScaAuthUserCreate) Mutation() *ScaAuthUserMutation {
|
|
return sauc.mutation
|
|
}
|
|
|
|
// Save creates the ScaAuthUser in the database.
|
|
func (sauc *ScaAuthUserCreate) Save(ctx context.Context) (*ScaAuthUser, error) {
|
|
sauc.defaults()
|
|
return withHooks(ctx, sauc.sqlSave, sauc.mutation, sauc.hooks)
|
|
}
|
|
|
|
// SaveX calls Save and panics if Save returns an error.
|
|
func (sauc *ScaAuthUserCreate) SaveX(ctx context.Context) *ScaAuthUser {
|
|
v, err := sauc.Save(ctx)
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
return v
|
|
}
|
|
|
|
// Exec executes the query.
|
|
func (sauc *ScaAuthUserCreate) Exec(ctx context.Context) error {
|
|
_, err := sauc.Save(ctx)
|
|
return err
|
|
}
|
|
|
|
// ExecX is like Exec, but panics if an error occurs.
|
|
func (sauc *ScaAuthUserCreate) ExecX(ctx context.Context) {
|
|
if err := sauc.Exec(ctx); err != nil {
|
|
panic(err)
|
|
}
|
|
}
|
|
|
|
// defaults sets the default values of the builder before save.
|
|
func (sauc *ScaAuthUserCreate) defaults() {
|
|
if _, ok := sauc.mutation.Status(); !ok {
|
|
v := scaauthuser.DefaultStatus
|
|
sauc.mutation.SetStatus(v)
|
|
}
|
|
if _, ok := sauc.mutation.CreatedAt(); !ok {
|
|
v := scaauthuser.DefaultCreatedAt()
|
|
sauc.mutation.SetCreatedAt(v)
|
|
}
|
|
if _, ok := sauc.mutation.UpdateAt(); !ok {
|
|
v := scaauthuser.DefaultUpdateAt()
|
|
sauc.mutation.SetUpdateAt(v)
|
|
}
|
|
if _, ok := sauc.mutation.Deleted(); !ok {
|
|
v := scaauthuser.DefaultDeleted
|
|
sauc.mutation.SetDeleted(v)
|
|
}
|
|
}
|
|
|
|
// check runs all checks and user-defined validators on the builder.
|
|
func (sauc *ScaAuthUserCreate) check() error {
|
|
if _, ok := sauc.mutation.UID(); !ok {
|
|
return &ValidationError{Name: "uid", err: errors.New(`ent: missing required field "ScaAuthUser.uid"`)}
|
|
}
|
|
if v, ok := sauc.mutation.UID(); ok {
|
|
if err := scaauthuser.UIDValidator(v); err != nil {
|
|
return &ValidationError{Name: "uid", err: fmt.Errorf(`ent: validator failed for field "ScaAuthUser.uid": %w`, err)}
|
|
}
|
|
}
|
|
if v, ok := sauc.mutation.Username(); ok {
|
|
if err := scaauthuser.UsernameValidator(v); err != nil {
|
|
return &ValidationError{Name: "username", err: fmt.Errorf(`ent: validator failed for field "ScaAuthUser.username": %w`, err)}
|
|
}
|
|
}
|
|
if v, ok := sauc.mutation.Nickname(); ok {
|
|
if err := scaauthuser.NicknameValidator(v); err != nil {
|
|
return &ValidationError{Name: "nickname", err: fmt.Errorf(`ent: validator failed for field "ScaAuthUser.nickname": %w`, err)}
|
|
}
|
|
}
|
|
if v, ok := sauc.mutation.Email(); ok {
|
|
if err := scaauthuser.EmailValidator(v); err != nil {
|
|
return &ValidationError{Name: "email", err: fmt.Errorf(`ent: validator failed for field "ScaAuthUser.email": %w`, err)}
|
|
}
|
|
}
|
|
if v, ok := sauc.mutation.Phone(); ok {
|
|
if err := scaauthuser.PhoneValidator(v); err != nil {
|
|
return &ValidationError{Name: "phone", err: fmt.Errorf(`ent: validator failed for field "ScaAuthUser.phone": %w`, err)}
|
|
}
|
|
}
|
|
if v, ok := sauc.mutation.Password(); ok {
|
|
if err := scaauthuser.PasswordValidator(v); err != nil {
|
|
return &ValidationError{Name: "password", err: fmt.Errorf(`ent: validator failed for field "ScaAuthUser.password": %w`, err)}
|
|
}
|
|
}
|
|
if v, ok := sauc.mutation.Gender(); ok {
|
|
if err := scaauthuser.GenderValidator(v); err != nil {
|
|
return &ValidationError{Name: "gender", err: fmt.Errorf(`ent: validator failed for field "ScaAuthUser.gender": %w`, err)}
|
|
}
|
|
}
|
|
if v, ok := sauc.mutation.Introduce(); ok {
|
|
if err := scaauthuser.IntroduceValidator(v); err != nil {
|
|
return &ValidationError{Name: "introduce", err: fmt.Errorf(`ent: validator failed for field "ScaAuthUser.introduce": %w`, err)}
|
|
}
|
|
}
|
|
if _, ok := sauc.mutation.CreatedAt(); !ok {
|
|
return &ValidationError{Name: "created_at", err: errors.New(`ent: missing required field "ScaAuthUser.created_at"`)}
|
|
}
|
|
if _, ok := sauc.mutation.Deleted(); !ok {
|
|
return &ValidationError{Name: "deleted", err: errors.New(`ent: missing required field "ScaAuthUser.deleted"`)}
|
|
}
|
|
if v, ok := sauc.mutation.Blog(); ok {
|
|
if err := scaauthuser.BlogValidator(v); err != nil {
|
|
return &ValidationError{Name: "blog", err: fmt.Errorf(`ent: validator failed for field "ScaAuthUser.blog": %w`, err)}
|
|
}
|
|
}
|
|
if v, ok := sauc.mutation.Location(); ok {
|
|
if err := scaauthuser.LocationValidator(v); err != nil {
|
|
return &ValidationError{Name: "location", err: fmt.Errorf(`ent: validator failed for field "ScaAuthUser.location": %w`, err)}
|
|
}
|
|
}
|
|
if v, ok := sauc.mutation.Company(); ok {
|
|
if err := scaauthuser.CompanyValidator(v); err != nil {
|
|
return &ValidationError{Name: "company", err: fmt.Errorf(`ent: validator failed for field "ScaAuthUser.company": %w`, err)}
|
|
}
|
|
}
|
|
return nil
|
|
}
|
|
|
|
func (sauc *ScaAuthUserCreate) sqlSave(ctx context.Context) (*ScaAuthUser, error) {
|
|
if err := sauc.check(); err != nil {
|
|
return nil, err
|
|
}
|
|
_node, _spec := sauc.createSpec()
|
|
if err := sqlgraph.CreateNode(ctx, sauc.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)
|
|
}
|
|
sauc.mutation.id = &_node.ID
|
|
sauc.mutation.done = true
|
|
return _node, nil
|
|
}
|
|
|
|
func (sauc *ScaAuthUserCreate) createSpec() (*ScaAuthUser, *sqlgraph.CreateSpec) {
|
|
var (
|
|
_node = &ScaAuthUser{config: sauc.config}
|
|
_spec = sqlgraph.NewCreateSpec(scaauthuser.Table, sqlgraph.NewFieldSpec(scaauthuser.FieldID, field.TypeInt64))
|
|
)
|
|
if id, ok := sauc.mutation.ID(); ok {
|
|
_node.ID = id
|
|
_spec.ID.Value = id
|
|
}
|
|
if value, ok := sauc.mutation.UID(); ok {
|
|
_spec.SetField(scaauthuser.FieldUID, field.TypeString, value)
|
|
_node.UID = value
|
|
}
|
|
if value, ok := sauc.mutation.Username(); ok {
|
|
_spec.SetField(scaauthuser.FieldUsername, field.TypeString, value)
|
|
_node.Username = value
|
|
}
|
|
if value, ok := sauc.mutation.Nickname(); ok {
|
|
_spec.SetField(scaauthuser.FieldNickname, field.TypeString, value)
|
|
_node.Nickname = value
|
|
}
|
|
if value, ok := sauc.mutation.Email(); ok {
|
|
_spec.SetField(scaauthuser.FieldEmail, field.TypeString, value)
|
|
_node.Email = value
|
|
}
|
|
if value, ok := sauc.mutation.Phone(); ok {
|
|
_spec.SetField(scaauthuser.FieldPhone, field.TypeString, value)
|
|
_node.Phone = value
|
|
}
|
|
if value, ok := sauc.mutation.Password(); ok {
|
|
_spec.SetField(scaauthuser.FieldPassword, field.TypeString, value)
|
|
_node.Password = value
|
|
}
|
|
if value, ok := sauc.mutation.Gender(); ok {
|
|
_spec.SetField(scaauthuser.FieldGender, field.TypeString, value)
|
|
_node.Gender = value
|
|
}
|
|
if value, ok := sauc.mutation.Avatar(); ok {
|
|
_spec.SetField(scaauthuser.FieldAvatar, field.TypeString, value)
|
|
_node.Avatar = value
|
|
}
|
|
if value, ok := sauc.mutation.Status(); ok {
|
|
_spec.SetField(scaauthuser.FieldStatus, field.TypeInt8, value)
|
|
_node.Status = value
|
|
}
|
|
if value, ok := sauc.mutation.Introduce(); ok {
|
|
_spec.SetField(scaauthuser.FieldIntroduce, field.TypeString, value)
|
|
_node.Introduce = value
|
|
}
|
|
if value, ok := sauc.mutation.CreatedAt(); ok {
|
|
_spec.SetField(scaauthuser.FieldCreatedAt, field.TypeTime, value)
|
|
_node.CreatedAt = value
|
|
}
|
|
if value, ok := sauc.mutation.UpdateAt(); ok {
|
|
_spec.SetField(scaauthuser.FieldUpdateAt, field.TypeTime, value)
|
|
_node.UpdateAt = &value
|
|
}
|
|
if value, ok := sauc.mutation.Deleted(); ok {
|
|
_spec.SetField(scaauthuser.FieldDeleted, field.TypeInt8, value)
|
|
_node.Deleted = value
|
|
}
|
|
if value, ok := sauc.mutation.Blog(); ok {
|
|
_spec.SetField(scaauthuser.FieldBlog, field.TypeString, value)
|
|
_node.Blog = &value
|
|
}
|
|
if value, ok := sauc.mutation.Location(); ok {
|
|
_spec.SetField(scaauthuser.FieldLocation, field.TypeString, value)
|
|
_node.Location = &value
|
|
}
|
|
if value, ok := sauc.mutation.Company(); ok {
|
|
_spec.SetField(scaauthuser.FieldCompany, field.TypeString, value)
|
|
_node.Company = &value
|
|
}
|
|
if nodes := sauc.mutation.ScaAuthUserSocialIDs(); len(nodes) > 0 {
|
|
edge := &sqlgraph.EdgeSpec{
|
|
Rel: sqlgraph.O2M,
|
|
Inverse: false,
|
|
Table: scaauthuser.ScaAuthUserSocialTable,
|
|
Columns: []string{scaauthuser.ScaAuthUserSocialColumn},
|
|
Bidi: false,
|
|
Target: &sqlgraph.EdgeTarget{
|
|
IDSpec: sqlgraph.NewFieldSpec(scaauthusersocial.FieldID, field.TypeInt64),
|
|
},
|
|
}
|
|
for _, k := range nodes {
|
|
edge.Target.Nodes = append(edge.Target.Nodes, k)
|
|
}
|
|
_spec.Edges = append(_spec.Edges, edge)
|
|
}
|
|
if nodes := sauc.mutation.ScaAuthUserDeviceIDs(); len(nodes) > 0 {
|
|
edge := &sqlgraph.EdgeSpec{
|
|
Rel: sqlgraph.O2M,
|
|
Inverse: false,
|
|
Table: scaauthuser.ScaAuthUserDeviceTable,
|
|
Columns: []string{scaauthuser.ScaAuthUserDeviceColumn},
|
|
Bidi: false,
|
|
Target: &sqlgraph.EdgeTarget{
|
|
IDSpec: sqlgraph.NewFieldSpec(scaauthuserdevice.FieldID, field.TypeInt64),
|
|
},
|
|
}
|
|
for _, k := range nodes {
|
|
edge.Target.Nodes = append(edge.Target.Nodes, k)
|
|
}
|
|
_spec.Edges = append(_spec.Edges, edge)
|
|
}
|
|
return _node, _spec
|
|
}
|
|
|
|
// ScaAuthUserCreateBulk is the builder for creating many ScaAuthUser entities in bulk.
|
|
type ScaAuthUserCreateBulk struct {
|
|
config
|
|
err error
|
|
builders []*ScaAuthUserCreate
|
|
}
|
|
|
|
// Save creates the ScaAuthUser entities in the database.
|
|
func (saucb *ScaAuthUserCreateBulk) Save(ctx context.Context) ([]*ScaAuthUser, error) {
|
|
if saucb.err != nil {
|
|
return nil, saucb.err
|
|
}
|
|
specs := make([]*sqlgraph.CreateSpec, len(saucb.builders))
|
|
nodes := make([]*ScaAuthUser, len(saucb.builders))
|
|
mutators := make([]Mutator, len(saucb.builders))
|
|
for i := range saucb.builders {
|
|
func(i int, root context.Context) {
|
|
builder := saucb.builders[i]
|
|
builder.defaults()
|
|
var mut Mutator = MutateFunc(func(ctx context.Context, m Mutation) (Value, error) {
|
|
mutation, ok := m.(*ScaAuthUserMutation)
|
|
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, saucb.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, saucb.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, saucb.builders[0].mutation); err != nil {
|
|
return nil, err
|
|
}
|
|
}
|
|
return nodes, nil
|
|
}
|
|
|
|
// SaveX is like Save, but panics if an error occurs.
|
|
func (saucb *ScaAuthUserCreateBulk) SaveX(ctx context.Context) []*ScaAuthUser {
|
|
v, err := saucb.Save(ctx)
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
return v
|
|
}
|
|
|
|
// Exec executes the query.
|
|
func (saucb *ScaAuthUserCreateBulk) Exec(ctx context.Context) error {
|
|
_, err := saucb.Save(ctx)
|
|
return err
|
|
}
|
|
|
|
// ExecX is like Exec, but panics if an error occurs.
|
|
func (saucb *ScaAuthUserCreateBulk) ExecX(ctx context.Context) {
|
|
if err := saucb.Exec(ctx); err != nil {
|
|
panic(err)
|
|
}
|
|
}
|