912 lines
26 KiB
Go
912 lines
26 KiB
Go
// Code generated by ent, DO NOT EDIT.
|
|
|
|
package ent
|
|
|
|
import (
|
|
"bj_power_wms/ent/alertrule"
|
|
"context"
|
|
"errors"
|
|
"fmt"
|
|
|
|
"entgo.io/ent/dialect/sql"
|
|
"entgo.io/ent/dialect/sql/sqlgraph"
|
|
"entgo.io/ent/schema/field"
|
|
)
|
|
|
|
// AlertRuleCreate is the builder for creating a AlertRule entity.
|
|
type AlertRuleCreate struct {
|
|
config
|
|
mutation *AlertRuleMutation
|
|
hooks []Hook
|
|
conflict []sql.ConflictOption
|
|
}
|
|
|
|
// SetCode sets the "code" field.
|
|
func (_c *AlertRuleCreate) SetCode(v string) *AlertRuleCreate {
|
|
_c.mutation.SetCode(v)
|
|
return _c
|
|
}
|
|
|
|
// SetName sets the "name" field.
|
|
func (_c *AlertRuleCreate) SetName(v string) *AlertRuleCreate {
|
|
_c.mutation.SetName(v)
|
|
return _c
|
|
}
|
|
|
|
// SetEnabled sets the "enabled" field.
|
|
func (_c *AlertRuleCreate) SetEnabled(v bool) *AlertRuleCreate {
|
|
_c.mutation.SetEnabled(v)
|
|
return _c
|
|
}
|
|
|
|
// SetNillableEnabled sets the "enabled" field if the given value is not nil.
|
|
func (_c *AlertRuleCreate) SetNillableEnabled(v *bool) *AlertRuleCreate {
|
|
if v != nil {
|
|
_c.SetEnabled(*v)
|
|
}
|
|
return _c
|
|
}
|
|
|
|
// SetThreshold sets the "threshold" field.
|
|
func (_c *AlertRuleCreate) SetThreshold(v int) *AlertRuleCreate {
|
|
_c.mutation.SetThreshold(v)
|
|
return _c
|
|
}
|
|
|
|
// SetNillableThreshold sets the "threshold" field if the given value is not nil.
|
|
func (_c *AlertRuleCreate) SetNillableThreshold(v *int) *AlertRuleCreate {
|
|
if v != nil {
|
|
_c.SetThreshold(*v)
|
|
}
|
|
return _c
|
|
}
|
|
|
|
// SetRemark sets the "remark" field.
|
|
func (_c *AlertRuleCreate) SetRemark(v string) *AlertRuleCreate {
|
|
_c.mutation.SetRemark(v)
|
|
return _c
|
|
}
|
|
|
|
// SetNillableRemark sets the "remark" field if the given value is not nil.
|
|
func (_c *AlertRuleCreate) SetNillableRemark(v *string) *AlertRuleCreate {
|
|
if v != nil {
|
|
_c.SetRemark(*v)
|
|
}
|
|
return _c
|
|
}
|
|
|
|
// SetCreatedAt sets the "created_at" field.
|
|
func (_c *AlertRuleCreate) SetCreatedAt(v int64) *AlertRuleCreate {
|
|
_c.mutation.SetCreatedAt(v)
|
|
return _c
|
|
}
|
|
|
|
// SetNillableCreatedAt sets the "created_at" field if the given value is not nil.
|
|
func (_c *AlertRuleCreate) SetNillableCreatedAt(v *int64) *AlertRuleCreate {
|
|
if v != nil {
|
|
_c.SetCreatedAt(*v)
|
|
}
|
|
return _c
|
|
}
|
|
|
|
// SetUpdatedAt sets the "updated_at" field.
|
|
func (_c *AlertRuleCreate) SetUpdatedAt(v int64) *AlertRuleCreate {
|
|
_c.mutation.SetUpdatedAt(v)
|
|
return _c
|
|
}
|
|
|
|
// SetNillableUpdatedAt sets the "updated_at" field if the given value is not nil.
|
|
func (_c *AlertRuleCreate) SetNillableUpdatedAt(v *int64) *AlertRuleCreate {
|
|
if v != nil {
|
|
_c.SetUpdatedAt(*v)
|
|
}
|
|
return _c
|
|
}
|
|
|
|
// Mutation returns the AlertRuleMutation object of the builder.
|
|
func (_c *AlertRuleCreate) Mutation() *AlertRuleMutation {
|
|
return _c.mutation
|
|
}
|
|
|
|
// Save creates the AlertRule in the database.
|
|
func (_c *AlertRuleCreate) Save(ctx context.Context) (*AlertRule, error) {
|
|
_c.defaults()
|
|
return withHooks(ctx, _c.sqlSave, _c.mutation, _c.hooks)
|
|
}
|
|
|
|
// SaveX calls Save and panics if Save returns an error.
|
|
func (_c *AlertRuleCreate) SaveX(ctx context.Context) *AlertRule {
|
|
v, err := _c.Save(ctx)
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
return v
|
|
}
|
|
|
|
// Exec executes the query.
|
|
func (_c *AlertRuleCreate) Exec(ctx context.Context) error {
|
|
_, err := _c.Save(ctx)
|
|
return err
|
|
}
|
|
|
|
// ExecX is like Exec, but panics if an error occurs.
|
|
func (_c *AlertRuleCreate) 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 *AlertRuleCreate) defaults() {
|
|
if _, ok := _c.mutation.Enabled(); !ok {
|
|
v := alertrule.DefaultEnabled
|
|
_c.mutation.SetEnabled(v)
|
|
}
|
|
if _, ok := _c.mutation.Threshold(); !ok {
|
|
v := alertrule.DefaultThreshold
|
|
_c.mutation.SetThreshold(v)
|
|
}
|
|
if _, ok := _c.mutation.CreatedAt(); !ok {
|
|
v := alertrule.DefaultCreatedAt()
|
|
_c.mutation.SetCreatedAt(v)
|
|
}
|
|
if _, ok := _c.mutation.UpdatedAt(); !ok {
|
|
v := alertrule.DefaultUpdatedAt()
|
|
_c.mutation.SetUpdatedAt(v)
|
|
}
|
|
}
|
|
|
|
// check runs all checks and user-defined validators on the builder.
|
|
func (_c *AlertRuleCreate) check() error {
|
|
if _, ok := _c.mutation.Code(); !ok {
|
|
return &ValidationError{Name: "code", err: errors.New(`ent: missing required field "AlertRule.code"`)}
|
|
}
|
|
if _, ok := _c.mutation.Name(); !ok {
|
|
return &ValidationError{Name: "name", err: errors.New(`ent: missing required field "AlertRule.name"`)}
|
|
}
|
|
if _, ok := _c.mutation.Enabled(); !ok {
|
|
return &ValidationError{Name: "enabled", err: errors.New(`ent: missing required field "AlertRule.enabled"`)}
|
|
}
|
|
if _, ok := _c.mutation.Threshold(); !ok {
|
|
return &ValidationError{Name: "threshold", err: errors.New(`ent: missing required field "AlertRule.threshold"`)}
|
|
}
|
|
if _, ok := _c.mutation.CreatedAt(); !ok {
|
|
return &ValidationError{Name: "created_at", err: errors.New(`ent: missing required field "AlertRule.created_at"`)}
|
|
}
|
|
if _, ok := _c.mutation.UpdatedAt(); !ok {
|
|
return &ValidationError{Name: "updated_at", err: errors.New(`ent: missing required field "AlertRule.updated_at"`)}
|
|
}
|
|
return nil
|
|
}
|
|
|
|
func (_c *AlertRuleCreate) sqlSave(ctx context.Context) (*AlertRule, 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 = int(id)
|
|
_c.mutation.id = &_node.ID
|
|
_c.mutation.done = true
|
|
return _node, nil
|
|
}
|
|
|
|
func (_c *AlertRuleCreate) createSpec() (*AlertRule, *sqlgraph.CreateSpec) {
|
|
var (
|
|
_node = &AlertRule{config: _c.config}
|
|
_spec = sqlgraph.NewCreateSpec(alertrule.Table, sqlgraph.NewFieldSpec(alertrule.FieldID, field.TypeInt))
|
|
)
|
|
_spec.OnConflict = _c.conflict
|
|
if value, ok := _c.mutation.Code(); ok {
|
|
_spec.SetField(alertrule.FieldCode, field.TypeString, value)
|
|
_node.Code = value
|
|
}
|
|
if value, ok := _c.mutation.Name(); ok {
|
|
_spec.SetField(alertrule.FieldName, field.TypeString, value)
|
|
_node.Name = value
|
|
}
|
|
if value, ok := _c.mutation.Enabled(); ok {
|
|
_spec.SetField(alertrule.FieldEnabled, field.TypeBool, value)
|
|
_node.Enabled = value
|
|
}
|
|
if value, ok := _c.mutation.Threshold(); ok {
|
|
_spec.SetField(alertrule.FieldThreshold, field.TypeInt, value)
|
|
_node.Threshold = value
|
|
}
|
|
if value, ok := _c.mutation.Remark(); ok {
|
|
_spec.SetField(alertrule.FieldRemark, field.TypeString, value)
|
|
_node.Remark = value
|
|
}
|
|
if value, ok := _c.mutation.CreatedAt(); ok {
|
|
_spec.SetField(alertrule.FieldCreatedAt, field.TypeInt64, value)
|
|
_node.CreatedAt = value
|
|
}
|
|
if value, ok := _c.mutation.UpdatedAt(); ok {
|
|
_spec.SetField(alertrule.FieldUpdatedAt, field.TypeInt64, value)
|
|
_node.UpdatedAt = value
|
|
}
|
|
return _node, _spec
|
|
}
|
|
|
|
// OnConflict allows configuring the `ON CONFLICT` / `ON DUPLICATE KEY` clause
|
|
// of the `INSERT` statement. For example:
|
|
//
|
|
// client.AlertRule.Create().
|
|
// SetCode(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.AlertRuleUpsert) {
|
|
// SetCode(v+v).
|
|
// }).
|
|
// Exec(ctx)
|
|
func (_c *AlertRuleCreate) OnConflict(opts ...sql.ConflictOption) *AlertRuleUpsertOne {
|
|
_c.conflict = opts
|
|
return &AlertRuleUpsertOne{
|
|
create: _c,
|
|
}
|
|
}
|
|
|
|
// OnConflictColumns calls `OnConflict` and configures the columns
|
|
// as conflict target. Using this option is equivalent to using:
|
|
//
|
|
// client.AlertRule.Create().
|
|
// OnConflict(sql.ConflictColumns(columns...)).
|
|
// Exec(ctx)
|
|
func (_c *AlertRuleCreate) OnConflictColumns(columns ...string) *AlertRuleUpsertOne {
|
|
_c.conflict = append(_c.conflict, sql.ConflictColumns(columns...))
|
|
return &AlertRuleUpsertOne{
|
|
create: _c,
|
|
}
|
|
}
|
|
|
|
type (
|
|
// AlertRuleUpsertOne is the builder for "upsert"-ing
|
|
// one AlertRule node.
|
|
AlertRuleUpsertOne struct {
|
|
create *AlertRuleCreate
|
|
}
|
|
|
|
// AlertRuleUpsert is the "OnConflict" setter.
|
|
AlertRuleUpsert struct {
|
|
*sql.UpdateSet
|
|
}
|
|
)
|
|
|
|
// SetCode sets the "code" field.
|
|
func (u *AlertRuleUpsert) SetCode(v string) *AlertRuleUpsert {
|
|
u.Set(alertrule.FieldCode, v)
|
|
return u
|
|
}
|
|
|
|
// UpdateCode sets the "code" field to the value that was provided on create.
|
|
func (u *AlertRuleUpsert) UpdateCode() *AlertRuleUpsert {
|
|
u.SetExcluded(alertrule.FieldCode)
|
|
return u
|
|
}
|
|
|
|
// SetName sets the "name" field.
|
|
func (u *AlertRuleUpsert) SetName(v string) *AlertRuleUpsert {
|
|
u.Set(alertrule.FieldName, v)
|
|
return u
|
|
}
|
|
|
|
// UpdateName sets the "name" field to the value that was provided on create.
|
|
func (u *AlertRuleUpsert) UpdateName() *AlertRuleUpsert {
|
|
u.SetExcluded(alertrule.FieldName)
|
|
return u
|
|
}
|
|
|
|
// SetEnabled sets the "enabled" field.
|
|
func (u *AlertRuleUpsert) SetEnabled(v bool) *AlertRuleUpsert {
|
|
u.Set(alertrule.FieldEnabled, v)
|
|
return u
|
|
}
|
|
|
|
// UpdateEnabled sets the "enabled" field to the value that was provided on create.
|
|
func (u *AlertRuleUpsert) UpdateEnabled() *AlertRuleUpsert {
|
|
u.SetExcluded(alertrule.FieldEnabled)
|
|
return u
|
|
}
|
|
|
|
// SetThreshold sets the "threshold" field.
|
|
func (u *AlertRuleUpsert) SetThreshold(v int) *AlertRuleUpsert {
|
|
u.Set(alertrule.FieldThreshold, v)
|
|
return u
|
|
}
|
|
|
|
// UpdateThreshold sets the "threshold" field to the value that was provided on create.
|
|
func (u *AlertRuleUpsert) UpdateThreshold() *AlertRuleUpsert {
|
|
u.SetExcluded(alertrule.FieldThreshold)
|
|
return u
|
|
}
|
|
|
|
// AddThreshold adds v to the "threshold" field.
|
|
func (u *AlertRuleUpsert) AddThreshold(v int) *AlertRuleUpsert {
|
|
u.Add(alertrule.FieldThreshold, v)
|
|
return u
|
|
}
|
|
|
|
// SetRemark sets the "remark" field.
|
|
func (u *AlertRuleUpsert) SetRemark(v string) *AlertRuleUpsert {
|
|
u.Set(alertrule.FieldRemark, v)
|
|
return u
|
|
}
|
|
|
|
// UpdateRemark sets the "remark" field to the value that was provided on create.
|
|
func (u *AlertRuleUpsert) UpdateRemark() *AlertRuleUpsert {
|
|
u.SetExcluded(alertrule.FieldRemark)
|
|
return u
|
|
}
|
|
|
|
// ClearRemark clears the value of the "remark" field.
|
|
func (u *AlertRuleUpsert) ClearRemark() *AlertRuleUpsert {
|
|
u.SetNull(alertrule.FieldRemark)
|
|
return u
|
|
}
|
|
|
|
// SetCreatedAt sets the "created_at" field.
|
|
func (u *AlertRuleUpsert) SetCreatedAt(v int64) *AlertRuleUpsert {
|
|
u.Set(alertrule.FieldCreatedAt, v)
|
|
return u
|
|
}
|
|
|
|
// UpdateCreatedAt sets the "created_at" field to the value that was provided on create.
|
|
func (u *AlertRuleUpsert) UpdateCreatedAt() *AlertRuleUpsert {
|
|
u.SetExcluded(alertrule.FieldCreatedAt)
|
|
return u
|
|
}
|
|
|
|
// AddCreatedAt adds v to the "created_at" field.
|
|
func (u *AlertRuleUpsert) AddCreatedAt(v int64) *AlertRuleUpsert {
|
|
u.Add(alertrule.FieldCreatedAt, v)
|
|
return u
|
|
}
|
|
|
|
// SetUpdatedAt sets the "updated_at" field.
|
|
func (u *AlertRuleUpsert) SetUpdatedAt(v int64) *AlertRuleUpsert {
|
|
u.Set(alertrule.FieldUpdatedAt, v)
|
|
return u
|
|
}
|
|
|
|
// UpdateUpdatedAt sets the "updated_at" field to the value that was provided on create.
|
|
func (u *AlertRuleUpsert) UpdateUpdatedAt() *AlertRuleUpsert {
|
|
u.SetExcluded(alertrule.FieldUpdatedAt)
|
|
return u
|
|
}
|
|
|
|
// AddUpdatedAt adds v to the "updated_at" field.
|
|
func (u *AlertRuleUpsert) AddUpdatedAt(v int64) *AlertRuleUpsert {
|
|
u.Add(alertrule.FieldUpdatedAt, v)
|
|
return u
|
|
}
|
|
|
|
// UpdateNewValues updates the mutable fields using the new values that were set on create.
|
|
// Using this option is equivalent to using:
|
|
//
|
|
// client.AlertRule.Create().
|
|
// OnConflict(
|
|
// sql.ResolveWithNewValues(),
|
|
// ).
|
|
// Exec(ctx)
|
|
func (u *AlertRuleUpsertOne) UpdateNewValues() *AlertRuleUpsertOne {
|
|
u.create.conflict = append(u.create.conflict, sql.ResolveWithNewValues())
|
|
return u
|
|
}
|
|
|
|
// Ignore sets each column to itself in case of conflict.
|
|
// Using this option is equivalent to using:
|
|
//
|
|
// client.AlertRule.Create().
|
|
// OnConflict(sql.ResolveWithIgnore()).
|
|
// Exec(ctx)
|
|
func (u *AlertRuleUpsertOne) Ignore() *AlertRuleUpsertOne {
|
|
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 *AlertRuleUpsertOne) DoNothing() *AlertRuleUpsertOne {
|
|
u.create.conflict = append(u.create.conflict, sql.DoNothing())
|
|
return u
|
|
}
|
|
|
|
// Update allows overriding fields `UPDATE` values. See the AlertRuleCreate.OnConflict
|
|
// documentation for more info.
|
|
func (u *AlertRuleUpsertOne) Update(set func(*AlertRuleUpsert)) *AlertRuleUpsertOne {
|
|
u.create.conflict = append(u.create.conflict, sql.ResolveWith(func(update *sql.UpdateSet) {
|
|
set(&AlertRuleUpsert{UpdateSet: update})
|
|
}))
|
|
return u
|
|
}
|
|
|
|
// SetCode sets the "code" field.
|
|
func (u *AlertRuleUpsertOne) SetCode(v string) *AlertRuleUpsertOne {
|
|
return u.Update(func(s *AlertRuleUpsert) {
|
|
s.SetCode(v)
|
|
})
|
|
}
|
|
|
|
// UpdateCode sets the "code" field to the value that was provided on create.
|
|
func (u *AlertRuleUpsertOne) UpdateCode() *AlertRuleUpsertOne {
|
|
return u.Update(func(s *AlertRuleUpsert) {
|
|
s.UpdateCode()
|
|
})
|
|
}
|
|
|
|
// SetName sets the "name" field.
|
|
func (u *AlertRuleUpsertOne) SetName(v string) *AlertRuleUpsertOne {
|
|
return u.Update(func(s *AlertRuleUpsert) {
|
|
s.SetName(v)
|
|
})
|
|
}
|
|
|
|
// UpdateName sets the "name" field to the value that was provided on create.
|
|
func (u *AlertRuleUpsertOne) UpdateName() *AlertRuleUpsertOne {
|
|
return u.Update(func(s *AlertRuleUpsert) {
|
|
s.UpdateName()
|
|
})
|
|
}
|
|
|
|
// SetEnabled sets the "enabled" field.
|
|
func (u *AlertRuleUpsertOne) SetEnabled(v bool) *AlertRuleUpsertOne {
|
|
return u.Update(func(s *AlertRuleUpsert) {
|
|
s.SetEnabled(v)
|
|
})
|
|
}
|
|
|
|
// UpdateEnabled sets the "enabled" field to the value that was provided on create.
|
|
func (u *AlertRuleUpsertOne) UpdateEnabled() *AlertRuleUpsertOne {
|
|
return u.Update(func(s *AlertRuleUpsert) {
|
|
s.UpdateEnabled()
|
|
})
|
|
}
|
|
|
|
// SetThreshold sets the "threshold" field.
|
|
func (u *AlertRuleUpsertOne) SetThreshold(v int) *AlertRuleUpsertOne {
|
|
return u.Update(func(s *AlertRuleUpsert) {
|
|
s.SetThreshold(v)
|
|
})
|
|
}
|
|
|
|
// AddThreshold adds v to the "threshold" field.
|
|
func (u *AlertRuleUpsertOne) AddThreshold(v int) *AlertRuleUpsertOne {
|
|
return u.Update(func(s *AlertRuleUpsert) {
|
|
s.AddThreshold(v)
|
|
})
|
|
}
|
|
|
|
// UpdateThreshold sets the "threshold" field to the value that was provided on create.
|
|
func (u *AlertRuleUpsertOne) UpdateThreshold() *AlertRuleUpsertOne {
|
|
return u.Update(func(s *AlertRuleUpsert) {
|
|
s.UpdateThreshold()
|
|
})
|
|
}
|
|
|
|
// SetRemark sets the "remark" field.
|
|
func (u *AlertRuleUpsertOne) SetRemark(v string) *AlertRuleUpsertOne {
|
|
return u.Update(func(s *AlertRuleUpsert) {
|
|
s.SetRemark(v)
|
|
})
|
|
}
|
|
|
|
// UpdateRemark sets the "remark" field to the value that was provided on create.
|
|
func (u *AlertRuleUpsertOne) UpdateRemark() *AlertRuleUpsertOne {
|
|
return u.Update(func(s *AlertRuleUpsert) {
|
|
s.UpdateRemark()
|
|
})
|
|
}
|
|
|
|
// ClearRemark clears the value of the "remark" field.
|
|
func (u *AlertRuleUpsertOne) ClearRemark() *AlertRuleUpsertOne {
|
|
return u.Update(func(s *AlertRuleUpsert) {
|
|
s.ClearRemark()
|
|
})
|
|
}
|
|
|
|
// SetCreatedAt sets the "created_at" field.
|
|
func (u *AlertRuleUpsertOne) SetCreatedAt(v int64) *AlertRuleUpsertOne {
|
|
return u.Update(func(s *AlertRuleUpsert) {
|
|
s.SetCreatedAt(v)
|
|
})
|
|
}
|
|
|
|
// AddCreatedAt adds v to the "created_at" field.
|
|
func (u *AlertRuleUpsertOne) AddCreatedAt(v int64) *AlertRuleUpsertOne {
|
|
return u.Update(func(s *AlertRuleUpsert) {
|
|
s.AddCreatedAt(v)
|
|
})
|
|
}
|
|
|
|
// UpdateCreatedAt sets the "created_at" field to the value that was provided on create.
|
|
func (u *AlertRuleUpsertOne) UpdateCreatedAt() *AlertRuleUpsertOne {
|
|
return u.Update(func(s *AlertRuleUpsert) {
|
|
s.UpdateCreatedAt()
|
|
})
|
|
}
|
|
|
|
// SetUpdatedAt sets the "updated_at" field.
|
|
func (u *AlertRuleUpsertOne) SetUpdatedAt(v int64) *AlertRuleUpsertOne {
|
|
return u.Update(func(s *AlertRuleUpsert) {
|
|
s.SetUpdatedAt(v)
|
|
})
|
|
}
|
|
|
|
// AddUpdatedAt adds v to the "updated_at" field.
|
|
func (u *AlertRuleUpsertOne) AddUpdatedAt(v int64) *AlertRuleUpsertOne {
|
|
return u.Update(func(s *AlertRuleUpsert) {
|
|
s.AddUpdatedAt(v)
|
|
})
|
|
}
|
|
|
|
// UpdateUpdatedAt sets the "updated_at" field to the value that was provided on create.
|
|
func (u *AlertRuleUpsertOne) UpdateUpdatedAt() *AlertRuleUpsertOne {
|
|
return u.Update(func(s *AlertRuleUpsert) {
|
|
s.UpdateUpdatedAt()
|
|
})
|
|
}
|
|
|
|
// Exec executes the query.
|
|
func (u *AlertRuleUpsertOne) Exec(ctx context.Context) error {
|
|
if len(u.create.conflict) == 0 {
|
|
return errors.New("ent: missing options for AlertRuleCreate.OnConflict")
|
|
}
|
|
return u.create.Exec(ctx)
|
|
}
|
|
|
|
// ExecX is like Exec, but panics if an error occurs.
|
|
func (u *AlertRuleUpsertOne) 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 *AlertRuleUpsertOne) ID(ctx context.Context) (id int, 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 *AlertRuleUpsertOne) IDX(ctx context.Context) int {
|
|
id, err := u.ID(ctx)
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
return id
|
|
}
|
|
|
|
// AlertRuleCreateBulk is the builder for creating many AlertRule entities in bulk.
|
|
type AlertRuleCreateBulk struct {
|
|
config
|
|
err error
|
|
builders []*AlertRuleCreate
|
|
conflict []sql.ConflictOption
|
|
}
|
|
|
|
// Save creates the AlertRule entities in the database.
|
|
func (_c *AlertRuleCreateBulk) Save(ctx context.Context) ([]*AlertRule, error) {
|
|
if _c.err != nil {
|
|
return nil, _c.err
|
|
}
|
|
specs := make([]*sqlgraph.CreateSpec, len(_c.builders))
|
|
nodes := make([]*AlertRule, 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.(*AlertRuleMutation)
|
|
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 = int(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 *AlertRuleCreateBulk) SaveX(ctx context.Context) []*AlertRule {
|
|
v, err := _c.Save(ctx)
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
return v
|
|
}
|
|
|
|
// Exec executes the query.
|
|
func (_c *AlertRuleCreateBulk) Exec(ctx context.Context) error {
|
|
_, err := _c.Save(ctx)
|
|
return err
|
|
}
|
|
|
|
// ExecX is like Exec, but panics if an error occurs.
|
|
func (_c *AlertRuleCreateBulk) 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.AlertRule.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.AlertRuleUpsert) {
|
|
// SetCode(v+v).
|
|
// }).
|
|
// Exec(ctx)
|
|
func (_c *AlertRuleCreateBulk) OnConflict(opts ...sql.ConflictOption) *AlertRuleUpsertBulk {
|
|
_c.conflict = opts
|
|
return &AlertRuleUpsertBulk{
|
|
create: _c,
|
|
}
|
|
}
|
|
|
|
// OnConflictColumns calls `OnConflict` and configures the columns
|
|
// as conflict target. Using this option is equivalent to using:
|
|
//
|
|
// client.AlertRule.Create().
|
|
// OnConflict(sql.ConflictColumns(columns...)).
|
|
// Exec(ctx)
|
|
func (_c *AlertRuleCreateBulk) OnConflictColumns(columns ...string) *AlertRuleUpsertBulk {
|
|
_c.conflict = append(_c.conflict, sql.ConflictColumns(columns...))
|
|
return &AlertRuleUpsertBulk{
|
|
create: _c,
|
|
}
|
|
}
|
|
|
|
// AlertRuleUpsertBulk is the builder for "upsert"-ing
|
|
// a bulk of AlertRule nodes.
|
|
type AlertRuleUpsertBulk struct {
|
|
create *AlertRuleCreateBulk
|
|
}
|
|
|
|
// UpdateNewValues updates the mutable fields using the new values that
|
|
// were set on create. Using this option is equivalent to using:
|
|
//
|
|
// client.AlertRule.Create().
|
|
// OnConflict(
|
|
// sql.ResolveWithNewValues(),
|
|
// ).
|
|
// Exec(ctx)
|
|
func (u *AlertRuleUpsertBulk) UpdateNewValues() *AlertRuleUpsertBulk {
|
|
u.create.conflict = append(u.create.conflict, sql.ResolveWithNewValues())
|
|
return u
|
|
}
|
|
|
|
// Ignore sets each column to itself in case of conflict.
|
|
// Using this option is equivalent to using:
|
|
//
|
|
// client.AlertRule.Create().
|
|
// OnConflict(sql.ResolveWithIgnore()).
|
|
// Exec(ctx)
|
|
func (u *AlertRuleUpsertBulk) Ignore() *AlertRuleUpsertBulk {
|
|
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 *AlertRuleUpsertBulk) DoNothing() *AlertRuleUpsertBulk {
|
|
u.create.conflict = append(u.create.conflict, sql.DoNothing())
|
|
return u
|
|
}
|
|
|
|
// Update allows overriding fields `UPDATE` values. See the AlertRuleCreateBulk.OnConflict
|
|
// documentation for more info.
|
|
func (u *AlertRuleUpsertBulk) Update(set func(*AlertRuleUpsert)) *AlertRuleUpsertBulk {
|
|
u.create.conflict = append(u.create.conflict, sql.ResolveWith(func(update *sql.UpdateSet) {
|
|
set(&AlertRuleUpsert{UpdateSet: update})
|
|
}))
|
|
return u
|
|
}
|
|
|
|
// SetCode sets the "code" field.
|
|
func (u *AlertRuleUpsertBulk) SetCode(v string) *AlertRuleUpsertBulk {
|
|
return u.Update(func(s *AlertRuleUpsert) {
|
|
s.SetCode(v)
|
|
})
|
|
}
|
|
|
|
// UpdateCode sets the "code" field to the value that was provided on create.
|
|
func (u *AlertRuleUpsertBulk) UpdateCode() *AlertRuleUpsertBulk {
|
|
return u.Update(func(s *AlertRuleUpsert) {
|
|
s.UpdateCode()
|
|
})
|
|
}
|
|
|
|
// SetName sets the "name" field.
|
|
func (u *AlertRuleUpsertBulk) SetName(v string) *AlertRuleUpsertBulk {
|
|
return u.Update(func(s *AlertRuleUpsert) {
|
|
s.SetName(v)
|
|
})
|
|
}
|
|
|
|
// UpdateName sets the "name" field to the value that was provided on create.
|
|
func (u *AlertRuleUpsertBulk) UpdateName() *AlertRuleUpsertBulk {
|
|
return u.Update(func(s *AlertRuleUpsert) {
|
|
s.UpdateName()
|
|
})
|
|
}
|
|
|
|
// SetEnabled sets the "enabled" field.
|
|
func (u *AlertRuleUpsertBulk) SetEnabled(v bool) *AlertRuleUpsertBulk {
|
|
return u.Update(func(s *AlertRuleUpsert) {
|
|
s.SetEnabled(v)
|
|
})
|
|
}
|
|
|
|
// UpdateEnabled sets the "enabled" field to the value that was provided on create.
|
|
func (u *AlertRuleUpsertBulk) UpdateEnabled() *AlertRuleUpsertBulk {
|
|
return u.Update(func(s *AlertRuleUpsert) {
|
|
s.UpdateEnabled()
|
|
})
|
|
}
|
|
|
|
// SetThreshold sets the "threshold" field.
|
|
func (u *AlertRuleUpsertBulk) SetThreshold(v int) *AlertRuleUpsertBulk {
|
|
return u.Update(func(s *AlertRuleUpsert) {
|
|
s.SetThreshold(v)
|
|
})
|
|
}
|
|
|
|
// AddThreshold adds v to the "threshold" field.
|
|
func (u *AlertRuleUpsertBulk) AddThreshold(v int) *AlertRuleUpsertBulk {
|
|
return u.Update(func(s *AlertRuleUpsert) {
|
|
s.AddThreshold(v)
|
|
})
|
|
}
|
|
|
|
// UpdateThreshold sets the "threshold" field to the value that was provided on create.
|
|
func (u *AlertRuleUpsertBulk) UpdateThreshold() *AlertRuleUpsertBulk {
|
|
return u.Update(func(s *AlertRuleUpsert) {
|
|
s.UpdateThreshold()
|
|
})
|
|
}
|
|
|
|
// SetRemark sets the "remark" field.
|
|
func (u *AlertRuleUpsertBulk) SetRemark(v string) *AlertRuleUpsertBulk {
|
|
return u.Update(func(s *AlertRuleUpsert) {
|
|
s.SetRemark(v)
|
|
})
|
|
}
|
|
|
|
// UpdateRemark sets the "remark" field to the value that was provided on create.
|
|
func (u *AlertRuleUpsertBulk) UpdateRemark() *AlertRuleUpsertBulk {
|
|
return u.Update(func(s *AlertRuleUpsert) {
|
|
s.UpdateRemark()
|
|
})
|
|
}
|
|
|
|
// ClearRemark clears the value of the "remark" field.
|
|
func (u *AlertRuleUpsertBulk) ClearRemark() *AlertRuleUpsertBulk {
|
|
return u.Update(func(s *AlertRuleUpsert) {
|
|
s.ClearRemark()
|
|
})
|
|
}
|
|
|
|
// SetCreatedAt sets the "created_at" field.
|
|
func (u *AlertRuleUpsertBulk) SetCreatedAt(v int64) *AlertRuleUpsertBulk {
|
|
return u.Update(func(s *AlertRuleUpsert) {
|
|
s.SetCreatedAt(v)
|
|
})
|
|
}
|
|
|
|
// AddCreatedAt adds v to the "created_at" field.
|
|
func (u *AlertRuleUpsertBulk) AddCreatedAt(v int64) *AlertRuleUpsertBulk {
|
|
return u.Update(func(s *AlertRuleUpsert) {
|
|
s.AddCreatedAt(v)
|
|
})
|
|
}
|
|
|
|
// UpdateCreatedAt sets the "created_at" field to the value that was provided on create.
|
|
func (u *AlertRuleUpsertBulk) UpdateCreatedAt() *AlertRuleUpsertBulk {
|
|
return u.Update(func(s *AlertRuleUpsert) {
|
|
s.UpdateCreatedAt()
|
|
})
|
|
}
|
|
|
|
// SetUpdatedAt sets the "updated_at" field.
|
|
func (u *AlertRuleUpsertBulk) SetUpdatedAt(v int64) *AlertRuleUpsertBulk {
|
|
return u.Update(func(s *AlertRuleUpsert) {
|
|
s.SetUpdatedAt(v)
|
|
})
|
|
}
|
|
|
|
// AddUpdatedAt adds v to the "updated_at" field.
|
|
func (u *AlertRuleUpsertBulk) AddUpdatedAt(v int64) *AlertRuleUpsertBulk {
|
|
return u.Update(func(s *AlertRuleUpsert) {
|
|
s.AddUpdatedAt(v)
|
|
})
|
|
}
|
|
|
|
// UpdateUpdatedAt sets the "updated_at" field to the value that was provided on create.
|
|
func (u *AlertRuleUpsertBulk) UpdateUpdatedAt() *AlertRuleUpsertBulk {
|
|
return u.Update(func(s *AlertRuleUpsert) {
|
|
s.UpdateUpdatedAt()
|
|
})
|
|
}
|
|
|
|
// Exec executes the query.
|
|
func (u *AlertRuleUpsertBulk) 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 AlertRuleCreateBulk instead", i)
|
|
}
|
|
}
|
|
if len(u.create.conflict) == 0 {
|
|
return errors.New("ent: missing options for AlertRuleCreateBulk.OnConflict")
|
|
}
|
|
return u.create.Exec(ctx)
|
|
}
|
|
|
|
// ExecX is like Exec, but panics if an error occurs.
|
|
func (u *AlertRuleUpsertBulk) ExecX(ctx context.Context) {
|
|
if err := u.create.Exec(ctx); err != nil {
|
|
panic(err)
|
|
}
|
|
}
|