mirror of
https://gitee.com/wanwujie/sub2api
synced 2026-05-05 05:30:44 +08:00
640 lines
23 KiB
Go
640 lines
23 KiB
Go
|
|
// Code generated by ent, DO NOT EDIT.
|
||
|
|
|
||
|
|
package ent
|
||
|
|
|
||
|
|
import (
|
||
|
|
"context"
|
||
|
|
"errors"
|
||
|
|
"fmt"
|
||
|
|
"time"
|
||
|
|
|
||
|
|
"entgo.io/ent/dialect/sql"
|
||
|
|
"entgo.io/ent/dialect/sql/sqlgraph"
|
||
|
|
"entgo.io/ent/schema/field"
|
||
|
|
"github.com/Wei-Shaw/sub2api/ent/channelmonitor"
|
||
|
|
"github.com/Wei-Shaw/sub2api/ent/channelmonitorrequesttemplate"
|
||
|
|
"github.com/Wei-Shaw/sub2api/ent/predicate"
|
||
|
|
)
|
||
|
|
|
||
|
|
// ChannelMonitorRequestTemplateUpdate is the builder for updating ChannelMonitorRequestTemplate entities.
|
||
|
|
type ChannelMonitorRequestTemplateUpdate struct {
|
||
|
|
config
|
||
|
|
hooks []Hook
|
||
|
|
mutation *ChannelMonitorRequestTemplateMutation
|
||
|
|
}
|
||
|
|
|
||
|
|
// Where appends a list predicates to the ChannelMonitorRequestTemplateUpdate builder.
|
||
|
|
func (_u *ChannelMonitorRequestTemplateUpdate) Where(ps ...predicate.ChannelMonitorRequestTemplate) *ChannelMonitorRequestTemplateUpdate {
|
||
|
|
_u.mutation.Where(ps...)
|
||
|
|
return _u
|
||
|
|
}
|
||
|
|
|
||
|
|
// SetUpdatedAt sets the "updated_at" field.
|
||
|
|
func (_u *ChannelMonitorRequestTemplateUpdate) SetUpdatedAt(v time.Time) *ChannelMonitorRequestTemplateUpdate {
|
||
|
|
_u.mutation.SetUpdatedAt(v)
|
||
|
|
return _u
|
||
|
|
}
|
||
|
|
|
||
|
|
// SetName sets the "name" field.
|
||
|
|
func (_u *ChannelMonitorRequestTemplateUpdate) SetName(v string) *ChannelMonitorRequestTemplateUpdate {
|
||
|
|
_u.mutation.SetName(v)
|
||
|
|
return _u
|
||
|
|
}
|
||
|
|
|
||
|
|
// SetNillableName sets the "name" field if the given value is not nil.
|
||
|
|
func (_u *ChannelMonitorRequestTemplateUpdate) SetNillableName(v *string) *ChannelMonitorRequestTemplateUpdate {
|
||
|
|
if v != nil {
|
||
|
|
_u.SetName(*v)
|
||
|
|
}
|
||
|
|
return _u
|
||
|
|
}
|
||
|
|
|
||
|
|
// SetProvider sets the "provider" field.
|
||
|
|
func (_u *ChannelMonitorRequestTemplateUpdate) SetProvider(v channelmonitorrequesttemplate.Provider) *ChannelMonitorRequestTemplateUpdate {
|
||
|
|
_u.mutation.SetProvider(v)
|
||
|
|
return _u
|
||
|
|
}
|
||
|
|
|
||
|
|
// SetNillableProvider sets the "provider" field if the given value is not nil.
|
||
|
|
func (_u *ChannelMonitorRequestTemplateUpdate) SetNillableProvider(v *channelmonitorrequesttemplate.Provider) *ChannelMonitorRequestTemplateUpdate {
|
||
|
|
if v != nil {
|
||
|
|
_u.SetProvider(*v)
|
||
|
|
}
|
||
|
|
return _u
|
||
|
|
}
|
||
|
|
|
||
|
|
// SetDescription sets the "description" field.
|
||
|
|
func (_u *ChannelMonitorRequestTemplateUpdate) SetDescription(v string) *ChannelMonitorRequestTemplateUpdate {
|
||
|
|
_u.mutation.SetDescription(v)
|
||
|
|
return _u
|
||
|
|
}
|
||
|
|
|
||
|
|
// SetNillableDescription sets the "description" field if the given value is not nil.
|
||
|
|
func (_u *ChannelMonitorRequestTemplateUpdate) SetNillableDescription(v *string) *ChannelMonitorRequestTemplateUpdate {
|
||
|
|
if v != nil {
|
||
|
|
_u.SetDescription(*v)
|
||
|
|
}
|
||
|
|
return _u
|
||
|
|
}
|
||
|
|
|
||
|
|
// ClearDescription clears the value of the "description" field.
|
||
|
|
func (_u *ChannelMonitorRequestTemplateUpdate) ClearDescription() *ChannelMonitorRequestTemplateUpdate {
|
||
|
|
_u.mutation.ClearDescription()
|
||
|
|
return _u
|
||
|
|
}
|
||
|
|
|
||
|
|
// SetExtraHeaders sets the "extra_headers" field.
|
||
|
|
func (_u *ChannelMonitorRequestTemplateUpdate) SetExtraHeaders(v map[string]string) *ChannelMonitorRequestTemplateUpdate {
|
||
|
|
_u.mutation.SetExtraHeaders(v)
|
||
|
|
return _u
|
||
|
|
}
|
||
|
|
|
||
|
|
// SetBodyOverrideMode sets the "body_override_mode" field.
|
||
|
|
func (_u *ChannelMonitorRequestTemplateUpdate) SetBodyOverrideMode(v string) *ChannelMonitorRequestTemplateUpdate {
|
||
|
|
_u.mutation.SetBodyOverrideMode(v)
|
||
|
|
return _u
|
||
|
|
}
|
||
|
|
|
||
|
|
// SetNillableBodyOverrideMode sets the "body_override_mode" field if the given value is not nil.
|
||
|
|
func (_u *ChannelMonitorRequestTemplateUpdate) SetNillableBodyOverrideMode(v *string) *ChannelMonitorRequestTemplateUpdate {
|
||
|
|
if v != nil {
|
||
|
|
_u.SetBodyOverrideMode(*v)
|
||
|
|
}
|
||
|
|
return _u
|
||
|
|
}
|
||
|
|
|
||
|
|
// SetBodyOverride sets the "body_override" field.
|
||
|
|
func (_u *ChannelMonitorRequestTemplateUpdate) SetBodyOverride(v map[string]interface{}) *ChannelMonitorRequestTemplateUpdate {
|
||
|
|
_u.mutation.SetBodyOverride(v)
|
||
|
|
return _u
|
||
|
|
}
|
||
|
|
|
||
|
|
// ClearBodyOverride clears the value of the "body_override" field.
|
||
|
|
func (_u *ChannelMonitorRequestTemplateUpdate) ClearBodyOverride() *ChannelMonitorRequestTemplateUpdate {
|
||
|
|
_u.mutation.ClearBodyOverride()
|
||
|
|
return _u
|
||
|
|
}
|
||
|
|
|
||
|
|
// AddMonitorIDs adds the "monitors" edge to the ChannelMonitor entity by IDs.
|
||
|
|
func (_u *ChannelMonitorRequestTemplateUpdate) AddMonitorIDs(ids ...int64) *ChannelMonitorRequestTemplateUpdate {
|
||
|
|
_u.mutation.AddMonitorIDs(ids...)
|
||
|
|
return _u
|
||
|
|
}
|
||
|
|
|
||
|
|
// AddMonitors adds the "monitors" edges to the ChannelMonitor entity.
|
||
|
|
func (_u *ChannelMonitorRequestTemplateUpdate) AddMonitors(v ...*ChannelMonitor) *ChannelMonitorRequestTemplateUpdate {
|
||
|
|
ids := make([]int64, len(v))
|
||
|
|
for i := range v {
|
||
|
|
ids[i] = v[i].ID
|
||
|
|
}
|
||
|
|
return _u.AddMonitorIDs(ids...)
|
||
|
|
}
|
||
|
|
|
||
|
|
// Mutation returns the ChannelMonitorRequestTemplateMutation object of the builder.
|
||
|
|
func (_u *ChannelMonitorRequestTemplateUpdate) Mutation() *ChannelMonitorRequestTemplateMutation {
|
||
|
|
return _u.mutation
|
||
|
|
}
|
||
|
|
|
||
|
|
// ClearMonitors clears all "monitors" edges to the ChannelMonitor entity.
|
||
|
|
func (_u *ChannelMonitorRequestTemplateUpdate) ClearMonitors() *ChannelMonitorRequestTemplateUpdate {
|
||
|
|
_u.mutation.ClearMonitors()
|
||
|
|
return _u
|
||
|
|
}
|
||
|
|
|
||
|
|
// RemoveMonitorIDs removes the "monitors" edge to ChannelMonitor entities by IDs.
|
||
|
|
func (_u *ChannelMonitorRequestTemplateUpdate) RemoveMonitorIDs(ids ...int64) *ChannelMonitorRequestTemplateUpdate {
|
||
|
|
_u.mutation.RemoveMonitorIDs(ids...)
|
||
|
|
return _u
|
||
|
|
}
|
||
|
|
|
||
|
|
// RemoveMonitors removes "monitors" edges to ChannelMonitor entities.
|
||
|
|
func (_u *ChannelMonitorRequestTemplateUpdate) RemoveMonitors(v ...*ChannelMonitor) *ChannelMonitorRequestTemplateUpdate {
|
||
|
|
ids := make([]int64, len(v))
|
||
|
|
for i := range v {
|
||
|
|
ids[i] = v[i].ID
|
||
|
|
}
|
||
|
|
return _u.RemoveMonitorIDs(ids...)
|
||
|
|
}
|
||
|
|
|
||
|
|
// Save executes the query and returns the number of nodes affected by the update operation.
|
||
|
|
func (_u *ChannelMonitorRequestTemplateUpdate) Save(ctx context.Context) (int, error) {
|
||
|
|
_u.defaults()
|
||
|
|
return withHooks(ctx, _u.sqlSave, _u.mutation, _u.hooks)
|
||
|
|
}
|
||
|
|
|
||
|
|
// SaveX is like Save, but panics if an error occurs.
|
||
|
|
func (_u *ChannelMonitorRequestTemplateUpdate) SaveX(ctx context.Context) int {
|
||
|
|
affected, err := _u.Save(ctx)
|
||
|
|
if err != nil {
|
||
|
|
panic(err)
|
||
|
|
}
|
||
|
|
return affected
|
||
|
|
}
|
||
|
|
|
||
|
|
// Exec executes the query.
|
||
|
|
func (_u *ChannelMonitorRequestTemplateUpdate) Exec(ctx context.Context) error {
|
||
|
|
_, err := _u.Save(ctx)
|
||
|
|
return err
|
||
|
|
}
|
||
|
|
|
||
|
|
// ExecX is like Exec, but panics if an error occurs.
|
||
|
|
func (_u *ChannelMonitorRequestTemplateUpdate) ExecX(ctx context.Context) {
|
||
|
|
if err := _u.Exec(ctx); err != nil {
|
||
|
|
panic(err)
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
// defaults sets the default values of the builder before save.
|
||
|
|
func (_u *ChannelMonitorRequestTemplateUpdate) defaults() {
|
||
|
|
if _, ok := _u.mutation.UpdatedAt(); !ok {
|
||
|
|
v := channelmonitorrequesttemplate.UpdateDefaultUpdatedAt()
|
||
|
|
_u.mutation.SetUpdatedAt(v)
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
// check runs all checks and user-defined validators on the builder.
|
||
|
|
func (_u *ChannelMonitorRequestTemplateUpdate) check() error {
|
||
|
|
if v, ok := _u.mutation.Name(); ok {
|
||
|
|
if err := channelmonitorrequesttemplate.NameValidator(v); err != nil {
|
||
|
|
return &ValidationError{Name: "name", err: fmt.Errorf(`ent: validator failed for field "ChannelMonitorRequestTemplate.name": %w`, err)}
|
||
|
|
}
|
||
|
|
}
|
||
|
|
if v, ok := _u.mutation.Provider(); ok {
|
||
|
|
if err := channelmonitorrequesttemplate.ProviderValidator(v); err != nil {
|
||
|
|
return &ValidationError{Name: "provider", err: fmt.Errorf(`ent: validator failed for field "ChannelMonitorRequestTemplate.provider": %w`, err)}
|
||
|
|
}
|
||
|
|
}
|
||
|
|
if v, ok := _u.mutation.Description(); ok {
|
||
|
|
if err := channelmonitorrequesttemplate.DescriptionValidator(v); err != nil {
|
||
|
|
return &ValidationError{Name: "description", err: fmt.Errorf(`ent: validator failed for field "ChannelMonitorRequestTemplate.description": %w`, err)}
|
||
|
|
}
|
||
|
|
}
|
||
|
|
if v, ok := _u.mutation.BodyOverrideMode(); ok {
|
||
|
|
if err := channelmonitorrequesttemplate.BodyOverrideModeValidator(v); err != nil {
|
||
|
|
return &ValidationError{Name: "body_override_mode", err: fmt.Errorf(`ent: validator failed for field "ChannelMonitorRequestTemplate.body_override_mode": %w`, err)}
|
||
|
|
}
|
||
|
|
}
|
||
|
|
return nil
|
||
|
|
}
|
||
|
|
|
||
|
|
func (_u *ChannelMonitorRequestTemplateUpdate) sqlSave(ctx context.Context) (_node int, err error) {
|
||
|
|
if err := _u.check(); err != nil {
|
||
|
|
return _node, err
|
||
|
|
}
|
||
|
|
_spec := sqlgraph.NewUpdateSpec(channelmonitorrequesttemplate.Table, channelmonitorrequesttemplate.Columns, sqlgraph.NewFieldSpec(channelmonitorrequesttemplate.FieldID, field.TypeInt64))
|
||
|
|
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.UpdatedAt(); ok {
|
||
|
|
_spec.SetField(channelmonitorrequesttemplate.FieldUpdatedAt, field.TypeTime, value)
|
||
|
|
}
|
||
|
|
if value, ok := _u.mutation.Name(); ok {
|
||
|
|
_spec.SetField(channelmonitorrequesttemplate.FieldName, field.TypeString, value)
|
||
|
|
}
|
||
|
|
if value, ok := _u.mutation.Provider(); ok {
|
||
|
|
_spec.SetField(channelmonitorrequesttemplate.FieldProvider, field.TypeEnum, value)
|
||
|
|
}
|
||
|
|
if value, ok := _u.mutation.Description(); ok {
|
||
|
|
_spec.SetField(channelmonitorrequesttemplate.FieldDescription, field.TypeString, value)
|
||
|
|
}
|
||
|
|
if _u.mutation.DescriptionCleared() {
|
||
|
|
_spec.ClearField(channelmonitorrequesttemplate.FieldDescription, field.TypeString)
|
||
|
|
}
|
||
|
|
if value, ok := _u.mutation.ExtraHeaders(); ok {
|
||
|
|
_spec.SetField(channelmonitorrequesttemplate.FieldExtraHeaders, field.TypeJSON, value)
|
||
|
|
}
|
||
|
|
if value, ok := _u.mutation.BodyOverrideMode(); ok {
|
||
|
|
_spec.SetField(channelmonitorrequesttemplate.FieldBodyOverrideMode, field.TypeString, value)
|
||
|
|
}
|
||
|
|
if value, ok := _u.mutation.BodyOverride(); ok {
|
||
|
|
_spec.SetField(channelmonitorrequesttemplate.FieldBodyOverride, field.TypeJSON, value)
|
||
|
|
}
|
||
|
|
if _u.mutation.BodyOverrideCleared() {
|
||
|
|
_spec.ClearField(channelmonitorrequesttemplate.FieldBodyOverride, field.TypeJSON)
|
||
|
|
}
|
||
|
|
if _u.mutation.MonitorsCleared() {
|
||
|
|
edge := &sqlgraph.EdgeSpec{
|
||
|
|
Rel: sqlgraph.O2M,
|
||
|
|
Inverse: true,
|
||
|
|
Table: channelmonitorrequesttemplate.MonitorsTable,
|
||
|
|
Columns: []string{channelmonitorrequesttemplate.MonitorsColumn},
|
||
|
|
Bidi: false,
|
||
|
|
Target: &sqlgraph.EdgeTarget{
|
||
|
|
IDSpec: sqlgraph.NewFieldSpec(channelmonitor.FieldID, field.TypeInt64),
|
||
|
|
},
|
||
|
|
}
|
||
|
|
_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
|
||
|
|
}
|
||
|
|
if nodes := _u.mutation.RemovedMonitorsIDs(); len(nodes) > 0 && !_u.mutation.MonitorsCleared() {
|
||
|
|
edge := &sqlgraph.EdgeSpec{
|
||
|
|
Rel: sqlgraph.O2M,
|
||
|
|
Inverse: true,
|
||
|
|
Table: channelmonitorrequesttemplate.MonitorsTable,
|
||
|
|
Columns: []string{channelmonitorrequesttemplate.MonitorsColumn},
|
||
|
|
Bidi: false,
|
||
|
|
Target: &sqlgraph.EdgeTarget{
|
||
|
|
IDSpec: sqlgraph.NewFieldSpec(channelmonitor.FieldID, field.TypeInt64),
|
||
|
|
},
|
||
|
|
}
|
||
|
|
for _, k := range nodes {
|
||
|
|
edge.Target.Nodes = append(edge.Target.Nodes, k)
|
||
|
|
}
|
||
|
|
_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
|
||
|
|
}
|
||
|
|
if nodes := _u.mutation.MonitorsIDs(); len(nodes) > 0 {
|
||
|
|
edge := &sqlgraph.EdgeSpec{
|
||
|
|
Rel: sqlgraph.O2M,
|
||
|
|
Inverse: true,
|
||
|
|
Table: channelmonitorrequesttemplate.MonitorsTable,
|
||
|
|
Columns: []string{channelmonitorrequesttemplate.MonitorsColumn},
|
||
|
|
Bidi: false,
|
||
|
|
Target: &sqlgraph.EdgeTarget{
|
||
|
|
IDSpec: sqlgraph.NewFieldSpec(channelmonitor.FieldID, field.TypeInt64),
|
||
|
|
},
|
||
|
|
}
|
||
|
|
for _, k := range nodes {
|
||
|
|
edge.Target.Nodes = append(edge.Target.Nodes, k)
|
||
|
|
}
|
||
|
|
_spec.Edges.Add = append(_spec.Edges.Add, edge)
|
||
|
|
}
|
||
|
|
if _node, err = sqlgraph.UpdateNodes(ctx, _u.driver, _spec); err != nil {
|
||
|
|
if _, ok := err.(*sqlgraph.NotFoundError); ok {
|
||
|
|
err = &NotFoundError{channelmonitorrequesttemplate.Label}
|
||
|
|
} else if sqlgraph.IsConstraintError(err) {
|
||
|
|
err = &ConstraintError{msg: err.Error(), wrap: err}
|
||
|
|
}
|
||
|
|
return 0, err
|
||
|
|
}
|
||
|
|
_u.mutation.done = true
|
||
|
|
return _node, nil
|
||
|
|
}
|
||
|
|
|
||
|
|
// ChannelMonitorRequestTemplateUpdateOne is the builder for updating a single ChannelMonitorRequestTemplate entity.
|
||
|
|
type ChannelMonitorRequestTemplateUpdateOne struct {
|
||
|
|
config
|
||
|
|
fields []string
|
||
|
|
hooks []Hook
|
||
|
|
mutation *ChannelMonitorRequestTemplateMutation
|
||
|
|
}
|
||
|
|
|
||
|
|
// SetUpdatedAt sets the "updated_at" field.
|
||
|
|
func (_u *ChannelMonitorRequestTemplateUpdateOne) SetUpdatedAt(v time.Time) *ChannelMonitorRequestTemplateUpdateOne {
|
||
|
|
_u.mutation.SetUpdatedAt(v)
|
||
|
|
return _u
|
||
|
|
}
|
||
|
|
|
||
|
|
// SetName sets the "name" field.
|
||
|
|
func (_u *ChannelMonitorRequestTemplateUpdateOne) SetName(v string) *ChannelMonitorRequestTemplateUpdateOne {
|
||
|
|
_u.mutation.SetName(v)
|
||
|
|
return _u
|
||
|
|
}
|
||
|
|
|
||
|
|
// SetNillableName sets the "name" field if the given value is not nil.
|
||
|
|
func (_u *ChannelMonitorRequestTemplateUpdateOne) SetNillableName(v *string) *ChannelMonitorRequestTemplateUpdateOne {
|
||
|
|
if v != nil {
|
||
|
|
_u.SetName(*v)
|
||
|
|
}
|
||
|
|
return _u
|
||
|
|
}
|
||
|
|
|
||
|
|
// SetProvider sets the "provider" field.
|
||
|
|
func (_u *ChannelMonitorRequestTemplateUpdateOne) SetProvider(v channelmonitorrequesttemplate.Provider) *ChannelMonitorRequestTemplateUpdateOne {
|
||
|
|
_u.mutation.SetProvider(v)
|
||
|
|
return _u
|
||
|
|
}
|
||
|
|
|
||
|
|
// SetNillableProvider sets the "provider" field if the given value is not nil.
|
||
|
|
func (_u *ChannelMonitorRequestTemplateUpdateOne) SetNillableProvider(v *channelmonitorrequesttemplate.Provider) *ChannelMonitorRequestTemplateUpdateOne {
|
||
|
|
if v != nil {
|
||
|
|
_u.SetProvider(*v)
|
||
|
|
}
|
||
|
|
return _u
|
||
|
|
}
|
||
|
|
|
||
|
|
// SetDescription sets the "description" field.
|
||
|
|
func (_u *ChannelMonitorRequestTemplateUpdateOne) SetDescription(v string) *ChannelMonitorRequestTemplateUpdateOne {
|
||
|
|
_u.mutation.SetDescription(v)
|
||
|
|
return _u
|
||
|
|
}
|
||
|
|
|
||
|
|
// SetNillableDescription sets the "description" field if the given value is not nil.
|
||
|
|
func (_u *ChannelMonitorRequestTemplateUpdateOne) SetNillableDescription(v *string) *ChannelMonitorRequestTemplateUpdateOne {
|
||
|
|
if v != nil {
|
||
|
|
_u.SetDescription(*v)
|
||
|
|
}
|
||
|
|
return _u
|
||
|
|
}
|
||
|
|
|
||
|
|
// ClearDescription clears the value of the "description" field.
|
||
|
|
func (_u *ChannelMonitorRequestTemplateUpdateOne) ClearDescription() *ChannelMonitorRequestTemplateUpdateOne {
|
||
|
|
_u.mutation.ClearDescription()
|
||
|
|
return _u
|
||
|
|
}
|
||
|
|
|
||
|
|
// SetExtraHeaders sets the "extra_headers" field.
|
||
|
|
func (_u *ChannelMonitorRequestTemplateUpdateOne) SetExtraHeaders(v map[string]string) *ChannelMonitorRequestTemplateUpdateOne {
|
||
|
|
_u.mutation.SetExtraHeaders(v)
|
||
|
|
return _u
|
||
|
|
}
|
||
|
|
|
||
|
|
// SetBodyOverrideMode sets the "body_override_mode" field.
|
||
|
|
func (_u *ChannelMonitorRequestTemplateUpdateOne) SetBodyOverrideMode(v string) *ChannelMonitorRequestTemplateUpdateOne {
|
||
|
|
_u.mutation.SetBodyOverrideMode(v)
|
||
|
|
return _u
|
||
|
|
}
|
||
|
|
|
||
|
|
// SetNillableBodyOverrideMode sets the "body_override_mode" field if the given value is not nil.
|
||
|
|
func (_u *ChannelMonitorRequestTemplateUpdateOne) SetNillableBodyOverrideMode(v *string) *ChannelMonitorRequestTemplateUpdateOne {
|
||
|
|
if v != nil {
|
||
|
|
_u.SetBodyOverrideMode(*v)
|
||
|
|
}
|
||
|
|
return _u
|
||
|
|
}
|
||
|
|
|
||
|
|
// SetBodyOverride sets the "body_override" field.
|
||
|
|
func (_u *ChannelMonitorRequestTemplateUpdateOne) SetBodyOverride(v map[string]interface{}) *ChannelMonitorRequestTemplateUpdateOne {
|
||
|
|
_u.mutation.SetBodyOverride(v)
|
||
|
|
return _u
|
||
|
|
}
|
||
|
|
|
||
|
|
// ClearBodyOverride clears the value of the "body_override" field.
|
||
|
|
func (_u *ChannelMonitorRequestTemplateUpdateOne) ClearBodyOverride() *ChannelMonitorRequestTemplateUpdateOne {
|
||
|
|
_u.mutation.ClearBodyOverride()
|
||
|
|
return _u
|
||
|
|
}
|
||
|
|
|
||
|
|
// AddMonitorIDs adds the "monitors" edge to the ChannelMonitor entity by IDs.
|
||
|
|
func (_u *ChannelMonitorRequestTemplateUpdateOne) AddMonitorIDs(ids ...int64) *ChannelMonitorRequestTemplateUpdateOne {
|
||
|
|
_u.mutation.AddMonitorIDs(ids...)
|
||
|
|
return _u
|
||
|
|
}
|
||
|
|
|
||
|
|
// AddMonitors adds the "monitors" edges to the ChannelMonitor entity.
|
||
|
|
func (_u *ChannelMonitorRequestTemplateUpdateOne) AddMonitors(v ...*ChannelMonitor) *ChannelMonitorRequestTemplateUpdateOne {
|
||
|
|
ids := make([]int64, len(v))
|
||
|
|
for i := range v {
|
||
|
|
ids[i] = v[i].ID
|
||
|
|
}
|
||
|
|
return _u.AddMonitorIDs(ids...)
|
||
|
|
}
|
||
|
|
|
||
|
|
// Mutation returns the ChannelMonitorRequestTemplateMutation object of the builder.
|
||
|
|
func (_u *ChannelMonitorRequestTemplateUpdateOne) Mutation() *ChannelMonitorRequestTemplateMutation {
|
||
|
|
return _u.mutation
|
||
|
|
}
|
||
|
|
|
||
|
|
// ClearMonitors clears all "monitors" edges to the ChannelMonitor entity.
|
||
|
|
func (_u *ChannelMonitorRequestTemplateUpdateOne) ClearMonitors() *ChannelMonitorRequestTemplateUpdateOne {
|
||
|
|
_u.mutation.ClearMonitors()
|
||
|
|
return _u
|
||
|
|
}
|
||
|
|
|
||
|
|
// RemoveMonitorIDs removes the "monitors" edge to ChannelMonitor entities by IDs.
|
||
|
|
func (_u *ChannelMonitorRequestTemplateUpdateOne) RemoveMonitorIDs(ids ...int64) *ChannelMonitorRequestTemplateUpdateOne {
|
||
|
|
_u.mutation.RemoveMonitorIDs(ids...)
|
||
|
|
return _u
|
||
|
|
}
|
||
|
|
|
||
|
|
// RemoveMonitors removes "monitors" edges to ChannelMonitor entities.
|
||
|
|
func (_u *ChannelMonitorRequestTemplateUpdateOne) RemoveMonitors(v ...*ChannelMonitor) *ChannelMonitorRequestTemplateUpdateOne {
|
||
|
|
ids := make([]int64, len(v))
|
||
|
|
for i := range v {
|
||
|
|
ids[i] = v[i].ID
|
||
|
|
}
|
||
|
|
return _u.RemoveMonitorIDs(ids...)
|
||
|
|
}
|
||
|
|
|
||
|
|
// Where appends a list predicates to the ChannelMonitorRequestTemplateUpdate builder.
|
||
|
|
func (_u *ChannelMonitorRequestTemplateUpdateOne) Where(ps ...predicate.ChannelMonitorRequestTemplate) *ChannelMonitorRequestTemplateUpdateOne {
|
||
|
|
_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 *ChannelMonitorRequestTemplateUpdateOne) Select(field string, fields ...string) *ChannelMonitorRequestTemplateUpdateOne {
|
||
|
|
_u.fields = append([]string{field}, fields...)
|
||
|
|
return _u
|
||
|
|
}
|
||
|
|
|
||
|
|
// Save executes the query and returns the updated ChannelMonitorRequestTemplate entity.
|
||
|
|
func (_u *ChannelMonitorRequestTemplateUpdateOne) Save(ctx context.Context) (*ChannelMonitorRequestTemplate, error) {
|
||
|
|
_u.defaults()
|
||
|
|
return withHooks(ctx, _u.sqlSave, _u.mutation, _u.hooks)
|
||
|
|
}
|
||
|
|
|
||
|
|
// SaveX is like Save, but panics if an error occurs.
|
||
|
|
func (_u *ChannelMonitorRequestTemplateUpdateOne) SaveX(ctx context.Context) *ChannelMonitorRequestTemplate {
|
||
|
|
node, err := _u.Save(ctx)
|
||
|
|
if err != nil {
|
||
|
|
panic(err)
|
||
|
|
}
|
||
|
|
return node
|
||
|
|
}
|
||
|
|
|
||
|
|
// Exec executes the query on the entity.
|
||
|
|
func (_u *ChannelMonitorRequestTemplateUpdateOne) Exec(ctx context.Context) error {
|
||
|
|
_, err := _u.Save(ctx)
|
||
|
|
return err
|
||
|
|
}
|
||
|
|
|
||
|
|
// ExecX is like Exec, but panics if an error occurs.
|
||
|
|
func (_u *ChannelMonitorRequestTemplateUpdateOne) ExecX(ctx context.Context) {
|
||
|
|
if err := _u.Exec(ctx); err != nil {
|
||
|
|
panic(err)
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
// defaults sets the default values of the builder before save.
|
||
|
|
func (_u *ChannelMonitorRequestTemplateUpdateOne) defaults() {
|
||
|
|
if _, ok := _u.mutation.UpdatedAt(); !ok {
|
||
|
|
v := channelmonitorrequesttemplate.UpdateDefaultUpdatedAt()
|
||
|
|
_u.mutation.SetUpdatedAt(v)
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
// check runs all checks and user-defined validators on the builder.
|
||
|
|
func (_u *ChannelMonitorRequestTemplateUpdateOne) check() error {
|
||
|
|
if v, ok := _u.mutation.Name(); ok {
|
||
|
|
if err := channelmonitorrequesttemplate.NameValidator(v); err != nil {
|
||
|
|
return &ValidationError{Name: "name", err: fmt.Errorf(`ent: validator failed for field "ChannelMonitorRequestTemplate.name": %w`, err)}
|
||
|
|
}
|
||
|
|
}
|
||
|
|
if v, ok := _u.mutation.Provider(); ok {
|
||
|
|
if err := channelmonitorrequesttemplate.ProviderValidator(v); err != nil {
|
||
|
|
return &ValidationError{Name: "provider", err: fmt.Errorf(`ent: validator failed for field "ChannelMonitorRequestTemplate.provider": %w`, err)}
|
||
|
|
}
|
||
|
|
}
|
||
|
|
if v, ok := _u.mutation.Description(); ok {
|
||
|
|
if err := channelmonitorrequesttemplate.DescriptionValidator(v); err != nil {
|
||
|
|
return &ValidationError{Name: "description", err: fmt.Errorf(`ent: validator failed for field "ChannelMonitorRequestTemplate.description": %w`, err)}
|
||
|
|
}
|
||
|
|
}
|
||
|
|
if v, ok := _u.mutation.BodyOverrideMode(); ok {
|
||
|
|
if err := channelmonitorrequesttemplate.BodyOverrideModeValidator(v); err != nil {
|
||
|
|
return &ValidationError{Name: "body_override_mode", err: fmt.Errorf(`ent: validator failed for field "ChannelMonitorRequestTemplate.body_override_mode": %w`, err)}
|
||
|
|
}
|
||
|
|
}
|
||
|
|
return nil
|
||
|
|
}
|
||
|
|
|
||
|
|
func (_u *ChannelMonitorRequestTemplateUpdateOne) sqlSave(ctx context.Context) (_node *ChannelMonitorRequestTemplate, err error) {
|
||
|
|
if err := _u.check(); err != nil {
|
||
|
|
return _node, err
|
||
|
|
}
|
||
|
|
_spec := sqlgraph.NewUpdateSpec(channelmonitorrequesttemplate.Table, channelmonitorrequesttemplate.Columns, sqlgraph.NewFieldSpec(channelmonitorrequesttemplate.FieldID, field.TypeInt64))
|
||
|
|
id, ok := _u.mutation.ID()
|
||
|
|
if !ok {
|
||
|
|
return nil, &ValidationError{Name: "id", err: errors.New(`ent: missing "ChannelMonitorRequestTemplate.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, channelmonitorrequesttemplate.FieldID)
|
||
|
|
for _, f := range fields {
|
||
|
|
if !channelmonitorrequesttemplate.ValidColumn(f) {
|
||
|
|
return nil, &ValidationError{Name: f, err: fmt.Errorf("ent: invalid field %q for query", f)}
|
||
|
|
}
|
||
|
|
if f != channelmonitorrequesttemplate.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.UpdatedAt(); ok {
|
||
|
|
_spec.SetField(channelmonitorrequesttemplate.FieldUpdatedAt, field.TypeTime, value)
|
||
|
|
}
|
||
|
|
if value, ok := _u.mutation.Name(); ok {
|
||
|
|
_spec.SetField(channelmonitorrequesttemplate.FieldName, field.TypeString, value)
|
||
|
|
}
|
||
|
|
if value, ok := _u.mutation.Provider(); ok {
|
||
|
|
_spec.SetField(channelmonitorrequesttemplate.FieldProvider, field.TypeEnum, value)
|
||
|
|
}
|
||
|
|
if value, ok := _u.mutation.Description(); ok {
|
||
|
|
_spec.SetField(channelmonitorrequesttemplate.FieldDescription, field.TypeString, value)
|
||
|
|
}
|
||
|
|
if _u.mutation.DescriptionCleared() {
|
||
|
|
_spec.ClearField(channelmonitorrequesttemplate.FieldDescription, field.TypeString)
|
||
|
|
}
|
||
|
|
if value, ok := _u.mutation.ExtraHeaders(); ok {
|
||
|
|
_spec.SetField(channelmonitorrequesttemplate.FieldExtraHeaders, field.TypeJSON, value)
|
||
|
|
}
|
||
|
|
if value, ok := _u.mutation.BodyOverrideMode(); ok {
|
||
|
|
_spec.SetField(channelmonitorrequesttemplate.FieldBodyOverrideMode, field.TypeString, value)
|
||
|
|
}
|
||
|
|
if value, ok := _u.mutation.BodyOverride(); ok {
|
||
|
|
_spec.SetField(channelmonitorrequesttemplate.FieldBodyOverride, field.TypeJSON, value)
|
||
|
|
}
|
||
|
|
if _u.mutation.BodyOverrideCleared() {
|
||
|
|
_spec.ClearField(channelmonitorrequesttemplate.FieldBodyOverride, field.TypeJSON)
|
||
|
|
}
|
||
|
|
if _u.mutation.MonitorsCleared() {
|
||
|
|
edge := &sqlgraph.EdgeSpec{
|
||
|
|
Rel: sqlgraph.O2M,
|
||
|
|
Inverse: true,
|
||
|
|
Table: channelmonitorrequesttemplate.MonitorsTable,
|
||
|
|
Columns: []string{channelmonitorrequesttemplate.MonitorsColumn},
|
||
|
|
Bidi: false,
|
||
|
|
Target: &sqlgraph.EdgeTarget{
|
||
|
|
IDSpec: sqlgraph.NewFieldSpec(channelmonitor.FieldID, field.TypeInt64),
|
||
|
|
},
|
||
|
|
}
|
||
|
|
_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
|
||
|
|
}
|
||
|
|
if nodes := _u.mutation.RemovedMonitorsIDs(); len(nodes) > 0 && !_u.mutation.MonitorsCleared() {
|
||
|
|
edge := &sqlgraph.EdgeSpec{
|
||
|
|
Rel: sqlgraph.O2M,
|
||
|
|
Inverse: true,
|
||
|
|
Table: channelmonitorrequesttemplate.MonitorsTable,
|
||
|
|
Columns: []string{channelmonitorrequesttemplate.MonitorsColumn},
|
||
|
|
Bidi: false,
|
||
|
|
Target: &sqlgraph.EdgeTarget{
|
||
|
|
IDSpec: sqlgraph.NewFieldSpec(channelmonitor.FieldID, field.TypeInt64),
|
||
|
|
},
|
||
|
|
}
|
||
|
|
for _, k := range nodes {
|
||
|
|
edge.Target.Nodes = append(edge.Target.Nodes, k)
|
||
|
|
}
|
||
|
|
_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
|
||
|
|
}
|
||
|
|
if nodes := _u.mutation.MonitorsIDs(); len(nodes) > 0 {
|
||
|
|
edge := &sqlgraph.EdgeSpec{
|
||
|
|
Rel: sqlgraph.O2M,
|
||
|
|
Inverse: true,
|
||
|
|
Table: channelmonitorrequesttemplate.MonitorsTable,
|
||
|
|
Columns: []string{channelmonitorrequesttemplate.MonitorsColumn},
|
||
|
|
Bidi: false,
|
||
|
|
Target: &sqlgraph.EdgeTarget{
|
||
|
|
IDSpec: sqlgraph.NewFieldSpec(channelmonitor.FieldID, field.TypeInt64),
|
||
|
|
},
|
||
|
|
}
|
||
|
|
for _, k := range nodes {
|
||
|
|
edge.Target.Nodes = append(edge.Target.Nodes, k)
|
||
|
|
}
|
||
|
|
_spec.Edges.Add = append(_spec.Edges.Add, edge)
|
||
|
|
}
|
||
|
|
_node = &ChannelMonitorRequestTemplate{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{channelmonitorrequesttemplate.Label}
|
||
|
|
} else if sqlgraph.IsConstraintError(err) {
|
||
|
|
err = &ConstraintError{msg: err.Error(), wrap: err}
|
||
|
|
}
|
||
|
|
return nil, err
|
||
|
|
}
|
||
|
|
_u.mutation.done = true
|
||
|
|
return _node, nil
|
||
|
|
}
|