378 lines
12 KiB
Go
378 lines
12 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/scaauthusersocial"
|
|
"time"
|
|
|
|
"entgo.io/ent/dialect/sql/sqlgraph"
|
|
"entgo.io/ent/schema/field"
|
|
)
|
|
|
|
// ScaAuthUserSocialCreate is the builder for creating a ScaAuthUserSocial entity.
|
|
type ScaAuthUserSocialCreate struct {
|
|
config
|
|
mutation *ScaAuthUserSocialMutation
|
|
hooks []Hook
|
|
}
|
|
|
|
// SetUserID sets the "user_id" field.
|
|
func (sausc *ScaAuthUserSocialCreate) SetUserID(s string) *ScaAuthUserSocialCreate {
|
|
sausc.mutation.SetUserID(s)
|
|
return sausc
|
|
}
|
|
|
|
// SetOpenID sets the "open_id" field.
|
|
func (sausc *ScaAuthUserSocialCreate) SetOpenID(s string) *ScaAuthUserSocialCreate {
|
|
sausc.mutation.SetOpenID(s)
|
|
return sausc
|
|
}
|
|
|
|
// SetSource sets the "source" field.
|
|
func (sausc *ScaAuthUserSocialCreate) SetSource(s string) *ScaAuthUserSocialCreate {
|
|
sausc.mutation.SetSource(s)
|
|
return sausc
|
|
}
|
|
|
|
// SetStatus sets the "status" field.
|
|
func (sausc *ScaAuthUserSocialCreate) SetStatus(i int) *ScaAuthUserSocialCreate {
|
|
sausc.mutation.SetStatus(i)
|
|
return sausc
|
|
}
|
|
|
|
// SetNillableStatus sets the "status" field if the given value is not nil.
|
|
func (sausc *ScaAuthUserSocialCreate) SetNillableStatus(i *int) *ScaAuthUserSocialCreate {
|
|
if i != nil {
|
|
sausc.SetStatus(*i)
|
|
}
|
|
return sausc
|
|
}
|
|
|
|
// SetCreatedAt sets the "created_at" field.
|
|
func (sausc *ScaAuthUserSocialCreate) SetCreatedAt(t time.Time) *ScaAuthUserSocialCreate {
|
|
sausc.mutation.SetCreatedAt(t)
|
|
return sausc
|
|
}
|
|
|
|
// SetNillableCreatedAt sets the "created_at" field if the given value is not nil.
|
|
func (sausc *ScaAuthUserSocialCreate) SetNillableCreatedAt(t *time.Time) *ScaAuthUserSocialCreate {
|
|
if t != nil {
|
|
sausc.SetCreatedAt(*t)
|
|
}
|
|
return sausc
|
|
}
|
|
|
|
// SetUpdateAt sets the "update_at" field.
|
|
func (sausc *ScaAuthUserSocialCreate) SetUpdateAt(t time.Time) *ScaAuthUserSocialCreate {
|
|
sausc.mutation.SetUpdateAt(t)
|
|
return sausc
|
|
}
|
|
|
|
// SetNillableUpdateAt sets the "update_at" field if the given value is not nil.
|
|
func (sausc *ScaAuthUserSocialCreate) SetNillableUpdateAt(t *time.Time) *ScaAuthUserSocialCreate {
|
|
if t != nil {
|
|
sausc.SetUpdateAt(*t)
|
|
}
|
|
return sausc
|
|
}
|
|
|
|
// SetDeleted sets the "deleted" field.
|
|
func (sausc *ScaAuthUserSocialCreate) SetDeleted(i int) *ScaAuthUserSocialCreate {
|
|
sausc.mutation.SetDeleted(i)
|
|
return sausc
|
|
}
|
|
|
|
// SetNillableDeleted sets the "deleted" field if the given value is not nil.
|
|
func (sausc *ScaAuthUserSocialCreate) SetNillableDeleted(i *int) *ScaAuthUserSocialCreate {
|
|
if i != nil {
|
|
sausc.SetDeleted(*i)
|
|
}
|
|
return sausc
|
|
}
|
|
|
|
// SetID sets the "id" field.
|
|
func (sausc *ScaAuthUserSocialCreate) SetID(i int64) *ScaAuthUserSocialCreate {
|
|
sausc.mutation.SetID(i)
|
|
return sausc
|
|
}
|
|
|
|
// SetScaAuthUserID sets the "sca_auth_user" edge to the ScaAuthUser entity by ID.
|
|
func (sausc *ScaAuthUserSocialCreate) SetScaAuthUserID(id int64) *ScaAuthUserSocialCreate {
|
|
sausc.mutation.SetScaAuthUserID(id)
|
|
return sausc
|
|
}
|
|
|
|
// SetNillableScaAuthUserID sets the "sca_auth_user" edge to the ScaAuthUser entity by ID if the given value is not nil.
|
|
func (sausc *ScaAuthUserSocialCreate) SetNillableScaAuthUserID(id *int64) *ScaAuthUserSocialCreate {
|
|
if id != nil {
|
|
sausc = sausc.SetScaAuthUserID(*id)
|
|
}
|
|
return sausc
|
|
}
|
|
|
|
// SetScaAuthUser sets the "sca_auth_user" edge to the ScaAuthUser entity.
|
|
func (sausc *ScaAuthUserSocialCreate) SetScaAuthUser(s *ScaAuthUser) *ScaAuthUserSocialCreate {
|
|
return sausc.SetScaAuthUserID(s.ID)
|
|
}
|
|
|
|
// Mutation returns the ScaAuthUserSocialMutation object of the builder.
|
|
func (sausc *ScaAuthUserSocialCreate) Mutation() *ScaAuthUserSocialMutation {
|
|
return sausc.mutation
|
|
}
|
|
|
|
// Save creates the ScaAuthUserSocial in the database.
|
|
func (sausc *ScaAuthUserSocialCreate) Save(ctx context.Context) (*ScaAuthUserSocial, error) {
|
|
sausc.defaults()
|
|
return withHooks(ctx, sausc.sqlSave, sausc.mutation, sausc.hooks)
|
|
}
|
|
|
|
// SaveX calls Save and panics if Save returns an error.
|
|
func (sausc *ScaAuthUserSocialCreate) SaveX(ctx context.Context) *ScaAuthUserSocial {
|
|
v, err := sausc.Save(ctx)
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
return v
|
|
}
|
|
|
|
// Exec executes the query.
|
|
func (sausc *ScaAuthUserSocialCreate) Exec(ctx context.Context) error {
|
|
_, err := sausc.Save(ctx)
|
|
return err
|
|
}
|
|
|
|
// ExecX is like Exec, but panics if an error occurs.
|
|
func (sausc *ScaAuthUserSocialCreate) ExecX(ctx context.Context) {
|
|
if err := sausc.Exec(ctx); err != nil {
|
|
panic(err)
|
|
}
|
|
}
|
|
|
|
// defaults sets the default values of the builder before save.
|
|
func (sausc *ScaAuthUserSocialCreate) defaults() {
|
|
if _, ok := sausc.mutation.Status(); !ok {
|
|
v := scaauthusersocial.DefaultStatus
|
|
sausc.mutation.SetStatus(v)
|
|
}
|
|
if _, ok := sausc.mutation.CreatedAt(); !ok {
|
|
v := scaauthusersocial.DefaultCreatedAt()
|
|
sausc.mutation.SetCreatedAt(v)
|
|
}
|
|
if _, ok := sausc.mutation.UpdateAt(); !ok {
|
|
v := scaauthusersocial.DefaultUpdateAt()
|
|
sausc.mutation.SetUpdateAt(v)
|
|
}
|
|
if _, ok := sausc.mutation.Deleted(); !ok {
|
|
v := scaauthusersocial.DefaultDeleted
|
|
sausc.mutation.SetDeleted(v)
|
|
}
|
|
}
|
|
|
|
// check runs all checks and user-defined validators on the builder.
|
|
func (sausc *ScaAuthUserSocialCreate) check() error {
|
|
if _, ok := sausc.mutation.UserID(); !ok {
|
|
return &ValidationError{Name: "user_id", err: errors.New(`ent: missing required field "ScaAuthUserSocial.user_id"`)}
|
|
}
|
|
if v, ok := sausc.mutation.UserID(); ok {
|
|
if err := scaauthusersocial.UserIDValidator(v); err != nil {
|
|
return &ValidationError{Name: "user_id", err: fmt.Errorf(`ent: validator failed for field "ScaAuthUserSocial.user_id": %w`, err)}
|
|
}
|
|
}
|
|
if _, ok := sausc.mutation.OpenID(); !ok {
|
|
return &ValidationError{Name: "open_id", err: errors.New(`ent: missing required field "ScaAuthUserSocial.open_id"`)}
|
|
}
|
|
if v, ok := sausc.mutation.OpenID(); ok {
|
|
if err := scaauthusersocial.OpenIDValidator(v); err != nil {
|
|
return &ValidationError{Name: "open_id", err: fmt.Errorf(`ent: validator failed for field "ScaAuthUserSocial.open_id": %w`, err)}
|
|
}
|
|
}
|
|
if _, ok := sausc.mutation.Source(); !ok {
|
|
return &ValidationError{Name: "source", err: errors.New(`ent: missing required field "ScaAuthUserSocial.source"`)}
|
|
}
|
|
if v, ok := sausc.mutation.Source(); ok {
|
|
if err := scaauthusersocial.SourceValidator(v); err != nil {
|
|
return &ValidationError{Name: "source", err: fmt.Errorf(`ent: validator failed for field "ScaAuthUserSocial.source": %w`, err)}
|
|
}
|
|
}
|
|
if _, ok := sausc.mutation.Status(); !ok {
|
|
return &ValidationError{Name: "status", err: errors.New(`ent: missing required field "ScaAuthUserSocial.status"`)}
|
|
}
|
|
if _, ok := sausc.mutation.CreatedAt(); !ok {
|
|
return &ValidationError{Name: "created_at", err: errors.New(`ent: missing required field "ScaAuthUserSocial.created_at"`)}
|
|
}
|
|
if _, ok := sausc.mutation.Deleted(); !ok {
|
|
return &ValidationError{Name: "deleted", err: errors.New(`ent: missing required field "ScaAuthUserSocial.deleted"`)}
|
|
}
|
|
return nil
|
|
}
|
|
|
|
func (sausc *ScaAuthUserSocialCreate) sqlSave(ctx context.Context) (*ScaAuthUserSocial, error) {
|
|
if err := sausc.check(); err != nil {
|
|
return nil, err
|
|
}
|
|
_node, _spec := sausc.createSpec()
|
|
if err := sqlgraph.CreateNode(ctx, sausc.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)
|
|
}
|
|
sausc.mutation.id = &_node.ID
|
|
sausc.mutation.done = true
|
|
return _node, nil
|
|
}
|
|
|
|
func (sausc *ScaAuthUserSocialCreate) createSpec() (*ScaAuthUserSocial, *sqlgraph.CreateSpec) {
|
|
var (
|
|
_node = &ScaAuthUserSocial{config: sausc.config}
|
|
_spec = sqlgraph.NewCreateSpec(scaauthusersocial.Table, sqlgraph.NewFieldSpec(scaauthusersocial.FieldID, field.TypeInt64))
|
|
)
|
|
if id, ok := sausc.mutation.ID(); ok {
|
|
_node.ID = id
|
|
_spec.ID.Value = id
|
|
}
|
|
if value, ok := sausc.mutation.UserID(); ok {
|
|
_spec.SetField(scaauthusersocial.FieldUserID, field.TypeString, value)
|
|
_node.UserID = value
|
|
}
|
|
if value, ok := sausc.mutation.OpenID(); ok {
|
|
_spec.SetField(scaauthusersocial.FieldOpenID, field.TypeString, value)
|
|
_node.OpenID = value
|
|
}
|
|
if value, ok := sausc.mutation.Source(); ok {
|
|
_spec.SetField(scaauthusersocial.FieldSource, field.TypeString, value)
|
|
_node.Source = value
|
|
}
|
|
if value, ok := sausc.mutation.Status(); ok {
|
|
_spec.SetField(scaauthusersocial.FieldStatus, field.TypeInt, value)
|
|
_node.Status = value
|
|
}
|
|
if value, ok := sausc.mutation.CreatedAt(); ok {
|
|
_spec.SetField(scaauthusersocial.FieldCreatedAt, field.TypeTime, value)
|
|
_node.CreatedAt = value
|
|
}
|
|
if value, ok := sausc.mutation.UpdateAt(); ok {
|
|
_spec.SetField(scaauthusersocial.FieldUpdateAt, field.TypeTime, value)
|
|
_node.UpdateAt = &value
|
|
}
|
|
if value, ok := sausc.mutation.Deleted(); ok {
|
|
_spec.SetField(scaauthusersocial.FieldDeleted, field.TypeInt, value)
|
|
_node.Deleted = value
|
|
}
|
|
if nodes := sausc.mutation.ScaAuthUserIDs(); len(nodes) > 0 {
|
|
edge := &sqlgraph.EdgeSpec{
|
|
Rel: sqlgraph.M2O,
|
|
Inverse: true,
|
|
Table: scaauthusersocial.ScaAuthUserTable,
|
|
Columns: []string{scaauthusersocial.ScaAuthUserColumn},
|
|
Bidi: false,
|
|
Target: &sqlgraph.EdgeTarget{
|
|
IDSpec: sqlgraph.NewFieldSpec(scaauthuser.FieldID, field.TypeInt64),
|
|
},
|
|
}
|
|
for _, k := range nodes {
|
|
edge.Target.Nodes = append(edge.Target.Nodes, k)
|
|
}
|
|
_node.sca_auth_user_sca_auth_user_social = &nodes[0]
|
|
_spec.Edges = append(_spec.Edges, edge)
|
|
}
|
|
return _node, _spec
|
|
}
|
|
|
|
// ScaAuthUserSocialCreateBulk is the builder for creating many ScaAuthUserSocial entities in bulk.
|
|
type ScaAuthUserSocialCreateBulk struct {
|
|
config
|
|
err error
|
|
builders []*ScaAuthUserSocialCreate
|
|
}
|
|
|
|
// Save creates the ScaAuthUserSocial entities in the database.
|
|
func (sauscb *ScaAuthUserSocialCreateBulk) Save(ctx context.Context) ([]*ScaAuthUserSocial, error) {
|
|
if sauscb.err != nil {
|
|
return nil, sauscb.err
|
|
}
|
|
specs := make([]*sqlgraph.CreateSpec, len(sauscb.builders))
|
|
nodes := make([]*ScaAuthUserSocial, len(sauscb.builders))
|
|
mutators := make([]Mutator, len(sauscb.builders))
|
|
for i := range sauscb.builders {
|
|
func(i int, root context.Context) {
|
|
builder := sauscb.builders[i]
|
|
builder.defaults()
|
|
var mut Mutator = MutateFunc(func(ctx context.Context, m Mutation) (Value, error) {
|
|
mutation, ok := m.(*ScaAuthUserSocialMutation)
|
|
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, sauscb.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, sauscb.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, sauscb.builders[0].mutation); err != nil {
|
|
return nil, err
|
|
}
|
|
}
|
|
return nodes, nil
|
|
}
|
|
|
|
// SaveX is like Save, but panics if an error occurs.
|
|
func (sauscb *ScaAuthUserSocialCreateBulk) SaveX(ctx context.Context) []*ScaAuthUserSocial {
|
|
v, err := sauscb.Save(ctx)
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
return v
|
|
}
|
|
|
|
// Exec executes the query.
|
|
func (sauscb *ScaAuthUserSocialCreateBulk) Exec(ctx context.Context) error {
|
|
_, err := sauscb.Save(ctx)
|
|
return err
|
|
}
|
|
|
|
// ExecX is like Exec, but panics if an error occurs.
|
|
func (sauscb *ScaAuthUserSocialCreateBulk) ExecX(ctx context.Context) {
|
|
if err := sauscb.Exec(ctx); err != nil {
|
|
panic(err)
|
|
}
|
|
}
|