Files
bj_power/bj_power_wms/ent/zone_update.go
T

350 lines
9.5 KiB
Go
Raw Normal View History

2026-08-27 19:50:57 +08:00
// Code generated by ent, DO NOT EDIT.
package ent
import (
"bj_power_wms/ent/predicate"
"bj_power_wms/ent/zone"
"context"
"errors"
"fmt"
"entgo.io/ent/dialect/sql"
"entgo.io/ent/dialect/sql/sqlgraph"
"entgo.io/ent/schema/field"
)
// ZoneUpdate is the builder for updating Zone entities.
type ZoneUpdate struct {
config
hooks []Hook
mutation *ZoneMutation
}
// Where appends a list predicates to the ZoneUpdate builder.
func (_u *ZoneUpdate) Where(ps ...predicate.Zone) *ZoneUpdate {
_u.mutation.Where(ps...)
return _u
}
// SetZoneCode sets the "zone_code" field.
func (_u *ZoneUpdate) SetZoneCode(v string) *ZoneUpdate {
_u.mutation.SetZoneCode(v)
return _u
}
// SetNillableZoneCode sets the "zone_code" field if the given value is not nil.
func (_u *ZoneUpdate) SetNillableZoneCode(v *string) *ZoneUpdate {
if v != nil {
_u.SetZoneCode(*v)
}
return _u
}
// SetZoneName sets the "zone_name" field.
func (_u *ZoneUpdate) SetZoneName(v string) *ZoneUpdate {
_u.mutation.SetZoneName(v)
return _u
}
// SetNillableZoneName sets the "zone_name" field if the given value is not nil.
func (_u *ZoneUpdate) SetNillableZoneName(v *string) *ZoneUpdate {
if v != nil {
_u.SetZoneName(*v)
}
return _u
}
// SetDescription sets the "description" field.
func (_u *ZoneUpdate) SetDescription(v string) *ZoneUpdate {
_u.mutation.SetDescription(v)
return _u
}
// SetNillableDescription sets the "description" field if the given value is not nil.
func (_u *ZoneUpdate) SetNillableDescription(v *string) *ZoneUpdate {
if v != nil {
_u.SetDescription(*v)
}
return _u
}
// ClearDescription clears the value of the "description" field.
func (_u *ZoneUpdate) ClearDescription() *ZoneUpdate {
_u.mutation.ClearDescription()
return _u
}
// SetCreatedAt sets the "created_at" field.
func (_u *ZoneUpdate) SetCreatedAt(v int64) *ZoneUpdate {
_u.mutation.ResetCreatedAt()
_u.mutation.SetCreatedAt(v)
return _u
}
// SetNillableCreatedAt sets the "created_at" field if the given value is not nil.
func (_u *ZoneUpdate) SetNillableCreatedAt(v *int64) *ZoneUpdate {
if v != nil {
_u.SetCreatedAt(*v)
}
return _u
}
// AddCreatedAt adds value to the "created_at" field.
func (_u *ZoneUpdate) AddCreatedAt(v int64) *ZoneUpdate {
_u.mutation.AddCreatedAt(v)
return _u
}
// Mutation returns the ZoneMutation object of the builder.
func (_u *ZoneUpdate) Mutation() *ZoneMutation {
return _u.mutation
}
// Save executes the query and returns the number of nodes affected by the update operation.
func (_u *ZoneUpdate) Save(ctx context.Context) (int, error) {
return withHooks(ctx, _u.sqlSave, _u.mutation, _u.hooks)
}
// SaveX is like Save, but panics if an error occurs.
func (_u *ZoneUpdate) SaveX(ctx context.Context) int {
affected, err := _u.Save(ctx)
if err != nil {
panic(err)
}
return affected
}
// Exec executes the query.
func (_u *ZoneUpdate) Exec(ctx context.Context) error {
_, err := _u.Save(ctx)
return err
}
// ExecX is like Exec, but panics if an error occurs.
func (_u *ZoneUpdate) ExecX(ctx context.Context) {
if err := _u.Exec(ctx); err != nil {
panic(err)
}
}
func (_u *ZoneUpdate) sqlSave(ctx context.Context) (_node int, err error) {
_spec := sqlgraph.NewUpdateSpec(zone.Table, zone.Columns, sqlgraph.NewFieldSpec(zone.FieldID, field.TypeInt))
if ps := _u.mutation.predicates; len(ps) > 0 {
_spec.Predicate = func(selector *sql.Selector) {
for i := range ps {
ps[i](selector)
}
}
}
if value, ok := _u.mutation.ZoneCode(); ok {
_spec.SetField(zone.FieldZoneCode, field.TypeString, value)
}
if value, ok := _u.mutation.ZoneName(); ok {
_spec.SetField(zone.FieldZoneName, field.TypeString, value)
}
if value, ok := _u.mutation.Description(); ok {
_spec.SetField(zone.FieldDescription, field.TypeString, value)
}
if _u.mutation.DescriptionCleared() {
_spec.ClearField(zone.FieldDescription, field.TypeString)
}
if value, ok := _u.mutation.CreatedAt(); ok {
_spec.SetField(zone.FieldCreatedAt, field.TypeInt64, value)
}
if value, ok := _u.mutation.AddedCreatedAt(); ok {
_spec.AddField(zone.FieldCreatedAt, field.TypeInt64, value)
}
if _node, err = sqlgraph.UpdateNodes(ctx, _u.driver, _spec); err != nil {
if _, ok := err.(*sqlgraph.NotFoundError); ok {
err = &NotFoundError{zone.Label}
} else if sqlgraph.IsConstraintError(err) {
err = &ConstraintError{msg: err.Error(), wrap: err}
}
return 0, err
}
_u.mutation.done = true
return _node, nil
}
// ZoneUpdateOne is the builder for updating a single Zone entity.
type ZoneUpdateOne struct {
config
fields []string
hooks []Hook
mutation *ZoneMutation
}
// SetZoneCode sets the "zone_code" field.
func (_u *ZoneUpdateOne) SetZoneCode(v string) *ZoneUpdateOne {
_u.mutation.SetZoneCode(v)
return _u
}
// SetNillableZoneCode sets the "zone_code" field if the given value is not nil.
func (_u *ZoneUpdateOne) SetNillableZoneCode(v *string) *ZoneUpdateOne {
if v != nil {
_u.SetZoneCode(*v)
}
return _u
}
// SetZoneName sets the "zone_name" field.
func (_u *ZoneUpdateOne) SetZoneName(v string) *ZoneUpdateOne {
_u.mutation.SetZoneName(v)
return _u
}
// SetNillableZoneName sets the "zone_name" field if the given value is not nil.
func (_u *ZoneUpdateOne) SetNillableZoneName(v *string) *ZoneUpdateOne {
if v != nil {
_u.SetZoneName(*v)
}
return _u
}
// SetDescription sets the "description" field.
func (_u *ZoneUpdateOne) SetDescription(v string) *ZoneUpdateOne {
_u.mutation.SetDescription(v)
return _u
}
// SetNillableDescription sets the "description" field if the given value is not nil.
func (_u *ZoneUpdateOne) SetNillableDescription(v *string) *ZoneUpdateOne {
if v != nil {
_u.SetDescription(*v)
}
return _u
}
// ClearDescription clears the value of the "description" field.
func (_u *ZoneUpdateOne) ClearDescription() *ZoneUpdateOne {
_u.mutation.ClearDescription()
return _u
}
// SetCreatedAt sets the "created_at" field.
func (_u *ZoneUpdateOne) SetCreatedAt(v int64) *ZoneUpdateOne {
_u.mutation.ResetCreatedAt()
_u.mutation.SetCreatedAt(v)
return _u
}
// SetNillableCreatedAt sets the "created_at" field if the given value is not nil.
func (_u *ZoneUpdateOne) SetNillableCreatedAt(v *int64) *ZoneUpdateOne {
if v != nil {
_u.SetCreatedAt(*v)
}
return _u
}
// AddCreatedAt adds value to the "created_at" field.
func (_u *ZoneUpdateOne) AddCreatedAt(v int64) *ZoneUpdateOne {
_u.mutation.AddCreatedAt(v)
return _u
}
// Mutation returns the ZoneMutation object of the builder.
func (_u *ZoneUpdateOne) Mutation() *ZoneMutation {
return _u.mutation
}
// Where appends a list predicates to the ZoneUpdate builder.
func (_u *ZoneUpdateOne) Where(ps ...predicate.Zone) *ZoneUpdateOne {
_u.mutation.Where(ps...)
return _u
}
// Select allows selecting one or more fields (columns) of the returned entity.
// The default is selecting all fields defined in the entity schema.
func (_u *ZoneUpdateOne) Select(field string, fields ...string) *ZoneUpdateOne {
_u.fields = append([]string{field}, fields...)
return _u
}
// Save executes the query and returns the updated Zone entity.
func (_u *ZoneUpdateOne) Save(ctx context.Context) (*Zone, error) {
return withHooks(ctx, _u.sqlSave, _u.mutation, _u.hooks)
}
// SaveX is like Save, but panics if an error occurs.
func (_u *ZoneUpdateOne) SaveX(ctx context.Context) *Zone {
node, err := _u.Save(ctx)
if err != nil {
panic(err)
}
return node
}
// Exec executes the query on the entity.
func (_u *ZoneUpdateOne) Exec(ctx context.Context) error {
_, err := _u.Save(ctx)
return err
}
// ExecX is like Exec, but panics if an error occurs.
func (_u *ZoneUpdateOne) ExecX(ctx context.Context) {
if err := _u.Exec(ctx); err != nil {
panic(err)
}
}
func (_u *ZoneUpdateOne) sqlSave(ctx context.Context) (_node *Zone, err error) {
_spec := sqlgraph.NewUpdateSpec(zone.Table, zone.Columns, sqlgraph.NewFieldSpec(zone.FieldID, field.TypeInt))
id, ok := _u.mutation.ID()
if !ok {
return nil, &ValidationError{Name: "id", err: errors.New(`ent: missing "Zone.id" for update`)}
}
_spec.Node.ID.Value = id
if fields := _u.fields; len(fields) > 0 {
_spec.Node.Columns = make([]string, 0, len(fields))
_spec.Node.Columns = append(_spec.Node.Columns, zone.FieldID)
for _, f := range fields {
if !zone.ValidColumn(f) {
return nil, &ValidationError{Name: f, err: fmt.Errorf("ent: invalid field %q for query", f)}
}
if f != zone.FieldID {
_spec.Node.Columns = append(_spec.Node.Columns, f)
}
}
}
if ps := _u.mutation.predicates; len(ps) > 0 {
_spec.Predicate = func(selector *sql.Selector) {
for i := range ps {
ps[i](selector)
}
}
}
if value, ok := _u.mutation.ZoneCode(); ok {
_spec.SetField(zone.FieldZoneCode, field.TypeString, value)
}
if value, ok := _u.mutation.ZoneName(); ok {
_spec.SetField(zone.FieldZoneName, field.TypeString, value)
}
if value, ok := _u.mutation.Description(); ok {
_spec.SetField(zone.FieldDescription, field.TypeString, value)
}
if _u.mutation.DescriptionCleared() {
_spec.ClearField(zone.FieldDescription, field.TypeString)
}
if value, ok := _u.mutation.CreatedAt(); ok {
_spec.SetField(zone.FieldCreatedAt, field.TypeInt64, value)
}
if value, ok := _u.mutation.AddedCreatedAt(); ok {
_spec.AddField(zone.FieldCreatedAt, field.TypeInt64, value)
}
_node = &Zone{config: _u.config}
_spec.Assign = _node.assignValues
_spec.ScanValues = _node.scanValues
if err = sqlgraph.UpdateNode(ctx, _u.driver, _spec); err != nil {
if _, ok := err.(*sqlgraph.NotFoundError); ok {
err = &NotFoundError{zone.Label}
} else if sqlgraph.IsConstraintError(err) {
err = &ConstraintError{msg: err.Error(), wrap: err}
}
return nil, err
}
_u.mutation.done = true
return _node, nil
}