- 新增区域状态字段与增删改查接口,支持区域启用/停用 - 重构实体字段JSON标签为camelCase格式统一接口规范 - 优化入库、盘点、装箱流程的交互与提示文案 - 新增装箱管理功能,支持合同号关联与装箱编辑 - 调整前端菜单与帮助文档适配业务场景变更
844 lines
23 KiB
Go
844 lines
23 KiB
Go
// Code generated by ent, DO NOT EDIT.
|
|
|
|
package ent
|
|
|
|
import (
|
|
"bj_power_wms/ent/zone"
|
|
"context"
|
|
"errors"
|
|
"fmt"
|
|
|
|
"entgo.io/ent/dialect/sql"
|
|
"entgo.io/ent/dialect/sql/sqlgraph"
|
|
"entgo.io/ent/schema/field"
|
|
)
|
|
|
|
// ZoneCreate is the builder for creating a Zone entity.
|
|
type ZoneCreate struct {
|
|
config
|
|
mutation *ZoneMutation
|
|
hooks []Hook
|
|
conflict []sql.ConflictOption
|
|
}
|
|
|
|
// SetZoneCode sets the "zone_code" field.
|
|
func (_c *ZoneCreate) SetZoneCode(v string) *ZoneCreate {
|
|
_c.mutation.SetZoneCode(v)
|
|
return _c
|
|
}
|
|
|
|
// SetZoneName sets the "zone_name" field.
|
|
func (_c *ZoneCreate) SetZoneName(v string) *ZoneCreate {
|
|
_c.mutation.SetZoneName(v)
|
|
return _c
|
|
}
|
|
|
|
// SetDescription sets the "description" field.
|
|
func (_c *ZoneCreate) SetDescription(v string) *ZoneCreate {
|
|
_c.mutation.SetDescription(v)
|
|
return _c
|
|
}
|
|
|
|
// SetNillableDescription sets the "description" field if the given value is not nil.
|
|
func (_c *ZoneCreate) SetNillableDescription(v *string) *ZoneCreate {
|
|
if v != nil {
|
|
_c.SetDescription(*v)
|
|
}
|
|
return _c
|
|
}
|
|
|
|
// SetStatus sets the "status" field.
|
|
func (_c *ZoneCreate) SetStatus(v string) *ZoneCreate {
|
|
_c.mutation.SetStatus(v)
|
|
return _c
|
|
}
|
|
|
|
// SetNillableStatus sets the "status" field if the given value is not nil.
|
|
func (_c *ZoneCreate) SetNillableStatus(v *string) *ZoneCreate {
|
|
if v != nil {
|
|
_c.SetStatus(*v)
|
|
}
|
|
return _c
|
|
}
|
|
|
|
// SetCreatedAt sets the "created_at" field.
|
|
func (_c *ZoneCreate) SetCreatedAt(v int64) *ZoneCreate {
|
|
_c.mutation.SetCreatedAt(v)
|
|
return _c
|
|
}
|
|
|
|
// SetNillableCreatedAt sets the "created_at" field if the given value is not nil.
|
|
func (_c *ZoneCreate) SetNillableCreatedAt(v *int64) *ZoneCreate {
|
|
if v != nil {
|
|
_c.SetCreatedAt(*v)
|
|
}
|
|
return _c
|
|
}
|
|
|
|
// SetUpdatedAt sets the "updated_at" field.
|
|
func (_c *ZoneCreate) SetUpdatedAt(v int64) *ZoneCreate {
|
|
_c.mutation.SetUpdatedAt(v)
|
|
return _c
|
|
}
|
|
|
|
// SetNillableUpdatedAt sets the "updated_at" field if the given value is not nil.
|
|
func (_c *ZoneCreate) SetNillableUpdatedAt(v *int64) *ZoneCreate {
|
|
if v != nil {
|
|
_c.SetUpdatedAt(*v)
|
|
}
|
|
return _c
|
|
}
|
|
|
|
// Mutation returns the ZoneMutation object of the builder.
|
|
func (_c *ZoneCreate) Mutation() *ZoneMutation {
|
|
return _c.mutation
|
|
}
|
|
|
|
// Save creates the Zone in the database.
|
|
func (_c *ZoneCreate) Save(ctx context.Context) (*Zone, error) {
|
|
_c.defaults()
|
|
return withHooks(ctx, _c.sqlSave, _c.mutation, _c.hooks)
|
|
}
|
|
|
|
// SaveX calls Save and panics if Save returns an error.
|
|
func (_c *ZoneCreate) SaveX(ctx context.Context) *Zone {
|
|
v, err := _c.Save(ctx)
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
return v
|
|
}
|
|
|
|
// Exec executes the query.
|
|
func (_c *ZoneCreate) Exec(ctx context.Context) error {
|
|
_, err := _c.Save(ctx)
|
|
return err
|
|
}
|
|
|
|
// ExecX is like Exec, but panics if an error occurs.
|
|
func (_c *ZoneCreate) ExecX(ctx context.Context) {
|
|
if err := _c.Exec(ctx); err != nil {
|
|
panic(err)
|
|
}
|
|
}
|
|
|
|
// defaults sets the default values of the builder before save.
|
|
func (_c *ZoneCreate) defaults() {
|
|
if _, ok := _c.mutation.Status(); !ok {
|
|
v := zone.DefaultStatus
|
|
_c.mutation.SetStatus(v)
|
|
}
|
|
if _, ok := _c.mutation.CreatedAt(); !ok {
|
|
v := zone.DefaultCreatedAt()
|
|
_c.mutation.SetCreatedAt(v)
|
|
}
|
|
if _, ok := _c.mutation.UpdatedAt(); !ok {
|
|
v := zone.DefaultUpdatedAt()
|
|
_c.mutation.SetUpdatedAt(v)
|
|
}
|
|
}
|
|
|
|
// check runs all checks and user-defined validators on the builder.
|
|
func (_c *ZoneCreate) check() error {
|
|
if _, ok := _c.mutation.ZoneCode(); !ok {
|
|
return &ValidationError{Name: "zone_code", err: errors.New(`ent: missing required field "Zone.zone_code"`)}
|
|
}
|
|
if _, ok := _c.mutation.ZoneName(); !ok {
|
|
return &ValidationError{Name: "zone_name", err: errors.New(`ent: missing required field "Zone.zone_name"`)}
|
|
}
|
|
if _, ok := _c.mutation.Status(); !ok {
|
|
return &ValidationError{Name: "status", err: errors.New(`ent: missing required field "Zone.status"`)}
|
|
}
|
|
if _, ok := _c.mutation.CreatedAt(); !ok {
|
|
return &ValidationError{Name: "created_at", err: errors.New(`ent: missing required field "Zone.created_at"`)}
|
|
}
|
|
return nil
|
|
}
|
|
|
|
func (_c *ZoneCreate) sqlSave(ctx context.Context) (*Zone, 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 *ZoneCreate) createSpec() (*Zone, *sqlgraph.CreateSpec) {
|
|
var (
|
|
_node = &Zone{config: _c.config}
|
|
_spec = sqlgraph.NewCreateSpec(zone.Table, sqlgraph.NewFieldSpec(zone.FieldID, field.TypeInt))
|
|
)
|
|
_spec.OnConflict = _c.conflict
|
|
if value, ok := _c.mutation.ZoneCode(); ok {
|
|
_spec.SetField(zone.FieldZoneCode, field.TypeString, value)
|
|
_node.ZoneCode = value
|
|
}
|
|
if value, ok := _c.mutation.ZoneName(); ok {
|
|
_spec.SetField(zone.FieldZoneName, field.TypeString, value)
|
|
_node.ZoneName = value
|
|
}
|
|
if value, ok := _c.mutation.Description(); ok {
|
|
_spec.SetField(zone.FieldDescription, field.TypeString, value)
|
|
_node.Description = value
|
|
}
|
|
if value, ok := _c.mutation.Status(); ok {
|
|
_spec.SetField(zone.FieldStatus, field.TypeString, value)
|
|
_node.Status = value
|
|
}
|
|
if value, ok := _c.mutation.CreatedAt(); ok {
|
|
_spec.SetField(zone.FieldCreatedAt, field.TypeInt64, value)
|
|
_node.CreatedAt = value
|
|
}
|
|
if value, ok := _c.mutation.UpdatedAt(); ok {
|
|
_spec.SetField(zone.FieldUpdatedAt, field.TypeInt64, value)
|
|
_node.UpdatedAt = value
|
|
}
|
|
return _node, _spec
|
|
}
|
|
|
|
// OnConflict allows configuring the `ON CONFLICT` / `ON DUPLICATE KEY` clause
|
|
// of the `INSERT` statement. For example:
|
|
//
|
|
// client.Zone.Create().
|
|
// SetZoneCode(v).
|
|
// OnConflict(
|
|
// // Update the row with the new values
|
|
// // the was proposed for insertion.
|
|
// sql.ResolveWithNewValues(),
|
|
// ).
|
|
// // Override some of the fields with custom
|
|
// // update values.
|
|
// Update(func(u *ent.ZoneUpsert) {
|
|
// SetZoneCode(v+v).
|
|
// }).
|
|
// Exec(ctx)
|
|
func (_c *ZoneCreate) OnConflict(opts ...sql.ConflictOption) *ZoneUpsertOne {
|
|
_c.conflict = opts
|
|
return &ZoneUpsertOne{
|
|
create: _c,
|
|
}
|
|
}
|
|
|
|
// OnConflictColumns calls `OnConflict` and configures the columns
|
|
// as conflict target. Using this option is equivalent to using:
|
|
//
|
|
// client.Zone.Create().
|
|
// OnConflict(sql.ConflictColumns(columns...)).
|
|
// Exec(ctx)
|
|
func (_c *ZoneCreate) OnConflictColumns(columns ...string) *ZoneUpsertOne {
|
|
_c.conflict = append(_c.conflict, sql.ConflictColumns(columns...))
|
|
return &ZoneUpsertOne{
|
|
create: _c,
|
|
}
|
|
}
|
|
|
|
type (
|
|
// ZoneUpsertOne is the builder for "upsert"-ing
|
|
// one Zone node.
|
|
ZoneUpsertOne struct {
|
|
create *ZoneCreate
|
|
}
|
|
|
|
// ZoneUpsert is the "OnConflict" setter.
|
|
ZoneUpsert struct {
|
|
*sql.UpdateSet
|
|
}
|
|
)
|
|
|
|
// SetZoneCode sets the "zone_code" field.
|
|
func (u *ZoneUpsert) SetZoneCode(v string) *ZoneUpsert {
|
|
u.Set(zone.FieldZoneCode, v)
|
|
return u
|
|
}
|
|
|
|
// UpdateZoneCode sets the "zone_code" field to the value that was provided on create.
|
|
func (u *ZoneUpsert) UpdateZoneCode() *ZoneUpsert {
|
|
u.SetExcluded(zone.FieldZoneCode)
|
|
return u
|
|
}
|
|
|
|
// SetZoneName sets the "zone_name" field.
|
|
func (u *ZoneUpsert) SetZoneName(v string) *ZoneUpsert {
|
|
u.Set(zone.FieldZoneName, v)
|
|
return u
|
|
}
|
|
|
|
// UpdateZoneName sets the "zone_name" field to the value that was provided on create.
|
|
func (u *ZoneUpsert) UpdateZoneName() *ZoneUpsert {
|
|
u.SetExcluded(zone.FieldZoneName)
|
|
return u
|
|
}
|
|
|
|
// SetDescription sets the "description" field.
|
|
func (u *ZoneUpsert) SetDescription(v string) *ZoneUpsert {
|
|
u.Set(zone.FieldDescription, v)
|
|
return u
|
|
}
|
|
|
|
// UpdateDescription sets the "description" field to the value that was provided on create.
|
|
func (u *ZoneUpsert) UpdateDescription() *ZoneUpsert {
|
|
u.SetExcluded(zone.FieldDescription)
|
|
return u
|
|
}
|
|
|
|
// ClearDescription clears the value of the "description" field.
|
|
func (u *ZoneUpsert) ClearDescription() *ZoneUpsert {
|
|
u.SetNull(zone.FieldDescription)
|
|
return u
|
|
}
|
|
|
|
// SetStatus sets the "status" field.
|
|
func (u *ZoneUpsert) SetStatus(v string) *ZoneUpsert {
|
|
u.Set(zone.FieldStatus, v)
|
|
return u
|
|
}
|
|
|
|
// UpdateStatus sets the "status" field to the value that was provided on create.
|
|
func (u *ZoneUpsert) UpdateStatus() *ZoneUpsert {
|
|
u.SetExcluded(zone.FieldStatus)
|
|
return u
|
|
}
|
|
|
|
// SetCreatedAt sets the "created_at" field.
|
|
func (u *ZoneUpsert) SetCreatedAt(v int64) *ZoneUpsert {
|
|
u.Set(zone.FieldCreatedAt, v)
|
|
return u
|
|
}
|
|
|
|
// UpdateCreatedAt sets the "created_at" field to the value that was provided on create.
|
|
func (u *ZoneUpsert) UpdateCreatedAt() *ZoneUpsert {
|
|
u.SetExcluded(zone.FieldCreatedAt)
|
|
return u
|
|
}
|
|
|
|
// AddCreatedAt adds v to the "created_at" field.
|
|
func (u *ZoneUpsert) AddCreatedAt(v int64) *ZoneUpsert {
|
|
u.Add(zone.FieldCreatedAt, v)
|
|
return u
|
|
}
|
|
|
|
// SetUpdatedAt sets the "updated_at" field.
|
|
func (u *ZoneUpsert) SetUpdatedAt(v int64) *ZoneUpsert {
|
|
u.Set(zone.FieldUpdatedAt, v)
|
|
return u
|
|
}
|
|
|
|
// UpdateUpdatedAt sets the "updated_at" field to the value that was provided on create.
|
|
func (u *ZoneUpsert) UpdateUpdatedAt() *ZoneUpsert {
|
|
u.SetExcluded(zone.FieldUpdatedAt)
|
|
return u
|
|
}
|
|
|
|
// AddUpdatedAt adds v to the "updated_at" field.
|
|
func (u *ZoneUpsert) AddUpdatedAt(v int64) *ZoneUpsert {
|
|
u.Add(zone.FieldUpdatedAt, v)
|
|
return u
|
|
}
|
|
|
|
// ClearUpdatedAt clears the value of the "updated_at" field.
|
|
func (u *ZoneUpsert) ClearUpdatedAt() *ZoneUpsert {
|
|
u.SetNull(zone.FieldUpdatedAt)
|
|
return u
|
|
}
|
|
|
|
// UpdateNewValues updates the mutable fields using the new values that were set on create.
|
|
// Using this option is equivalent to using:
|
|
//
|
|
// client.Zone.Create().
|
|
// OnConflict(
|
|
// sql.ResolveWithNewValues(),
|
|
// ).
|
|
// Exec(ctx)
|
|
func (u *ZoneUpsertOne) UpdateNewValues() *ZoneUpsertOne {
|
|
u.create.conflict = append(u.create.conflict, sql.ResolveWithNewValues())
|
|
return u
|
|
}
|
|
|
|
// Ignore sets each column to itself in case of conflict.
|
|
// Using this option is equivalent to using:
|
|
//
|
|
// client.Zone.Create().
|
|
// OnConflict(sql.ResolveWithIgnore()).
|
|
// Exec(ctx)
|
|
func (u *ZoneUpsertOne) Ignore() *ZoneUpsertOne {
|
|
u.create.conflict = append(u.create.conflict, sql.ResolveWithIgnore())
|
|
return u
|
|
}
|
|
|
|
// DoNothing configures the conflict_action to `DO NOTHING`.
|
|
// Supported only by SQLite and PostgreSQL.
|
|
func (u *ZoneUpsertOne) DoNothing() *ZoneUpsertOne {
|
|
u.create.conflict = append(u.create.conflict, sql.DoNothing())
|
|
return u
|
|
}
|
|
|
|
// Update allows overriding fields `UPDATE` values. See the ZoneCreate.OnConflict
|
|
// documentation for more info.
|
|
func (u *ZoneUpsertOne) Update(set func(*ZoneUpsert)) *ZoneUpsertOne {
|
|
u.create.conflict = append(u.create.conflict, sql.ResolveWith(func(update *sql.UpdateSet) {
|
|
set(&ZoneUpsert{UpdateSet: update})
|
|
}))
|
|
return u
|
|
}
|
|
|
|
// SetZoneCode sets the "zone_code" field.
|
|
func (u *ZoneUpsertOne) SetZoneCode(v string) *ZoneUpsertOne {
|
|
return u.Update(func(s *ZoneUpsert) {
|
|
s.SetZoneCode(v)
|
|
})
|
|
}
|
|
|
|
// UpdateZoneCode sets the "zone_code" field to the value that was provided on create.
|
|
func (u *ZoneUpsertOne) UpdateZoneCode() *ZoneUpsertOne {
|
|
return u.Update(func(s *ZoneUpsert) {
|
|
s.UpdateZoneCode()
|
|
})
|
|
}
|
|
|
|
// SetZoneName sets the "zone_name" field.
|
|
func (u *ZoneUpsertOne) SetZoneName(v string) *ZoneUpsertOne {
|
|
return u.Update(func(s *ZoneUpsert) {
|
|
s.SetZoneName(v)
|
|
})
|
|
}
|
|
|
|
// UpdateZoneName sets the "zone_name" field to the value that was provided on create.
|
|
func (u *ZoneUpsertOne) UpdateZoneName() *ZoneUpsertOne {
|
|
return u.Update(func(s *ZoneUpsert) {
|
|
s.UpdateZoneName()
|
|
})
|
|
}
|
|
|
|
// SetDescription sets the "description" field.
|
|
func (u *ZoneUpsertOne) SetDescription(v string) *ZoneUpsertOne {
|
|
return u.Update(func(s *ZoneUpsert) {
|
|
s.SetDescription(v)
|
|
})
|
|
}
|
|
|
|
// UpdateDescription sets the "description" field to the value that was provided on create.
|
|
func (u *ZoneUpsertOne) UpdateDescription() *ZoneUpsertOne {
|
|
return u.Update(func(s *ZoneUpsert) {
|
|
s.UpdateDescription()
|
|
})
|
|
}
|
|
|
|
// ClearDescription clears the value of the "description" field.
|
|
func (u *ZoneUpsertOne) ClearDescription() *ZoneUpsertOne {
|
|
return u.Update(func(s *ZoneUpsert) {
|
|
s.ClearDescription()
|
|
})
|
|
}
|
|
|
|
// SetStatus sets the "status" field.
|
|
func (u *ZoneUpsertOne) SetStatus(v string) *ZoneUpsertOne {
|
|
return u.Update(func(s *ZoneUpsert) {
|
|
s.SetStatus(v)
|
|
})
|
|
}
|
|
|
|
// UpdateStatus sets the "status" field to the value that was provided on create.
|
|
func (u *ZoneUpsertOne) UpdateStatus() *ZoneUpsertOne {
|
|
return u.Update(func(s *ZoneUpsert) {
|
|
s.UpdateStatus()
|
|
})
|
|
}
|
|
|
|
// SetCreatedAt sets the "created_at" field.
|
|
func (u *ZoneUpsertOne) SetCreatedAt(v int64) *ZoneUpsertOne {
|
|
return u.Update(func(s *ZoneUpsert) {
|
|
s.SetCreatedAt(v)
|
|
})
|
|
}
|
|
|
|
// AddCreatedAt adds v to the "created_at" field.
|
|
func (u *ZoneUpsertOne) AddCreatedAt(v int64) *ZoneUpsertOne {
|
|
return u.Update(func(s *ZoneUpsert) {
|
|
s.AddCreatedAt(v)
|
|
})
|
|
}
|
|
|
|
// UpdateCreatedAt sets the "created_at" field to the value that was provided on create.
|
|
func (u *ZoneUpsertOne) UpdateCreatedAt() *ZoneUpsertOne {
|
|
return u.Update(func(s *ZoneUpsert) {
|
|
s.UpdateCreatedAt()
|
|
})
|
|
}
|
|
|
|
// SetUpdatedAt sets the "updated_at" field.
|
|
func (u *ZoneUpsertOne) SetUpdatedAt(v int64) *ZoneUpsertOne {
|
|
return u.Update(func(s *ZoneUpsert) {
|
|
s.SetUpdatedAt(v)
|
|
})
|
|
}
|
|
|
|
// AddUpdatedAt adds v to the "updated_at" field.
|
|
func (u *ZoneUpsertOne) AddUpdatedAt(v int64) *ZoneUpsertOne {
|
|
return u.Update(func(s *ZoneUpsert) {
|
|
s.AddUpdatedAt(v)
|
|
})
|
|
}
|
|
|
|
// UpdateUpdatedAt sets the "updated_at" field to the value that was provided on create.
|
|
func (u *ZoneUpsertOne) UpdateUpdatedAt() *ZoneUpsertOne {
|
|
return u.Update(func(s *ZoneUpsert) {
|
|
s.UpdateUpdatedAt()
|
|
})
|
|
}
|
|
|
|
// ClearUpdatedAt clears the value of the "updated_at" field.
|
|
func (u *ZoneUpsertOne) ClearUpdatedAt() *ZoneUpsertOne {
|
|
return u.Update(func(s *ZoneUpsert) {
|
|
s.ClearUpdatedAt()
|
|
})
|
|
}
|
|
|
|
// Exec executes the query.
|
|
func (u *ZoneUpsertOne) Exec(ctx context.Context) error {
|
|
if len(u.create.conflict) == 0 {
|
|
return errors.New("ent: missing options for ZoneCreate.OnConflict")
|
|
}
|
|
return u.create.Exec(ctx)
|
|
}
|
|
|
|
// ExecX is like Exec, but panics if an error occurs.
|
|
func (u *ZoneUpsertOne) ExecX(ctx context.Context) {
|
|
if err := u.create.Exec(ctx); err != nil {
|
|
panic(err)
|
|
}
|
|
}
|
|
|
|
// Exec executes the UPSERT query and returns the inserted/updated ID.
|
|
func (u *ZoneUpsertOne) ID(ctx context.Context) (id int, err error) {
|
|
node, err := u.create.Save(ctx)
|
|
if err != nil {
|
|
return id, err
|
|
}
|
|
return node.ID, nil
|
|
}
|
|
|
|
// IDX is like ID, but panics if an error occurs.
|
|
func (u *ZoneUpsertOne) IDX(ctx context.Context) int {
|
|
id, err := u.ID(ctx)
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
return id
|
|
}
|
|
|
|
// ZoneCreateBulk is the builder for creating many Zone entities in bulk.
|
|
type ZoneCreateBulk struct {
|
|
config
|
|
err error
|
|
builders []*ZoneCreate
|
|
conflict []sql.ConflictOption
|
|
}
|
|
|
|
// Save creates the Zone entities in the database.
|
|
func (_c *ZoneCreateBulk) Save(ctx context.Context) ([]*Zone, error) {
|
|
if _c.err != nil {
|
|
return nil, _c.err
|
|
}
|
|
specs := make([]*sqlgraph.CreateSpec, len(_c.builders))
|
|
nodes := make([]*Zone, len(_c.builders))
|
|
mutators := make([]Mutator, len(_c.builders))
|
|
for i := range _c.builders {
|
|
func(i int, root context.Context) {
|
|
builder := _c.builders[i]
|
|
builder.defaults()
|
|
var mut Mutator = MutateFunc(func(ctx context.Context, m Mutation) (Value, error) {
|
|
mutation, ok := m.(*ZoneMutation)
|
|
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}
|
|
spec.OnConflict = _c.conflict
|
|
// 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 *ZoneCreateBulk) SaveX(ctx context.Context) []*Zone {
|
|
v, err := _c.Save(ctx)
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
return v
|
|
}
|
|
|
|
// Exec executes the query.
|
|
func (_c *ZoneCreateBulk) Exec(ctx context.Context) error {
|
|
_, err := _c.Save(ctx)
|
|
return err
|
|
}
|
|
|
|
// ExecX is like Exec, but panics if an error occurs.
|
|
func (_c *ZoneCreateBulk) ExecX(ctx context.Context) {
|
|
if err := _c.Exec(ctx); err != nil {
|
|
panic(err)
|
|
}
|
|
}
|
|
|
|
// OnConflict allows configuring the `ON CONFLICT` / `ON DUPLICATE KEY` clause
|
|
// of the `INSERT` statement. For example:
|
|
//
|
|
// client.Zone.CreateBulk(builders...).
|
|
// OnConflict(
|
|
// // Update the row with the new values
|
|
// // the was proposed for insertion.
|
|
// sql.ResolveWithNewValues(),
|
|
// ).
|
|
// // Override some of the fields with custom
|
|
// // update values.
|
|
// Update(func(u *ent.ZoneUpsert) {
|
|
// SetZoneCode(v+v).
|
|
// }).
|
|
// Exec(ctx)
|
|
func (_c *ZoneCreateBulk) OnConflict(opts ...sql.ConflictOption) *ZoneUpsertBulk {
|
|
_c.conflict = opts
|
|
return &ZoneUpsertBulk{
|
|
create: _c,
|
|
}
|
|
}
|
|
|
|
// OnConflictColumns calls `OnConflict` and configures the columns
|
|
// as conflict target. Using this option is equivalent to using:
|
|
//
|
|
// client.Zone.Create().
|
|
// OnConflict(sql.ConflictColumns(columns...)).
|
|
// Exec(ctx)
|
|
func (_c *ZoneCreateBulk) OnConflictColumns(columns ...string) *ZoneUpsertBulk {
|
|
_c.conflict = append(_c.conflict, sql.ConflictColumns(columns...))
|
|
return &ZoneUpsertBulk{
|
|
create: _c,
|
|
}
|
|
}
|
|
|
|
// ZoneUpsertBulk is the builder for "upsert"-ing
|
|
// a bulk of Zone nodes.
|
|
type ZoneUpsertBulk struct {
|
|
create *ZoneCreateBulk
|
|
}
|
|
|
|
// UpdateNewValues updates the mutable fields using the new values that
|
|
// were set on create. Using this option is equivalent to using:
|
|
//
|
|
// client.Zone.Create().
|
|
// OnConflict(
|
|
// sql.ResolveWithNewValues(),
|
|
// ).
|
|
// Exec(ctx)
|
|
func (u *ZoneUpsertBulk) UpdateNewValues() *ZoneUpsertBulk {
|
|
u.create.conflict = append(u.create.conflict, sql.ResolveWithNewValues())
|
|
return u
|
|
}
|
|
|
|
// Ignore sets each column to itself in case of conflict.
|
|
// Using this option is equivalent to using:
|
|
//
|
|
// client.Zone.Create().
|
|
// OnConflict(sql.ResolveWithIgnore()).
|
|
// Exec(ctx)
|
|
func (u *ZoneUpsertBulk) Ignore() *ZoneUpsertBulk {
|
|
u.create.conflict = append(u.create.conflict, sql.ResolveWithIgnore())
|
|
return u
|
|
}
|
|
|
|
// DoNothing configures the conflict_action to `DO NOTHING`.
|
|
// Supported only by SQLite and PostgreSQL.
|
|
func (u *ZoneUpsertBulk) DoNothing() *ZoneUpsertBulk {
|
|
u.create.conflict = append(u.create.conflict, sql.DoNothing())
|
|
return u
|
|
}
|
|
|
|
// Update allows overriding fields `UPDATE` values. See the ZoneCreateBulk.OnConflict
|
|
// documentation for more info.
|
|
func (u *ZoneUpsertBulk) Update(set func(*ZoneUpsert)) *ZoneUpsertBulk {
|
|
u.create.conflict = append(u.create.conflict, sql.ResolveWith(func(update *sql.UpdateSet) {
|
|
set(&ZoneUpsert{UpdateSet: update})
|
|
}))
|
|
return u
|
|
}
|
|
|
|
// SetZoneCode sets the "zone_code" field.
|
|
func (u *ZoneUpsertBulk) SetZoneCode(v string) *ZoneUpsertBulk {
|
|
return u.Update(func(s *ZoneUpsert) {
|
|
s.SetZoneCode(v)
|
|
})
|
|
}
|
|
|
|
// UpdateZoneCode sets the "zone_code" field to the value that was provided on create.
|
|
func (u *ZoneUpsertBulk) UpdateZoneCode() *ZoneUpsertBulk {
|
|
return u.Update(func(s *ZoneUpsert) {
|
|
s.UpdateZoneCode()
|
|
})
|
|
}
|
|
|
|
// SetZoneName sets the "zone_name" field.
|
|
func (u *ZoneUpsertBulk) SetZoneName(v string) *ZoneUpsertBulk {
|
|
return u.Update(func(s *ZoneUpsert) {
|
|
s.SetZoneName(v)
|
|
})
|
|
}
|
|
|
|
// UpdateZoneName sets the "zone_name" field to the value that was provided on create.
|
|
func (u *ZoneUpsertBulk) UpdateZoneName() *ZoneUpsertBulk {
|
|
return u.Update(func(s *ZoneUpsert) {
|
|
s.UpdateZoneName()
|
|
})
|
|
}
|
|
|
|
// SetDescription sets the "description" field.
|
|
func (u *ZoneUpsertBulk) SetDescription(v string) *ZoneUpsertBulk {
|
|
return u.Update(func(s *ZoneUpsert) {
|
|
s.SetDescription(v)
|
|
})
|
|
}
|
|
|
|
// UpdateDescription sets the "description" field to the value that was provided on create.
|
|
func (u *ZoneUpsertBulk) UpdateDescription() *ZoneUpsertBulk {
|
|
return u.Update(func(s *ZoneUpsert) {
|
|
s.UpdateDescription()
|
|
})
|
|
}
|
|
|
|
// ClearDescription clears the value of the "description" field.
|
|
func (u *ZoneUpsertBulk) ClearDescription() *ZoneUpsertBulk {
|
|
return u.Update(func(s *ZoneUpsert) {
|
|
s.ClearDescription()
|
|
})
|
|
}
|
|
|
|
// SetStatus sets the "status" field.
|
|
func (u *ZoneUpsertBulk) SetStatus(v string) *ZoneUpsertBulk {
|
|
return u.Update(func(s *ZoneUpsert) {
|
|
s.SetStatus(v)
|
|
})
|
|
}
|
|
|
|
// UpdateStatus sets the "status" field to the value that was provided on create.
|
|
func (u *ZoneUpsertBulk) UpdateStatus() *ZoneUpsertBulk {
|
|
return u.Update(func(s *ZoneUpsert) {
|
|
s.UpdateStatus()
|
|
})
|
|
}
|
|
|
|
// SetCreatedAt sets the "created_at" field.
|
|
func (u *ZoneUpsertBulk) SetCreatedAt(v int64) *ZoneUpsertBulk {
|
|
return u.Update(func(s *ZoneUpsert) {
|
|
s.SetCreatedAt(v)
|
|
})
|
|
}
|
|
|
|
// AddCreatedAt adds v to the "created_at" field.
|
|
func (u *ZoneUpsertBulk) AddCreatedAt(v int64) *ZoneUpsertBulk {
|
|
return u.Update(func(s *ZoneUpsert) {
|
|
s.AddCreatedAt(v)
|
|
})
|
|
}
|
|
|
|
// UpdateCreatedAt sets the "created_at" field to the value that was provided on create.
|
|
func (u *ZoneUpsertBulk) UpdateCreatedAt() *ZoneUpsertBulk {
|
|
return u.Update(func(s *ZoneUpsert) {
|
|
s.UpdateCreatedAt()
|
|
})
|
|
}
|
|
|
|
// SetUpdatedAt sets the "updated_at" field.
|
|
func (u *ZoneUpsertBulk) SetUpdatedAt(v int64) *ZoneUpsertBulk {
|
|
return u.Update(func(s *ZoneUpsert) {
|
|
s.SetUpdatedAt(v)
|
|
})
|
|
}
|
|
|
|
// AddUpdatedAt adds v to the "updated_at" field.
|
|
func (u *ZoneUpsertBulk) AddUpdatedAt(v int64) *ZoneUpsertBulk {
|
|
return u.Update(func(s *ZoneUpsert) {
|
|
s.AddUpdatedAt(v)
|
|
})
|
|
}
|
|
|
|
// UpdateUpdatedAt sets the "updated_at" field to the value that was provided on create.
|
|
func (u *ZoneUpsertBulk) UpdateUpdatedAt() *ZoneUpsertBulk {
|
|
return u.Update(func(s *ZoneUpsert) {
|
|
s.UpdateUpdatedAt()
|
|
})
|
|
}
|
|
|
|
// ClearUpdatedAt clears the value of the "updated_at" field.
|
|
func (u *ZoneUpsertBulk) ClearUpdatedAt() *ZoneUpsertBulk {
|
|
return u.Update(func(s *ZoneUpsert) {
|
|
s.ClearUpdatedAt()
|
|
})
|
|
}
|
|
|
|
// Exec executes the query.
|
|
func (u *ZoneUpsertBulk) Exec(ctx context.Context) error {
|
|
if u.create.err != nil {
|
|
return u.create.err
|
|
}
|
|
for i, b := range u.create.builders {
|
|
if len(b.conflict) != 0 {
|
|
return fmt.Errorf("ent: OnConflict was set for builder %d. Set it on the ZoneCreateBulk instead", i)
|
|
}
|
|
}
|
|
if len(u.create.conflict) == 0 {
|
|
return errors.New("ent: missing options for ZoneCreateBulk.OnConflict")
|
|
}
|
|
return u.create.Exec(ctx)
|
|
}
|
|
|
|
// ExecX is like Exec, but panics if an error occurs.
|
|
func (u *ZoneUpsertBulk) ExecX(ctx context.Context) {
|
|
if err := u.create.Exec(ctx); err != nil {
|
|
panic(err)
|
|
}
|
|
}
|