snapshot of https://github.com/ent/ent.git (master, 2026-09-15; blobs > 131072B omitted)
This commit is contained in:
335
entc/integration/migrate/entv2/conversion_create.go
Normal file
335
entc/integration/migrate/entv2/conversion_create.go
Normal file
@@ -0,0 +1,335 @@
|
||||
// Copyright 2019-present Facebook Inc. All rights reserved.
|
||||
// This source code is licensed under the Apache 2.0 license found
|
||||
// in the LICENSE file in the root directory of this source tree.
|
||||
|
||||
// Code generated by ent, DO NOT EDIT.
|
||||
|
||||
package entv2
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
|
||||
"entgo.io/ent/dialect/sql/sqlgraph"
|
||||
"entgo.io/ent/entc/integration/migrate/entv2/conversion"
|
||||
"entgo.io/ent/schema/field"
|
||||
)
|
||||
|
||||
// ConversionCreate is the builder for creating a Conversion entity.
|
||||
type ConversionCreate struct {
|
||||
config
|
||||
mutation *ConversionMutation
|
||||
hooks []Hook
|
||||
}
|
||||
|
||||
// SetName sets the "name" field.
|
||||
func (_c *ConversionCreate) SetName(v string) *ConversionCreate {
|
||||
_c.mutation.SetName(v)
|
||||
return _c
|
||||
}
|
||||
|
||||
// SetNillableName sets the "name" field if the given value is not nil.
|
||||
func (_c *ConversionCreate) SetNillableName(v *string) *ConversionCreate {
|
||||
if v != nil {
|
||||
_c.SetName(*v)
|
||||
}
|
||||
return _c
|
||||
}
|
||||
|
||||
// SetInt8ToString sets the "int8_to_string" field.
|
||||
func (_c *ConversionCreate) SetInt8ToString(v string) *ConversionCreate {
|
||||
_c.mutation.SetInt8ToString(v)
|
||||
return _c
|
||||
}
|
||||
|
||||
// SetNillableInt8ToString sets the "int8_to_string" field if the given value is not nil.
|
||||
func (_c *ConversionCreate) SetNillableInt8ToString(v *string) *ConversionCreate {
|
||||
if v != nil {
|
||||
_c.SetInt8ToString(*v)
|
||||
}
|
||||
return _c
|
||||
}
|
||||
|
||||
// SetUint8ToString sets the "uint8_to_string" field.
|
||||
func (_c *ConversionCreate) SetUint8ToString(v string) *ConversionCreate {
|
||||
_c.mutation.SetUint8ToString(v)
|
||||
return _c
|
||||
}
|
||||
|
||||
// SetNillableUint8ToString sets the "uint8_to_string" field if the given value is not nil.
|
||||
func (_c *ConversionCreate) SetNillableUint8ToString(v *string) *ConversionCreate {
|
||||
if v != nil {
|
||||
_c.SetUint8ToString(*v)
|
||||
}
|
||||
return _c
|
||||
}
|
||||
|
||||
// SetInt16ToString sets the "int16_to_string" field.
|
||||
func (_c *ConversionCreate) SetInt16ToString(v string) *ConversionCreate {
|
||||
_c.mutation.SetInt16ToString(v)
|
||||
return _c
|
||||
}
|
||||
|
||||
// SetNillableInt16ToString sets the "int16_to_string" field if the given value is not nil.
|
||||
func (_c *ConversionCreate) SetNillableInt16ToString(v *string) *ConversionCreate {
|
||||
if v != nil {
|
||||
_c.SetInt16ToString(*v)
|
||||
}
|
||||
return _c
|
||||
}
|
||||
|
||||
// SetUint16ToString sets the "uint16_to_string" field.
|
||||
func (_c *ConversionCreate) SetUint16ToString(v string) *ConversionCreate {
|
||||
_c.mutation.SetUint16ToString(v)
|
||||
return _c
|
||||
}
|
||||
|
||||
// SetNillableUint16ToString sets the "uint16_to_string" field if the given value is not nil.
|
||||
func (_c *ConversionCreate) SetNillableUint16ToString(v *string) *ConversionCreate {
|
||||
if v != nil {
|
||||
_c.SetUint16ToString(*v)
|
||||
}
|
||||
return _c
|
||||
}
|
||||
|
||||
// SetInt32ToString sets the "int32_to_string" field.
|
||||
func (_c *ConversionCreate) SetInt32ToString(v string) *ConversionCreate {
|
||||
_c.mutation.SetInt32ToString(v)
|
||||
return _c
|
||||
}
|
||||
|
||||
// SetNillableInt32ToString sets the "int32_to_string" field if the given value is not nil.
|
||||
func (_c *ConversionCreate) SetNillableInt32ToString(v *string) *ConversionCreate {
|
||||
if v != nil {
|
||||
_c.SetInt32ToString(*v)
|
||||
}
|
||||
return _c
|
||||
}
|
||||
|
||||
// SetUint32ToString sets the "uint32_to_string" field.
|
||||
func (_c *ConversionCreate) SetUint32ToString(v string) *ConversionCreate {
|
||||
_c.mutation.SetUint32ToString(v)
|
||||
return _c
|
||||
}
|
||||
|
||||
// SetNillableUint32ToString sets the "uint32_to_string" field if the given value is not nil.
|
||||
func (_c *ConversionCreate) SetNillableUint32ToString(v *string) *ConversionCreate {
|
||||
if v != nil {
|
||||
_c.SetUint32ToString(*v)
|
||||
}
|
||||
return _c
|
||||
}
|
||||
|
||||
// SetInt64ToString sets the "int64_to_string" field.
|
||||
func (_c *ConversionCreate) SetInt64ToString(v string) *ConversionCreate {
|
||||
_c.mutation.SetInt64ToString(v)
|
||||
return _c
|
||||
}
|
||||
|
||||
// SetNillableInt64ToString sets the "int64_to_string" field if the given value is not nil.
|
||||
func (_c *ConversionCreate) SetNillableInt64ToString(v *string) *ConversionCreate {
|
||||
if v != nil {
|
||||
_c.SetInt64ToString(*v)
|
||||
}
|
||||
return _c
|
||||
}
|
||||
|
||||
// SetUint64ToString sets the "uint64_to_string" field.
|
||||
func (_c *ConversionCreate) SetUint64ToString(v string) *ConversionCreate {
|
||||
_c.mutation.SetUint64ToString(v)
|
||||
return _c
|
||||
}
|
||||
|
||||
// SetNillableUint64ToString sets the "uint64_to_string" field if the given value is not nil.
|
||||
func (_c *ConversionCreate) SetNillableUint64ToString(v *string) *ConversionCreate {
|
||||
if v != nil {
|
||||
_c.SetUint64ToString(*v)
|
||||
}
|
||||
return _c
|
||||
}
|
||||
|
||||
// Mutation returns the ConversionMutation object of the builder.
|
||||
func (_c *ConversionCreate) Mutation() *ConversionMutation {
|
||||
return _c.mutation
|
||||
}
|
||||
|
||||
// Save creates the Conversion in the database.
|
||||
func (_c *ConversionCreate) Save(ctx context.Context) (*Conversion, error) {
|
||||
return withHooks(ctx, _c.sqlSave, _c.mutation, _c.hooks)
|
||||
}
|
||||
|
||||
// SaveX calls Save and panics if Save returns an error.
|
||||
func (_c *ConversionCreate) SaveX(ctx context.Context) *Conversion {
|
||||
v, err := _c.Save(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return v
|
||||
}
|
||||
|
||||
// Exec executes the query.
|
||||
func (_c *ConversionCreate) Exec(ctx context.Context) error {
|
||||
_, err := _c.Save(ctx)
|
||||
return err
|
||||
}
|
||||
|
||||
// ExecX is like Exec, but panics if an error occurs.
|
||||
func (_c *ConversionCreate) 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 *ConversionCreate) check() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (_c *ConversionCreate) sqlSave(ctx context.Context) (*Conversion, 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
|
||||
}
|
||||
id := _spec.ID.Value.(int64)
|
||||
_node.ID = int(id)
|
||||
_c.mutation.id = &_node.ID
|
||||
_c.mutation.done = true
|
||||
return _node, nil
|
||||
}
|
||||
|
||||
func (_c *ConversionCreate) createSpec() (*Conversion, *sqlgraph.CreateSpec) {
|
||||
var (
|
||||
_node = &Conversion{config: _c.config}
|
||||
_spec = sqlgraph.NewCreateSpec(conversion.Table, sqlgraph.NewFieldSpec(conversion.FieldID, field.TypeInt))
|
||||
)
|
||||
if value, ok := _c.mutation.Name(); ok {
|
||||
_spec.SetField(conversion.FieldName, field.TypeString, value)
|
||||
_node.Name = value
|
||||
}
|
||||
if value, ok := _c.mutation.Int8ToString(); ok {
|
||||
_spec.SetField(conversion.FieldInt8ToString, field.TypeString, value)
|
||||
_node.Int8ToString = value
|
||||
}
|
||||
if value, ok := _c.mutation.Uint8ToString(); ok {
|
||||
_spec.SetField(conversion.FieldUint8ToString, field.TypeString, value)
|
||||
_node.Uint8ToString = value
|
||||
}
|
||||
if value, ok := _c.mutation.Int16ToString(); ok {
|
||||
_spec.SetField(conversion.FieldInt16ToString, field.TypeString, value)
|
||||
_node.Int16ToString = value
|
||||
}
|
||||
if value, ok := _c.mutation.Uint16ToString(); ok {
|
||||
_spec.SetField(conversion.FieldUint16ToString, field.TypeString, value)
|
||||
_node.Uint16ToString = value
|
||||
}
|
||||
if value, ok := _c.mutation.Int32ToString(); ok {
|
||||
_spec.SetField(conversion.FieldInt32ToString, field.TypeString, value)
|
||||
_node.Int32ToString = value
|
||||
}
|
||||
if value, ok := _c.mutation.Uint32ToString(); ok {
|
||||
_spec.SetField(conversion.FieldUint32ToString, field.TypeString, value)
|
||||
_node.Uint32ToString = value
|
||||
}
|
||||
if value, ok := _c.mutation.Int64ToString(); ok {
|
||||
_spec.SetField(conversion.FieldInt64ToString, field.TypeString, value)
|
||||
_node.Int64ToString = value
|
||||
}
|
||||
if value, ok := _c.mutation.Uint64ToString(); ok {
|
||||
_spec.SetField(conversion.FieldUint64ToString, field.TypeString, value)
|
||||
_node.Uint64ToString = value
|
||||
}
|
||||
return _node, _spec
|
||||
}
|
||||
|
||||
// ConversionCreateBulk is the builder for creating many Conversion entities in bulk.
|
||||
type ConversionCreateBulk struct {
|
||||
config
|
||||
err error
|
||||
builders []*ConversionCreate
|
||||
}
|
||||
|
||||
// Save creates the Conversion entities in the database.
|
||||
func (_c *ConversionCreateBulk) Save(ctx context.Context) ([]*Conversion, error) {
|
||||
if _c.err != nil {
|
||||
return nil, _c.err
|
||||
}
|
||||
specs := make([]*sqlgraph.CreateSpec, len(_c.builders))
|
||||
nodes := make([]*Conversion, 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.(*ConversionMutation)
|
||||
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 {
|
||||
id := specs[i].ID.Value.(int64)
|
||||
nodes[i].ID = int(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 *ConversionCreateBulk) SaveX(ctx context.Context) []*Conversion {
|
||||
v, err := _c.Save(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return v
|
||||
}
|
||||
|
||||
// Exec executes the query.
|
||||
func (_c *ConversionCreateBulk) Exec(ctx context.Context) error {
|
||||
_, err := _c.Save(ctx)
|
||||
return err
|
||||
}
|
||||
|
||||
// ExecX is like Exec, but panics if an error occurs.
|
||||
func (_c *ConversionCreateBulk) ExecX(ctx context.Context) {
|
||||
if err := _c.Exec(ctx); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user