🎉 init
This commit is contained in:
332
common/ent/scaauthrole_create.go
Normal file
332
common/ent/scaauthrole_create.go
Normal file
@@ -0,0 +1,332 @@
|
||||
// Code generated by ent, DO NOT EDIT.
|
||||
|
||||
package ent
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
"schisandra-album-cloud-microservices/common/ent/scaauthpermissionrule"
|
||||
"schisandra-album-cloud-microservices/common/ent/scaauthrole"
|
||||
"time"
|
||||
|
||||
"entgo.io/ent/dialect/sql/sqlgraph"
|
||||
"entgo.io/ent/schema/field"
|
||||
)
|
||||
|
||||
// ScaAuthRoleCreate is the builder for creating a ScaAuthRole entity.
|
||||
type ScaAuthRoleCreate struct {
|
||||
config
|
||||
mutation *ScaAuthRoleMutation
|
||||
hooks []Hook
|
||||
}
|
||||
|
||||
// SetRoleName sets the "role_name" field.
|
||||
func (sarc *ScaAuthRoleCreate) SetRoleName(s string) *ScaAuthRoleCreate {
|
||||
sarc.mutation.SetRoleName(s)
|
||||
return sarc
|
||||
}
|
||||
|
||||
// SetRoleKey sets the "role_key" field.
|
||||
func (sarc *ScaAuthRoleCreate) SetRoleKey(s string) *ScaAuthRoleCreate {
|
||||
sarc.mutation.SetRoleKey(s)
|
||||
return sarc
|
||||
}
|
||||
|
||||
// SetCreatedAt sets the "created_at" field.
|
||||
func (sarc *ScaAuthRoleCreate) SetCreatedAt(t time.Time) *ScaAuthRoleCreate {
|
||||
sarc.mutation.SetCreatedAt(t)
|
||||
return sarc
|
||||
}
|
||||
|
||||
// SetNillableCreatedAt sets the "created_at" field if the given value is not nil.
|
||||
func (sarc *ScaAuthRoleCreate) SetNillableCreatedAt(t *time.Time) *ScaAuthRoleCreate {
|
||||
if t != nil {
|
||||
sarc.SetCreatedAt(*t)
|
||||
}
|
||||
return sarc
|
||||
}
|
||||
|
||||
// SetUpdateAt sets the "update_at" field.
|
||||
func (sarc *ScaAuthRoleCreate) SetUpdateAt(t time.Time) *ScaAuthRoleCreate {
|
||||
sarc.mutation.SetUpdateAt(t)
|
||||
return sarc
|
||||
}
|
||||
|
||||
// SetNillableUpdateAt sets the "update_at" field if the given value is not nil.
|
||||
func (sarc *ScaAuthRoleCreate) SetNillableUpdateAt(t *time.Time) *ScaAuthRoleCreate {
|
||||
if t != nil {
|
||||
sarc.SetUpdateAt(*t)
|
||||
}
|
||||
return sarc
|
||||
}
|
||||
|
||||
// SetDeleted sets the "deleted" field.
|
||||
func (sarc *ScaAuthRoleCreate) SetDeleted(i int) *ScaAuthRoleCreate {
|
||||
sarc.mutation.SetDeleted(i)
|
||||
return sarc
|
||||
}
|
||||
|
||||
// SetNillableDeleted sets the "deleted" field if the given value is not nil.
|
||||
func (sarc *ScaAuthRoleCreate) SetNillableDeleted(i *int) *ScaAuthRoleCreate {
|
||||
if i != nil {
|
||||
sarc.SetDeleted(*i)
|
||||
}
|
||||
return sarc
|
||||
}
|
||||
|
||||
// SetID sets the "id" field.
|
||||
func (sarc *ScaAuthRoleCreate) SetID(i int64) *ScaAuthRoleCreate {
|
||||
sarc.mutation.SetID(i)
|
||||
return sarc
|
||||
}
|
||||
|
||||
// AddScaAuthPermissionRuleIDs adds the "sca_auth_permission_rule" edge to the ScaAuthPermissionRule entity by IDs.
|
||||
func (sarc *ScaAuthRoleCreate) AddScaAuthPermissionRuleIDs(ids ...int64) *ScaAuthRoleCreate {
|
||||
sarc.mutation.AddScaAuthPermissionRuleIDs(ids...)
|
||||
return sarc
|
||||
}
|
||||
|
||||
// AddScaAuthPermissionRule adds the "sca_auth_permission_rule" edges to the ScaAuthPermissionRule entity.
|
||||
func (sarc *ScaAuthRoleCreate) AddScaAuthPermissionRule(s ...*ScaAuthPermissionRule) *ScaAuthRoleCreate {
|
||||
ids := make([]int64, len(s))
|
||||
for i := range s {
|
||||
ids[i] = s[i].ID
|
||||
}
|
||||
return sarc.AddScaAuthPermissionRuleIDs(ids...)
|
||||
}
|
||||
|
||||
// Mutation returns the ScaAuthRoleMutation object of the builder.
|
||||
func (sarc *ScaAuthRoleCreate) Mutation() *ScaAuthRoleMutation {
|
||||
return sarc.mutation
|
||||
}
|
||||
|
||||
// Save creates the ScaAuthRole in the database.
|
||||
func (sarc *ScaAuthRoleCreate) Save(ctx context.Context) (*ScaAuthRole, error) {
|
||||
sarc.defaults()
|
||||
return withHooks(ctx, sarc.sqlSave, sarc.mutation, sarc.hooks)
|
||||
}
|
||||
|
||||
// SaveX calls Save and panics if Save returns an error.
|
||||
func (sarc *ScaAuthRoleCreate) SaveX(ctx context.Context) *ScaAuthRole {
|
||||
v, err := sarc.Save(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return v
|
||||
}
|
||||
|
||||
// Exec executes the query.
|
||||
func (sarc *ScaAuthRoleCreate) Exec(ctx context.Context) error {
|
||||
_, err := sarc.Save(ctx)
|
||||
return err
|
||||
}
|
||||
|
||||
// ExecX is like Exec, but panics if an error occurs.
|
||||
func (sarc *ScaAuthRoleCreate) ExecX(ctx context.Context) {
|
||||
if err := sarc.Exec(ctx); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
|
||||
// defaults sets the default values of the builder before save.
|
||||
func (sarc *ScaAuthRoleCreate) defaults() {
|
||||
if _, ok := sarc.mutation.CreatedAt(); !ok {
|
||||
v := scaauthrole.DefaultCreatedAt()
|
||||
sarc.mutation.SetCreatedAt(v)
|
||||
}
|
||||
if _, ok := sarc.mutation.UpdateAt(); !ok {
|
||||
v := scaauthrole.DefaultUpdateAt()
|
||||
sarc.mutation.SetUpdateAt(v)
|
||||
}
|
||||
if _, ok := sarc.mutation.Deleted(); !ok {
|
||||
v := scaauthrole.DefaultDeleted
|
||||
sarc.mutation.SetDeleted(v)
|
||||
}
|
||||
}
|
||||
|
||||
// check runs all checks and user-defined validators on the builder.
|
||||
func (sarc *ScaAuthRoleCreate) check() error {
|
||||
if _, ok := sarc.mutation.RoleName(); !ok {
|
||||
return &ValidationError{Name: "role_name", err: errors.New(`ent: missing required field "ScaAuthRole.role_name"`)}
|
||||
}
|
||||
if v, ok := sarc.mutation.RoleName(); ok {
|
||||
if err := scaauthrole.RoleNameValidator(v); err != nil {
|
||||
return &ValidationError{Name: "role_name", err: fmt.Errorf(`ent: validator failed for field "ScaAuthRole.role_name": %w`, err)}
|
||||
}
|
||||
}
|
||||
if _, ok := sarc.mutation.RoleKey(); !ok {
|
||||
return &ValidationError{Name: "role_key", err: errors.New(`ent: missing required field "ScaAuthRole.role_key"`)}
|
||||
}
|
||||
if v, ok := sarc.mutation.RoleKey(); ok {
|
||||
if err := scaauthrole.RoleKeyValidator(v); err != nil {
|
||||
return &ValidationError{Name: "role_key", err: fmt.Errorf(`ent: validator failed for field "ScaAuthRole.role_key": %w`, err)}
|
||||
}
|
||||
}
|
||||
if _, ok := sarc.mutation.CreatedAt(); !ok {
|
||||
return &ValidationError{Name: "created_at", err: errors.New(`ent: missing required field "ScaAuthRole.created_at"`)}
|
||||
}
|
||||
if _, ok := sarc.mutation.UpdateAt(); !ok {
|
||||
return &ValidationError{Name: "update_at", err: errors.New(`ent: missing required field "ScaAuthRole.update_at"`)}
|
||||
}
|
||||
if _, ok := sarc.mutation.Deleted(); !ok {
|
||||
return &ValidationError{Name: "deleted", err: errors.New(`ent: missing required field "ScaAuthRole.deleted"`)}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (sarc *ScaAuthRoleCreate) sqlSave(ctx context.Context) (*ScaAuthRole, error) {
|
||||
if err := sarc.check(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
_node, _spec := sarc.createSpec()
|
||||
if err := sqlgraph.CreateNode(ctx, sarc.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)
|
||||
}
|
||||
sarc.mutation.id = &_node.ID
|
||||
sarc.mutation.done = true
|
||||
return _node, nil
|
||||
}
|
||||
|
||||
func (sarc *ScaAuthRoleCreate) createSpec() (*ScaAuthRole, *sqlgraph.CreateSpec) {
|
||||
var (
|
||||
_node = &ScaAuthRole{config: sarc.config}
|
||||
_spec = sqlgraph.NewCreateSpec(scaauthrole.Table, sqlgraph.NewFieldSpec(scaauthrole.FieldID, field.TypeInt64))
|
||||
)
|
||||
if id, ok := sarc.mutation.ID(); ok {
|
||||
_node.ID = id
|
||||
_spec.ID.Value = id
|
||||
}
|
||||
if value, ok := sarc.mutation.RoleName(); ok {
|
||||
_spec.SetField(scaauthrole.FieldRoleName, field.TypeString, value)
|
||||
_node.RoleName = value
|
||||
}
|
||||
if value, ok := sarc.mutation.RoleKey(); ok {
|
||||
_spec.SetField(scaauthrole.FieldRoleKey, field.TypeString, value)
|
||||
_node.RoleKey = value
|
||||
}
|
||||
if value, ok := sarc.mutation.CreatedAt(); ok {
|
||||
_spec.SetField(scaauthrole.FieldCreatedAt, field.TypeTime, value)
|
||||
_node.CreatedAt = value
|
||||
}
|
||||
if value, ok := sarc.mutation.UpdateAt(); ok {
|
||||
_spec.SetField(scaauthrole.FieldUpdateAt, field.TypeTime, value)
|
||||
_node.UpdateAt = value
|
||||
}
|
||||
if value, ok := sarc.mutation.Deleted(); ok {
|
||||
_spec.SetField(scaauthrole.FieldDeleted, field.TypeInt, value)
|
||||
_node.Deleted = value
|
||||
}
|
||||
if nodes := sarc.mutation.ScaAuthPermissionRuleIDs(); len(nodes) > 0 {
|
||||
edge := &sqlgraph.EdgeSpec{
|
||||
Rel: sqlgraph.O2M,
|
||||
Inverse: false,
|
||||
Table: scaauthrole.ScaAuthPermissionRuleTable,
|
||||
Columns: []string{scaauthrole.ScaAuthPermissionRuleColumn},
|
||||
Bidi: false,
|
||||
Target: &sqlgraph.EdgeTarget{
|
||||
IDSpec: sqlgraph.NewFieldSpec(scaauthpermissionrule.FieldID, field.TypeInt64),
|
||||
},
|
||||
}
|
||||
for _, k := range nodes {
|
||||
edge.Target.Nodes = append(edge.Target.Nodes, k)
|
||||
}
|
||||
_spec.Edges = append(_spec.Edges, edge)
|
||||
}
|
||||
return _node, _spec
|
||||
}
|
||||
|
||||
// ScaAuthRoleCreateBulk is the builder for creating many ScaAuthRole entities in bulk.
|
||||
type ScaAuthRoleCreateBulk struct {
|
||||
config
|
||||
err error
|
||||
builders []*ScaAuthRoleCreate
|
||||
}
|
||||
|
||||
// Save creates the ScaAuthRole entities in the database.
|
||||
func (sarcb *ScaAuthRoleCreateBulk) Save(ctx context.Context) ([]*ScaAuthRole, error) {
|
||||
if sarcb.err != nil {
|
||||
return nil, sarcb.err
|
||||
}
|
||||
specs := make([]*sqlgraph.CreateSpec, len(sarcb.builders))
|
||||
nodes := make([]*ScaAuthRole, len(sarcb.builders))
|
||||
mutators := make([]Mutator, len(sarcb.builders))
|
||||
for i := range sarcb.builders {
|
||||
func(i int, root context.Context) {
|
||||
builder := sarcb.builders[i]
|
||||
builder.defaults()
|
||||
var mut Mutator = MutateFunc(func(ctx context.Context, m Mutation) (Value, error) {
|
||||
mutation, ok := m.(*ScaAuthRoleMutation)
|
||||
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, sarcb.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, sarcb.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, sarcb.builders[0].mutation); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
return nodes, nil
|
||||
}
|
||||
|
||||
// SaveX is like Save, but panics if an error occurs.
|
||||
func (sarcb *ScaAuthRoleCreateBulk) SaveX(ctx context.Context) []*ScaAuthRole {
|
||||
v, err := sarcb.Save(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return v
|
||||
}
|
||||
|
||||
// Exec executes the query.
|
||||
func (sarcb *ScaAuthRoleCreateBulk) Exec(ctx context.Context) error {
|
||||
_, err := sarcb.Save(ctx)
|
||||
return err
|
||||
}
|
||||
|
||||
// ExecX is like Exec, but panics if an error occurs.
|
||||
func (sarcb *ScaAuthRoleCreateBulk) ExecX(ctx context.Context) {
|
||||
if err := sarcb.Exec(ctx); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user