// 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/group" "github.com/Wei-Shaw/sub2api/ent/securitypolicykeyword" ) // SecurityPolicyKeywordCreate is the builder for creating a SecurityPolicyKeyword entity. type SecurityPolicyKeywordCreate struct { config mutation *SecurityPolicyKeywordMutation hooks []Hook conflict []sql.ConflictOption } // SetCreatedAt sets the "created_at" field. func (_c *SecurityPolicyKeywordCreate) SetCreatedAt(v time.Time) *SecurityPolicyKeywordCreate { _c.mutation.SetCreatedAt(v) return _c } // SetNillableCreatedAt sets the "created_at" field if the given value is not nil. func (_c *SecurityPolicyKeywordCreate) SetNillableCreatedAt(v *time.Time) *SecurityPolicyKeywordCreate { if v != nil { _c.SetCreatedAt(*v) } return _c } // SetUpdatedAt sets the "updated_at" field. func (_c *SecurityPolicyKeywordCreate) SetUpdatedAt(v time.Time) *SecurityPolicyKeywordCreate { _c.mutation.SetUpdatedAt(v) return _c } // SetNillableUpdatedAt sets the "updated_at" field if the given value is not nil. func (_c *SecurityPolicyKeywordCreate) SetNillableUpdatedAt(v *time.Time) *SecurityPolicyKeywordCreate { if v != nil { _c.SetUpdatedAt(*v) } return _c } // SetDeletedAt sets the "deleted_at" field. func (_c *SecurityPolicyKeywordCreate) SetDeletedAt(v time.Time) *SecurityPolicyKeywordCreate { _c.mutation.SetDeletedAt(v) return _c } // SetNillableDeletedAt sets the "deleted_at" field if the given value is not nil. func (_c *SecurityPolicyKeywordCreate) SetNillableDeletedAt(v *time.Time) *SecurityPolicyKeywordCreate { if v != nil { _c.SetDeletedAt(*v) } return _c } // SetGroupID sets the "group_id" field. func (_c *SecurityPolicyKeywordCreate) SetGroupID(v int64) *SecurityPolicyKeywordCreate { _c.mutation.SetGroupID(v) return _c } // SetNillableGroupID sets the "group_id" field if the given value is not nil. func (_c *SecurityPolicyKeywordCreate) SetNillableGroupID(v *int64) *SecurityPolicyKeywordCreate { if v != nil { _c.SetGroupID(*v) } return _c } // SetKeyword sets the "keyword" field. func (_c *SecurityPolicyKeywordCreate) SetKeyword(v string) *SecurityPolicyKeywordCreate { _c.mutation.SetKeyword(v) return _c } // SetCategory sets the "category" field. func (_c *SecurityPolicyKeywordCreate) SetCategory(v string) *SecurityPolicyKeywordCreate { _c.mutation.SetCategory(v) return _c } // SetNillableCategory sets the "category" field if the given value is not nil. func (_c *SecurityPolicyKeywordCreate) SetNillableCategory(v *string) *SecurityPolicyKeywordCreate { if v != nil { _c.SetCategory(*v) } return _c } // SetEnabled sets the "enabled" field. func (_c *SecurityPolicyKeywordCreate) SetEnabled(v bool) *SecurityPolicyKeywordCreate { _c.mutation.SetEnabled(v) return _c } // SetNillableEnabled sets the "enabled" field if the given value is not nil. func (_c *SecurityPolicyKeywordCreate) SetNillableEnabled(v *bool) *SecurityPolicyKeywordCreate { if v != nil { _c.SetEnabled(*v) } return _c } // SetGroup sets the "group" edge to the Group entity. func (_c *SecurityPolicyKeywordCreate) SetGroup(v *Group) *SecurityPolicyKeywordCreate { return _c.SetGroupID(v.ID) } // Mutation returns the SecurityPolicyKeywordMutation object of the builder. func (_c *SecurityPolicyKeywordCreate) Mutation() *SecurityPolicyKeywordMutation { return _c.mutation } // Save creates the SecurityPolicyKeyword in the database. func (_c *SecurityPolicyKeywordCreate) Save(ctx context.Context) (*SecurityPolicyKeyword, error) { if err := _c.defaults(); err != nil { return nil, err } return withHooks(ctx, _c.sqlSave, _c.mutation, _c.hooks) } // SaveX calls Save and panics if Save returns an error. func (_c *SecurityPolicyKeywordCreate) SaveX(ctx context.Context) *SecurityPolicyKeyword { v, err := _c.Save(ctx) if err != nil { panic(err) } return v } // Exec executes the query. func (_c *SecurityPolicyKeywordCreate) Exec(ctx context.Context) error { _, err := _c.Save(ctx) return err } // ExecX is like Exec, but panics if an error occurs. func (_c *SecurityPolicyKeywordCreate) 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 *SecurityPolicyKeywordCreate) defaults() error { if _, ok := _c.mutation.CreatedAt(); !ok { if securitypolicykeyword.DefaultCreatedAt == nil { return fmt.Errorf("ent: uninitialized securitypolicykeyword.DefaultCreatedAt (forgotten import ent/runtime?)") } v := securitypolicykeyword.DefaultCreatedAt() _c.mutation.SetCreatedAt(v) } if _, ok := _c.mutation.UpdatedAt(); !ok { if securitypolicykeyword.DefaultUpdatedAt == nil { return fmt.Errorf("ent: uninitialized securitypolicykeyword.DefaultUpdatedAt (forgotten import ent/runtime?)") } v := securitypolicykeyword.DefaultUpdatedAt() _c.mutation.SetUpdatedAt(v) } if _, ok := _c.mutation.Category(); !ok { v := securitypolicykeyword.DefaultCategory _c.mutation.SetCategory(v) } if _, ok := _c.mutation.Enabled(); !ok { v := securitypolicykeyword.DefaultEnabled _c.mutation.SetEnabled(v) } return nil } // check runs all checks and user-defined validators on the builder. func (_c *SecurityPolicyKeywordCreate) check() error { if _, ok := _c.mutation.CreatedAt(); !ok { return &ValidationError{Name: "created_at", err: errors.New(`ent: missing required field "SecurityPolicyKeyword.created_at"`)} } if _, ok := _c.mutation.UpdatedAt(); !ok { return &ValidationError{Name: "updated_at", err: errors.New(`ent: missing required field "SecurityPolicyKeyword.updated_at"`)} } if _, ok := _c.mutation.Keyword(); !ok { return &ValidationError{Name: "keyword", err: errors.New(`ent: missing required field "SecurityPolicyKeyword.keyword"`)} } if v, ok := _c.mutation.Keyword(); ok { if err := securitypolicykeyword.KeywordValidator(v); err != nil { return &ValidationError{Name: "keyword", err: fmt.Errorf(`ent: validator failed for field "SecurityPolicyKeyword.keyword": %w`, err)} } } if _, ok := _c.mutation.Category(); !ok { return &ValidationError{Name: "category", err: errors.New(`ent: missing required field "SecurityPolicyKeyword.category"`)} } if v, ok := _c.mutation.Category(); ok { if err := securitypolicykeyword.CategoryValidator(v); err != nil { return &ValidationError{Name: "category", err: fmt.Errorf(`ent: validator failed for field "SecurityPolicyKeyword.category": %w`, err)} } } if _, ok := _c.mutation.Enabled(); !ok { return &ValidationError{Name: "enabled", err: errors.New(`ent: missing required field "SecurityPolicyKeyword.enabled"`)} } return nil } func (_c *SecurityPolicyKeywordCreate) sqlSave(ctx context.Context) (*SecurityPolicyKeyword, 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 *SecurityPolicyKeywordCreate) createSpec() (*SecurityPolicyKeyword, *sqlgraph.CreateSpec) { var ( _node = &SecurityPolicyKeyword{config: _c.config} _spec = sqlgraph.NewCreateSpec(securitypolicykeyword.Table, sqlgraph.NewFieldSpec(securitypolicykeyword.FieldID, field.TypeInt64)) ) _spec.OnConflict = _c.conflict if value, ok := _c.mutation.CreatedAt(); ok { _spec.SetField(securitypolicykeyword.FieldCreatedAt, field.TypeTime, value) _node.CreatedAt = value } if value, ok := _c.mutation.UpdatedAt(); ok { _spec.SetField(securitypolicykeyword.FieldUpdatedAt, field.TypeTime, value) _node.UpdatedAt = value } if value, ok := _c.mutation.DeletedAt(); ok { _spec.SetField(securitypolicykeyword.FieldDeletedAt, field.TypeTime, value) _node.DeletedAt = &value } if value, ok := _c.mutation.Keyword(); ok { _spec.SetField(securitypolicykeyword.FieldKeyword, field.TypeString, value) _node.Keyword = value } if value, ok := _c.mutation.Category(); ok { _spec.SetField(securitypolicykeyword.FieldCategory, field.TypeString, value) _node.Category = value } if value, ok := _c.mutation.Enabled(); ok { _spec.SetField(securitypolicykeyword.FieldEnabled, field.TypeBool, value) _node.Enabled = value } if nodes := _c.mutation.GroupIDs(); len(nodes) > 0 { edge := &sqlgraph.EdgeSpec{ Rel: sqlgraph.M2O, Inverse: false, Table: securitypolicykeyword.GroupTable, Columns: []string{securitypolicykeyword.GroupColumn}, Bidi: false, Target: &sqlgraph.EdgeTarget{ IDSpec: sqlgraph.NewFieldSpec(group.FieldID, field.TypeInt64), }, } for _, k := range nodes { edge.Target.Nodes = append(edge.Target.Nodes, k) } _node.GroupID = &nodes[0] _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.SecurityPolicyKeyword.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.SecurityPolicyKeywordUpsert) { // SetCreatedAt(v+v). // }). // Exec(ctx) func (_c *SecurityPolicyKeywordCreate) OnConflict(opts ...sql.ConflictOption) *SecurityPolicyKeywordUpsertOne { _c.conflict = opts return &SecurityPolicyKeywordUpsertOne{ create: _c, } } // OnConflictColumns calls `OnConflict` and configures the columns // as conflict target. Using this option is equivalent to using: // // client.SecurityPolicyKeyword.Create(). // OnConflict(sql.ConflictColumns(columns...)). // Exec(ctx) func (_c *SecurityPolicyKeywordCreate) OnConflictColumns(columns ...string) *SecurityPolicyKeywordUpsertOne { _c.conflict = append(_c.conflict, sql.ConflictColumns(columns...)) return &SecurityPolicyKeywordUpsertOne{ create: _c, } } type ( // SecurityPolicyKeywordUpsertOne is the builder for "upsert"-ing // one SecurityPolicyKeyword node. SecurityPolicyKeywordUpsertOne struct { create *SecurityPolicyKeywordCreate } // SecurityPolicyKeywordUpsert is the "OnConflict" setter. SecurityPolicyKeywordUpsert struct { *sql.UpdateSet } ) // SetUpdatedAt sets the "updated_at" field. func (u *SecurityPolicyKeywordUpsert) SetUpdatedAt(v time.Time) *SecurityPolicyKeywordUpsert { u.Set(securitypolicykeyword.FieldUpdatedAt, v) return u } // UpdateUpdatedAt sets the "updated_at" field to the value that was provided on create. func (u *SecurityPolicyKeywordUpsert) UpdateUpdatedAt() *SecurityPolicyKeywordUpsert { u.SetExcluded(securitypolicykeyword.FieldUpdatedAt) return u } // SetDeletedAt sets the "deleted_at" field. func (u *SecurityPolicyKeywordUpsert) SetDeletedAt(v time.Time) *SecurityPolicyKeywordUpsert { u.Set(securitypolicykeyword.FieldDeletedAt, v) return u } // UpdateDeletedAt sets the "deleted_at" field to the value that was provided on create. func (u *SecurityPolicyKeywordUpsert) UpdateDeletedAt() *SecurityPolicyKeywordUpsert { u.SetExcluded(securitypolicykeyword.FieldDeletedAt) return u } // ClearDeletedAt clears the value of the "deleted_at" field. func (u *SecurityPolicyKeywordUpsert) ClearDeletedAt() *SecurityPolicyKeywordUpsert { u.SetNull(securitypolicykeyword.FieldDeletedAt) return u } // SetGroupID sets the "group_id" field. func (u *SecurityPolicyKeywordUpsert) SetGroupID(v int64) *SecurityPolicyKeywordUpsert { u.Set(securitypolicykeyword.FieldGroupID, v) return u } // UpdateGroupID sets the "group_id" field to the value that was provided on create. func (u *SecurityPolicyKeywordUpsert) UpdateGroupID() *SecurityPolicyKeywordUpsert { u.SetExcluded(securitypolicykeyword.FieldGroupID) return u } // ClearGroupID clears the value of the "group_id" field. func (u *SecurityPolicyKeywordUpsert) ClearGroupID() *SecurityPolicyKeywordUpsert { u.SetNull(securitypolicykeyword.FieldGroupID) return u } // SetKeyword sets the "keyword" field. func (u *SecurityPolicyKeywordUpsert) SetKeyword(v string) *SecurityPolicyKeywordUpsert { u.Set(securitypolicykeyword.FieldKeyword, v) return u } // UpdateKeyword sets the "keyword" field to the value that was provided on create. func (u *SecurityPolicyKeywordUpsert) UpdateKeyword() *SecurityPolicyKeywordUpsert { u.SetExcluded(securitypolicykeyword.FieldKeyword) return u } // SetCategory sets the "category" field. func (u *SecurityPolicyKeywordUpsert) SetCategory(v string) *SecurityPolicyKeywordUpsert { u.Set(securitypolicykeyword.FieldCategory, v) return u } // UpdateCategory sets the "category" field to the value that was provided on create. func (u *SecurityPolicyKeywordUpsert) UpdateCategory() *SecurityPolicyKeywordUpsert { u.SetExcluded(securitypolicykeyword.FieldCategory) return u } // SetEnabled sets the "enabled" field. func (u *SecurityPolicyKeywordUpsert) SetEnabled(v bool) *SecurityPolicyKeywordUpsert { u.Set(securitypolicykeyword.FieldEnabled, v) return u } // UpdateEnabled sets the "enabled" field to the value that was provided on create. func (u *SecurityPolicyKeywordUpsert) UpdateEnabled() *SecurityPolicyKeywordUpsert { u.SetExcluded(securitypolicykeyword.FieldEnabled) return u } // UpdateNewValues updates the mutable fields using the new values that were set on create. // Using this option is equivalent to using: // // client.SecurityPolicyKeyword.Create(). // OnConflict( // sql.ResolveWithNewValues(), // ). // Exec(ctx) func (u *SecurityPolicyKeywordUpsertOne) UpdateNewValues() *SecurityPolicyKeywordUpsertOne { 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(securitypolicykeyword.FieldCreatedAt) } })) return u } // Ignore sets each column to itself in case of conflict. // Using this option is equivalent to using: // // client.SecurityPolicyKeyword.Create(). // OnConflict(sql.ResolveWithIgnore()). // Exec(ctx) func (u *SecurityPolicyKeywordUpsertOne) Ignore() *SecurityPolicyKeywordUpsertOne { 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 *SecurityPolicyKeywordUpsertOne) DoNothing() *SecurityPolicyKeywordUpsertOne { u.create.conflict = append(u.create.conflict, sql.DoNothing()) return u } // Update allows overriding fields `UPDATE` values. See the SecurityPolicyKeywordCreate.OnConflict // documentation for more info. func (u *SecurityPolicyKeywordUpsertOne) Update(set func(*SecurityPolicyKeywordUpsert)) *SecurityPolicyKeywordUpsertOne { u.create.conflict = append(u.create.conflict, sql.ResolveWith(func(update *sql.UpdateSet) { set(&SecurityPolicyKeywordUpsert{UpdateSet: update}) })) return u } // SetUpdatedAt sets the "updated_at" field. func (u *SecurityPolicyKeywordUpsertOne) SetUpdatedAt(v time.Time) *SecurityPolicyKeywordUpsertOne { return u.Update(func(s *SecurityPolicyKeywordUpsert) { s.SetUpdatedAt(v) }) } // UpdateUpdatedAt sets the "updated_at" field to the value that was provided on create. func (u *SecurityPolicyKeywordUpsertOne) UpdateUpdatedAt() *SecurityPolicyKeywordUpsertOne { return u.Update(func(s *SecurityPolicyKeywordUpsert) { s.UpdateUpdatedAt() }) } // SetDeletedAt sets the "deleted_at" field. func (u *SecurityPolicyKeywordUpsertOne) SetDeletedAt(v time.Time) *SecurityPolicyKeywordUpsertOne { return u.Update(func(s *SecurityPolicyKeywordUpsert) { s.SetDeletedAt(v) }) } // UpdateDeletedAt sets the "deleted_at" field to the value that was provided on create. func (u *SecurityPolicyKeywordUpsertOne) UpdateDeletedAt() *SecurityPolicyKeywordUpsertOne { return u.Update(func(s *SecurityPolicyKeywordUpsert) { s.UpdateDeletedAt() }) } // ClearDeletedAt clears the value of the "deleted_at" field. func (u *SecurityPolicyKeywordUpsertOne) ClearDeletedAt() *SecurityPolicyKeywordUpsertOne { return u.Update(func(s *SecurityPolicyKeywordUpsert) { s.ClearDeletedAt() }) } // SetGroupID sets the "group_id" field. func (u *SecurityPolicyKeywordUpsertOne) SetGroupID(v int64) *SecurityPolicyKeywordUpsertOne { return u.Update(func(s *SecurityPolicyKeywordUpsert) { s.SetGroupID(v) }) } // UpdateGroupID sets the "group_id" field to the value that was provided on create. func (u *SecurityPolicyKeywordUpsertOne) UpdateGroupID() *SecurityPolicyKeywordUpsertOne { return u.Update(func(s *SecurityPolicyKeywordUpsert) { s.UpdateGroupID() }) } // ClearGroupID clears the value of the "group_id" field. func (u *SecurityPolicyKeywordUpsertOne) ClearGroupID() *SecurityPolicyKeywordUpsertOne { return u.Update(func(s *SecurityPolicyKeywordUpsert) { s.ClearGroupID() }) } // SetKeyword sets the "keyword" field. func (u *SecurityPolicyKeywordUpsertOne) SetKeyword(v string) *SecurityPolicyKeywordUpsertOne { return u.Update(func(s *SecurityPolicyKeywordUpsert) { s.SetKeyword(v) }) } // UpdateKeyword sets the "keyword" field to the value that was provided on create. func (u *SecurityPolicyKeywordUpsertOne) UpdateKeyword() *SecurityPolicyKeywordUpsertOne { return u.Update(func(s *SecurityPolicyKeywordUpsert) { s.UpdateKeyword() }) } // SetCategory sets the "category" field. func (u *SecurityPolicyKeywordUpsertOne) SetCategory(v string) *SecurityPolicyKeywordUpsertOne { return u.Update(func(s *SecurityPolicyKeywordUpsert) { s.SetCategory(v) }) } // UpdateCategory sets the "category" field to the value that was provided on create. func (u *SecurityPolicyKeywordUpsertOne) UpdateCategory() *SecurityPolicyKeywordUpsertOne { return u.Update(func(s *SecurityPolicyKeywordUpsert) { s.UpdateCategory() }) } // SetEnabled sets the "enabled" field. func (u *SecurityPolicyKeywordUpsertOne) SetEnabled(v bool) *SecurityPolicyKeywordUpsertOne { return u.Update(func(s *SecurityPolicyKeywordUpsert) { s.SetEnabled(v) }) } // UpdateEnabled sets the "enabled" field to the value that was provided on create. func (u *SecurityPolicyKeywordUpsertOne) UpdateEnabled() *SecurityPolicyKeywordUpsertOne { return u.Update(func(s *SecurityPolicyKeywordUpsert) { s.UpdateEnabled() }) } // Exec executes the query. func (u *SecurityPolicyKeywordUpsertOne) Exec(ctx context.Context) error { if len(u.create.conflict) == 0 { return errors.New("ent: missing options for SecurityPolicyKeywordCreate.OnConflict") } return u.create.Exec(ctx) } // ExecX is like Exec, but panics if an error occurs. func (u *SecurityPolicyKeywordUpsertOne) 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 *SecurityPolicyKeywordUpsertOne) 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 *SecurityPolicyKeywordUpsertOne) IDX(ctx context.Context) int64 { id, err := u.ID(ctx) if err != nil { panic(err) } return id } // SecurityPolicyKeywordCreateBulk is the builder for creating many SecurityPolicyKeyword entities in bulk. type SecurityPolicyKeywordCreateBulk struct { config err error builders []*SecurityPolicyKeywordCreate conflict []sql.ConflictOption } // Save creates the SecurityPolicyKeyword entities in the database. func (_c *SecurityPolicyKeywordCreateBulk) Save(ctx context.Context) ([]*SecurityPolicyKeyword, error) { if _c.err != nil { return nil, _c.err } specs := make([]*sqlgraph.CreateSpec, len(_c.builders)) nodes := make([]*SecurityPolicyKeyword, 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.(*SecurityPolicyKeywordMutation) 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 *SecurityPolicyKeywordCreateBulk) SaveX(ctx context.Context) []*SecurityPolicyKeyword { v, err := _c.Save(ctx) if err != nil { panic(err) } return v } // Exec executes the query. func (_c *SecurityPolicyKeywordCreateBulk) Exec(ctx context.Context) error { _, err := _c.Save(ctx) return err } // ExecX is like Exec, but panics if an error occurs. func (_c *SecurityPolicyKeywordCreateBulk) 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.SecurityPolicyKeyword.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.SecurityPolicyKeywordUpsert) { // SetCreatedAt(v+v). // }). // Exec(ctx) func (_c *SecurityPolicyKeywordCreateBulk) OnConflict(opts ...sql.ConflictOption) *SecurityPolicyKeywordUpsertBulk { _c.conflict = opts return &SecurityPolicyKeywordUpsertBulk{ create: _c, } } // OnConflictColumns calls `OnConflict` and configures the columns // as conflict target. Using this option is equivalent to using: // // client.SecurityPolicyKeyword.Create(). // OnConflict(sql.ConflictColumns(columns...)). // Exec(ctx) func (_c *SecurityPolicyKeywordCreateBulk) OnConflictColumns(columns ...string) *SecurityPolicyKeywordUpsertBulk { _c.conflict = append(_c.conflict, sql.ConflictColumns(columns...)) return &SecurityPolicyKeywordUpsertBulk{ create: _c, } } // SecurityPolicyKeywordUpsertBulk is the builder for "upsert"-ing // a bulk of SecurityPolicyKeyword nodes. type SecurityPolicyKeywordUpsertBulk struct { create *SecurityPolicyKeywordCreateBulk } // UpdateNewValues updates the mutable fields using the new values that // were set on create. Using this option is equivalent to using: // // client.SecurityPolicyKeyword.Create(). // OnConflict( // sql.ResolveWithNewValues(), // ). // Exec(ctx) func (u *SecurityPolicyKeywordUpsertBulk) UpdateNewValues() *SecurityPolicyKeywordUpsertBulk { 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(securitypolicykeyword.FieldCreatedAt) } } })) return u } // Ignore sets each column to itself in case of conflict. // Using this option is equivalent to using: // // client.SecurityPolicyKeyword.Create(). // OnConflict(sql.ResolveWithIgnore()). // Exec(ctx) func (u *SecurityPolicyKeywordUpsertBulk) Ignore() *SecurityPolicyKeywordUpsertBulk { 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 *SecurityPolicyKeywordUpsertBulk) DoNothing() *SecurityPolicyKeywordUpsertBulk { u.create.conflict = append(u.create.conflict, sql.DoNothing()) return u } // Update allows overriding fields `UPDATE` values. See the SecurityPolicyKeywordCreateBulk.OnConflict // documentation for more info. func (u *SecurityPolicyKeywordUpsertBulk) Update(set func(*SecurityPolicyKeywordUpsert)) *SecurityPolicyKeywordUpsertBulk { u.create.conflict = append(u.create.conflict, sql.ResolveWith(func(update *sql.UpdateSet) { set(&SecurityPolicyKeywordUpsert{UpdateSet: update}) })) return u } // SetUpdatedAt sets the "updated_at" field. func (u *SecurityPolicyKeywordUpsertBulk) SetUpdatedAt(v time.Time) *SecurityPolicyKeywordUpsertBulk { return u.Update(func(s *SecurityPolicyKeywordUpsert) { s.SetUpdatedAt(v) }) } // UpdateUpdatedAt sets the "updated_at" field to the value that was provided on create. func (u *SecurityPolicyKeywordUpsertBulk) UpdateUpdatedAt() *SecurityPolicyKeywordUpsertBulk { return u.Update(func(s *SecurityPolicyKeywordUpsert) { s.UpdateUpdatedAt() }) } // SetDeletedAt sets the "deleted_at" field. func (u *SecurityPolicyKeywordUpsertBulk) SetDeletedAt(v time.Time) *SecurityPolicyKeywordUpsertBulk { return u.Update(func(s *SecurityPolicyKeywordUpsert) { s.SetDeletedAt(v) }) } // UpdateDeletedAt sets the "deleted_at" field to the value that was provided on create. func (u *SecurityPolicyKeywordUpsertBulk) UpdateDeletedAt() *SecurityPolicyKeywordUpsertBulk { return u.Update(func(s *SecurityPolicyKeywordUpsert) { s.UpdateDeletedAt() }) } // ClearDeletedAt clears the value of the "deleted_at" field. func (u *SecurityPolicyKeywordUpsertBulk) ClearDeletedAt() *SecurityPolicyKeywordUpsertBulk { return u.Update(func(s *SecurityPolicyKeywordUpsert) { s.ClearDeletedAt() }) } // SetGroupID sets the "group_id" field. func (u *SecurityPolicyKeywordUpsertBulk) SetGroupID(v int64) *SecurityPolicyKeywordUpsertBulk { return u.Update(func(s *SecurityPolicyKeywordUpsert) { s.SetGroupID(v) }) } // UpdateGroupID sets the "group_id" field to the value that was provided on create. func (u *SecurityPolicyKeywordUpsertBulk) UpdateGroupID() *SecurityPolicyKeywordUpsertBulk { return u.Update(func(s *SecurityPolicyKeywordUpsert) { s.UpdateGroupID() }) } // ClearGroupID clears the value of the "group_id" field. func (u *SecurityPolicyKeywordUpsertBulk) ClearGroupID() *SecurityPolicyKeywordUpsertBulk { return u.Update(func(s *SecurityPolicyKeywordUpsert) { s.ClearGroupID() }) } // SetKeyword sets the "keyword" field. func (u *SecurityPolicyKeywordUpsertBulk) SetKeyword(v string) *SecurityPolicyKeywordUpsertBulk { return u.Update(func(s *SecurityPolicyKeywordUpsert) { s.SetKeyword(v) }) } // UpdateKeyword sets the "keyword" field to the value that was provided on create. func (u *SecurityPolicyKeywordUpsertBulk) UpdateKeyword() *SecurityPolicyKeywordUpsertBulk { return u.Update(func(s *SecurityPolicyKeywordUpsert) { s.UpdateKeyword() }) } // SetCategory sets the "category" field. func (u *SecurityPolicyKeywordUpsertBulk) SetCategory(v string) *SecurityPolicyKeywordUpsertBulk { return u.Update(func(s *SecurityPolicyKeywordUpsert) { s.SetCategory(v) }) } // UpdateCategory sets the "category" field to the value that was provided on create. func (u *SecurityPolicyKeywordUpsertBulk) UpdateCategory() *SecurityPolicyKeywordUpsertBulk { return u.Update(func(s *SecurityPolicyKeywordUpsert) { s.UpdateCategory() }) } // SetEnabled sets the "enabled" field. func (u *SecurityPolicyKeywordUpsertBulk) SetEnabled(v bool) *SecurityPolicyKeywordUpsertBulk { return u.Update(func(s *SecurityPolicyKeywordUpsert) { s.SetEnabled(v) }) } // UpdateEnabled sets the "enabled" field to the value that was provided on create. func (u *SecurityPolicyKeywordUpsertBulk) UpdateEnabled() *SecurityPolicyKeywordUpsertBulk { return u.Update(func(s *SecurityPolicyKeywordUpsert) { s.UpdateEnabled() }) } // Exec executes the query. func (u *SecurityPolicyKeywordUpsertBulk) 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 SecurityPolicyKeywordCreateBulk instead", i) } } if len(u.create.conflict) == 0 { return errors.New("ent: missing options for SecurityPolicyKeywordCreateBulk.OnConflict") } return u.create.Exec(ctx) } // ExecX is like Exec, but panics if an error occurs. func (u *SecurityPolicyKeywordUpsertBulk) ExecX(ctx context.Context) { if err := u.create.Exec(ctx); err != nil { panic(err) } }