516 lines
17 KiB
Go
516 lines
17 KiB
Go
// Code generated by ent, DO NOT EDIT.
|
|||
|
|
|
||
|
|
package ent
|
||
|
|
|
||
|
|
import (
|
||
|
|
"bj_power_mes/ent/predicate"
|
||
|
|
"bj_power_mes/ent/stationterminalstate"
|
||
|
|
"context"
|
||
|
|
"errors"
|
||
|
|
"fmt"
|
||
|
|
|
||
|
|
"entgo.io/ent/dialect/sql"
|
||
|
|
"entgo.io/ent/dialect/sql/sqlgraph"
|
||
|
|
"entgo.io/ent/schema/field"
|
||
|
|
)
|
||
|
|
|
||
|
|
// StationTerminalStateUpdate is the builder for updating StationTerminalState entities.
|
||
|
|
type StationTerminalStateUpdate struct {
|
||
|
|
config
|
||
|
|
hooks []Hook
|
||
|
|
mutation *StationTerminalStateMutation
|
||
|
|
modifiers []func(*sql.UpdateBuilder)
|
||
|
|
}
|
||
|
|
|
||
|
|
// Where appends a list predicates to the StationTerminalStateUpdate builder.
|
||
|
|
func (_u *StationTerminalStateUpdate) Where(ps ...predicate.StationTerminalState) *StationTerminalStateUpdate {
|
||
|
|
_u.mutation.Where(ps...)
|
||
|
|
return _u
|
||
|
|
}
|
||
|
|
|
||
|
|
// SetStationNo sets the "stationNo" field.
|
||
|
|
func (_u *StationTerminalStateUpdate) SetStationNo(v int) *StationTerminalStateUpdate {
|
||
|
|
_u.mutation.ResetStationNo()
|
||
|
|
_u.mutation.SetStationNo(v)
|
||
|
|
return _u
|
||
|
|
}
|
||
|
|
|
||
|
|
// SetNillableStationNo sets the "stationNo" field if the given value is not nil.
|
||
|
|
func (_u *StationTerminalStateUpdate) SetNillableStationNo(v *int) *StationTerminalStateUpdate {
|
||
|
|
if v != nil {
|
||
|
|
_u.SetStationNo(*v)
|
||
|
|
}
|
||
|
|
return _u
|
||
|
|
}
|
||
|
|
|
||
|
|
// AddStationNo adds value to the "stationNo" field.
|
||
|
|
func (_u *StationTerminalStateUpdate) AddStationNo(v int) *StationTerminalStateUpdate {
|
||
|
|
_u.mutation.AddStationNo(v)
|
||
|
|
return _u
|
||
|
|
}
|
||
|
|
|
||
|
|
// SetPowered sets the "powered" field.
|
||
|
|
func (_u *StationTerminalStateUpdate) SetPowered(v bool) *StationTerminalStateUpdate {
|
||
|
|
_u.mutation.SetPowered(v)
|
||
|
|
return _u
|
||
|
|
}
|
||
|
|
|
||
|
|
// SetNillablePowered sets the "powered" field if the given value is not nil.
|
||
|
|
func (_u *StationTerminalStateUpdate) SetNillablePowered(v *bool) *StationTerminalStateUpdate {
|
||
|
|
if v != nil {
|
||
|
|
_u.SetPowered(*v)
|
||
|
|
}
|
||
|
|
return _u
|
||
|
|
}
|
||
|
|
|
||
|
|
// SetLoggedIn sets the "loggedIn" field.
|
||
|
|
func (_u *StationTerminalStateUpdate) SetLoggedIn(v bool) *StationTerminalStateUpdate {
|
||
|
|
_u.mutation.SetLoggedIn(v)
|
||
|
|
return _u
|
||
|
|
}
|
||
|
|
|
||
|
|
// SetNillableLoggedIn sets the "loggedIn" field if the given value is not nil.
|
||
|
|
func (_u *StationTerminalStateUpdate) SetNillableLoggedIn(v *bool) *StationTerminalStateUpdate {
|
||
|
|
if v != nil {
|
||
|
|
_u.SetLoggedIn(*v)
|
||
|
|
}
|
||
|
|
return _u
|
||
|
|
}
|
||
|
|
|
||
|
|
// SetOperator sets the "operator" field.
|
||
|
|
func (_u *StationTerminalStateUpdate) SetOperator(v string) *StationTerminalStateUpdate {
|
||
|
|
_u.mutation.SetOperator(v)
|
||
|
|
return _u
|
||
|
|
}
|
||
|
|
|
||
|
|
// SetNillableOperator sets the "operator" field if the given value is not nil.
|
||
|
|
func (_u *StationTerminalStateUpdate) SetNillableOperator(v *string) *StationTerminalStateUpdate {
|
||
|
|
if v != nil {
|
||
|
|
_u.SetOperator(*v)
|
||
|
|
}
|
||
|
|
return _u
|
||
|
|
}
|
||
|
|
|
||
|
|
// SetPaused sets the "paused" field.
|
||
|
|
func (_u *StationTerminalStateUpdate) SetPaused(v bool) *StationTerminalStateUpdate {
|
||
|
|
_u.mutation.SetPaused(v)
|
||
|
|
return _u
|
||
|
|
}
|
||
|
|
|
||
|
|
// SetNillablePaused sets the "paused" field if the given value is not nil.
|
||
|
|
func (_u *StationTerminalStateUpdate) SetNillablePaused(v *bool) *StationTerminalStateUpdate {
|
||
|
|
if v != nil {
|
||
|
|
_u.SetPaused(*v)
|
||
|
|
}
|
||
|
|
return _u
|
||
|
|
}
|
||
|
|
|
||
|
|
// SetLastHeartbeatAt sets the "lastHeartbeatAt" field.
|
||
|
|
func (_u *StationTerminalStateUpdate) SetLastHeartbeatAt(v int64) *StationTerminalStateUpdate {
|
||
|
|
_u.mutation.ResetLastHeartbeatAt()
|
||
|
|
_u.mutation.SetLastHeartbeatAt(v)
|
||
|
|
return _u
|
||
|
|
}
|
||
|
|
|
||
|
|
// SetNillableLastHeartbeatAt sets the "lastHeartbeatAt" field if the given value is not nil.
|
||
|
|
func (_u *StationTerminalStateUpdate) SetNillableLastHeartbeatAt(v *int64) *StationTerminalStateUpdate {
|
||
|
|
if v != nil {
|
||
|
|
_u.SetLastHeartbeatAt(*v)
|
||
|
|
}
|
||
|
|
return _u
|
||
|
|
}
|
||
|
|
|
||
|
|
// AddLastHeartbeatAt adds value to the "lastHeartbeatAt" field.
|
||
|
|
func (_u *StationTerminalStateUpdate) AddLastHeartbeatAt(v int64) *StationTerminalStateUpdate {
|
||
|
|
_u.mutation.AddLastHeartbeatAt(v)
|
||
|
|
return _u
|
||
|
|
}
|
||
|
|
|
||
|
|
// SetUpdatedAt sets the "updatedAt" field.
|
||
|
|
func (_u *StationTerminalStateUpdate) SetUpdatedAt(v int64) *StationTerminalStateUpdate {
|
||
|
|
_u.mutation.ResetUpdatedAt()
|
||
|
|
_u.mutation.SetUpdatedAt(v)
|
||
|
|
return _u
|
||
|
|
}
|
||
|
|
|
||
|
|
// SetNillableUpdatedAt sets the "updatedAt" field if the given value is not nil.
|
||
|
|
func (_u *StationTerminalStateUpdate) SetNillableUpdatedAt(v *int64) *StationTerminalStateUpdate {
|
||
|
|
if v != nil {
|
||
|
|
_u.SetUpdatedAt(*v)
|
||
|
|
}
|
||
|
|
return _u
|
||
|
|
}
|
||
|
|
|
||
|
|
// AddUpdatedAt adds value to the "updatedAt" field.
|
||
|
|
func (_u *StationTerminalStateUpdate) AddUpdatedAt(v int64) *StationTerminalStateUpdate {
|
||
|
|
_u.mutation.AddUpdatedAt(v)
|
||
|
|
return _u
|
||
|
|
}
|
||
|
|
|
||
|
|
// Mutation returns the StationTerminalStateMutation object of the builder.
|
||
|
|
func (_u *StationTerminalStateUpdate) Mutation() *StationTerminalStateMutation {
|
||
|
|
return _u.mutation
|
||
|
|
}
|
||
|
|
|
||
|
|
// Save executes the query and returns the number of nodes affected by the update operation.
|
||
|
|
func (_u *StationTerminalStateUpdate) 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 *StationTerminalStateUpdate) SaveX(ctx context.Context) int {
|
||
|
|
affected, err := _u.Save(ctx)
|
||
|
|
if err != nil {
|
||
|
|
panic(err)
|
||
|
|
}
|
||
|
|
return affected
|
||
|
|
}
|
||
|
|
|
||
|
|
// Exec executes the query.
|
||
|
|
func (_u *StationTerminalStateUpdate) Exec(ctx context.Context) error {
|
||
|
|
_, err := _u.Save(ctx)
|
||
|
|
return err
|
||
|
|
}
|
||
|
|
|
||
|
|
// ExecX is like Exec, but panics if an error occurs.
|
||
|
|
func (_u *StationTerminalStateUpdate) 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 *StationTerminalStateUpdate) check() error {
|
||
|
|
if v, ok := _u.mutation.Operator(); ok {
|
||
|
|
if err := stationterminalstate.OperatorValidator(v); err != nil {
|
||
|
|
return &ValidationError{Name: "operator", err: fmt.Errorf(`ent: validator failed for field "StationTerminalState.operator": %w`, err)}
|
||
|
|
}
|
||
|
|
}
|
||
|
|
return nil
|
||
|
|
}
|
||
|
|
|
||
|
|
// Modify adds a statement modifier for attaching custom logic to the UPDATE statement.
|
||
|
|
func (_u *StationTerminalStateUpdate) Modify(modifiers ...func(u *sql.UpdateBuilder)) *StationTerminalStateUpdate {
|
||
|
|
_u.modifiers = append(_u.modifiers, modifiers...)
|
||
|
|
return _u
|
||
|
|
}
|
||
|
|
|
||
|
|
func (_u *StationTerminalStateUpdate) sqlSave(ctx context.Context) (_node int, err error) {
|
||
|
|
if err := _u.check(); err != nil {
|
||
|
|
return _node, err
|
||
|
|
}
|
||
|
|
_spec := sqlgraph.NewUpdateSpec(stationterminalstate.Table, stationterminalstate.Columns, sqlgraph.NewFieldSpec(stationterminalstate.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(stationterminalstate.FieldStationNo, field.TypeInt, value)
|
||
|
|
}
|
||
|
|
if value, ok := _u.mutation.AddedStationNo(); ok {
|
||
|
|
_spec.AddField(stationterminalstate.FieldStationNo, field.TypeInt, value)
|
||
|
|
}
|
||
|
|
if value, ok := _u.mutation.Powered(); ok {
|
||
|
|
_spec.SetField(stationterminalstate.FieldPowered, field.TypeBool, value)
|
||
|
|
}
|
||
|
|
if value, ok := _u.mutation.LoggedIn(); ok {
|
||
|
|
_spec.SetField(stationterminalstate.FieldLoggedIn, field.TypeBool, value)
|
||
|
|
}
|
||
|
|
if value, ok := _u.mutation.Operator(); ok {
|
||
|
|
_spec.SetField(stationterminalstate.FieldOperator, field.TypeString, value)
|
||
|
|
}
|
||
|
|
if value, ok := _u.mutation.Paused(); ok {
|
||
|
|
_spec.SetField(stationterminalstate.FieldPaused, field.TypeBool, value)
|
||
|
|
}
|
||
|
|
if value, ok := _u.mutation.LastHeartbeatAt(); ok {
|
||
|
|
_spec.SetField(stationterminalstate.FieldLastHeartbeatAt, field.TypeInt64, value)
|
||
|
|
}
|
||
|
|
if value, ok := _u.mutation.AddedLastHeartbeatAt(); ok {
|
||
|
|
_spec.AddField(stationterminalstate.FieldLastHeartbeatAt, field.TypeInt64, value)
|
||
|
|
}
|
||
|
|
if value, ok := _u.mutation.UpdatedAt(); ok {
|
||
|
|
_spec.SetField(stationterminalstate.FieldUpdatedAt, field.TypeInt64, value)
|
||
|
|
}
|
||
|
|
if value, ok := _u.mutation.AddedUpdatedAt(); ok {
|
||
|
|
_spec.AddField(stationterminalstate.FieldUpdatedAt, 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{stationterminalstate.Label}
|
||
|
|
} else if sqlgraph.IsConstraintError(err) {
|
||
|
|
err = &ConstraintError{msg: err.Error(), wrap: err}
|
||
|
|
}
|
||
|
|
return 0, err
|
||
|
|
}
|
||
|
|
_u.mutation.done = true
|
||
|
|
return _node, nil
|
||
|
|
}
|
||
|
|
|
||
|
|
// StationTerminalStateUpdateOne is the builder for updating a single StationTerminalState entity.
|
||
|
|
type StationTerminalStateUpdateOne struct {
|
||
|
|
config
|
||
|
|
fields []string
|
||
|
|
hooks []Hook
|
||
|
|
mutation *StationTerminalStateMutation
|
||
|
|
modifiers []func(*sql.UpdateBuilder)
|
||
|
|
}
|
||
|
|
|
||
|
|
// SetStationNo sets the "stationNo" field.
|
||
|
|
func (_u *StationTerminalStateUpdateOne) SetStationNo(v int) *StationTerminalStateUpdateOne {
|
||
|
|
_u.mutation.ResetStationNo()
|
||
|
|
_u.mutation.SetStationNo(v)
|
||
|
|
return _u
|
||
|
|
}
|
||
|
|
|
||
|
|
// SetNillableStationNo sets the "stationNo" field if the given value is not nil.
|
||
|
|
func (_u *StationTerminalStateUpdateOne) SetNillableStationNo(v *int) *StationTerminalStateUpdateOne {
|
||
|
|
if v != nil {
|
||
|
|
_u.SetStationNo(*v)
|
||
|
|
}
|
||
|
|
return _u
|
||
|
|
}
|
||
|
|
|
||
|
|
// AddStationNo adds value to the "stationNo" field.
|
||
|
|
func (_u *StationTerminalStateUpdateOne) AddStationNo(v int) *StationTerminalStateUpdateOne {
|
||
|
|
_u.mutation.AddStationNo(v)
|
||
|
|
return _u
|
||
|
|
}
|
||
|
|
|
||
|
|
// SetPowered sets the "powered" field.
|
||
|
|
func (_u *StationTerminalStateUpdateOne) SetPowered(v bool) *StationTerminalStateUpdateOne {
|
||
|
|
_u.mutation.SetPowered(v)
|
||
|
|
return _u
|
||
|
|
}
|
||
|
|
|
||
|
|
// SetNillablePowered sets the "powered" field if the given value is not nil.
|
||
|
|
func (_u *StationTerminalStateUpdateOne) SetNillablePowered(v *bool) *StationTerminalStateUpdateOne {
|
||
|
|
if v != nil {
|
||
|
|
_u.SetPowered(*v)
|
||
|
|
}
|
||
|
|
return _u
|
||
|
|
}
|
||
|
|
|
||
|
|
// SetLoggedIn sets the "loggedIn" field.
|
||
|
|
func (_u *StationTerminalStateUpdateOne) SetLoggedIn(v bool) *StationTerminalStateUpdateOne {
|
||
|
|
_u.mutation.SetLoggedIn(v)
|
||
|
|
return _u
|
||
|
|
}
|
||
|
|
|
||
|
|
// SetNillableLoggedIn sets the "loggedIn" field if the given value is not nil.
|
||
|
|
func (_u *StationTerminalStateUpdateOne) SetNillableLoggedIn(v *bool) *StationTerminalStateUpdateOne {
|
||
|
|
if v != nil {
|
||
|
|
_u.SetLoggedIn(*v)
|
||
|
|
}
|
||
|
|
return _u
|
||
|
|
}
|
||
|
|
|
||
|
|
// SetOperator sets the "operator" field.
|
||
|
|
func (_u *StationTerminalStateUpdateOne) SetOperator(v string) *StationTerminalStateUpdateOne {
|
||
|
|
_u.mutation.SetOperator(v)
|
||
|
|
return _u
|
||
|
|
}
|
||
|
|
|
||
|
|
// SetNillableOperator sets the "operator" field if the given value is not nil.
|
||
|
|
func (_u *StationTerminalStateUpdateOne) SetNillableOperator(v *string) *StationTerminalStateUpdateOne {
|
||
|
|
if v != nil {
|
||
|
|
_u.SetOperator(*v)
|
||
|
|
}
|
||
|
|
return _u
|
||
|
|
}
|
||
|
|
|
||
|
|
// SetPaused sets the "paused" field.
|
||
|
|
func (_u *StationTerminalStateUpdateOne) SetPaused(v bool) *StationTerminalStateUpdateOne {
|
||
|
|
_u.mutation.SetPaused(v)
|
||
|
|
return _u
|
||
|
|
}
|
||
|
|
|
||
|
|
// SetNillablePaused sets the "paused" field if the given value is not nil.
|
||
|
|
func (_u *StationTerminalStateUpdateOne) SetNillablePaused(v *bool) *StationTerminalStateUpdateOne {
|
||
|
|
if v != nil {
|
||
|
|
_u.SetPaused(*v)
|
||
|
|
}
|
||
|
|
return _u
|
||
|
|
}
|
||
|
|
|
||
|
|
// SetLastHeartbeatAt sets the "lastHeartbeatAt" field.
|
||
|
|
func (_u *StationTerminalStateUpdateOne) SetLastHeartbeatAt(v int64) *StationTerminalStateUpdateOne {
|
||
|
|
_u.mutation.ResetLastHeartbeatAt()
|
||
|
|
_u.mutation.SetLastHeartbeatAt(v)
|
||
|
|
return _u
|
||
|
|
}
|
||
|
|
|
||
|
|
// SetNillableLastHeartbeatAt sets the "lastHeartbeatAt" field if the given value is not nil.
|
||
|
|
func (_u *StationTerminalStateUpdateOne) SetNillableLastHeartbeatAt(v *int64) *StationTerminalStateUpdateOne {
|
||
|
|
if v != nil {
|
||
|
|
_u.SetLastHeartbeatAt(*v)
|
||
|
|
}
|
||
|
|
return _u
|
||
|
|
}
|
||
|
|
|
||
|
|
// AddLastHeartbeatAt adds value to the "lastHeartbeatAt" field.
|
||
|
|
func (_u *StationTerminalStateUpdateOne) AddLastHeartbeatAt(v int64) *StationTerminalStateUpdateOne {
|
||
|
|
_u.mutation.AddLastHeartbeatAt(v)
|
||
|
|
return _u
|
||
|
|
}
|
||
|
|
|
||
|
|
// SetUpdatedAt sets the "updatedAt" field.
|
||
|
|
func (_u *StationTerminalStateUpdateOne) SetUpdatedAt(v int64) *StationTerminalStateUpdateOne {
|
||
|
|
_u.mutation.ResetUpdatedAt()
|
||
|
|
_u.mutation.SetUpdatedAt(v)
|
||
|
|
return _u
|
||
|
|
}
|
||
|
|
|
||
|
|
// SetNillableUpdatedAt sets the "updatedAt" field if the given value is not nil.
|
||
|
|
func (_u *StationTerminalStateUpdateOne) SetNillableUpdatedAt(v *int64) *StationTerminalStateUpdateOne {
|
||
|
|
if v != nil {
|
||
|
|
_u.SetUpdatedAt(*v)
|
||
|
|
}
|
||
|
|
return _u
|
||
|
|
}
|
||
|
|
|
||
|
|
// AddUpdatedAt adds value to the "updatedAt" field.
|
||
|
|
func (_u *StationTerminalStateUpdateOne) AddUpdatedAt(v int64) *StationTerminalStateUpdateOne {
|
||
|
|
_u.mutation.AddUpdatedAt(v)
|
||
|
|
return _u
|
||
|
|
}
|
||
|
|
|
||
|
|
// Mutation returns the StationTerminalStateMutation object of the builder.
|
||
|
|
func (_u *StationTerminalStateUpdateOne) Mutation() *StationTerminalStateMutation {
|
||
|
|
return _u.mutation
|
||
|
|
}
|
||
|
|
|
||
|
|
// Where appends a list predicates to the StationTerminalStateUpdate builder.
|
||
|
|
func (_u *StationTerminalStateUpdateOne) Where(ps ...predicate.StationTerminalState) *StationTerminalStateUpdateOne {
|
||
|
|
_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 *StationTerminalStateUpdateOne) Select(field string, fields ...string) *StationTerminalStateUpdateOne {
|
||
|
|
_u.fields = append([]string{field}, fields...)
|
||
|
|
return _u
|
||
|
|
}
|
||
|
|
|
||
|
|
// Save executes the query and returns the updated StationTerminalState entity.
|
||
|
|
func (_u *StationTerminalStateUpdateOne) Save(ctx context.Context) (*StationTerminalState, error) {
|
||
|
|
return withHooks(ctx, _u.sqlSave, _u.mutation, _u.hooks)
|
||
|
|
}
|
||
|
|
|
||
|
|
// SaveX is like Save, but panics if an error occurs.
|
||
|
|
func (_u *StationTerminalStateUpdateOne) SaveX(ctx context.Context) *StationTerminalState {
|
||
|
|
node, err := _u.Save(ctx)
|
||
|
|
if err != nil {
|
||
|
|
panic(err)
|
||
|
|
}
|
||
|
|
return node
|
||
|
|
}
|
||
|
|
|
||
|
|
// Exec executes the query on the entity.
|
||
|
|
func (_u *StationTerminalStateUpdateOne) Exec(ctx context.Context) error {
|
||
|
|
_, err := _u.Save(ctx)
|
||
|
|
return err
|
||
|
|
}
|
||
|
|
|
||
|
|
// ExecX is like Exec, but panics if an error occurs.
|
||
|
|
func (_u *StationTerminalStateUpdateOne) 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 *StationTerminalStateUpdateOne) check() error {
|
||
|
|
if v, ok := _u.mutation.Operator(); ok {
|
||
|
|
if err := stationterminalstate.OperatorValidator(v); err != nil {
|
||
|
|
return &ValidationError{Name: "operator", err: fmt.Errorf(`ent: validator failed for field "StationTerminalState.operator": %w`, err)}
|
||
|
|
}
|
||
|
|
}
|
||
|
|
return nil
|
||
|
|
}
|
||
|
|
|
||
|
|
// Modify adds a statement modifier for attaching custom logic to the UPDATE statement.
|
||
|
|
func (_u *StationTerminalStateUpdateOne) Modify(modifiers ...func(u *sql.UpdateBuilder)) *StationTerminalStateUpdateOne {
|
||
|
|
_u.modifiers = append(_u.modifiers, modifiers...)
|
||
|
|
return _u
|
||
|
|
}
|
||
|
|
|
||
|
|
func (_u *StationTerminalStateUpdateOne) sqlSave(ctx context.Context) (_node *StationTerminalState, err error) {
|
||
|
|
if err := _u.check(); err != nil {
|
||
|
|
return _node, err
|
||
|
|
}
|
||
|
|
_spec := sqlgraph.NewUpdateSpec(stationterminalstate.Table, stationterminalstate.Columns, sqlgraph.NewFieldSpec(stationterminalstate.FieldID, field.TypeInt))
|
||
|
|
id, ok := _u.mutation.ID()
|
||
|
|
if !ok {
|
||
|
|
return nil, &ValidationError{Name: "id", err: errors.New(`ent: missing "StationTerminalState.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, stationterminalstate.FieldID)
|
||
|
|
for _, f := range fields {
|
||
|
|
if !stationterminalstate.ValidColumn(f) {
|
||
|
|
return nil, &ValidationError{Name: f, err: fmt.Errorf("ent: invalid field %q for query", f)}
|
||
|
|
}
|
||
|
|
if f != stationterminalstate.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(stationterminalstate.FieldStationNo, field.TypeInt, value)
|
||
|
|
}
|
||
|
|
if value, ok := _u.mutation.AddedStationNo(); ok {
|
||
|
|
_spec.AddField(stationterminalstate.FieldStationNo, field.TypeInt, value)
|
||
|
|
}
|
||
|
|
if value, ok := _u.mutation.Powered(); ok {
|
||
|
|
_spec.SetField(stationterminalstate.FieldPowered, field.TypeBool, value)
|
||
|
|
}
|
||
|
|
if value, ok := _u.mutation.LoggedIn(); ok {
|
||
|
|
_spec.SetField(stationterminalstate.FieldLoggedIn, field.TypeBool, value)
|
||
|
|
}
|
||
|
|
if value, ok := _u.mutation.Operator(); ok {
|
||
|
|
_spec.SetField(stationterminalstate.FieldOperator, field.TypeString, value)
|
||
|
|
}
|
||
|
|
if value, ok := _u.mutation.Paused(); ok {
|
||
|
|
_spec.SetField(stationterminalstate.FieldPaused, field.TypeBool, value)
|
||
|
|
}
|
||
|
|
if value, ok := _u.mutation.LastHeartbeatAt(); ok {
|
||
|
|
_spec.SetField(stationterminalstate.FieldLastHeartbeatAt, field.TypeInt64, value)
|
||
|
|
}
|
||
|
|
if value, ok := _u.mutation.AddedLastHeartbeatAt(); ok {
|
||
|
|
_spec.AddField(stationterminalstate.FieldLastHeartbeatAt, field.TypeInt64, value)
|
||
|
|
}
|
||
|
|
if value, ok := _u.mutation.UpdatedAt(); ok {
|
||
|
|
_spec.SetField(stationterminalstate.FieldUpdatedAt, field.TypeInt64, value)
|
||
|
|
}
|
||
|
|
if value, ok := _u.mutation.AddedUpdatedAt(); ok {
|
||
|
|
_spec.AddField(stationterminalstate.FieldUpdatedAt, field.TypeInt64, value)
|
||
|
|
}
|
||
|
|
_spec.AddModifiers(_u.modifiers...)
|
||
|
|
_node = &StationTerminalState{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{stationterminalstate.Label}
|
||
|
|
} else if sqlgraph.IsConstraintError(err) {
|
||
|
|
err = &ConstraintError{msg: err.Error(), wrap: err}
|
||
|
|
}
|
||
|
|
return nil, err
|
||
|
|
}
|
||
|
|
_u.mutation.done = true
|
||
|
|
return _node, nil
|
||
|
|
}
|