415 lines
12 KiB
Go
415 lines
12 KiB
Go
|
// Code generated by ent, DO NOT EDIT.
|
||
|
|
||
|
package ent
|
||
|
|
||
|
import (
|
||
|
"context"
|
||
|
"errors"
|
||
|
"fmt"
|
||
|
"time"
|
||
|
|
||
|
"entgo.io/ent/dialect/sql/sqlgraph"
|
||
|
"entgo.io/ent/schema/field"
|
||
|
"gitserver.in/patialtech/rano/db/ent/accesscontrol"
|
||
|
)
|
||
|
|
||
|
// AccessControlCreate is the builder for creating a AccessControl entity.
|
||
|
type AccessControlCreate struct {
|
||
|
config
|
||
|
mutation *AccessControlMutation
|
||
|
hooks []Hook
|
||
|
}
|
||
|
|
||
|
// SetCreatedAt sets the "created_at" field.
|
||
|
func (acc *AccessControlCreate) SetCreatedAt(t time.Time) *AccessControlCreate {
|
||
|
acc.mutation.SetCreatedAt(t)
|
||
|
return acc
|
||
|
}
|
||
|
|
||
|
// SetNillableCreatedAt sets the "created_at" field if the given value is not nil.
|
||
|
func (acc *AccessControlCreate) SetNillableCreatedAt(t *time.Time) *AccessControlCreate {
|
||
|
if t != nil {
|
||
|
acc.SetCreatedAt(*t)
|
||
|
}
|
||
|
return acc
|
||
|
}
|
||
|
|
||
|
// SetUpdatedAt sets the "updated_at" field.
|
||
|
func (acc *AccessControlCreate) SetUpdatedAt(t time.Time) *AccessControlCreate {
|
||
|
acc.mutation.SetUpdatedAt(t)
|
||
|
return acc
|
||
|
}
|
||
|
|
||
|
// SetNillableUpdatedAt sets the "updated_at" field if the given value is not nil.
|
||
|
func (acc *AccessControlCreate) SetNillableUpdatedAt(t *time.Time) *AccessControlCreate {
|
||
|
if t != nil {
|
||
|
acc.SetUpdatedAt(*t)
|
||
|
}
|
||
|
return acc
|
||
|
}
|
||
|
|
||
|
// SetPtype sets the "ptype" field.
|
||
|
func (acc *AccessControlCreate) SetPtype(s string) *AccessControlCreate {
|
||
|
acc.mutation.SetPtype(s)
|
||
|
return acc
|
||
|
}
|
||
|
|
||
|
// SetNillablePtype sets the "ptype" field if the given value is not nil.
|
||
|
func (acc *AccessControlCreate) SetNillablePtype(s *string) *AccessControlCreate {
|
||
|
if s != nil {
|
||
|
acc.SetPtype(*s)
|
||
|
}
|
||
|
return acc
|
||
|
}
|
||
|
|
||
|
// SetV0 sets the "v0" field.
|
||
|
func (acc *AccessControlCreate) SetV0(s string) *AccessControlCreate {
|
||
|
acc.mutation.SetV0(s)
|
||
|
return acc
|
||
|
}
|
||
|
|
||
|
// SetNillableV0 sets the "v0" field if the given value is not nil.
|
||
|
func (acc *AccessControlCreate) SetNillableV0(s *string) *AccessControlCreate {
|
||
|
if s != nil {
|
||
|
acc.SetV0(*s)
|
||
|
}
|
||
|
return acc
|
||
|
}
|
||
|
|
||
|
// SetV1 sets the "v1" field.
|
||
|
func (acc *AccessControlCreate) SetV1(s string) *AccessControlCreate {
|
||
|
acc.mutation.SetV1(s)
|
||
|
return acc
|
||
|
}
|
||
|
|
||
|
// SetNillableV1 sets the "v1" field if the given value is not nil.
|
||
|
func (acc *AccessControlCreate) SetNillableV1(s *string) *AccessControlCreate {
|
||
|
if s != nil {
|
||
|
acc.SetV1(*s)
|
||
|
}
|
||
|
return acc
|
||
|
}
|
||
|
|
||
|
// SetV2 sets the "v2" field.
|
||
|
func (acc *AccessControlCreate) SetV2(s string) *AccessControlCreate {
|
||
|
acc.mutation.SetV2(s)
|
||
|
return acc
|
||
|
}
|
||
|
|
||
|
// SetNillableV2 sets the "v2" field if the given value is not nil.
|
||
|
func (acc *AccessControlCreate) SetNillableV2(s *string) *AccessControlCreate {
|
||
|
if s != nil {
|
||
|
acc.SetV2(*s)
|
||
|
}
|
||
|
return acc
|
||
|
}
|
||
|
|
||
|
// SetV3 sets the "v3" field.
|
||
|
func (acc *AccessControlCreate) SetV3(s string) *AccessControlCreate {
|
||
|
acc.mutation.SetV3(s)
|
||
|
return acc
|
||
|
}
|
||
|
|
||
|
// SetNillableV3 sets the "v3" field if the given value is not nil.
|
||
|
func (acc *AccessControlCreate) SetNillableV3(s *string) *AccessControlCreate {
|
||
|
if s != nil {
|
||
|
acc.SetV3(*s)
|
||
|
}
|
||
|
return acc
|
||
|
}
|
||
|
|
||
|
// SetV4 sets the "v4" field.
|
||
|
func (acc *AccessControlCreate) SetV4(s string) *AccessControlCreate {
|
||
|
acc.mutation.SetV4(s)
|
||
|
return acc
|
||
|
}
|
||
|
|
||
|
// SetNillableV4 sets the "v4" field if the given value is not nil.
|
||
|
func (acc *AccessControlCreate) SetNillableV4(s *string) *AccessControlCreate {
|
||
|
if s != nil {
|
||
|
acc.SetV4(*s)
|
||
|
}
|
||
|
return acc
|
||
|
}
|
||
|
|
||
|
// SetV5 sets the "v5" field.
|
||
|
func (acc *AccessControlCreate) SetV5(s string) *AccessControlCreate {
|
||
|
acc.mutation.SetV5(s)
|
||
|
return acc
|
||
|
}
|
||
|
|
||
|
// SetNillableV5 sets the "v5" field if the given value is not nil.
|
||
|
func (acc *AccessControlCreate) SetNillableV5(s *string) *AccessControlCreate {
|
||
|
if s != nil {
|
||
|
acc.SetV5(*s)
|
||
|
}
|
||
|
return acc
|
||
|
}
|
||
|
|
||
|
// SetID sets the "id" field.
|
||
|
func (acc *AccessControlCreate) SetID(i int64) *AccessControlCreate {
|
||
|
acc.mutation.SetID(i)
|
||
|
return acc
|
||
|
}
|
||
|
|
||
|
// Mutation returns the AccessControlMutation object of the builder.
|
||
|
func (acc *AccessControlCreate) Mutation() *AccessControlMutation {
|
||
|
return acc.mutation
|
||
|
}
|
||
|
|
||
|
// Save creates the AccessControl in the database.
|
||
|
func (acc *AccessControlCreate) Save(ctx context.Context) (*AccessControl, error) {
|
||
|
acc.defaults()
|
||
|
return withHooks(ctx, acc.sqlSave, acc.mutation, acc.hooks)
|
||
|
}
|
||
|
|
||
|
// SaveX calls Save and panics if Save returns an error.
|
||
|
func (acc *AccessControlCreate) SaveX(ctx context.Context) *AccessControl {
|
||
|
v, err := acc.Save(ctx)
|
||
|
if err != nil {
|
||
|
panic(err)
|
||
|
}
|
||
|
return v
|
||
|
}
|
||
|
|
||
|
// Exec executes the query.
|
||
|
func (acc *AccessControlCreate) Exec(ctx context.Context) error {
|
||
|
_, err := acc.Save(ctx)
|
||
|
return err
|
||
|
}
|
||
|
|
||
|
// ExecX is like Exec, but panics if an error occurs.
|
||
|
func (acc *AccessControlCreate) ExecX(ctx context.Context) {
|
||
|
if err := acc.Exec(ctx); err != nil {
|
||
|
panic(err)
|
||
|
}
|
||
|
}
|
||
|
|
||
|
// defaults sets the default values of the builder before save.
|
||
|
func (acc *AccessControlCreate) defaults() {
|
||
|
if _, ok := acc.mutation.CreatedAt(); !ok {
|
||
|
v := accesscontrol.DefaultCreatedAt()
|
||
|
acc.mutation.SetCreatedAt(v)
|
||
|
}
|
||
|
if _, ok := acc.mutation.UpdatedAt(); !ok {
|
||
|
v := accesscontrol.DefaultUpdatedAt()
|
||
|
acc.mutation.SetUpdatedAt(v)
|
||
|
}
|
||
|
if _, ok := acc.mutation.Ptype(); !ok {
|
||
|
v := accesscontrol.DefaultPtype
|
||
|
acc.mutation.SetPtype(v)
|
||
|
}
|
||
|
if _, ok := acc.mutation.V0(); !ok {
|
||
|
v := accesscontrol.DefaultV0
|
||
|
acc.mutation.SetV0(v)
|
||
|
}
|
||
|
if _, ok := acc.mutation.V1(); !ok {
|
||
|
v := accesscontrol.DefaultV1
|
||
|
acc.mutation.SetV1(v)
|
||
|
}
|
||
|
if _, ok := acc.mutation.V2(); !ok {
|
||
|
v := accesscontrol.DefaultV2
|
||
|
acc.mutation.SetV2(v)
|
||
|
}
|
||
|
if _, ok := acc.mutation.V3(); !ok {
|
||
|
v := accesscontrol.DefaultV3
|
||
|
acc.mutation.SetV3(v)
|
||
|
}
|
||
|
if _, ok := acc.mutation.V4(); !ok {
|
||
|
v := accesscontrol.DefaultV4
|
||
|
acc.mutation.SetV4(v)
|
||
|
}
|
||
|
if _, ok := acc.mutation.V5(); !ok {
|
||
|
v := accesscontrol.DefaultV5
|
||
|
acc.mutation.SetV5(v)
|
||
|
}
|
||
|
}
|
||
|
|
||
|
// check runs all checks and user-defined validators on the builder.
|
||
|
func (acc *AccessControlCreate) check() error {
|
||
|
if _, ok := acc.mutation.CreatedAt(); !ok {
|
||
|
return &ValidationError{Name: "created_at", err: errors.New(`ent: missing required field "AccessControl.created_at"`)}
|
||
|
}
|
||
|
if _, ok := acc.mutation.UpdatedAt(); !ok {
|
||
|
return &ValidationError{Name: "updated_at", err: errors.New(`ent: missing required field "AccessControl.updated_at"`)}
|
||
|
}
|
||
|
if _, ok := acc.mutation.Ptype(); !ok {
|
||
|
return &ValidationError{Name: "ptype", err: errors.New(`ent: missing required field "AccessControl.ptype"`)}
|
||
|
}
|
||
|
if _, ok := acc.mutation.V0(); !ok {
|
||
|
return &ValidationError{Name: "v0", err: errors.New(`ent: missing required field "AccessControl.v0"`)}
|
||
|
}
|
||
|
if _, ok := acc.mutation.V1(); !ok {
|
||
|
return &ValidationError{Name: "v1", err: errors.New(`ent: missing required field "AccessControl.v1"`)}
|
||
|
}
|
||
|
if _, ok := acc.mutation.V2(); !ok {
|
||
|
return &ValidationError{Name: "v2", err: errors.New(`ent: missing required field "AccessControl.v2"`)}
|
||
|
}
|
||
|
if _, ok := acc.mutation.V3(); !ok {
|
||
|
return &ValidationError{Name: "v3", err: errors.New(`ent: missing required field "AccessControl.v3"`)}
|
||
|
}
|
||
|
if _, ok := acc.mutation.V4(); !ok {
|
||
|
return &ValidationError{Name: "v4", err: errors.New(`ent: missing required field "AccessControl.v4"`)}
|
||
|
}
|
||
|
if _, ok := acc.mutation.V5(); !ok {
|
||
|
return &ValidationError{Name: "v5", err: errors.New(`ent: missing required field "AccessControl.v5"`)}
|
||
|
}
|
||
|
return nil
|
||
|
}
|
||
|
|
||
|
func (acc *AccessControlCreate) sqlSave(ctx context.Context) (*AccessControl, error) {
|
||
|
if err := acc.check(); err != nil {
|
||
|
return nil, err
|
||
|
}
|
||
|
_node, _spec := acc.createSpec()
|
||
|
if err := sqlgraph.CreateNode(ctx, acc.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)
|
||
|
}
|
||
|
acc.mutation.id = &_node.ID
|
||
|
acc.mutation.done = true
|
||
|
return _node, nil
|
||
|
}
|
||
|
|
||
|
func (acc *AccessControlCreate) createSpec() (*AccessControl, *sqlgraph.CreateSpec) {
|
||
|
var (
|
||
|
_node = &AccessControl{config: acc.config}
|
||
|
_spec = sqlgraph.NewCreateSpec(accesscontrol.Table, sqlgraph.NewFieldSpec(accesscontrol.FieldID, field.TypeInt64))
|
||
|
)
|
||
|
if id, ok := acc.mutation.ID(); ok {
|
||
|
_node.ID = id
|
||
|
_spec.ID.Value = id
|
||
|
}
|
||
|
if value, ok := acc.mutation.CreatedAt(); ok {
|
||
|
_spec.SetField(accesscontrol.FieldCreatedAt, field.TypeTime, value)
|
||
|
_node.CreatedAt = value
|
||
|
}
|
||
|
if value, ok := acc.mutation.UpdatedAt(); ok {
|
||
|
_spec.SetField(accesscontrol.FieldUpdatedAt, field.TypeTime, value)
|
||
|
_node.UpdatedAt = value
|
||
|
}
|
||
|
if value, ok := acc.mutation.Ptype(); ok {
|
||
|
_spec.SetField(accesscontrol.FieldPtype, field.TypeString, value)
|
||
|
_node.Ptype = value
|
||
|
}
|
||
|
if value, ok := acc.mutation.V0(); ok {
|
||
|
_spec.SetField(accesscontrol.FieldV0, field.TypeString, value)
|
||
|
_node.V0 = value
|
||
|
}
|
||
|
if value, ok := acc.mutation.V1(); ok {
|
||
|
_spec.SetField(accesscontrol.FieldV1, field.TypeString, value)
|
||
|
_node.V1 = value
|
||
|
}
|
||
|
if value, ok := acc.mutation.V2(); ok {
|
||
|
_spec.SetField(accesscontrol.FieldV2, field.TypeString, value)
|
||
|
_node.V2 = value
|
||
|
}
|
||
|
if value, ok := acc.mutation.V3(); ok {
|
||
|
_spec.SetField(accesscontrol.FieldV3, field.TypeString, value)
|
||
|
_node.V3 = value
|
||
|
}
|
||
|
if value, ok := acc.mutation.V4(); ok {
|
||
|
_spec.SetField(accesscontrol.FieldV4, field.TypeString, value)
|
||
|
_node.V4 = value
|
||
|
}
|
||
|
if value, ok := acc.mutation.V5(); ok {
|
||
|
_spec.SetField(accesscontrol.FieldV5, field.TypeString, value)
|
||
|
_node.V5 = value
|
||
|
}
|
||
|
return _node, _spec
|
||
|
}
|
||
|
|
||
|
// AccessControlCreateBulk is the builder for creating many AccessControl entities in bulk.
|
||
|
type AccessControlCreateBulk struct {
|
||
|
config
|
||
|
err error
|
||
|
builders []*AccessControlCreate
|
||
|
}
|
||
|
|
||
|
// Save creates the AccessControl entities in the database.
|
||
|
func (accb *AccessControlCreateBulk) Save(ctx context.Context) ([]*AccessControl, error) {
|
||
|
if accb.err != nil {
|
||
|
return nil, accb.err
|
||
|
}
|
||
|
specs := make([]*sqlgraph.CreateSpec, len(accb.builders))
|
||
|
nodes := make([]*AccessControl, len(accb.builders))
|
||
|
mutators := make([]Mutator, len(accb.builders))
|
||
|
for i := range accb.builders {
|
||
|
func(i int, root context.Context) {
|
||
|
builder := accb.builders[i]
|
||
|
builder.defaults()
|
||
|
var mut Mutator = MutateFunc(func(ctx context.Context, m Mutation) (Value, error) {
|
||
|
mutation, ok := m.(*AccessControlMutation)
|
||
|
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, accb.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, accb.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, accb.builders[0].mutation); err != nil {
|
||
|
return nil, err
|
||
|
}
|
||
|
}
|
||
|
return nodes, nil
|
||
|
}
|
||
|
|
||
|
// SaveX is like Save, but panics if an error occurs.
|
||
|
func (accb *AccessControlCreateBulk) SaveX(ctx context.Context) []*AccessControl {
|
||
|
v, err := accb.Save(ctx)
|
||
|
if err != nil {
|
||
|
panic(err)
|
||
|
}
|
||
|
return v
|
||
|
}
|
||
|
|
||
|
// Exec executes the query.
|
||
|
func (accb *AccessControlCreateBulk) Exec(ctx context.Context) error {
|
||
|
_, err := accb.Save(ctx)
|
||
|
return err
|
||
|
}
|
||
|
|
||
|
// ExecX is like Exec, but panics if an error occurs.
|
||
|
func (accb *AccessControlCreateBulk) ExecX(ctx context.Context) {
|
||
|
if err := accb.Exec(ctx); err != nil {
|
||
|
panic(err)
|
||
|
}
|
||
|
}
|