498 lines
15 KiB
Go
498 lines
15 KiB
Go
// Code generated by ent, DO NOT EDIT.
|
|
|
|
package ent
|
|
|
|
import (
|
|
"bj_power_mes/ent/eventlog"
|
|
"bj_power_mes/ent/predicate"
|
|
"context"
|
|
"errors"
|
|
"fmt"
|
|
|
|
"entgo.io/ent/dialect/sql"
|
|
"entgo.io/ent/dialect/sql/sqlgraph"
|
|
"entgo.io/ent/schema/field"
|
|
)
|
|
|
|
// EventLogUpdate is the builder for updating EventLog entities.
|
|
type EventLogUpdate struct {
|
|
config
|
|
hooks []Hook
|
|
mutation *EventLogMutation
|
|
modifiers []func(*sql.UpdateBuilder)
|
|
}
|
|
|
|
// Where appends a list predicates to the EventLogUpdate builder.
|
|
func (_u *EventLogUpdate) Where(ps ...predicate.EventLog) *EventLogUpdate {
|
|
_u.mutation.Where(ps...)
|
|
return _u
|
|
}
|
|
|
|
// SetEventType sets the "eventType" field.
|
|
func (_u *EventLogUpdate) SetEventType(v string) *EventLogUpdate {
|
|
_u.mutation.SetEventType(v)
|
|
return _u
|
|
}
|
|
|
|
// SetNillableEventType sets the "eventType" field if the given value is not nil.
|
|
func (_u *EventLogUpdate) SetNillableEventType(v *string) *EventLogUpdate {
|
|
if v != nil {
|
|
_u.SetEventType(*v)
|
|
}
|
|
return _u
|
|
}
|
|
|
|
// SetWorkOrderNo sets the "workOrderNo" field.
|
|
func (_u *EventLogUpdate) SetWorkOrderNo(v string) *EventLogUpdate {
|
|
_u.mutation.SetWorkOrderNo(v)
|
|
return _u
|
|
}
|
|
|
|
// SetNillableWorkOrderNo sets the "workOrderNo" field if the given value is not nil.
|
|
func (_u *EventLogUpdate) SetNillableWorkOrderNo(v *string) *EventLogUpdate {
|
|
if v != nil {
|
|
_u.SetWorkOrderNo(*v)
|
|
}
|
|
return _u
|
|
}
|
|
|
|
// SetOperator sets the "operator" field.
|
|
func (_u *EventLogUpdate) SetOperator(v string) *EventLogUpdate {
|
|
_u.mutation.SetOperator(v)
|
|
return _u
|
|
}
|
|
|
|
// SetNillableOperator sets the "operator" field if the given value is not nil.
|
|
func (_u *EventLogUpdate) SetNillableOperator(v *string) *EventLogUpdate {
|
|
if v != nil {
|
|
_u.SetOperator(*v)
|
|
}
|
|
return _u
|
|
}
|
|
|
|
// SetEntityType sets the "entityType" field.
|
|
func (_u *EventLogUpdate) SetEntityType(v string) *EventLogUpdate {
|
|
_u.mutation.SetEntityType(v)
|
|
return _u
|
|
}
|
|
|
|
// SetNillableEntityType sets the "entityType" field if the given value is not nil.
|
|
func (_u *EventLogUpdate) SetNillableEntityType(v *string) *EventLogUpdate {
|
|
if v != nil {
|
|
_u.SetEntityType(*v)
|
|
}
|
|
return _u
|
|
}
|
|
|
|
// SetEntityId sets the "entityId" field.
|
|
func (_u *EventLogUpdate) SetEntityId(v string) *EventLogUpdate {
|
|
_u.mutation.SetEntityId(v)
|
|
return _u
|
|
}
|
|
|
|
// SetNillableEntityId sets the "entityId" field if the given value is not nil.
|
|
func (_u *EventLogUpdate) SetNillableEntityId(v *string) *EventLogUpdate {
|
|
if v != nil {
|
|
_u.SetEntityId(*v)
|
|
}
|
|
return _u
|
|
}
|
|
|
|
// SetDescription sets the "description" field.
|
|
func (_u *EventLogUpdate) SetDescription(v string) *EventLogUpdate {
|
|
_u.mutation.SetDescription(v)
|
|
return _u
|
|
}
|
|
|
|
// SetNillableDescription sets the "description" field if the given value is not nil.
|
|
func (_u *EventLogUpdate) SetNillableDescription(v *string) *EventLogUpdate {
|
|
if v != nil {
|
|
_u.SetDescription(*v)
|
|
}
|
|
return _u
|
|
}
|
|
|
|
// SetPayload sets the "payload" field.
|
|
func (_u *EventLogUpdate) SetPayload(v map[string]interface{}) *EventLogUpdate {
|
|
_u.mutation.SetPayload(v)
|
|
return _u
|
|
}
|
|
|
|
// ClearPayload clears the value of the "payload" field.
|
|
func (_u *EventLogUpdate) ClearPayload() *EventLogUpdate {
|
|
_u.mutation.ClearPayload()
|
|
return _u
|
|
}
|
|
|
|
// Mutation returns the EventLogMutation object of the builder.
|
|
func (_u *EventLogUpdate) Mutation() *EventLogMutation {
|
|
return _u.mutation
|
|
}
|
|
|
|
// Save executes the query and returns the number of nodes affected by the update operation.
|
|
func (_u *EventLogUpdate) 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 *EventLogUpdate) SaveX(ctx context.Context) int {
|
|
affected, err := _u.Save(ctx)
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
return affected
|
|
}
|
|
|
|
// Exec executes the query.
|
|
func (_u *EventLogUpdate) Exec(ctx context.Context) error {
|
|
_, err := _u.Save(ctx)
|
|
return err
|
|
}
|
|
|
|
// ExecX is like Exec, but panics if an error occurs.
|
|
func (_u *EventLogUpdate) 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 *EventLogUpdate) check() error {
|
|
if v, ok := _u.mutation.EventType(); ok {
|
|
if err := eventlog.EventTypeValidator(v); err != nil {
|
|
return &ValidationError{Name: "eventType", err: fmt.Errorf(`ent: validator failed for field "EventLog.eventType": %w`, err)}
|
|
}
|
|
}
|
|
if v, ok := _u.mutation.WorkOrderNo(); ok {
|
|
if err := eventlog.WorkOrderNoValidator(v); err != nil {
|
|
return &ValidationError{Name: "workOrderNo", err: fmt.Errorf(`ent: validator failed for field "EventLog.workOrderNo": %w`, err)}
|
|
}
|
|
}
|
|
if v, ok := _u.mutation.Operator(); ok {
|
|
if err := eventlog.OperatorValidator(v); err != nil {
|
|
return &ValidationError{Name: "operator", err: fmt.Errorf(`ent: validator failed for field "EventLog.operator": %w`, err)}
|
|
}
|
|
}
|
|
if v, ok := _u.mutation.EntityType(); ok {
|
|
if err := eventlog.EntityTypeValidator(v); err != nil {
|
|
return &ValidationError{Name: "entityType", err: fmt.Errorf(`ent: validator failed for field "EventLog.entityType": %w`, err)}
|
|
}
|
|
}
|
|
if v, ok := _u.mutation.EntityId(); ok {
|
|
if err := eventlog.EntityIdValidator(v); err != nil {
|
|
return &ValidationError{Name: "entityId", err: fmt.Errorf(`ent: validator failed for field "EventLog.entityId": %w`, err)}
|
|
}
|
|
}
|
|
return nil
|
|
}
|
|
|
|
// Modify adds a statement modifier for attaching custom logic to the UPDATE statement.
|
|
func (_u *EventLogUpdate) Modify(modifiers ...func(u *sql.UpdateBuilder)) *EventLogUpdate {
|
|
_u.modifiers = append(_u.modifiers, modifiers...)
|
|
return _u
|
|
}
|
|
|
|
func (_u *EventLogUpdate) sqlSave(ctx context.Context) (_node int, err error) {
|
|
if err := _u.check(); err != nil {
|
|
return _node, err
|
|
}
|
|
_spec := sqlgraph.NewUpdateSpec(eventlog.Table, eventlog.Columns, sqlgraph.NewFieldSpec(eventlog.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.EventType(); ok {
|
|
_spec.SetField(eventlog.FieldEventType, field.TypeString, value)
|
|
}
|
|
if value, ok := _u.mutation.WorkOrderNo(); ok {
|
|
_spec.SetField(eventlog.FieldWorkOrderNo, field.TypeString, value)
|
|
}
|
|
if value, ok := _u.mutation.Operator(); ok {
|
|
_spec.SetField(eventlog.FieldOperator, field.TypeString, value)
|
|
}
|
|
if value, ok := _u.mutation.EntityType(); ok {
|
|
_spec.SetField(eventlog.FieldEntityType, field.TypeString, value)
|
|
}
|
|
if value, ok := _u.mutation.EntityId(); ok {
|
|
_spec.SetField(eventlog.FieldEntityId, field.TypeString, value)
|
|
}
|
|
if value, ok := _u.mutation.Description(); ok {
|
|
_spec.SetField(eventlog.FieldDescription, field.TypeString, value)
|
|
}
|
|
if value, ok := _u.mutation.Payload(); ok {
|
|
_spec.SetField(eventlog.FieldPayload, field.TypeJSON, value)
|
|
}
|
|
if _u.mutation.PayloadCleared() {
|
|
_spec.ClearField(eventlog.FieldPayload, field.TypeJSON)
|
|
}
|
|
_spec.AddModifiers(_u.modifiers...)
|
|
if _node, err = sqlgraph.UpdateNodes(ctx, _u.driver, _spec); err != nil {
|
|
if _, ok := err.(*sqlgraph.NotFoundError); ok {
|
|
err = &NotFoundError{eventlog.Label}
|
|
} else if sqlgraph.IsConstraintError(err) {
|
|
err = &ConstraintError{msg: err.Error(), wrap: err}
|
|
}
|
|
return 0, err
|
|
}
|
|
_u.mutation.done = true
|
|
return _node, nil
|
|
}
|
|
|
|
// EventLogUpdateOne is the builder for updating a single EventLog entity.
|
|
type EventLogUpdateOne struct {
|
|
config
|
|
fields []string
|
|
hooks []Hook
|
|
mutation *EventLogMutation
|
|
modifiers []func(*sql.UpdateBuilder)
|
|
}
|
|
|
|
// SetEventType sets the "eventType" field.
|
|
func (_u *EventLogUpdateOne) SetEventType(v string) *EventLogUpdateOne {
|
|
_u.mutation.SetEventType(v)
|
|
return _u
|
|
}
|
|
|
|
// SetNillableEventType sets the "eventType" field if the given value is not nil.
|
|
func (_u *EventLogUpdateOne) SetNillableEventType(v *string) *EventLogUpdateOne {
|
|
if v != nil {
|
|
_u.SetEventType(*v)
|
|
}
|
|
return _u
|
|
}
|
|
|
|
// SetWorkOrderNo sets the "workOrderNo" field.
|
|
func (_u *EventLogUpdateOne) SetWorkOrderNo(v string) *EventLogUpdateOne {
|
|
_u.mutation.SetWorkOrderNo(v)
|
|
return _u
|
|
}
|
|
|
|
// SetNillableWorkOrderNo sets the "workOrderNo" field if the given value is not nil.
|
|
func (_u *EventLogUpdateOne) SetNillableWorkOrderNo(v *string) *EventLogUpdateOne {
|
|
if v != nil {
|
|
_u.SetWorkOrderNo(*v)
|
|
}
|
|
return _u
|
|
}
|
|
|
|
// SetOperator sets the "operator" field.
|
|
func (_u *EventLogUpdateOne) SetOperator(v string) *EventLogUpdateOne {
|
|
_u.mutation.SetOperator(v)
|
|
return _u
|
|
}
|
|
|
|
// SetNillableOperator sets the "operator" field if the given value is not nil.
|
|
func (_u *EventLogUpdateOne) SetNillableOperator(v *string) *EventLogUpdateOne {
|
|
if v != nil {
|
|
_u.SetOperator(*v)
|
|
}
|
|
return _u
|
|
}
|
|
|
|
// SetEntityType sets the "entityType" field.
|
|
func (_u *EventLogUpdateOne) SetEntityType(v string) *EventLogUpdateOne {
|
|
_u.mutation.SetEntityType(v)
|
|
return _u
|
|
}
|
|
|
|
// SetNillableEntityType sets the "entityType" field if the given value is not nil.
|
|
func (_u *EventLogUpdateOne) SetNillableEntityType(v *string) *EventLogUpdateOne {
|
|
if v != nil {
|
|
_u.SetEntityType(*v)
|
|
}
|
|
return _u
|
|
}
|
|
|
|
// SetEntityId sets the "entityId" field.
|
|
func (_u *EventLogUpdateOne) SetEntityId(v string) *EventLogUpdateOne {
|
|
_u.mutation.SetEntityId(v)
|
|
return _u
|
|
}
|
|
|
|
// SetNillableEntityId sets the "entityId" field if the given value is not nil.
|
|
func (_u *EventLogUpdateOne) SetNillableEntityId(v *string) *EventLogUpdateOne {
|
|
if v != nil {
|
|
_u.SetEntityId(*v)
|
|
}
|
|
return _u
|
|
}
|
|
|
|
// SetDescription sets the "description" field.
|
|
func (_u *EventLogUpdateOne) SetDescription(v string) *EventLogUpdateOne {
|
|
_u.mutation.SetDescription(v)
|
|
return _u
|
|
}
|
|
|
|
// SetNillableDescription sets the "description" field if the given value is not nil.
|
|
func (_u *EventLogUpdateOne) SetNillableDescription(v *string) *EventLogUpdateOne {
|
|
if v != nil {
|
|
_u.SetDescription(*v)
|
|
}
|
|
return _u
|
|
}
|
|
|
|
// SetPayload sets the "payload" field.
|
|
func (_u *EventLogUpdateOne) SetPayload(v map[string]interface{}) *EventLogUpdateOne {
|
|
_u.mutation.SetPayload(v)
|
|
return _u
|
|
}
|
|
|
|
// ClearPayload clears the value of the "payload" field.
|
|
func (_u *EventLogUpdateOne) ClearPayload() *EventLogUpdateOne {
|
|
_u.mutation.ClearPayload()
|
|
return _u
|
|
}
|
|
|
|
// Mutation returns the EventLogMutation object of the builder.
|
|
func (_u *EventLogUpdateOne) Mutation() *EventLogMutation {
|
|
return _u.mutation
|
|
}
|
|
|
|
// Where appends a list predicates to the EventLogUpdate builder.
|
|
func (_u *EventLogUpdateOne) Where(ps ...predicate.EventLog) *EventLogUpdateOne {
|
|
_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 *EventLogUpdateOne) Select(field string, fields ...string) *EventLogUpdateOne {
|
|
_u.fields = append([]string{field}, fields...)
|
|
return _u
|
|
}
|
|
|
|
// Save executes the query and returns the updated EventLog entity.
|
|
func (_u *EventLogUpdateOne) Save(ctx context.Context) (*EventLog, error) {
|
|
return withHooks(ctx, _u.sqlSave, _u.mutation, _u.hooks)
|
|
}
|
|
|
|
// SaveX is like Save, but panics if an error occurs.
|
|
func (_u *EventLogUpdateOne) SaveX(ctx context.Context) *EventLog {
|
|
node, err := _u.Save(ctx)
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
return node
|
|
}
|
|
|
|
// Exec executes the query on the entity.
|
|
func (_u *EventLogUpdateOne) Exec(ctx context.Context) error {
|
|
_, err := _u.Save(ctx)
|
|
return err
|
|
}
|
|
|
|
// ExecX is like Exec, but panics if an error occurs.
|
|
func (_u *EventLogUpdateOne) 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 *EventLogUpdateOne) check() error {
|
|
if v, ok := _u.mutation.EventType(); ok {
|
|
if err := eventlog.EventTypeValidator(v); err != nil {
|
|
return &ValidationError{Name: "eventType", err: fmt.Errorf(`ent: validator failed for field "EventLog.eventType": %w`, err)}
|
|
}
|
|
}
|
|
if v, ok := _u.mutation.WorkOrderNo(); ok {
|
|
if err := eventlog.WorkOrderNoValidator(v); err != nil {
|
|
return &ValidationError{Name: "workOrderNo", err: fmt.Errorf(`ent: validator failed for field "EventLog.workOrderNo": %w`, err)}
|
|
}
|
|
}
|
|
if v, ok := _u.mutation.Operator(); ok {
|
|
if err := eventlog.OperatorValidator(v); err != nil {
|
|
return &ValidationError{Name: "operator", err: fmt.Errorf(`ent: validator failed for field "EventLog.operator": %w`, err)}
|
|
}
|
|
}
|
|
if v, ok := _u.mutation.EntityType(); ok {
|
|
if err := eventlog.EntityTypeValidator(v); err != nil {
|
|
return &ValidationError{Name: "entityType", err: fmt.Errorf(`ent: validator failed for field "EventLog.entityType": %w`, err)}
|
|
}
|
|
}
|
|
if v, ok := _u.mutation.EntityId(); ok {
|
|
if err := eventlog.EntityIdValidator(v); err != nil {
|
|
return &ValidationError{Name: "entityId", err: fmt.Errorf(`ent: validator failed for field "EventLog.entityId": %w`, err)}
|
|
}
|
|
}
|
|
return nil
|
|
}
|
|
|
|
// Modify adds a statement modifier for attaching custom logic to the UPDATE statement.
|
|
func (_u *EventLogUpdateOne) Modify(modifiers ...func(u *sql.UpdateBuilder)) *EventLogUpdateOne {
|
|
_u.modifiers = append(_u.modifiers, modifiers...)
|
|
return _u
|
|
}
|
|
|
|
func (_u *EventLogUpdateOne) sqlSave(ctx context.Context) (_node *EventLog, err error) {
|
|
if err := _u.check(); err != nil {
|
|
return _node, err
|
|
}
|
|
_spec := sqlgraph.NewUpdateSpec(eventlog.Table, eventlog.Columns, sqlgraph.NewFieldSpec(eventlog.FieldID, field.TypeInt))
|
|
id, ok := _u.mutation.ID()
|
|
if !ok {
|
|
return nil, &ValidationError{Name: "id", err: errors.New(`ent: missing "EventLog.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, eventlog.FieldID)
|
|
for _, f := range fields {
|
|
if !eventlog.ValidColumn(f) {
|
|
return nil, &ValidationError{Name: f, err: fmt.Errorf("ent: invalid field %q for query", f)}
|
|
}
|
|
if f != eventlog.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.EventType(); ok {
|
|
_spec.SetField(eventlog.FieldEventType, field.TypeString, value)
|
|
}
|
|
if value, ok := _u.mutation.WorkOrderNo(); ok {
|
|
_spec.SetField(eventlog.FieldWorkOrderNo, field.TypeString, value)
|
|
}
|
|
if value, ok := _u.mutation.Operator(); ok {
|
|
_spec.SetField(eventlog.FieldOperator, field.TypeString, value)
|
|
}
|
|
if value, ok := _u.mutation.EntityType(); ok {
|
|
_spec.SetField(eventlog.FieldEntityType, field.TypeString, value)
|
|
}
|
|
if value, ok := _u.mutation.EntityId(); ok {
|
|
_spec.SetField(eventlog.FieldEntityId, field.TypeString, value)
|
|
}
|
|
if value, ok := _u.mutation.Description(); ok {
|
|
_spec.SetField(eventlog.FieldDescription, field.TypeString, value)
|
|
}
|
|
if value, ok := _u.mutation.Payload(); ok {
|
|
_spec.SetField(eventlog.FieldPayload, field.TypeJSON, value)
|
|
}
|
|
if _u.mutation.PayloadCleared() {
|
|
_spec.ClearField(eventlog.FieldPayload, field.TypeJSON)
|
|
}
|
|
_spec.AddModifiers(_u.modifiers...)
|
|
_node = &EventLog{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{eventlog.Label}
|
|
} else if sqlgraph.IsConstraintError(err) {
|
|
err = &ConstraintError{msg: err.Error(), wrap: err}
|
|
}
|
|
return nil, err
|
|
}
|
|
_u.mutation.done = true
|
|
return _node, nil
|
|
}
|