// Code generated by ent, DO NOT EDIT. package ent import ( "bj_power_wms/ent/dock" "bj_power_wms/ent/predicate" "context" "errors" "fmt" "entgo.io/ent/dialect/sql" "entgo.io/ent/dialect/sql/sqlgraph" "entgo.io/ent/schema/field" ) // DockUpdate is the builder for updating Dock entities. type DockUpdate struct { config hooks []Hook mutation *DockMutation } // Where appends a list predicates to the DockUpdate builder. func (_u *DockUpdate) Where(ps ...predicate.Dock) *DockUpdate { _u.mutation.Where(ps...) return _u } // SetDockCode sets the "dock_code" field. func (_u *DockUpdate) SetDockCode(v string) *DockUpdate { _u.mutation.SetDockCode(v) return _u } // SetNillableDockCode sets the "dock_code" field if the given value is not nil. func (_u *DockUpdate) SetNillableDockCode(v *string) *DockUpdate { if v != nil { _u.SetDockCode(*v) } return _u } // SetName sets the "name" field. func (_u *DockUpdate) SetName(v string) *DockUpdate { _u.mutation.SetName(v) return _u } // SetNillableName sets the "name" field if the given value is not nil. func (_u *DockUpdate) SetNillableName(v *string) *DockUpdate { if v != nil { _u.SetName(*v) } return _u } // SetDockType sets the "dock_type" field. func (_u *DockUpdate) SetDockType(v string) *DockUpdate { _u.mutation.SetDockType(v) return _u } // SetNillableDockType sets the "dock_type" field if the given value is not nil. func (_u *DockUpdate) SetNillableDockType(v *string) *DockUpdate { if v != nil { _u.SetDockType(*v) } return _u } // SetStationNo sets the "station_no" field. func (_u *DockUpdate) SetStationNo(v int) *DockUpdate { _u.mutation.ResetStationNo() _u.mutation.SetStationNo(v) return _u } // SetNillableStationNo sets the "station_no" field if the given value is not nil. func (_u *DockUpdate) SetNillableStationNo(v *int) *DockUpdate { if v != nil { _u.SetStationNo(*v) } return _u } // AddStationNo adds value to the "station_no" field. func (_u *DockUpdate) AddStationNo(v int) *DockUpdate { _u.mutation.AddStationNo(v) return _u } // SetHasPallet sets the "has_pallet" field. func (_u *DockUpdate) SetHasPallet(v bool) *DockUpdate { _u.mutation.SetHasPallet(v) return _u } // SetNillableHasPallet sets the "has_pallet" field if the given value is not nil. func (_u *DockUpdate) SetNillableHasPallet(v *bool) *DockUpdate { if v != nil { _u.SetHasPallet(*v) } return _u } // SetPalletRef sets the "pallet_ref" field. func (_u *DockUpdate) SetPalletRef(v string) *DockUpdate { _u.mutation.SetPalletRef(v) return _u } // SetNillablePalletRef sets the "pallet_ref" field if the given value is not nil. func (_u *DockUpdate) SetNillablePalletRef(v *string) *DockUpdate { if v != nil { _u.SetPalletRef(*v) } return _u } // ClearPalletRef clears the value of the "pallet_ref" field. func (_u *DockUpdate) ClearPalletRef() *DockUpdate { _u.mutation.ClearPalletRef() return _u } // SetStatus sets the "status" field. func (_u *DockUpdate) SetStatus(v string) *DockUpdate { _u.mutation.SetStatus(v) return _u } // SetNillableStatus sets the "status" field if the given value is not nil. func (_u *DockUpdate) SetNillableStatus(v *string) *DockUpdate { if v != nil { _u.SetStatus(*v) } return _u } // SetCreatedAt sets the "created_at" field. func (_u *DockUpdate) SetCreatedAt(v int64) *DockUpdate { _u.mutation.ResetCreatedAt() _u.mutation.SetCreatedAt(v) return _u } // SetNillableCreatedAt sets the "created_at" field if the given value is not nil. func (_u *DockUpdate) SetNillableCreatedAt(v *int64) *DockUpdate { if v != nil { _u.SetCreatedAt(*v) } return _u } // AddCreatedAt adds value to the "created_at" field. func (_u *DockUpdate) AddCreatedAt(v int64) *DockUpdate { _u.mutation.AddCreatedAt(v) return _u } // Mutation returns the DockMutation object of the builder. func (_u *DockUpdate) Mutation() *DockMutation { return _u.mutation } // Save executes the query and returns the number of nodes affected by the update operation. func (_u *DockUpdate) 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 *DockUpdate) SaveX(ctx context.Context) int { affected, err := _u.Save(ctx) if err != nil { panic(err) } return affected } // Exec executes the query. func (_u *DockUpdate) Exec(ctx context.Context) error { _, err := _u.Save(ctx) return err } // ExecX is like Exec, but panics if an error occurs. func (_u *DockUpdate) ExecX(ctx context.Context) { if err := _u.Exec(ctx); err != nil { panic(err) } } // check runs all checks and user-defined validators on the builder. func (_u *DockUpdate) check() error { if v, ok := _u.mutation.DockCode(); ok { if err := dock.DockCodeValidator(v); err != nil { return &ValidationError{Name: "dock_code", err: fmt.Errorf(`ent: validator failed for field "Dock.dock_code": %w`, err)} } } if v, ok := _u.mutation.Name(); ok { if err := dock.NameValidator(v); err != nil { return &ValidationError{Name: "name", err: fmt.Errorf(`ent: validator failed for field "Dock.name": %w`, err)} } } if v, ok := _u.mutation.DockType(); ok { if err := dock.DockTypeValidator(v); err != nil { return &ValidationError{Name: "dock_type", err: fmt.Errorf(`ent: validator failed for field "Dock.dock_type": %w`, err)} } } if v, ok := _u.mutation.PalletRef(); ok { if err := dock.PalletRefValidator(v); err != nil { return &ValidationError{Name: "pallet_ref", err: fmt.Errorf(`ent: validator failed for field "Dock.pallet_ref": %w`, err)} } } if v, ok := _u.mutation.Status(); ok { if err := dock.StatusValidator(v); err != nil { return &ValidationError{Name: "status", err: fmt.Errorf(`ent: validator failed for field "Dock.status": %w`, err)} } } return nil } func (_u *DockUpdate) sqlSave(ctx context.Context) (_node int, err error) { if err := _u.check(); err != nil { return _node, err } _spec := sqlgraph.NewUpdateSpec(dock.Table, dock.Columns, sqlgraph.NewFieldSpec(dock.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.DockCode(); ok { _spec.SetField(dock.FieldDockCode, field.TypeString, value) } if value, ok := _u.mutation.Name(); ok { _spec.SetField(dock.FieldName, field.TypeString, value) } if value, ok := _u.mutation.DockType(); ok { _spec.SetField(dock.FieldDockType, field.TypeString, value) } if value, ok := _u.mutation.StationNo(); ok { _spec.SetField(dock.FieldStationNo, field.TypeInt, value) } if value, ok := _u.mutation.AddedStationNo(); ok { _spec.AddField(dock.FieldStationNo, field.TypeInt, value) } if value, ok := _u.mutation.HasPallet(); ok { _spec.SetField(dock.FieldHasPallet, field.TypeBool, value) } if value, ok := _u.mutation.PalletRef(); ok { _spec.SetField(dock.FieldPalletRef, field.TypeString, value) } if _u.mutation.PalletRefCleared() { _spec.ClearField(dock.FieldPalletRef, field.TypeString) } if value, ok := _u.mutation.Status(); ok { _spec.SetField(dock.FieldStatus, field.TypeString, value) } if value, ok := _u.mutation.CreatedAt(); ok { _spec.SetField(dock.FieldCreatedAt, field.TypeInt64, value) } if value, ok := _u.mutation.AddedCreatedAt(); ok { _spec.AddField(dock.FieldCreatedAt, field.TypeInt64, value) } if _node, err = sqlgraph.UpdateNodes(ctx, _u.driver, _spec); err != nil { if _, ok := err.(*sqlgraph.NotFoundError); ok { err = &NotFoundError{dock.Label} } else if sqlgraph.IsConstraintError(err) { err = &ConstraintError{msg: err.Error(), wrap: err} } return 0, err } _u.mutation.done = true return _node, nil } // DockUpdateOne is the builder for updating a single Dock entity. type DockUpdateOne struct { config fields []string hooks []Hook mutation *DockMutation } // SetDockCode sets the "dock_code" field. func (_u *DockUpdateOne) SetDockCode(v string) *DockUpdateOne { _u.mutation.SetDockCode(v) return _u } // SetNillableDockCode sets the "dock_code" field if the given value is not nil. func (_u *DockUpdateOne) SetNillableDockCode(v *string) *DockUpdateOne { if v != nil { _u.SetDockCode(*v) } return _u } // SetName sets the "name" field. func (_u *DockUpdateOne) SetName(v string) *DockUpdateOne { _u.mutation.SetName(v) return _u } // SetNillableName sets the "name" field if the given value is not nil. func (_u *DockUpdateOne) SetNillableName(v *string) *DockUpdateOne { if v != nil { _u.SetName(*v) } return _u } // SetDockType sets the "dock_type" field. func (_u *DockUpdateOne) SetDockType(v string) *DockUpdateOne { _u.mutation.SetDockType(v) return _u } // SetNillableDockType sets the "dock_type" field if the given value is not nil. func (_u *DockUpdateOne) SetNillableDockType(v *string) *DockUpdateOne { if v != nil { _u.SetDockType(*v) } return _u } // SetStationNo sets the "station_no" field. func (_u *DockUpdateOne) SetStationNo(v int) *DockUpdateOne { _u.mutation.ResetStationNo() _u.mutation.SetStationNo(v) return _u } // SetNillableStationNo sets the "station_no" field if the given value is not nil. func (_u *DockUpdateOne) SetNillableStationNo(v *int) *DockUpdateOne { if v != nil { _u.SetStationNo(*v) } return _u } // AddStationNo adds value to the "station_no" field. func (_u *DockUpdateOne) AddStationNo(v int) *DockUpdateOne { _u.mutation.AddStationNo(v) return _u } // SetHasPallet sets the "has_pallet" field. func (_u *DockUpdateOne) SetHasPallet(v bool) *DockUpdateOne { _u.mutation.SetHasPallet(v) return _u } // SetNillableHasPallet sets the "has_pallet" field if the given value is not nil. func (_u *DockUpdateOne) SetNillableHasPallet(v *bool) *DockUpdateOne { if v != nil { _u.SetHasPallet(*v) } return _u } // SetPalletRef sets the "pallet_ref" field. func (_u *DockUpdateOne) SetPalletRef(v string) *DockUpdateOne { _u.mutation.SetPalletRef(v) return _u } // SetNillablePalletRef sets the "pallet_ref" field if the given value is not nil. func (_u *DockUpdateOne) SetNillablePalletRef(v *string) *DockUpdateOne { if v != nil { _u.SetPalletRef(*v) } return _u } // ClearPalletRef clears the value of the "pallet_ref" field. func (_u *DockUpdateOne) ClearPalletRef() *DockUpdateOne { _u.mutation.ClearPalletRef() return _u } // SetStatus sets the "status" field. func (_u *DockUpdateOne) SetStatus(v string) *DockUpdateOne { _u.mutation.SetStatus(v) return _u } // SetNillableStatus sets the "status" field if the given value is not nil. func (_u *DockUpdateOne) SetNillableStatus(v *string) *DockUpdateOne { if v != nil { _u.SetStatus(*v) } return _u } // SetCreatedAt sets the "created_at" field. func (_u *DockUpdateOne) SetCreatedAt(v int64) *DockUpdateOne { _u.mutation.ResetCreatedAt() _u.mutation.SetCreatedAt(v) return _u } // SetNillableCreatedAt sets the "created_at" field if the given value is not nil. func (_u *DockUpdateOne) SetNillableCreatedAt(v *int64) *DockUpdateOne { if v != nil { _u.SetCreatedAt(*v) } return _u } // AddCreatedAt adds value to the "created_at" field. func (_u *DockUpdateOne) AddCreatedAt(v int64) *DockUpdateOne { _u.mutation.AddCreatedAt(v) return _u } // Mutation returns the DockMutation object of the builder. func (_u *DockUpdateOne) Mutation() *DockMutation { return _u.mutation } // Where appends a list predicates to the DockUpdate builder. func (_u *DockUpdateOne) Where(ps ...predicate.Dock) *DockUpdateOne { _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 *DockUpdateOne) Select(field string, fields ...string) *DockUpdateOne { _u.fields = append([]string{field}, fields...) return _u } // Save executes the query and returns the updated Dock entity. func (_u *DockUpdateOne) Save(ctx context.Context) (*Dock, error) { return withHooks(ctx, _u.sqlSave, _u.mutation, _u.hooks) } // SaveX is like Save, but panics if an error occurs. func (_u *DockUpdateOne) SaveX(ctx context.Context) *Dock { node, err := _u.Save(ctx) if err != nil { panic(err) } return node } // Exec executes the query on the entity. func (_u *DockUpdateOne) Exec(ctx context.Context) error { _, err := _u.Save(ctx) return err } // ExecX is like Exec, but panics if an error occurs. func (_u *DockUpdateOne) ExecX(ctx context.Context) { if err := _u.Exec(ctx); err != nil { panic(err) } } // check runs all checks and user-defined validators on the builder. func (_u *DockUpdateOne) check() error { if v, ok := _u.mutation.DockCode(); ok { if err := dock.DockCodeValidator(v); err != nil { return &ValidationError{Name: "dock_code", err: fmt.Errorf(`ent: validator failed for field "Dock.dock_code": %w`, err)} } } if v, ok := _u.mutation.Name(); ok { if err := dock.NameValidator(v); err != nil { return &ValidationError{Name: "name", err: fmt.Errorf(`ent: validator failed for field "Dock.name": %w`, err)} } } if v, ok := _u.mutation.DockType(); ok { if err := dock.DockTypeValidator(v); err != nil { return &ValidationError{Name: "dock_type", err: fmt.Errorf(`ent: validator failed for field "Dock.dock_type": %w`, err)} } } if v, ok := _u.mutation.PalletRef(); ok { if err := dock.PalletRefValidator(v); err != nil { return &ValidationError{Name: "pallet_ref", err: fmt.Errorf(`ent: validator failed for field "Dock.pallet_ref": %w`, err)} } } if v, ok := _u.mutation.Status(); ok { if err := dock.StatusValidator(v); err != nil { return &ValidationError{Name: "status", err: fmt.Errorf(`ent: validator failed for field "Dock.status": %w`, err)} } } return nil } func (_u *DockUpdateOne) sqlSave(ctx context.Context) (_node *Dock, err error) { if err := _u.check(); err != nil { return _node, err } _spec := sqlgraph.NewUpdateSpec(dock.Table, dock.Columns, sqlgraph.NewFieldSpec(dock.FieldID, field.TypeInt)) id, ok := _u.mutation.ID() if !ok { return nil, &ValidationError{Name: "id", err: errors.New(`ent: missing "Dock.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, dock.FieldID) for _, f := range fields { if !dock.ValidColumn(f) { return nil, &ValidationError{Name: f, err: fmt.Errorf("ent: invalid field %q for query", f)} } if f != dock.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.DockCode(); ok { _spec.SetField(dock.FieldDockCode, field.TypeString, value) } if value, ok := _u.mutation.Name(); ok { _spec.SetField(dock.FieldName, field.TypeString, value) } if value, ok := _u.mutation.DockType(); ok { _spec.SetField(dock.FieldDockType, field.TypeString, value) } if value, ok := _u.mutation.StationNo(); ok { _spec.SetField(dock.FieldStationNo, field.TypeInt, value) } if value, ok := _u.mutation.AddedStationNo(); ok { _spec.AddField(dock.FieldStationNo, field.TypeInt, value) } if value, ok := _u.mutation.HasPallet(); ok { _spec.SetField(dock.FieldHasPallet, field.TypeBool, value) } if value, ok := _u.mutation.PalletRef(); ok { _spec.SetField(dock.FieldPalletRef, field.TypeString, value) } if _u.mutation.PalletRefCleared() { _spec.ClearField(dock.FieldPalletRef, field.TypeString) } if value, ok := _u.mutation.Status(); ok { _spec.SetField(dock.FieldStatus, field.TypeString, value) } if value, ok := _u.mutation.CreatedAt(); ok { _spec.SetField(dock.FieldCreatedAt, field.TypeInt64, value) } if value, ok := _u.mutation.AddedCreatedAt(); ok { _spec.AddField(dock.FieldCreatedAt, field.TypeInt64, value) } _node = &Dock{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{dock.Label} } else if sqlgraph.IsConstraintError(err) { err = &ConstraintError{msg: err.Error(), wrap: err} } return nil, err } _u.mutation.done = true return _node, nil }