372 lines
12 KiB
Go
372 lines
12 KiB
Go
// Code generated by ent, DO NOT EDIT.
|
|
|
|
package ent
|
|
|
|
import (
|
|
"context"
|
|
"epic-ent/internal/ent/epici18nmappings"
|
|
"errors"
|
|
"fmt"
|
|
"time"
|
|
|
|
"entgo.io/ent/dialect/sql/sqlgraph"
|
|
"entgo.io/ent/schema/field"
|
|
)
|
|
|
|
// EpicI18NMappingsCreate is the builder for creating a EpicI18NMappings entity.
|
|
type EpicI18NMappingsCreate struct {
|
|
config
|
|
mutation *EpicI18NMappingsMutation
|
|
hooks []Hook
|
|
}
|
|
|
|
// SetKeyName sets the "key_name" field.
|
|
func (_c *EpicI18NMappingsCreate) SetKeyName(v string) *EpicI18NMappingsCreate {
|
|
_c.mutation.SetKeyName(v)
|
|
return _c
|
|
}
|
|
|
|
// SetLanguage sets the "language" field.
|
|
func (_c *EpicI18NMappingsCreate) SetLanguage(v string) *EpicI18NMappingsCreate {
|
|
_c.mutation.SetLanguage(v)
|
|
return _c
|
|
}
|
|
|
|
// SetValue sets the "value" field.
|
|
func (_c *EpicI18NMappingsCreate) SetValue(v string) *EpicI18NMappingsCreate {
|
|
_c.mutation.SetValue(v)
|
|
return _c
|
|
}
|
|
|
|
// SetCategory sets the "category" field.
|
|
func (_c *EpicI18NMappingsCreate) SetCategory(v string) *EpicI18NMappingsCreate {
|
|
_c.mutation.SetCategory(v)
|
|
return _c
|
|
}
|
|
|
|
// SetStatus sets the "status" field.
|
|
func (_c *EpicI18NMappingsCreate) SetStatus(v int) *EpicI18NMappingsCreate {
|
|
_c.mutation.SetStatus(v)
|
|
return _c
|
|
}
|
|
|
|
// SetCreator sets the "creator" field.
|
|
func (_c *EpicI18NMappingsCreate) SetCreator(v string) *EpicI18NMappingsCreate {
|
|
_c.mutation.SetCreator(v)
|
|
return _c
|
|
}
|
|
|
|
// SetCreateTime sets the "create_time" field.
|
|
func (_c *EpicI18NMappingsCreate) SetCreateTime(v time.Time) *EpicI18NMappingsCreate {
|
|
_c.mutation.SetCreateTime(v)
|
|
return _c
|
|
}
|
|
|
|
// SetNillableCreateTime sets the "create_time" field if the given value is not nil.
|
|
func (_c *EpicI18NMappingsCreate) SetNillableCreateTime(v *time.Time) *EpicI18NMappingsCreate {
|
|
if v != nil {
|
|
_c.SetCreateTime(*v)
|
|
}
|
|
return _c
|
|
}
|
|
|
|
// SetUpdater sets the "updater" field.
|
|
func (_c *EpicI18NMappingsCreate) SetUpdater(v string) *EpicI18NMappingsCreate {
|
|
_c.mutation.SetUpdater(v)
|
|
return _c
|
|
}
|
|
|
|
// SetUpdateTime sets the "update_time" field.
|
|
func (_c *EpicI18NMappingsCreate) SetUpdateTime(v time.Time) *EpicI18NMappingsCreate {
|
|
_c.mutation.SetUpdateTime(v)
|
|
return _c
|
|
}
|
|
|
|
// SetNillableUpdateTime sets the "update_time" field if the given value is not nil.
|
|
func (_c *EpicI18NMappingsCreate) SetNillableUpdateTime(v *time.Time) *EpicI18NMappingsCreate {
|
|
if v != nil {
|
|
_c.SetUpdateTime(*v)
|
|
}
|
|
return _c
|
|
}
|
|
|
|
// SetDeleted sets the "deleted" field.
|
|
func (_c *EpicI18NMappingsCreate) SetDeleted(v int) *EpicI18NMappingsCreate {
|
|
_c.mutation.SetDeleted(v)
|
|
return _c
|
|
}
|
|
|
|
// SetCode sets the "code" field.
|
|
func (_c *EpicI18NMappingsCreate) SetCode(v string) *EpicI18NMappingsCreate {
|
|
_c.mutation.SetCode(v)
|
|
return _c
|
|
}
|
|
|
|
// SetID sets the "id" field.
|
|
func (_c *EpicI18NMappingsCreate) SetID(v int64) *EpicI18NMappingsCreate {
|
|
_c.mutation.SetID(v)
|
|
return _c
|
|
}
|
|
|
|
// Mutation returns the EpicI18NMappingsMutation object of the builder.
|
|
func (_c *EpicI18NMappingsCreate) Mutation() *EpicI18NMappingsMutation {
|
|
return _c.mutation
|
|
}
|
|
|
|
// Save creates the EpicI18NMappings in the database.
|
|
func (_c *EpicI18NMappingsCreate) Save(ctx context.Context) (*EpicI18NMappings, error) {
|
|
return withHooks(ctx, _c.sqlSave, _c.mutation, _c.hooks)
|
|
}
|
|
|
|
// SaveX calls Save and panics if Save returns an error.
|
|
func (_c *EpicI18NMappingsCreate) SaveX(ctx context.Context) *EpicI18NMappings {
|
|
v, err := _c.Save(ctx)
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
return v
|
|
}
|
|
|
|
// Exec executes the query.
|
|
func (_c *EpicI18NMappingsCreate) Exec(ctx context.Context) error {
|
|
_, err := _c.Save(ctx)
|
|
return err
|
|
}
|
|
|
|
// ExecX is like Exec, but panics if an error occurs.
|
|
func (_c *EpicI18NMappingsCreate) ExecX(ctx context.Context) {
|
|
if err := _c.Exec(ctx); err != nil {
|
|
panic(err)
|
|
}
|
|
}
|
|
|
|
// check runs all checks and user-defined validators on the builder.
|
|
func (_c *EpicI18NMappingsCreate) check() error {
|
|
if _, ok := _c.mutation.KeyName(); !ok {
|
|
return &ValidationError{Name: "key_name", err: errors.New(`ent: missing required field "EpicI18NMappings.key_name"`)}
|
|
}
|
|
if v, ok := _c.mutation.KeyName(); ok {
|
|
if err := epici18nmappings.KeyNameValidator(v); err != nil {
|
|
return &ValidationError{Name: "key_name", err: fmt.Errorf(`ent: validator failed for field "EpicI18NMappings.key_name": %w`, err)}
|
|
}
|
|
}
|
|
if _, ok := _c.mutation.Language(); !ok {
|
|
return &ValidationError{Name: "language", err: errors.New(`ent: missing required field "EpicI18NMappings.language"`)}
|
|
}
|
|
if v, ok := _c.mutation.Language(); ok {
|
|
if err := epici18nmappings.LanguageValidator(v); err != nil {
|
|
return &ValidationError{Name: "language", err: fmt.Errorf(`ent: validator failed for field "EpicI18NMappings.language": %w`, err)}
|
|
}
|
|
}
|
|
if _, ok := _c.mutation.Value(); !ok {
|
|
return &ValidationError{Name: "value", err: errors.New(`ent: missing required field "EpicI18NMappings.value"`)}
|
|
}
|
|
if v, ok := _c.mutation.Value(); ok {
|
|
if err := epici18nmappings.ValueValidator(v); err != nil {
|
|
return &ValidationError{Name: "value", err: fmt.Errorf(`ent: validator failed for field "EpicI18NMappings.value": %w`, err)}
|
|
}
|
|
}
|
|
if _, ok := _c.mutation.Category(); !ok {
|
|
return &ValidationError{Name: "category", err: errors.New(`ent: missing required field "EpicI18NMappings.category"`)}
|
|
}
|
|
if v, ok := _c.mutation.Category(); ok {
|
|
if err := epici18nmappings.CategoryValidator(v); err != nil {
|
|
return &ValidationError{Name: "category", err: fmt.Errorf(`ent: validator failed for field "EpicI18NMappings.category": %w`, err)}
|
|
}
|
|
}
|
|
if _, ok := _c.mutation.Status(); !ok {
|
|
return &ValidationError{Name: "status", err: errors.New(`ent: missing required field "EpicI18NMappings.status"`)}
|
|
}
|
|
if _, ok := _c.mutation.Creator(); !ok {
|
|
return &ValidationError{Name: "creator", err: errors.New(`ent: missing required field "EpicI18NMappings.creator"`)}
|
|
}
|
|
if v, ok := _c.mutation.Creator(); ok {
|
|
if err := epici18nmappings.CreatorValidator(v); err != nil {
|
|
return &ValidationError{Name: "creator", err: fmt.Errorf(`ent: validator failed for field "EpicI18NMappings.creator": %w`, err)}
|
|
}
|
|
}
|
|
if _, ok := _c.mutation.Updater(); !ok {
|
|
return &ValidationError{Name: "updater", err: errors.New(`ent: missing required field "EpicI18NMappings.updater"`)}
|
|
}
|
|
if v, ok := _c.mutation.Updater(); ok {
|
|
if err := epici18nmappings.UpdaterValidator(v); err != nil {
|
|
return &ValidationError{Name: "updater", err: fmt.Errorf(`ent: validator failed for field "EpicI18NMappings.updater": %w`, err)}
|
|
}
|
|
}
|
|
if _, ok := _c.mutation.Deleted(); !ok {
|
|
return &ValidationError{Name: "deleted", err: errors.New(`ent: missing required field "EpicI18NMappings.deleted"`)}
|
|
}
|
|
if _, ok := _c.mutation.Code(); !ok {
|
|
return &ValidationError{Name: "code", err: errors.New(`ent: missing required field "EpicI18NMappings.code"`)}
|
|
}
|
|
if v, ok := _c.mutation.Code(); ok {
|
|
if err := epici18nmappings.CodeValidator(v); err != nil {
|
|
return &ValidationError{Name: "code", err: fmt.Errorf(`ent: validator failed for field "EpicI18NMappings.code": %w`, err)}
|
|
}
|
|
}
|
|
return nil
|
|
}
|
|
|
|
func (_c *EpicI18NMappingsCreate) sqlSave(ctx context.Context) (*EpicI18NMappings, 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 = int64(id)
|
|
}
|
|
_c.mutation.id = &_node.ID
|
|
_c.mutation.done = true
|
|
return _node, nil
|
|
}
|
|
|
|
func (_c *EpicI18NMappingsCreate) createSpec() (*EpicI18NMappings, *sqlgraph.CreateSpec) {
|
|
var (
|
|
_node = &EpicI18NMappings{config: _c.config}
|
|
_spec = sqlgraph.NewCreateSpec(epici18nmappings.Table, sqlgraph.NewFieldSpec(epici18nmappings.FieldID, field.TypeInt64))
|
|
)
|
|
if id, ok := _c.mutation.ID(); ok {
|
|
_node.ID = id
|
|
_spec.ID.Value = id
|
|
}
|
|
if value, ok := _c.mutation.KeyName(); ok {
|
|
_spec.SetField(epici18nmappings.FieldKeyName, field.TypeString, value)
|
|
_node.KeyName = value
|
|
}
|
|
if value, ok := _c.mutation.Language(); ok {
|
|
_spec.SetField(epici18nmappings.FieldLanguage, field.TypeString, value)
|
|
_node.Language = value
|
|
}
|
|
if value, ok := _c.mutation.Value(); ok {
|
|
_spec.SetField(epici18nmappings.FieldValue, field.TypeString, value)
|
|
_node.Value = value
|
|
}
|
|
if value, ok := _c.mutation.Category(); ok {
|
|
_spec.SetField(epici18nmappings.FieldCategory, field.TypeString, value)
|
|
_node.Category = value
|
|
}
|
|
if value, ok := _c.mutation.Status(); ok {
|
|
_spec.SetField(epici18nmappings.FieldStatus, field.TypeInt, value)
|
|
_node.Status = value
|
|
}
|
|
if value, ok := _c.mutation.Creator(); ok {
|
|
_spec.SetField(epici18nmappings.FieldCreator, field.TypeString, value)
|
|
_node.Creator = value
|
|
}
|
|
if value, ok := _c.mutation.CreateTime(); ok {
|
|
_spec.SetField(epici18nmappings.FieldCreateTime, field.TypeTime, value)
|
|
_node.CreateTime = &value
|
|
}
|
|
if value, ok := _c.mutation.Updater(); ok {
|
|
_spec.SetField(epici18nmappings.FieldUpdater, field.TypeString, value)
|
|
_node.Updater = value
|
|
}
|
|
if value, ok := _c.mutation.UpdateTime(); ok {
|
|
_spec.SetField(epici18nmappings.FieldUpdateTime, field.TypeTime, value)
|
|
_node.UpdateTime = &value
|
|
}
|
|
if value, ok := _c.mutation.Deleted(); ok {
|
|
_spec.SetField(epici18nmappings.FieldDeleted, field.TypeInt, value)
|
|
_node.Deleted = value
|
|
}
|
|
if value, ok := _c.mutation.Code(); ok {
|
|
_spec.SetField(epici18nmappings.FieldCode, field.TypeString, value)
|
|
_node.Code = value
|
|
}
|
|
return _node, _spec
|
|
}
|
|
|
|
// EpicI18NMappingsCreateBulk is the builder for creating many EpicI18NMappings entities in bulk.
|
|
type EpicI18NMappingsCreateBulk struct {
|
|
config
|
|
err error
|
|
builders []*EpicI18NMappingsCreate
|
|
}
|
|
|
|
// Save creates the EpicI18NMappings entities in the database.
|
|
func (_c *EpicI18NMappingsCreateBulk) Save(ctx context.Context) ([]*EpicI18NMappings, error) {
|
|
if _c.err != nil {
|
|
return nil, _c.err
|
|
}
|
|
specs := make([]*sqlgraph.CreateSpec, len(_c.builders))
|
|
nodes := make([]*EpicI18NMappings, len(_c.builders))
|
|
mutators := make([]Mutator, len(_c.builders))
|
|
for i := range _c.builders {
|
|
func(i int, root context.Context) {
|
|
builder := _c.builders[i]
|
|
var mut Mutator = MutateFunc(func(ctx context.Context, m Mutation) (Value, error) {
|
|
mutation, ok := m.(*EpicI18NMappingsMutation)
|
|
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 = 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, _c.builders[0].mutation); err != nil {
|
|
return nil, err
|
|
}
|
|
}
|
|
return nodes, nil
|
|
}
|
|
|
|
// SaveX is like Save, but panics if an error occurs.
|
|
func (_c *EpicI18NMappingsCreateBulk) SaveX(ctx context.Context) []*EpicI18NMappings {
|
|
v, err := _c.Save(ctx)
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
return v
|
|
}
|
|
|
|
// Exec executes the query.
|
|
func (_c *EpicI18NMappingsCreateBulk) Exec(ctx context.Context) error {
|
|
_, err := _c.Save(ctx)
|
|
return err
|
|
}
|
|
|
|
// ExecX is like Exec, but panics if an error occurs.
|
|
func (_c *EpicI18NMappingsCreateBulk) ExecX(ctx context.Context) {
|
|
if err := _c.Exec(ctx); err != nil {
|
|
panic(err)
|
|
}
|
|
}
|