// 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" ) // ChannelMonitorRequestTemplateCreate is the builder for creating a ChannelMonitorRequestTemplate entity. type ChannelMonitorRequestTemplateCreate struct { config mutation *ChannelMonitorRequestTemplateMutation hooks []Hook conflict []sql.ConflictOption } // SetCreatedAt sets the "created_at" field. func (_c *ChannelMonitorRequestTemplateCreate) SetCreatedAt(v time.Time) *ChannelMonitorRequestTemplateCreate { _c.mutation.SetCreatedAt(v) return _c } // SetNillableCreatedAt sets the "created_at" field if the given value is not nil. func (_c *ChannelMonitorRequestTemplateCreate) SetNillableCreatedAt(v *time.Time) *ChannelMonitorRequestTemplateCreate { if v != nil { _c.SetCreatedAt(*v) } return _c } // SetUpdatedAt sets the "updated_at" field. func (_c *ChannelMonitorRequestTemplateCreate) SetUpdatedAt(v time.Time) *ChannelMonitorRequestTemplateCreate { _c.mutation.SetUpdatedAt(v) return _c } // SetNillableUpdatedAt sets the "updated_at" field if the given value is not nil. func (_c *ChannelMonitorRequestTemplateCreate) SetNillableUpdatedAt(v *time.Time) *ChannelMonitorRequestTemplateCreate { if v != nil { _c.SetUpdatedAt(*v) } return _c } // SetName sets the "name" field. func (_c *ChannelMonitorRequestTemplateCreate) SetName(v string) *ChannelMonitorRequestTemplateCreate { _c.mutation.SetName(v) return _c } // SetProvider sets the "provider" field. func (_c *ChannelMonitorRequestTemplateCreate) SetProvider(v channelmonitorrequesttemplate.Provider) *ChannelMonitorRequestTemplateCreate { _c.mutation.SetProvider(v) return _c } // SetDescription sets the "description" field. func (_c *ChannelMonitorRequestTemplateCreate) SetDescription(v string) *ChannelMonitorRequestTemplateCreate { _c.mutation.SetDescription(v) return _c } // SetNillableDescription sets the "description" field if the given value is not nil. func (_c *ChannelMonitorRequestTemplateCreate) SetNillableDescription(v *string) *ChannelMonitorRequestTemplateCreate { if v != nil { _c.SetDescription(*v) } return _c } // SetExtraHeaders sets the "extra_headers" field. func (_c *ChannelMonitorRequestTemplateCreate) SetExtraHeaders(v map[string]string) *ChannelMonitorRequestTemplateCreate { _c.mutation.SetExtraHeaders(v) return _c } // SetBodyOverrideMode sets the "body_override_mode" field. func (_c *ChannelMonitorRequestTemplateCreate) SetBodyOverrideMode(v string) *ChannelMonitorRequestTemplateCreate { _c.mutation.SetBodyOverrideMode(v) return _c } // SetNillableBodyOverrideMode sets the "body_override_mode" field if the given value is not nil. func (_c *ChannelMonitorRequestTemplateCreate) SetNillableBodyOverrideMode(v *string) *ChannelMonitorRequestTemplateCreate { if v != nil { _c.SetBodyOverrideMode(*v) } return _c } // SetBodyOverride sets the "body_override" field. func (_c *ChannelMonitorRequestTemplateCreate) SetBodyOverride(v map[string]interface{}) *ChannelMonitorRequestTemplateCreate { _c.mutation.SetBodyOverride(v) return _c } // AddMonitorIDs adds the "monitors" edge to the ChannelMonitor entity by IDs. func (_c *ChannelMonitorRequestTemplateCreate) AddMonitorIDs(ids ...int64) *ChannelMonitorRequestTemplateCreate { _c.mutation.AddMonitorIDs(ids...) return _c } // AddMonitors adds the "monitors" edges to the ChannelMonitor entity. func (_c *ChannelMonitorRequestTemplateCreate) AddMonitors(v ...*ChannelMonitor) *ChannelMonitorRequestTemplateCreate { ids := make([]int64, len(v)) for i := range v { ids[i] = v[i].ID } return _c.AddMonitorIDs(ids...) } // Mutation returns the ChannelMonitorRequestTemplateMutation object of the builder. func (_c *ChannelMonitorRequestTemplateCreate) Mutation() *ChannelMonitorRequestTemplateMutation { return _c.mutation } // Save creates the ChannelMonitorRequestTemplate in the database. func (_c *ChannelMonitorRequestTemplateCreate) Save(ctx context.Context) (*ChannelMonitorRequestTemplate, error) { _c.defaults() return withHooks(ctx, _c.sqlSave, _c.mutation, _c.hooks) } // SaveX calls Save and panics if Save returns an error. func (_c *ChannelMonitorRequestTemplateCreate) SaveX(ctx context.Context) *ChannelMonitorRequestTemplate { v, err := _c.Save(ctx) if err != nil { panic(err) } return v } // Exec executes the query. func (_c *ChannelMonitorRequestTemplateCreate) Exec(ctx context.Context) error { _, err := _c.Save(ctx) return err } // ExecX is like Exec, but panics if an error occurs. func (_c *ChannelMonitorRequestTemplateCreate) ExecX(ctx context.Context) { if err := _c.Exec(ctx); err != nil { panic(err) } } // defaults sets the default values of the builder before save. func (_c *ChannelMonitorRequestTemplateCreate) defaults() { if _, ok := _c.mutation.CreatedAt(); !ok { v := channelmonitorrequesttemplate.DefaultCreatedAt() _c.mutation.SetCreatedAt(v) } if _, ok := _c.mutation.UpdatedAt(); !ok { v := channelmonitorrequesttemplate.DefaultUpdatedAt() _c.mutation.SetUpdatedAt(v) } if _, ok := _c.mutation.Description(); !ok { v := channelmonitorrequesttemplate.DefaultDescription _c.mutation.SetDescription(v) } if _, ok := _c.mutation.ExtraHeaders(); !ok { v := channelmonitorrequesttemplate.DefaultExtraHeaders _c.mutation.SetExtraHeaders(v) } if _, ok := _c.mutation.BodyOverrideMode(); !ok { v := channelmonitorrequesttemplate.DefaultBodyOverrideMode _c.mutation.SetBodyOverrideMode(v) } } // check runs all checks and user-defined validators on the builder. func (_c *ChannelMonitorRequestTemplateCreate) check() error { if _, ok := _c.mutation.CreatedAt(); !ok { return &ValidationError{Name: "created_at", err: errors.New(`ent: missing required field "ChannelMonitorRequestTemplate.created_at"`)} } if _, ok := _c.mutation.UpdatedAt(); !ok { return &ValidationError{Name: "updated_at", err: errors.New(`ent: missing required field "ChannelMonitorRequestTemplate.updated_at"`)} } if _, ok := _c.mutation.Name(); !ok { return &ValidationError{Name: "name", err: errors.New(`ent: missing required field "ChannelMonitorRequestTemplate.name"`)} } if v, ok := _c.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 _, ok := _c.mutation.Provider(); !ok { return &ValidationError{Name: "provider", err: errors.New(`ent: missing required field "ChannelMonitorRequestTemplate.provider"`)} } if v, ok := _c.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 := _c.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 _, ok := _c.mutation.ExtraHeaders(); !ok { return &ValidationError{Name: "extra_headers", err: errors.New(`ent: missing required field "ChannelMonitorRequestTemplate.extra_headers"`)} } if _, ok := _c.mutation.BodyOverrideMode(); !ok { return &ValidationError{Name: "body_override_mode", err: errors.New(`ent: missing required field "ChannelMonitorRequestTemplate.body_override_mode"`)} } if v, ok := _c.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 (_c *ChannelMonitorRequestTemplateCreate) sqlSave(ctx context.Context) (*ChannelMonitorRequestTemplate, error) { if err := _c.check(); err != nil { return nil, err } _node, _spec := _c.createSpec() if err := sqlgraph.CreateNode(ctx, _c.driver, _spec); err != nil { if sqlgraph.IsConstraintError(err) { err = &ConstraintError{msg: err.Error(), wrap: err} } return nil, err } id := _spec.ID.Value.(int64) _node.ID = int64(id) _c.mutation.id = &_node.ID _c.mutation.done = true return _node, nil } func (_c *ChannelMonitorRequestTemplateCreate) createSpec() (*ChannelMonitorRequestTemplate, *sqlgraph.CreateSpec) { var ( _node = &ChannelMonitorRequestTemplate{config: _c.config} _spec = sqlgraph.NewCreateSpec(channelmonitorrequesttemplate.Table, sqlgraph.NewFieldSpec(channelmonitorrequesttemplate.FieldID, field.TypeInt64)) ) _spec.OnConflict = _c.conflict if value, ok := _c.mutation.CreatedAt(); ok { _spec.SetField(channelmonitorrequesttemplate.FieldCreatedAt, field.TypeTime, value) _node.CreatedAt = value } if value, ok := _c.mutation.UpdatedAt(); ok { _spec.SetField(channelmonitorrequesttemplate.FieldUpdatedAt, field.TypeTime, value) _node.UpdatedAt = value } if value, ok := _c.mutation.Name(); ok { _spec.SetField(channelmonitorrequesttemplate.FieldName, field.TypeString, value) _node.Name = value } if value, ok := _c.mutation.Provider(); ok { _spec.SetField(channelmonitorrequesttemplate.FieldProvider, field.TypeEnum, value) _node.Provider = value } if value, ok := _c.mutation.Description(); ok { _spec.SetField(channelmonitorrequesttemplate.FieldDescription, field.TypeString, value) _node.Description = value } if value, ok := _c.mutation.ExtraHeaders(); ok { _spec.SetField(channelmonitorrequesttemplate.FieldExtraHeaders, field.TypeJSON, value) _node.ExtraHeaders = value } if value, ok := _c.mutation.BodyOverrideMode(); ok { _spec.SetField(channelmonitorrequesttemplate.FieldBodyOverrideMode, field.TypeString, value) _node.BodyOverrideMode = value } if value, ok := _c.mutation.BodyOverride(); ok { _spec.SetField(channelmonitorrequesttemplate.FieldBodyOverride, field.TypeJSON, value) _node.BodyOverride = value } if nodes := _c.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 = append(_spec.Edges, edge) } return _node, _spec } // OnConflict allows configuring the `ON CONFLICT` / `ON DUPLICATE KEY` clause // of the `INSERT` statement. For example: // // client.ChannelMonitorRequestTemplate.Create(). // SetCreatedAt(v). // OnConflict( // // Update the row with the new values // // the was proposed for insertion. // sql.ResolveWithNewValues(), // ). // // Override some of the fields with custom // // update values. // Update(func(u *ent.ChannelMonitorRequestTemplateUpsert) { // SetCreatedAt(v+v). // }). // Exec(ctx) func (_c *ChannelMonitorRequestTemplateCreate) OnConflict(opts ...sql.ConflictOption) *ChannelMonitorRequestTemplateUpsertOne { _c.conflict = opts return &ChannelMonitorRequestTemplateUpsertOne{ create: _c, } } // OnConflictColumns calls `OnConflict` and configures the columns // as conflict target. Using this option is equivalent to using: // // client.ChannelMonitorRequestTemplate.Create(). // OnConflict(sql.ConflictColumns(columns...)). // Exec(ctx) func (_c *ChannelMonitorRequestTemplateCreate) OnConflictColumns(columns ...string) *ChannelMonitorRequestTemplateUpsertOne { _c.conflict = append(_c.conflict, sql.ConflictColumns(columns...)) return &ChannelMonitorRequestTemplateUpsertOne{ create: _c, } } type ( // ChannelMonitorRequestTemplateUpsertOne is the builder for "upsert"-ing // one ChannelMonitorRequestTemplate node. ChannelMonitorRequestTemplateUpsertOne struct { create *ChannelMonitorRequestTemplateCreate } // ChannelMonitorRequestTemplateUpsert is the "OnConflict" setter. ChannelMonitorRequestTemplateUpsert struct { *sql.UpdateSet } ) // SetUpdatedAt sets the "updated_at" field. func (u *ChannelMonitorRequestTemplateUpsert) SetUpdatedAt(v time.Time) *ChannelMonitorRequestTemplateUpsert { u.Set(channelmonitorrequesttemplate.FieldUpdatedAt, v) return u } // UpdateUpdatedAt sets the "updated_at" field to the value that was provided on create. func (u *ChannelMonitorRequestTemplateUpsert) UpdateUpdatedAt() *ChannelMonitorRequestTemplateUpsert { u.SetExcluded(channelmonitorrequesttemplate.FieldUpdatedAt) return u } // SetName sets the "name" field. func (u *ChannelMonitorRequestTemplateUpsert) SetName(v string) *ChannelMonitorRequestTemplateUpsert { u.Set(channelmonitorrequesttemplate.FieldName, v) return u } // UpdateName sets the "name" field to the value that was provided on create. func (u *ChannelMonitorRequestTemplateUpsert) UpdateName() *ChannelMonitorRequestTemplateUpsert { u.SetExcluded(channelmonitorrequesttemplate.FieldName) return u } // SetProvider sets the "provider" field. func (u *ChannelMonitorRequestTemplateUpsert) SetProvider(v channelmonitorrequesttemplate.Provider) *ChannelMonitorRequestTemplateUpsert { u.Set(channelmonitorrequesttemplate.FieldProvider, v) return u } // UpdateProvider sets the "provider" field to the value that was provided on create. func (u *ChannelMonitorRequestTemplateUpsert) UpdateProvider() *ChannelMonitorRequestTemplateUpsert { u.SetExcluded(channelmonitorrequesttemplate.FieldProvider) return u } // SetDescription sets the "description" field. func (u *ChannelMonitorRequestTemplateUpsert) SetDescription(v string) *ChannelMonitorRequestTemplateUpsert { u.Set(channelmonitorrequesttemplate.FieldDescription, v) return u } // UpdateDescription sets the "description" field to the value that was provided on create. func (u *ChannelMonitorRequestTemplateUpsert) UpdateDescription() *ChannelMonitorRequestTemplateUpsert { u.SetExcluded(channelmonitorrequesttemplate.FieldDescription) return u } // ClearDescription clears the value of the "description" field. func (u *ChannelMonitorRequestTemplateUpsert) ClearDescription() *ChannelMonitorRequestTemplateUpsert { u.SetNull(channelmonitorrequesttemplate.FieldDescription) return u } // SetExtraHeaders sets the "extra_headers" field. func (u *ChannelMonitorRequestTemplateUpsert) SetExtraHeaders(v map[string]string) *ChannelMonitorRequestTemplateUpsert { u.Set(channelmonitorrequesttemplate.FieldExtraHeaders, v) return u } // UpdateExtraHeaders sets the "extra_headers" field to the value that was provided on create. func (u *ChannelMonitorRequestTemplateUpsert) UpdateExtraHeaders() *ChannelMonitorRequestTemplateUpsert { u.SetExcluded(channelmonitorrequesttemplate.FieldExtraHeaders) return u } // SetBodyOverrideMode sets the "body_override_mode" field. func (u *ChannelMonitorRequestTemplateUpsert) SetBodyOverrideMode(v string) *ChannelMonitorRequestTemplateUpsert { u.Set(channelmonitorrequesttemplate.FieldBodyOverrideMode, v) return u } // UpdateBodyOverrideMode sets the "body_override_mode" field to the value that was provided on create. func (u *ChannelMonitorRequestTemplateUpsert) UpdateBodyOverrideMode() *ChannelMonitorRequestTemplateUpsert { u.SetExcluded(channelmonitorrequesttemplate.FieldBodyOverrideMode) return u } // SetBodyOverride sets the "body_override" field. func (u *ChannelMonitorRequestTemplateUpsert) SetBodyOverride(v map[string]interface{}) *ChannelMonitorRequestTemplateUpsert { u.Set(channelmonitorrequesttemplate.FieldBodyOverride, v) return u } // UpdateBodyOverride sets the "body_override" field to the value that was provided on create. func (u *ChannelMonitorRequestTemplateUpsert) UpdateBodyOverride() *ChannelMonitorRequestTemplateUpsert { u.SetExcluded(channelmonitorrequesttemplate.FieldBodyOverride) return u } // ClearBodyOverride clears the value of the "body_override" field. func (u *ChannelMonitorRequestTemplateUpsert) ClearBodyOverride() *ChannelMonitorRequestTemplateUpsert { u.SetNull(channelmonitorrequesttemplate.FieldBodyOverride) return u } // UpdateNewValues updates the mutable fields using the new values that were set on create. // Using this option is equivalent to using: // // client.ChannelMonitorRequestTemplate.Create(). // OnConflict( // sql.ResolveWithNewValues(), // ). // Exec(ctx) func (u *ChannelMonitorRequestTemplateUpsertOne) UpdateNewValues() *ChannelMonitorRequestTemplateUpsertOne { u.create.conflict = append(u.create.conflict, sql.ResolveWithNewValues()) u.create.conflict = append(u.create.conflict, sql.ResolveWith(func(s *sql.UpdateSet) { if _, exists := u.create.mutation.CreatedAt(); exists { s.SetIgnore(channelmonitorrequesttemplate.FieldCreatedAt) } })) return u } // Ignore sets each column to itself in case of conflict. // Using this option is equivalent to using: // // client.ChannelMonitorRequestTemplate.Create(). // OnConflict(sql.ResolveWithIgnore()). // Exec(ctx) func (u *ChannelMonitorRequestTemplateUpsertOne) Ignore() *ChannelMonitorRequestTemplateUpsertOne { u.create.conflict = append(u.create.conflict, sql.ResolveWithIgnore()) return u } // DoNothing configures the conflict_action to `DO NOTHING`. // Supported only by SQLite and PostgreSQL. func (u *ChannelMonitorRequestTemplateUpsertOne) DoNothing() *ChannelMonitorRequestTemplateUpsertOne { u.create.conflict = append(u.create.conflict, sql.DoNothing()) return u } // Update allows overriding fields `UPDATE` values. See the ChannelMonitorRequestTemplateCreate.OnConflict // documentation for more info. func (u *ChannelMonitorRequestTemplateUpsertOne) Update(set func(*ChannelMonitorRequestTemplateUpsert)) *ChannelMonitorRequestTemplateUpsertOne { u.create.conflict = append(u.create.conflict, sql.ResolveWith(func(update *sql.UpdateSet) { set(&ChannelMonitorRequestTemplateUpsert{UpdateSet: update}) })) return u } // SetUpdatedAt sets the "updated_at" field. func (u *ChannelMonitorRequestTemplateUpsertOne) SetUpdatedAt(v time.Time) *ChannelMonitorRequestTemplateUpsertOne { return u.Update(func(s *ChannelMonitorRequestTemplateUpsert) { s.SetUpdatedAt(v) }) } // UpdateUpdatedAt sets the "updated_at" field to the value that was provided on create. func (u *ChannelMonitorRequestTemplateUpsertOne) UpdateUpdatedAt() *ChannelMonitorRequestTemplateUpsertOne { return u.Update(func(s *ChannelMonitorRequestTemplateUpsert) { s.UpdateUpdatedAt() }) } // SetName sets the "name" field. func (u *ChannelMonitorRequestTemplateUpsertOne) SetName(v string) *ChannelMonitorRequestTemplateUpsertOne { return u.Update(func(s *ChannelMonitorRequestTemplateUpsert) { s.SetName(v) }) } // UpdateName sets the "name" field to the value that was provided on create. func (u *ChannelMonitorRequestTemplateUpsertOne) UpdateName() *ChannelMonitorRequestTemplateUpsertOne { return u.Update(func(s *ChannelMonitorRequestTemplateUpsert) { s.UpdateName() }) } // SetProvider sets the "provider" field. func (u *ChannelMonitorRequestTemplateUpsertOne) SetProvider(v channelmonitorrequesttemplate.Provider) *ChannelMonitorRequestTemplateUpsertOne { return u.Update(func(s *ChannelMonitorRequestTemplateUpsert) { s.SetProvider(v) }) } // UpdateProvider sets the "provider" field to the value that was provided on create. func (u *ChannelMonitorRequestTemplateUpsertOne) UpdateProvider() *ChannelMonitorRequestTemplateUpsertOne { return u.Update(func(s *ChannelMonitorRequestTemplateUpsert) { s.UpdateProvider() }) } // SetDescription sets the "description" field. func (u *ChannelMonitorRequestTemplateUpsertOne) SetDescription(v string) *ChannelMonitorRequestTemplateUpsertOne { return u.Update(func(s *ChannelMonitorRequestTemplateUpsert) { s.SetDescription(v) }) } // UpdateDescription sets the "description" field to the value that was provided on create. func (u *ChannelMonitorRequestTemplateUpsertOne) UpdateDescription() *ChannelMonitorRequestTemplateUpsertOne { return u.Update(func(s *ChannelMonitorRequestTemplateUpsert) { s.UpdateDescription() }) } // ClearDescription clears the value of the "description" field. func (u *ChannelMonitorRequestTemplateUpsertOne) ClearDescription() *ChannelMonitorRequestTemplateUpsertOne { return u.Update(func(s *ChannelMonitorRequestTemplateUpsert) { s.ClearDescription() }) } // SetExtraHeaders sets the "extra_headers" field. func (u *ChannelMonitorRequestTemplateUpsertOne) SetExtraHeaders(v map[string]string) *ChannelMonitorRequestTemplateUpsertOne { return u.Update(func(s *ChannelMonitorRequestTemplateUpsert) { s.SetExtraHeaders(v) }) } // UpdateExtraHeaders sets the "extra_headers" field to the value that was provided on create. func (u *ChannelMonitorRequestTemplateUpsertOne) UpdateExtraHeaders() *ChannelMonitorRequestTemplateUpsertOne { return u.Update(func(s *ChannelMonitorRequestTemplateUpsert) { s.UpdateExtraHeaders() }) } // SetBodyOverrideMode sets the "body_override_mode" field. func (u *ChannelMonitorRequestTemplateUpsertOne) SetBodyOverrideMode(v string) *ChannelMonitorRequestTemplateUpsertOne { return u.Update(func(s *ChannelMonitorRequestTemplateUpsert) { s.SetBodyOverrideMode(v) }) } // UpdateBodyOverrideMode sets the "body_override_mode" field to the value that was provided on create. func (u *ChannelMonitorRequestTemplateUpsertOne) UpdateBodyOverrideMode() *ChannelMonitorRequestTemplateUpsertOne { return u.Update(func(s *ChannelMonitorRequestTemplateUpsert) { s.UpdateBodyOverrideMode() }) } // SetBodyOverride sets the "body_override" field. func (u *ChannelMonitorRequestTemplateUpsertOne) SetBodyOverride(v map[string]interface{}) *ChannelMonitorRequestTemplateUpsertOne { return u.Update(func(s *ChannelMonitorRequestTemplateUpsert) { s.SetBodyOverride(v) }) } // UpdateBodyOverride sets the "body_override" field to the value that was provided on create. func (u *ChannelMonitorRequestTemplateUpsertOne) UpdateBodyOverride() *ChannelMonitorRequestTemplateUpsertOne { return u.Update(func(s *ChannelMonitorRequestTemplateUpsert) { s.UpdateBodyOverride() }) } // ClearBodyOverride clears the value of the "body_override" field. func (u *ChannelMonitorRequestTemplateUpsertOne) ClearBodyOverride() *ChannelMonitorRequestTemplateUpsertOne { return u.Update(func(s *ChannelMonitorRequestTemplateUpsert) { s.ClearBodyOverride() }) } // Exec executes the query. func (u *ChannelMonitorRequestTemplateUpsertOne) Exec(ctx context.Context) error { if len(u.create.conflict) == 0 { return errors.New("ent: missing options for ChannelMonitorRequestTemplateCreate.OnConflict") } return u.create.Exec(ctx) } // ExecX is like Exec, but panics if an error occurs. func (u *ChannelMonitorRequestTemplateUpsertOne) ExecX(ctx context.Context) { if err := u.create.Exec(ctx); err != nil { panic(err) } } // Exec executes the UPSERT query and returns the inserted/updated ID. func (u *ChannelMonitorRequestTemplateUpsertOne) ID(ctx context.Context) (id int64, err error) { node, err := u.create.Save(ctx) if err != nil { return id, err } return node.ID, nil } // IDX is like ID, but panics if an error occurs. func (u *ChannelMonitorRequestTemplateUpsertOne) IDX(ctx context.Context) int64 { id, err := u.ID(ctx) if err != nil { panic(err) } return id } // ChannelMonitorRequestTemplateCreateBulk is the builder for creating many ChannelMonitorRequestTemplate entities in bulk. type ChannelMonitorRequestTemplateCreateBulk struct { config err error builders []*ChannelMonitorRequestTemplateCreate conflict []sql.ConflictOption } // Save creates the ChannelMonitorRequestTemplate entities in the database. func (_c *ChannelMonitorRequestTemplateCreateBulk) Save(ctx context.Context) ([]*ChannelMonitorRequestTemplate, error) { if _c.err != nil { return nil, _c.err } specs := make([]*sqlgraph.CreateSpec, len(_c.builders)) nodes := make([]*ChannelMonitorRequestTemplate, len(_c.builders)) mutators := make([]Mutator, len(_c.builders)) for i := range _c.builders { func(i int, root context.Context) { builder := _c.builders[i] builder.defaults() var mut Mutator = MutateFunc(func(ctx context.Context, m Mutation) (Value, error) { mutation, ok := m.(*ChannelMonitorRequestTemplateMutation) if !ok { return nil, fmt.Errorf("unexpected mutation type %T", m) } if err := builder.check(); err != nil { return nil, err } builder.mutation = mutation var err error nodes[i], specs[i] = builder.createSpec() if i < len(mutators)-1 { _, err = mutators[i+1].Mutate(root, _c.builders[i+1].mutation) } else { spec := &sqlgraph.BatchCreateSpec{Nodes: specs} spec.OnConflict = _c.conflict // Invoke the actual operation on the latest mutation in the chain. if err = sqlgraph.BatchCreate(ctx, _c.driver, spec); err != nil { if sqlgraph.IsConstraintError(err) { err = &ConstraintError{msg: err.Error(), wrap: err} } } } if err != nil { return nil, err } mutation.id = &nodes[i].ID if specs[i].ID.Value != nil { id := specs[i].ID.Value.(int64) nodes[i].ID = int64(id) } mutation.done = true return nodes[i], nil }) for i := len(builder.hooks) - 1; i >= 0; i-- { mut = builder.hooks[i](mut) } mutators[i] = mut }(i, ctx) } if len(mutators) > 0 { if _, err := mutators[0].Mutate(ctx, _c.builders[0].mutation); err != nil { return nil, err } } return nodes, nil } // SaveX is like Save, but panics if an error occurs. func (_c *ChannelMonitorRequestTemplateCreateBulk) SaveX(ctx context.Context) []*ChannelMonitorRequestTemplate { v, err := _c.Save(ctx) if err != nil { panic(err) } return v } // Exec executes the query. func (_c *ChannelMonitorRequestTemplateCreateBulk) Exec(ctx context.Context) error { _, err := _c.Save(ctx) return err } // ExecX is like Exec, but panics if an error occurs. func (_c *ChannelMonitorRequestTemplateCreateBulk) ExecX(ctx context.Context) { if err := _c.Exec(ctx); err != nil { panic(err) } } // OnConflict allows configuring the `ON CONFLICT` / `ON DUPLICATE KEY` clause // of the `INSERT` statement. For example: // // client.ChannelMonitorRequestTemplate.CreateBulk(builders...). // OnConflict( // // Update the row with the new values // // the was proposed for insertion. // sql.ResolveWithNewValues(), // ). // // Override some of the fields with custom // // update values. // Update(func(u *ent.ChannelMonitorRequestTemplateUpsert) { // SetCreatedAt(v+v). // }). // Exec(ctx) func (_c *ChannelMonitorRequestTemplateCreateBulk) OnConflict(opts ...sql.ConflictOption) *ChannelMonitorRequestTemplateUpsertBulk { _c.conflict = opts return &ChannelMonitorRequestTemplateUpsertBulk{ create: _c, } } // OnConflictColumns calls `OnConflict` and configures the columns // as conflict target. Using this option is equivalent to using: // // client.ChannelMonitorRequestTemplate.Create(). // OnConflict(sql.ConflictColumns(columns...)). // Exec(ctx) func (_c *ChannelMonitorRequestTemplateCreateBulk) OnConflictColumns(columns ...string) *ChannelMonitorRequestTemplateUpsertBulk { _c.conflict = append(_c.conflict, sql.ConflictColumns(columns...)) return &ChannelMonitorRequestTemplateUpsertBulk{ create: _c, } } // ChannelMonitorRequestTemplateUpsertBulk is the builder for "upsert"-ing // a bulk of ChannelMonitorRequestTemplate nodes. type ChannelMonitorRequestTemplateUpsertBulk struct { create *ChannelMonitorRequestTemplateCreateBulk } // UpdateNewValues updates the mutable fields using the new values that // were set on create. Using this option is equivalent to using: // // client.ChannelMonitorRequestTemplate.Create(). // OnConflict( // sql.ResolveWithNewValues(), // ). // Exec(ctx) func (u *ChannelMonitorRequestTemplateUpsertBulk) UpdateNewValues() *ChannelMonitorRequestTemplateUpsertBulk { u.create.conflict = append(u.create.conflict, sql.ResolveWithNewValues()) u.create.conflict = append(u.create.conflict, sql.ResolveWith(func(s *sql.UpdateSet) { for _, b := range u.create.builders { if _, exists := b.mutation.CreatedAt(); exists { s.SetIgnore(channelmonitorrequesttemplate.FieldCreatedAt) } } })) return u } // Ignore sets each column to itself in case of conflict. // Using this option is equivalent to using: // // client.ChannelMonitorRequestTemplate.Create(). // OnConflict(sql.ResolveWithIgnore()). // Exec(ctx) func (u *ChannelMonitorRequestTemplateUpsertBulk) Ignore() *ChannelMonitorRequestTemplateUpsertBulk { u.create.conflict = append(u.create.conflict, sql.ResolveWithIgnore()) return u } // DoNothing configures the conflict_action to `DO NOTHING`. // Supported only by SQLite and PostgreSQL. func (u *ChannelMonitorRequestTemplateUpsertBulk) DoNothing() *ChannelMonitorRequestTemplateUpsertBulk { u.create.conflict = append(u.create.conflict, sql.DoNothing()) return u } // Update allows overriding fields `UPDATE` values. See the ChannelMonitorRequestTemplateCreateBulk.OnConflict // documentation for more info. func (u *ChannelMonitorRequestTemplateUpsertBulk) Update(set func(*ChannelMonitorRequestTemplateUpsert)) *ChannelMonitorRequestTemplateUpsertBulk { u.create.conflict = append(u.create.conflict, sql.ResolveWith(func(update *sql.UpdateSet) { set(&ChannelMonitorRequestTemplateUpsert{UpdateSet: update}) })) return u } // SetUpdatedAt sets the "updated_at" field. func (u *ChannelMonitorRequestTemplateUpsertBulk) SetUpdatedAt(v time.Time) *ChannelMonitorRequestTemplateUpsertBulk { return u.Update(func(s *ChannelMonitorRequestTemplateUpsert) { s.SetUpdatedAt(v) }) } // UpdateUpdatedAt sets the "updated_at" field to the value that was provided on create. func (u *ChannelMonitorRequestTemplateUpsertBulk) UpdateUpdatedAt() *ChannelMonitorRequestTemplateUpsertBulk { return u.Update(func(s *ChannelMonitorRequestTemplateUpsert) { s.UpdateUpdatedAt() }) } // SetName sets the "name" field. func (u *ChannelMonitorRequestTemplateUpsertBulk) SetName(v string) *ChannelMonitorRequestTemplateUpsertBulk { return u.Update(func(s *ChannelMonitorRequestTemplateUpsert) { s.SetName(v) }) } // UpdateName sets the "name" field to the value that was provided on create. func (u *ChannelMonitorRequestTemplateUpsertBulk) UpdateName() *ChannelMonitorRequestTemplateUpsertBulk { return u.Update(func(s *ChannelMonitorRequestTemplateUpsert) { s.UpdateName() }) } // SetProvider sets the "provider" field. func (u *ChannelMonitorRequestTemplateUpsertBulk) SetProvider(v channelmonitorrequesttemplate.Provider) *ChannelMonitorRequestTemplateUpsertBulk { return u.Update(func(s *ChannelMonitorRequestTemplateUpsert) { s.SetProvider(v) }) } // UpdateProvider sets the "provider" field to the value that was provided on create. func (u *ChannelMonitorRequestTemplateUpsertBulk) UpdateProvider() *ChannelMonitorRequestTemplateUpsertBulk { return u.Update(func(s *ChannelMonitorRequestTemplateUpsert) { s.UpdateProvider() }) } // SetDescription sets the "description" field. func (u *ChannelMonitorRequestTemplateUpsertBulk) SetDescription(v string) *ChannelMonitorRequestTemplateUpsertBulk { return u.Update(func(s *ChannelMonitorRequestTemplateUpsert) { s.SetDescription(v) }) } // UpdateDescription sets the "description" field to the value that was provided on create. func (u *ChannelMonitorRequestTemplateUpsertBulk) UpdateDescription() *ChannelMonitorRequestTemplateUpsertBulk { return u.Update(func(s *ChannelMonitorRequestTemplateUpsert) { s.UpdateDescription() }) } // ClearDescription clears the value of the "description" field. func (u *ChannelMonitorRequestTemplateUpsertBulk) ClearDescription() *ChannelMonitorRequestTemplateUpsertBulk { return u.Update(func(s *ChannelMonitorRequestTemplateUpsert) { s.ClearDescription() }) } // SetExtraHeaders sets the "extra_headers" field. func (u *ChannelMonitorRequestTemplateUpsertBulk) SetExtraHeaders(v map[string]string) *ChannelMonitorRequestTemplateUpsertBulk { return u.Update(func(s *ChannelMonitorRequestTemplateUpsert) { s.SetExtraHeaders(v) }) } // UpdateExtraHeaders sets the "extra_headers" field to the value that was provided on create. func (u *ChannelMonitorRequestTemplateUpsertBulk) UpdateExtraHeaders() *ChannelMonitorRequestTemplateUpsertBulk { return u.Update(func(s *ChannelMonitorRequestTemplateUpsert) { s.UpdateExtraHeaders() }) } // SetBodyOverrideMode sets the "body_override_mode" field. func (u *ChannelMonitorRequestTemplateUpsertBulk) SetBodyOverrideMode(v string) *ChannelMonitorRequestTemplateUpsertBulk { return u.Update(func(s *ChannelMonitorRequestTemplateUpsert) { s.SetBodyOverrideMode(v) }) } // UpdateBodyOverrideMode sets the "body_override_mode" field to the value that was provided on create. func (u *ChannelMonitorRequestTemplateUpsertBulk) UpdateBodyOverrideMode() *ChannelMonitorRequestTemplateUpsertBulk { return u.Update(func(s *ChannelMonitorRequestTemplateUpsert) { s.UpdateBodyOverrideMode() }) } // SetBodyOverride sets the "body_override" field. func (u *ChannelMonitorRequestTemplateUpsertBulk) SetBodyOverride(v map[string]interface{}) *ChannelMonitorRequestTemplateUpsertBulk { return u.Update(func(s *ChannelMonitorRequestTemplateUpsert) { s.SetBodyOverride(v) }) } // UpdateBodyOverride sets the "body_override" field to the value that was provided on create. func (u *ChannelMonitorRequestTemplateUpsertBulk) UpdateBodyOverride() *ChannelMonitorRequestTemplateUpsertBulk { return u.Update(func(s *ChannelMonitorRequestTemplateUpsert) { s.UpdateBodyOverride() }) } // ClearBodyOverride clears the value of the "body_override" field. func (u *ChannelMonitorRequestTemplateUpsertBulk) ClearBodyOverride() *ChannelMonitorRequestTemplateUpsertBulk { return u.Update(func(s *ChannelMonitorRequestTemplateUpsert) { s.ClearBodyOverride() }) } // Exec executes the query. func (u *ChannelMonitorRequestTemplateUpsertBulk) Exec(ctx context.Context) error { if u.create.err != nil { return u.create.err } for i, b := range u.create.builders { if len(b.conflict) != 0 { return fmt.Errorf("ent: OnConflict was set for builder %d. Set it on the ChannelMonitorRequestTemplateCreateBulk instead", i) } } if len(u.create.conflict) == 0 { return errors.New("ent: missing options for ChannelMonitorRequestTemplateCreateBulk.OnConflict") } return u.create.Exec(ctx) } // ExecX is like Exec, but panics if an error occurs. func (u *ChannelMonitorRequestTemplateUpsertBulk) ExecX(ctx context.Context) { if err := u.create.Exec(ctx); err != nil { panic(err) } }