Files

300 lines
8.8 KiB
Go
Raw Permalink Normal View History

// Code generated by ent, DO NOT EDIT.
package ent
import (
"bj_power_mes/ent/predicate"
"bj_power_mes/ent/userstation"
"context"
"errors"
"fmt"
"entgo.io/ent/dialect/sql"
"entgo.io/ent/dialect/sql/sqlgraph"
"entgo.io/ent/schema/field"
)
// UserStationUpdate is the builder for updating UserStation entities.
type UserStationUpdate struct {
config
2026-09-15 16:37:39 +08:00
hooks []Hook
mutation *UserStationMutation
modifiers []func(*sql.UpdateBuilder)
}
// Where appends a list predicates to the UserStationUpdate builder.
func (_u *UserStationUpdate) Where(ps ...predicate.UserStation) *UserStationUpdate {
_u.mutation.Where(ps...)
return _u
}
// SetUserId sets the "userId" field.
func (_u *UserStationUpdate) SetUserId(v int) *UserStationUpdate {
_u.mutation.ResetUserId()
_u.mutation.SetUserId(v)
return _u
}
// SetNillableUserId sets the "userId" field if the given value is not nil.
func (_u *UserStationUpdate) SetNillableUserId(v *int) *UserStationUpdate {
if v != nil {
_u.SetUserId(*v)
}
return _u
}
// AddUserId adds value to the "userId" field.
func (_u *UserStationUpdate) AddUserId(v int) *UserStationUpdate {
_u.mutation.AddUserId(v)
return _u
}
// SetStationNo sets the "stationNo" field.
func (_u *UserStationUpdate) SetStationNo(v int) *UserStationUpdate {
_u.mutation.ResetStationNo()
_u.mutation.SetStationNo(v)
return _u
}
// SetNillableStationNo sets the "stationNo" field if the given value is not nil.
func (_u *UserStationUpdate) SetNillableStationNo(v *int) *UserStationUpdate {
if v != nil {
_u.SetStationNo(*v)
}
return _u
}
// AddStationNo adds value to the "stationNo" field.
func (_u *UserStationUpdate) AddStationNo(v int) *UserStationUpdate {
_u.mutation.AddStationNo(v)
return _u
}
// Mutation returns the UserStationMutation object of the builder.
func (_u *UserStationUpdate) Mutation() *UserStationMutation {
return _u.mutation
}
// Save executes the query and returns the number of nodes affected by the update operation.
func (_u *UserStationUpdate) 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 *UserStationUpdate) SaveX(ctx context.Context) int {
affected, err := _u.Save(ctx)
if err != nil {
panic(err)
}
return affected
}
// Exec executes the query.
func (_u *UserStationUpdate) Exec(ctx context.Context) error {
_, err := _u.Save(ctx)
return err
}
// ExecX is like Exec, but panics if an error occurs.
func (_u *UserStationUpdate) ExecX(ctx context.Context) {
if err := _u.Exec(ctx); err != nil {
panic(err)
}
}
2026-09-15 16:37:39 +08:00
// Modify adds a statement modifier for attaching custom logic to the UPDATE statement.
func (_u *UserStationUpdate) Modify(modifiers ...func(u *sql.UpdateBuilder)) *UserStationUpdate {
_u.modifiers = append(_u.modifiers, modifiers...)
return _u
}
func (_u *UserStationUpdate) sqlSave(ctx context.Context) (_node int, err error) {
_spec := sqlgraph.NewUpdateSpec(userstation.Table, userstation.Columns, sqlgraph.NewFieldSpec(userstation.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.UserId(); ok {
_spec.SetField(userstation.FieldUserId, field.TypeInt, value)
}
if value, ok := _u.mutation.AddedUserId(); ok {
_spec.AddField(userstation.FieldUserId, field.TypeInt, value)
}
if value, ok := _u.mutation.StationNo(); ok {
_spec.SetField(userstation.FieldStationNo, field.TypeInt, value)
}
if value, ok := _u.mutation.AddedStationNo(); ok {
_spec.AddField(userstation.FieldStationNo, field.TypeInt, value)
}
2026-09-15 16:37:39 +08:00
_spec.AddModifiers(_u.modifiers...)
if _node, err = sqlgraph.UpdateNodes(ctx, _u.driver, _spec); err != nil {
if _, ok := err.(*sqlgraph.NotFoundError); ok {
err = &NotFoundError{userstation.Label}
} else if sqlgraph.IsConstraintError(err) {
err = &ConstraintError{msg: err.Error(), wrap: err}
}
return 0, err
}
_u.mutation.done = true
return _node, nil
}
// UserStationUpdateOne is the builder for updating a single UserStation entity.
type UserStationUpdateOne struct {
config
2026-09-15 16:37:39 +08:00
fields []string
hooks []Hook
mutation *UserStationMutation
modifiers []func(*sql.UpdateBuilder)
}
// SetUserId sets the "userId" field.
func (_u *UserStationUpdateOne) SetUserId(v int) *UserStationUpdateOne {
_u.mutation.ResetUserId()
_u.mutation.SetUserId(v)
return _u
}
// SetNillableUserId sets the "userId" field if the given value is not nil.
func (_u *UserStationUpdateOne) SetNillableUserId(v *int) *UserStationUpdateOne {
if v != nil {
_u.SetUserId(*v)
}
return _u
}
// AddUserId adds value to the "userId" field.
func (_u *UserStationUpdateOne) AddUserId(v int) *UserStationUpdateOne {
_u.mutation.AddUserId(v)
return _u
}
// SetStationNo sets the "stationNo" field.
func (_u *UserStationUpdateOne) SetStationNo(v int) *UserStationUpdateOne {
_u.mutation.ResetStationNo()
_u.mutation.SetStationNo(v)
return _u
}
// SetNillableStationNo sets the "stationNo" field if the given value is not nil.
func (_u *UserStationUpdateOne) SetNillableStationNo(v *int) *UserStationUpdateOne {
if v != nil {
_u.SetStationNo(*v)
}
return _u
}
// AddStationNo adds value to the "stationNo" field.
func (_u *UserStationUpdateOne) AddStationNo(v int) *UserStationUpdateOne {
_u.mutation.AddStationNo(v)
return _u
}
// Mutation returns the UserStationMutation object of the builder.
func (_u *UserStationUpdateOne) Mutation() *UserStationMutation {
return _u.mutation
}
// Where appends a list predicates to the UserStationUpdate builder.
func (_u *UserStationUpdateOne) Where(ps ...predicate.UserStation) *UserStationUpdateOne {
_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 *UserStationUpdateOne) Select(field string, fields ...string) *UserStationUpdateOne {
_u.fields = append([]string{field}, fields...)
return _u
}
// Save executes the query and returns the updated UserStation entity.
func (_u *UserStationUpdateOne) Save(ctx context.Context) (*UserStation, error) {
return withHooks(ctx, _u.sqlSave, _u.mutation, _u.hooks)
}
// SaveX is like Save, but panics if an error occurs.
func (_u *UserStationUpdateOne) SaveX(ctx context.Context) *UserStation {
node, err := _u.Save(ctx)
if err != nil {
panic(err)
}
return node
}
// Exec executes the query on the entity.
func (_u *UserStationUpdateOne) Exec(ctx context.Context) error {
_, err := _u.Save(ctx)
return err
}
// ExecX is like Exec, but panics if an error occurs.
func (_u *UserStationUpdateOne) ExecX(ctx context.Context) {
if err := _u.Exec(ctx); err != nil {
panic(err)
}
}
2026-09-15 16:37:39 +08:00
// Modify adds a statement modifier for attaching custom logic to the UPDATE statement.
func (_u *UserStationUpdateOne) Modify(modifiers ...func(u *sql.UpdateBuilder)) *UserStationUpdateOne {
_u.modifiers = append(_u.modifiers, modifiers...)
return _u
}
func (_u *UserStationUpdateOne) sqlSave(ctx context.Context) (_node *UserStation, err error) {
_spec := sqlgraph.NewUpdateSpec(userstation.Table, userstation.Columns, sqlgraph.NewFieldSpec(userstation.FieldID, field.TypeInt))
id, ok := _u.mutation.ID()
if !ok {
return nil, &ValidationError{Name: "id", err: errors.New(`ent: missing "UserStation.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, userstation.FieldID)
for _, f := range fields {
if !userstation.ValidColumn(f) {
return nil, &ValidationError{Name: f, err: fmt.Errorf("ent: invalid field %q for query", f)}
}
if f != userstation.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.UserId(); ok {
_spec.SetField(userstation.FieldUserId, field.TypeInt, value)
}
if value, ok := _u.mutation.AddedUserId(); ok {
_spec.AddField(userstation.FieldUserId, field.TypeInt, value)
}
if value, ok := _u.mutation.StationNo(); ok {
_spec.SetField(userstation.FieldStationNo, field.TypeInt, value)
}
if value, ok := _u.mutation.AddedStationNo(); ok {
_spec.AddField(userstation.FieldStationNo, field.TypeInt, value)
}
2026-09-15 16:37:39 +08:00
_spec.AddModifiers(_u.modifiers...)
_node = &UserStation{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{userstation.Label}
} else if sqlgraph.IsConstraintError(err) {
err = &ConstraintError{msg: err.Error(), wrap: err}
}
return nil, err
}
_u.mutation.done = true
return _node, nil
}