// Code generated by ent, DO NOT EDIT. package ent import ( "bj_power_mes/ent/predicate" "bj_power_mes/ent/stationterminalevent" "context" "errors" "fmt" "entgo.io/ent/dialect/sql" "entgo.io/ent/dialect/sql/sqlgraph" "entgo.io/ent/schema/field" ) // StationTerminalEventUpdate is the builder for updating StationTerminalEvent entities. type StationTerminalEventUpdate struct { config hooks []Hook mutation *StationTerminalEventMutation modifiers []func(*sql.UpdateBuilder) } // Where appends a list predicates to the StationTerminalEventUpdate builder. func (_u *StationTerminalEventUpdate) Where(ps ...predicate.StationTerminalEvent) *StationTerminalEventUpdate { _u.mutation.Where(ps...) return _u } // SetStationNo sets the "stationNo" field. func (_u *StationTerminalEventUpdate) SetStationNo(v int) *StationTerminalEventUpdate { _u.mutation.ResetStationNo() _u.mutation.SetStationNo(v) return _u } // SetNillableStationNo sets the "stationNo" field if the given value is not nil. func (_u *StationTerminalEventUpdate) SetNillableStationNo(v *int) *StationTerminalEventUpdate { if v != nil { _u.SetStationNo(*v) } return _u } // AddStationNo adds value to the "stationNo" field. func (_u *StationTerminalEventUpdate) AddStationNo(v int) *StationTerminalEventUpdate { _u.mutation.AddStationNo(v) return _u } // SetEvent sets the "event" field. func (_u *StationTerminalEventUpdate) SetEvent(v string) *StationTerminalEventUpdate { _u.mutation.SetEvent(v) return _u } // SetNillableEvent sets the "event" field if the given value is not nil. func (_u *StationTerminalEventUpdate) SetNillableEvent(v *string) *StationTerminalEventUpdate { if v != nil { _u.SetEvent(*v) } return _u } // SetLoggedIn sets the "loggedIn" field. func (_u *StationTerminalEventUpdate) SetLoggedIn(v bool) *StationTerminalEventUpdate { _u.mutation.SetLoggedIn(v) return _u } // SetNillableLoggedIn sets the "loggedIn" field if the given value is not nil. func (_u *StationTerminalEventUpdate) SetNillableLoggedIn(v *bool) *StationTerminalEventUpdate { if v != nil { _u.SetLoggedIn(*v) } return _u } // SetPowered sets the "powered" field. func (_u *StationTerminalEventUpdate) SetPowered(v bool) *StationTerminalEventUpdate { _u.mutation.SetPowered(v) return _u } // SetNillablePowered sets the "powered" field if the given value is not nil. func (_u *StationTerminalEventUpdate) SetNillablePowered(v *bool) *StationTerminalEventUpdate { if v != nil { _u.SetPowered(*v) } return _u } // SetOperator sets the "operator" field. func (_u *StationTerminalEventUpdate) SetOperator(v string) *StationTerminalEventUpdate { _u.mutation.SetOperator(v) return _u } // SetNillableOperator sets the "operator" field if the given value is not nil. func (_u *StationTerminalEventUpdate) SetNillableOperator(v *string) *StationTerminalEventUpdate { if v != nil { _u.SetOperator(*v) } return _u } // SetDetail sets the "detail" field. func (_u *StationTerminalEventUpdate) SetDetail(v string) *StationTerminalEventUpdate { _u.mutation.SetDetail(v) return _u } // SetNillableDetail sets the "detail" field if the given value is not nil. func (_u *StationTerminalEventUpdate) SetNillableDetail(v *string) *StationTerminalEventUpdate { if v != nil { _u.SetDetail(*v) } return _u } // SetCreatedAt sets the "createdAt" field. func (_u *StationTerminalEventUpdate) SetCreatedAt(v int64) *StationTerminalEventUpdate { _u.mutation.ResetCreatedAt() _u.mutation.SetCreatedAt(v) return _u } // SetNillableCreatedAt sets the "createdAt" field if the given value is not nil. func (_u *StationTerminalEventUpdate) SetNillableCreatedAt(v *int64) *StationTerminalEventUpdate { if v != nil { _u.SetCreatedAt(*v) } return _u } // AddCreatedAt adds value to the "createdAt" field. func (_u *StationTerminalEventUpdate) AddCreatedAt(v int64) *StationTerminalEventUpdate { _u.mutation.AddCreatedAt(v) return _u } // Mutation returns the StationTerminalEventMutation object of the builder. func (_u *StationTerminalEventUpdate) Mutation() *StationTerminalEventMutation { return _u.mutation } // Save executes the query and returns the number of nodes affected by the update operation. func (_u *StationTerminalEventUpdate) 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 *StationTerminalEventUpdate) SaveX(ctx context.Context) int { affected, err := _u.Save(ctx) if err != nil { panic(err) } return affected } // Exec executes the query. func (_u *StationTerminalEventUpdate) Exec(ctx context.Context) error { _, err := _u.Save(ctx) return err } // ExecX is like Exec, but panics if an error occurs. func (_u *StationTerminalEventUpdate) 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 *StationTerminalEventUpdate) check() error { if v, ok := _u.mutation.Event(); ok { if err := stationterminalevent.EventValidator(v); err != nil { return &ValidationError{Name: "event", err: fmt.Errorf(`ent: validator failed for field "StationTerminalEvent.event": %w`, err)} } } if v, ok := _u.mutation.Operator(); ok { if err := stationterminalevent.OperatorValidator(v); err != nil { return &ValidationError{Name: "operator", err: fmt.Errorf(`ent: validator failed for field "StationTerminalEvent.operator": %w`, err)} } } if v, ok := _u.mutation.Detail(); ok { if err := stationterminalevent.DetailValidator(v); err != nil { return &ValidationError{Name: "detail", err: fmt.Errorf(`ent: validator failed for field "StationTerminalEvent.detail": %w`, err)} } } return nil } // Modify adds a statement modifier for attaching custom logic to the UPDATE statement. func (_u *StationTerminalEventUpdate) Modify(modifiers ...func(u *sql.UpdateBuilder)) *StationTerminalEventUpdate { _u.modifiers = append(_u.modifiers, modifiers...) return _u } func (_u *StationTerminalEventUpdate) sqlSave(ctx context.Context) (_node int, err error) { if err := _u.check(); err != nil { return _node, err } _spec := sqlgraph.NewUpdateSpec(stationterminalevent.Table, stationterminalevent.Columns, sqlgraph.NewFieldSpec(stationterminalevent.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.StationNo(); ok { _spec.SetField(stationterminalevent.FieldStationNo, field.TypeInt, value) } if value, ok := _u.mutation.AddedStationNo(); ok { _spec.AddField(stationterminalevent.FieldStationNo, field.TypeInt, value) } if value, ok := _u.mutation.Event(); ok { _spec.SetField(stationterminalevent.FieldEvent, field.TypeString, value) } if value, ok := _u.mutation.LoggedIn(); ok { _spec.SetField(stationterminalevent.FieldLoggedIn, field.TypeBool, value) } if value, ok := _u.mutation.Powered(); ok { _spec.SetField(stationterminalevent.FieldPowered, field.TypeBool, value) } if value, ok := _u.mutation.Operator(); ok { _spec.SetField(stationterminalevent.FieldOperator, field.TypeString, value) } if value, ok := _u.mutation.Detail(); ok { _spec.SetField(stationterminalevent.FieldDetail, field.TypeString, value) } if value, ok := _u.mutation.CreatedAt(); ok { _spec.SetField(stationterminalevent.FieldCreatedAt, field.TypeInt64, value) } if value, ok := _u.mutation.AddedCreatedAt(); ok { _spec.AddField(stationterminalevent.FieldCreatedAt, field.TypeInt64, value) } _spec.AddModifiers(_u.modifiers...) if _node, err = sqlgraph.UpdateNodes(ctx, _u.driver, _spec); err != nil { if _, ok := err.(*sqlgraph.NotFoundError); ok { err = &NotFoundError{stationterminalevent.Label} } else if sqlgraph.IsConstraintError(err) { err = &ConstraintError{msg: err.Error(), wrap: err} } return 0, err } _u.mutation.done = true return _node, nil } // StationTerminalEventUpdateOne is the builder for updating a single StationTerminalEvent entity. type StationTerminalEventUpdateOne struct { config fields []string hooks []Hook mutation *StationTerminalEventMutation modifiers []func(*sql.UpdateBuilder) } // SetStationNo sets the "stationNo" field. func (_u *StationTerminalEventUpdateOne) SetStationNo(v int) *StationTerminalEventUpdateOne { _u.mutation.ResetStationNo() _u.mutation.SetStationNo(v) return _u } // SetNillableStationNo sets the "stationNo" field if the given value is not nil. func (_u *StationTerminalEventUpdateOne) SetNillableStationNo(v *int) *StationTerminalEventUpdateOne { if v != nil { _u.SetStationNo(*v) } return _u } // AddStationNo adds value to the "stationNo" field. func (_u *StationTerminalEventUpdateOne) AddStationNo(v int) *StationTerminalEventUpdateOne { _u.mutation.AddStationNo(v) return _u } // SetEvent sets the "event" field. func (_u *StationTerminalEventUpdateOne) SetEvent(v string) *StationTerminalEventUpdateOne { _u.mutation.SetEvent(v) return _u } // SetNillableEvent sets the "event" field if the given value is not nil. func (_u *StationTerminalEventUpdateOne) SetNillableEvent(v *string) *StationTerminalEventUpdateOne { if v != nil { _u.SetEvent(*v) } return _u } // SetLoggedIn sets the "loggedIn" field. func (_u *StationTerminalEventUpdateOne) SetLoggedIn(v bool) *StationTerminalEventUpdateOne { _u.mutation.SetLoggedIn(v) return _u } // SetNillableLoggedIn sets the "loggedIn" field if the given value is not nil. func (_u *StationTerminalEventUpdateOne) SetNillableLoggedIn(v *bool) *StationTerminalEventUpdateOne { if v != nil { _u.SetLoggedIn(*v) } return _u } // SetPowered sets the "powered" field. func (_u *StationTerminalEventUpdateOne) SetPowered(v bool) *StationTerminalEventUpdateOne { _u.mutation.SetPowered(v) return _u } // SetNillablePowered sets the "powered" field if the given value is not nil. func (_u *StationTerminalEventUpdateOne) SetNillablePowered(v *bool) *StationTerminalEventUpdateOne { if v != nil { _u.SetPowered(*v) } return _u } // SetOperator sets the "operator" field. func (_u *StationTerminalEventUpdateOne) SetOperator(v string) *StationTerminalEventUpdateOne { _u.mutation.SetOperator(v) return _u } // SetNillableOperator sets the "operator" field if the given value is not nil. func (_u *StationTerminalEventUpdateOne) SetNillableOperator(v *string) *StationTerminalEventUpdateOne { if v != nil { _u.SetOperator(*v) } return _u } // SetDetail sets the "detail" field. func (_u *StationTerminalEventUpdateOne) SetDetail(v string) *StationTerminalEventUpdateOne { _u.mutation.SetDetail(v) return _u } // SetNillableDetail sets the "detail" field if the given value is not nil. func (_u *StationTerminalEventUpdateOne) SetNillableDetail(v *string) *StationTerminalEventUpdateOne { if v != nil { _u.SetDetail(*v) } return _u } // SetCreatedAt sets the "createdAt" field. func (_u *StationTerminalEventUpdateOne) SetCreatedAt(v int64) *StationTerminalEventUpdateOne { _u.mutation.ResetCreatedAt() _u.mutation.SetCreatedAt(v) return _u } // SetNillableCreatedAt sets the "createdAt" field if the given value is not nil. func (_u *StationTerminalEventUpdateOne) SetNillableCreatedAt(v *int64) *StationTerminalEventUpdateOne { if v != nil { _u.SetCreatedAt(*v) } return _u } // AddCreatedAt adds value to the "createdAt" field. func (_u *StationTerminalEventUpdateOne) AddCreatedAt(v int64) *StationTerminalEventUpdateOne { _u.mutation.AddCreatedAt(v) return _u } // Mutation returns the StationTerminalEventMutation object of the builder. func (_u *StationTerminalEventUpdateOne) Mutation() *StationTerminalEventMutation { return _u.mutation } // Where appends a list predicates to the StationTerminalEventUpdate builder. func (_u *StationTerminalEventUpdateOne) Where(ps ...predicate.StationTerminalEvent) *StationTerminalEventUpdateOne { _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 *StationTerminalEventUpdateOne) Select(field string, fields ...string) *StationTerminalEventUpdateOne { _u.fields = append([]string{field}, fields...) return _u } // Save executes the query and returns the updated StationTerminalEvent entity. func (_u *StationTerminalEventUpdateOne) Save(ctx context.Context) (*StationTerminalEvent, error) { return withHooks(ctx, _u.sqlSave, _u.mutation, _u.hooks) } // SaveX is like Save, but panics if an error occurs. func (_u *StationTerminalEventUpdateOne) SaveX(ctx context.Context) *StationTerminalEvent { node, err := _u.Save(ctx) if err != nil { panic(err) } return node } // Exec executes the query on the entity. func (_u *StationTerminalEventUpdateOne) Exec(ctx context.Context) error { _, err := _u.Save(ctx) return err } // ExecX is like Exec, but panics if an error occurs. func (_u *StationTerminalEventUpdateOne) 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 *StationTerminalEventUpdateOne) check() error { if v, ok := _u.mutation.Event(); ok { if err := stationterminalevent.EventValidator(v); err != nil { return &ValidationError{Name: "event", err: fmt.Errorf(`ent: validator failed for field "StationTerminalEvent.event": %w`, err)} } } if v, ok := _u.mutation.Operator(); ok { if err := stationterminalevent.OperatorValidator(v); err != nil { return &ValidationError{Name: "operator", err: fmt.Errorf(`ent: validator failed for field "StationTerminalEvent.operator": %w`, err)} } } if v, ok := _u.mutation.Detail(); ok { if err := stationterminalevent.DetailValidator(v); err != nil { return &ValidationError{Name: "detail", err: fmt.Errorf(`ent: validator failed for field "StationTerminalEvent.detail": %w`, err)} } } return nil } // Modify adds a statement modifier for attaching custom logic to the UPDATE statement. func (_u *StationTerminalEventUpdateOne) Modify(modifiers ...func(u *sql.UpdateBuilder)) *StationTerminalEventUpdateOne { _u.modifiers = append(_u.modifiers, modifiers...) return _u } func (_u *StationTerminalEventUpdateOne) sqlSave(ctx context.Context) (_node *StationTerminalEvent, err error) { if err := _u.check(); err != nil { return _node, err } _spec := sqlgraph.NewUpdateSpec(stationterminalevent.Table, stationterminalevent.Columns, sqlgraph.NewFieldSpec(stationterminalevent.FieldID, field.TypeInt)) id, ok := _u.mutation.ID() if !ok { return nil, &ValidationError{Name: "id", err: errors.New(`ent: missing "StationTerminalEvent.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, stationterminalevent.FieldID) for _, f := range fields { if !stationterminalevent.ValidColumn(f) { return nil, &ValidationError{Name: f, err: fmt.Errorf("ent: invalid field %q for query", f)} } if f != stationterminalevent.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.StationNo(); ok { _spec.SetField(stationterminalevent.FieldStationNo, field.TypeInt, value) } if value, ok := _u.mutation.AddedStationNo(); ok { _spec.AddField(stationterminalevent.FieldStationNo, field.TypeInt, value) } if value, ok := _u.mutation.Event(); ok { _spec.SetField(stationterminalevent.FieldEvent, field.TypeString, value) } if value, ok := _u.mutation.LoggedIn(); ok { _spec.SetField(stationterminalevent.FieldLoggedIn, field.TypeBool, value) } if value, ok := _u.mutation.Powered(); ok { _spec.SetField(stationterminalevent.FieldPowered, field.TypeBool, value) } if value, ok := _u.mutation.Operator(); ok { _spec.SetField(stationterminalevent.FieldOperator, field.TypeString, value) } if value, ok := _u.mutation.Detail(); ok { _spec.SetField(stationterminalevent.FieldDetail, field.TypeString, value) } if value, ok := _u.mutation.CreatedAt(); ok { _spec.SetField(stationterminalevent.FieldCreatedAt, field.TypeInt64, value) } if value, ok := _u.mutation.AddedCreatedAt(); ok { _spec.AddField(stationterminalevent.FieldCreatedAt, field.TypeInt64, value) } _spec.AddModifiers(_u.modifiers...) _node = &StationTerminalEvent{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{stationterminalevent.Label} } else if sqlgraph.IsConstraintError(err) { err = &ConstraintError{msg: err.Error(), wrap: err} } return nil, err } _u.mutation.done = true return _node, nil }