mirror of
https://github.com/chaitin/MonkeyCode.git
synced 2026-11-24 21:29:00 +08:00
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
708 lines
22 KiB
Go
708 lines
22 KiB
Go
// Code generated by ent, DO NOT EDIT.
|
|
|
|
package db
|
|
|
|
import (
|
|
"context"
|
|
"errors"
|
|
"fmt"
|
|
"time"
|
|
|
|
"entgo.io/ent/dialect"
|
|
"entgo.io/ent/dialect/sql"
|
|
"entgo.io/ent/dialect/sql/sqlgraph"
|
|
"entgo.io/ent/schema/field"
|
|
"github.com/chaitin/MonkeyCode/backend/db/agentrule"
|
|
"github.com/chaitin/MonkeyCode/backend/db/agentruleversion"
|
|
"github.com/google/uuid"
|
|
)
|
|
|
|
// AgentRuleVersionCreate is the builder for creating a AgentRuleVersion entity.
|
|
type AgentRuleVersionCreate struct {
|
|
config
|
|
mutation *AgentRuleVersionMutation
|
|
hooks []Hook
|
|
conflict []sql.ConflictOption
|
|
}
|
|
|
|
// SetRuleID sets the "rule_id" field.
|
|
func (_c *AgentRuleVersionCreate) SetRuleID(v uuid.UUID) *AgentRuleVersionCreate {
|
|
_c.mutation.SetRuleID(v)
|
|
return _c
|
|
}
|
|
|
|
// SetVersion sets the "version" field.
|
|
func (_c *AgentRuleVersionCreate) SetVersion(v string) *AgentRuleVersionCreate {
|
|
_c.mutation.SetVersion(v)
|
|
return _c
|
|
}
|
|
|
|
// SetContent sets the "content" field.
|
|
func (_c *AgentRuleVersionCreate) SetContent(v string) *AgentRuleVersionCreate {
|
|
_c.mutation.SetContent(v)
|
|
return _c
|
|
}
|
|
|
|
// SetCreatedAt sets the "created_at" field.
|
|
func (_c *AgentRuleVersionCreate) SetCreatedAt(v time.Time) *AgentRuleVersionCreate {
|
|
_c.mutation.SetCreatedAt(v)
|
|
return _c
|
|
}
|
|
|
|
// SetNillableCreatedAt sets the "created_at" field if the given value is not nil.
|
|
func (_c *AgentRuleVersionCreate) SetNillableCreatedAt(v *time.Time) *AgentRuleVersionCreate {
|
|
if v != nil {
|
|
_c.SetCreatedAt(*v)
|
|
}
|
|
return _c
|
|
}
|
|
|
|
// SetID sets the "id" field.
|
|
func (_c *AgentRuleVersionCreate) SetID(v uuid.UUID) *AgentRuleVersionCreate {
|
|
_c.mutation.SetID(v)
|
|
return _c
|
|
}
|
|
|
|
// SetNillableID sets the "id" field if the given value is not nil.
|
|
func (_c *AgentRuleVersionCreate) SetNillableID(v *uuid.UUID) *AgentRuleVersionCreate {
|
|
if v != nil {
|
|
_c.SetID(*v)
|
|
}
|
|
return _c
|
|
}
|
|
|
|
// SetRule sets the "rule" edge to the AgentRule entity.
|
|
func (_c *AgentRuleVersionCreate) SetRule(v *AgentRule) *AgentRuleVersionCreate {
|
|
return _c.SetRuleID(v.ID)
|
|
}
|
|
|
|
// Mutation returns the AgentRuleVersionMutation object of the builder.
|
|
func (_c *AgentRuleVersionCreate) Mutation() *AgentRuleVersionMutation {
|
|
return _c.mutation
|
|
}
|
|
|
|
// Save creates the AgentRuleVersion in the database.
|
|
func (_c *AgentRuleVersionCreate) Save(ctx context.Context) (*AgentRuleVersion, error) {
|
|
_c.defaults()
|
|
return withHooks(ctx, _c.sqlSave, _c.mutation, _c.hooks)
|
|
}
|
|
|
|
// SaveX calls Save and panics if Save returns an error.
|
|
func (_c *AgentRuleVersionCreate) SaveX(ctx context.Context) *AgentRuleVersion {
|
|
v, err := _c.Save(ctx)
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
return v
|
|
}
|
|
|
|
// Exec executes the query.
|
|
func (_c *AgentRuleVersionCreate) Exec(ctx context.Context) error {
|
|
_, err := _c.Save(ctx)
|
|
return err
|
|
}
|
|
|
|
// ExecX is like Exec, but panics if an error occurs.
|
|
func (_c *AgentRuleVersionCreate) 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 *AgentRuleVersionCreate) defaults() {
|
|
if _, ok := _c.mutation.CreatedAt(); !ok {
|
|
v := agentruleversion.DefaultCreatedAt()
|
|
_c.mutation.SetCreatedAt(v)
|
|
}
|
|
if _, ok := _c.mutation.ID(); !ok {
|
|
v := agentruleversion.DefaultID()
|
|
_c.mutation.SetID(v)
|
|
}
|
|
}
|
|
|
|
// check runs all checks and user-defined validators on the builder.
|
|
func (_c *AgentRuleVersionCreate) check() error {
|
|
if _, ok := _c.mutation.RuleID(); !ok {
|
|
return &ValidationError{Name: "rule_id", err: errors.New(`db: missing required field "AgentRuleVersion.rule_id"`)}
|
|
}
|
|
if _, ok := _c.mutation.Version(); !ok {
|
|
return &ValidationError{Name: "version", err: errors.New(`db: missing required field "AgentRuleVersion.version"`)}
|
|
}
|
|
if v, ok := _c.mutation.Version(); ok {
|
|
if err := agentruleversion.VersionValidator(v); err != nil {
|
|
return &ValidationError{Name: "version", err: fmt.Errorf(`db: validator failed for field "AgentRuleVersion.version": %w`, err)}
|
|
}
|
|
}
|
|
if _, ok := _c.mutation.Content(); !ok {
|
|
return &ValidationError{Name: "content", err: errors.New(`db: missing required field "AgentRuleVersion.content"`)}
|
|
}
|
|
if _, ok := _c.mutation.CreatedAt(); !ok {
|
|
return &ValidationError{Name: "created_at", err: errors.New(`db: missing required field "AgentRuleVersion.created_at"`)}
|
|
}
|
|
if len(_c.mutation.RuleIDs()) == 0 {
|
|
return &ValidationError{Name: "rule", err: errors.New(`db: missing required edge "AgentRuleVersion.rule"`)}
|
|
}
|
|
return nil
|
|
}
|
|
|
|
func (_c *AgentRuleVersionCreate) sqlSave(ctx context.Context) (*AgentRuleVersion, 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
|
|
}
|
|
if _spec.ID.Value != nil {
|
|
if id, ok := _spec.ID.Value.(*uuid.UUID); ok {
|
|
_node.ID = *id
|
|
} else if err := _node.ID.Scan(_spec.ID.Value); err != nil {
|
|
return nil, err
|
|
}
|
|
}
|
|
_c.mutation.id = &_node.ID
|
|
_c.mutation.done = true
|
|
return _node, nil
|
|
}
|
|
|
|
func (_c *AgentRuleVersionCreate) createSpec() (*AgentRuleVersion, *sqlgraph.CreateSpec) {
|
|
var (
|
|
_node = &AgentRuleVersion{config: _c.config}
|
|
_spec = sqlgraph.NewCreateSpec(agentruleversion.Table, sqlgraph.NewFieldSpec(agentruleversion.FieldID, field.TypeUUID))
|
|
)
|
|
_spec.OnConflict = _c.conflict
|
|
if id, ok := _c.mutation.ID(); ok {
|
|
_node.ID = id
|
|
_spec.ID.Value = &id
|
|
}
|
|
if value, ok := _c.mutation.Version(); ok {
|
|
_spec.SetField(agentruleversion.FieldVersion, field.TypeString, value)
|
|
_node.Version = value
|
|
}
|
|
if value, ok := _c.mutation.Content(); ok {
|
|
_spec.SetField(agentruleversion.FieldContent, field.TypeString, value)
|
|
_node.Content = value
|
|
}
|
|
if value, ok := _c.mutation.CreatedAt(); ok {
|
|
_spec.SetField(agentruleversion.FieldCreatedAt, field.TypeTime, value)
|
|
_node.CreatedAt = value
|
|
}
|
|
if nodes := _c.mutation.RuleIDs(); len(nodes) > 0 {
|
|
edge := &sqlgraph.EdgeSpec{
|
|
Rel: sqlgraph.M2O,
|
|
Inverse: true,
|
|
Table: agentruleversion.RuleTable,
|
|
Columns: []string{agentruleversion.RuleColumn},
|
|
Bidi: false,
|
|
Target: &sqlgraph.EdgeTarget{
|
|
IDSpec: sqlgraph.NewFieldSpec(agentrule.FieldID, field.TypeUUID),
|
|
},
|
|
}
|
|
for _, k := range nodes {
|
|
edge.Target.Nodes = append(edge.Target.Nodes, k)
|
|
}
|
|
_node.RuleID = 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.AgentRuleVersion.Create().
|
|
// SetRuleID(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.AgentRuleVersionUpsert) {
|
|
// SetRuleID(v+v).
|
|
// }).
|
|
// Exec(ctx)
|
|
func (_c *AgentRuleVersionCreate) OnConflict(opts ...sql.ConflictOption) *AgentRuleVersionUpsertOne {
|
|
_c.conflict = opts
|
|
return &AgentRuleVersionUpsertOne{
|
|
create: _c,
|
|
}
|
|
}
|
|
|
|
// OnConflictColumns calls `OnConflict` and configures the columns
|
|
// as conflict target. Using this option is equivalent to using:
|
|
//
|
|
// client.AgentRuleVersion.Create().
|
|
// OnConflict(sql.ConflictColumns(columns...)).
|
|
// Exec(ctx)
|
|
func (_c *AgentRuleVersionCreate) OnConflictColumns(columns ...string) *AgentRuleVersionUpsertOne {
|
|
_c.conflict = append(_c.conflict, sql.ConflictColumns(columns...))
|
|
return &AgentRuleVersionUpsertOne{
|
|
create: _c,
|
|
}
|
|
}
|
|
|
|
type (
|
|
// AgentRuleVersionUpsertOne is the builder for "upsert"-ing
|
|
// one AgentRuleVersion node.
|
|
AgentRuleVersionUpsertOne struct {
|
|
create *AgentRuleVersionCreate
|
|
}
|
|
|
|
// AgentRuleVersionUpsert is the "OnConflict" setter.
|
|
AgentRuleVersionUpsert struct {
|
|
*sql.UpdateSet
|
|
}
|
|
)
|
|
|
|
// SetRuleID sets the "rule_id" field.
|
|
func (u *AgentRuleVersionUpsert) SetRuleID(v uuid.UUID) *AgentRuleVersionUpsert {
|
|
u.Set(agentruleversion.FieldRuleID, v)
|
|
return u
|
|
}
|
|
|
|
// UpdateRuleID sets the "rule_id" field to the value that was provided on create.
|
|
func (u *AgentRuleVersionUpsert) UpdateRuleID() *AgentRuleVersionUpsert {
|
|
u.SetExcluded(agentruleversion.FieldRuleID)
|
|
return u
|
|
}
|
|
|
|
// SetVersion sets the "version" field.
|
|
func (u *AgentRuleVersionUpsert) SetVersion(v string) *AgentRuleVersionUpsert {
|
|
u.Set(agentruleversion.FieldVersion, v)
|
|
return u
|
|
}
|
|
|
|
// UpdateVersion sets the "version" field to the value that was provided on create.
|
|
func (u *AgentRuleVersionUpsert) UpdateVersion() *AgentRuleVersionUpsert {
|
|
u.SetExcluded(agentruleversion.FieldVersion)
|
|
return u
|
|
}
|
|
|
|
// SetContent sets the "content" field.
|
|
func (u *AgentRuleVersionUpsert) SetContent(v string) *AgentRuleVersionUpsert {
|
|
u.Set(agentruleversion.FieldContent, v)
|
|
return u
|
|
}
|
|
|
|
// UpdateContent sets the "content" field to the value that was provided on create.
|
|
func (u *AgentRuleVersionUpsert) UpdateContent() *AgentRuleVersionUpsert {
|
|
u.SetExcluded(agentruleversion.FieldContent)
|
|
return u
|
|
}
|
|
|
|
// SetCreatedAt sets the "created_at" field.
|
|
func (u *AgentRuleVersionUpsert) SetCreatedAt(v time.Time) *AgentRuleVersionUpsert {
|
|
u.Set(agentruleversion.FieldCreatedAt, v)
|
|
return u
|
|
}
|
|
|
|
// UpdateCreatedAt sets the "created_at" field to the value that was provided on create.
|
|
func (u *AgentRuleVersionUpsert) UpdateCreatedAt() *AgentRuleVersionUpsert {
|
|
u.SetExcluded(agentruleversion.FieldCreatedAt)
|
|
return u
|
|
}
|
|
|
|
// UpdateNewValues updates the mutable fields using the new values that were set on create except the ID field.
|
|
// Using this option is equivalent to using:
|
|
//
|
|
// client.AgentRuleVersion.Create().
|
|
// OnConflict(
|
|
// sql.ResolveWithNewValues(),
|
|
// sql.ResolveWith(func(u *sql.UpdateSet) {
|
|
// u.SetIgnore(agentruleversion.FieldID)
|
|
// }),
|
|
// ).
|
|
// Exec(ctx)
|
|
func (u *AgentRuleVersionUpsertOne) UpdateNewValues() *AgentRuleVersionUpsertOne {
|
|
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.ID(); exists {
|
|
s.SetIgnore(agentruleversion.FieldID)
|
|
}
|
|
}))
|
|
return u
|
|
}
|
|
|
|
// Ignore sets each column to itself in case of conflict.
|
|
// Using this option is equivalent to using:
|
|
//
|
|
// client.AgentRuleVersion.Create().
|
|
// OnConflict(sql.ResolveWithIgnore()).
|
|
// Exec(ctx)
|
|
func (u *AgentRuleVersionUpsertOne) Ignore() *AgentRuleVersionUpsertOne {
|
|
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 *AgentRuleVersionUpsertOne) DoNothing() *AgentRuleVersionUpsertOne {
|
|
u.create.conflict = append(u.create.conflict, sql.DoNothing())
|
|
return u
|
|
}
|
|
|
|
// Update allows overriding fields `UPDATE` values. See the AgentRuleVersionCreate.OnConflict
|
|
// documentation for more info.
|
|
func (u *AgentRuleVersionUpsertOne) Update(set func(*AgentRuleVersionUpsert)) *AgentRuleVersionUpsertOne {
|
|
u.create.conflict = append(u.create.conflict, sql.ResolveWith(func(update *sql.UpdateSet) {
|
|
set(&AgentRuleVersionUpsert{UpdateSet: update})
|
|
}))
|
|
return u
|
|
}
|
|
|
|
// SetRuleID sets the "rule_id" field.
|
|
func (u *AgentRuleVersionUpsertOne) SetRuleID(v uuid.UUID) *AgentRuleVersionUpsertOne {
|
|
return u.Update(func(s *AgentRuleVersionUpsert) {
|
|
s.SetRuleID(v)
|
|
})
|
|
}
|
|
|
|
// UpdateRuleID sets the "rule_id" field to the value that was provided on create.
|
|
func (u *AgentRuleVersionUpsertOne) UpdateRuleID() *AgentRuleVersionUpsertOne {
|
|
return u.Update(func(s *AgentRuleVersionUpsert) {
|
|
s.UpdateRuleID()
|
|
})
|
|
}
|
|
|
|
// SetVersion sets the "version" field.
|
|
func (u *AgentRuleVersionUpsertOne) SetVersion(v string) *AgentRuleVersionUpsertOne {
|
|
return u.Update(func(s *AgentRuleVersionUpsert) {
|
|
s.SetVersion(v)
|
|
})
|
|
}
|
|
|
|
// UpdateVersion sets the "version" field to the value that was provided on create.
|
|
func (u *AgentRuleVersionUpsertOne) UpdateVersion() *AgentRuleVersionUpsertOne {
|
|
return u.Update(func(s *AgentRuleVersionUpsert) {
|
|
s.UpdateVersion()
|
|
})
|
|
}
|
|
|
|
// SetContent sets the "content" field.
|
|
func (u *AgentRuleVersionUpsertOne) SetContent(v string) *AgentRuleVersionUpsertOne {
|
|
return u.Update(func(s *AgentRuleVersionUpsert) {
|
|
s.SetContent(v)
|
|
})
|
|
}
|
|
|
|
// UpdateContent sets the "content" field to the value that was provided on create.
|
|
func (u *AgentRuleVersionUpsertOne) UpdateContent() *AgentRuleVersionUpsertOne {
|
|
return u.Update(func(s *AgentRuleVersionUpsert) {
|
|
s.UpdateContent()
|
|
})
|
|
}
|
|
|
|
// SetCreatedAt sets the "created_at" field.
|
|
func (u *AgentRuleVersionUpsertOne) SetCreatedAt(v time.Time) *AgentRuleVersionUpsertOne {
|
|
return u.Update(func(s *AgentRuleVersionUpsert) {
|
|
s.SetCreatedAt(v)
|
|
})
|
|
}
|
|
|
|
// UpdateCreatedAt sets the "created_at" field to the value that was provided on create.
|
|
func (u *AgentRuleVersionUpsertOne) UpdateCreatedAt() *AgentRuleVersionUpsertOne {
|
|
return u.Update(func(s *AgentRuleVersionUpsert) {
|
|
s.UpdateCreatedAt()
|
|
})
|
|
}
|
|
|
|
// Exec executes the query.
|
|
func (u *AgentRuleVersionUpsertOne) Exec(ctx context.Context) error {
|
|
if len(u.create.conflict) == 0 {
|
|
return errors.New("db: missing options for AgentRuleVersionCreate.OnConflict")
|
|
}
|
|
return u.create.Exec(ctx)
|
|
}
|
|
|
|
// ExecX is like Exec, but panics if an error occurs.
|
|
func (u *AgentRuleVersionUpsertOne) 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 *AgentRuleVersionUpsertOne) ID(ctx context.Context) (id uuid.UUID, err error) {
|
|
if u.create.driver.Dialect() == dialect.MySQL {
|
|
// In case of "ON CONFLICT", there is no way to get back non-numeric ID
|
|
// fields from the database since MySQL does not support the RETURNING clause.
|
|
return id, errors.New("db: AgentRuleVersionUpsertOne.ID is not supported by MySQL driver. Use AgentRuleVersionUpsertOne.Exec instead")
|
|
}
|
|
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 *AgentRuleVersionUpsertOne) IDX(ctx context.Context) uuid.UUID {
|
|
id, err := u.ID(ctx)
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
return id
|
|
}
|
|
|
|
// AgentRuleVersionCreateBulk is the builder for creating many AgentRuleVersion entities in bulk.
|
|
type AgentRuleVersionCreateBulk struct {
|
|
config
|
|
err error
|
|
builders []*AgentRuleVersionCreate
|
|
conflict []sql.ConflictOption
|
|
}
|
|
|
|
// Save creates the AgentRuleVersion entities in the database.
|
|
func (_c *AgentRuleVersionCreateBulk) Save(ctx context.Context) ([]*AgentRuleVersion, error) {
|
|
if _c.err != nil {
|
|
return nil, _c.err
|
|
}
|
|
specs := make([]*sqlgraph.CreateSpec, len(_c.builders))
|
|
nodes := make([]*AgentRuleVersion, 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.(*AgentRuleVersionMutation)
|
|
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
|
|
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 *AgentRuleVersionCreateBulk) SaveX(ctx context.Context) []*AgentRuleVersion {
|
|
v, err := _c.Save(ctx)
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
return v
|
|
}
|
|
|
|
// Exec executes the query.
|
|
func (_c *AgentRuleVersionCreateBulk) Exec(ctx context.Context) error {
|
|
_, err := _c.Save(ctx)
|
|
return err
|
|
}
|
|
|
|
// ExecX is like Exec, but panics if an error occurs.
|
|
func (_c *AgentRuleVersionCreateBulk) 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.AgentRuleVersion.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.AgentRuleVersionUpsert) {
|
|
// SetRuleID(v+v).
|
|
// }).
|
|
// Exec(ctx)
|
|
func (_c *AgentRuleVersionCreateBulk) OnConflict(opts ...sql.ConflictOption) *AgentRuleVersionUpsertBulk {
|
|
_c.conflict = opts
|
|
return &AgentRuleVersionUpsertBulk{
|
|
create: _c,
|
|
}
|
|
}
|
|
|
|
// OnConflictColumns calls `OnConflict` and configures the columns
|
|
// as conflict target. Using this option is equivalent to using:
|
|
//
|
|
// client.AgentRuleVersion.Create().
|
|
// OnConflict(sql.ConflictColumns(columns...)).
|
|
// Exec(ctx)
|
|
func (_c *AgentRuleVersionCreateBulk) OnConflictColumns(columns ...string) *AgentRuleVersionUpsertBulk {
|
|
_c.conflict = append(_c.conflict, sql.ConflictColumns(columns...))
|
|
return &AgentRuleVersionUpsertBulk{
|
|
create: _c,
|
|
}
|
|
}
|
|
|
|
// AgentRuleVersionUpsertBulk is the builder for "upsert"-ing
|
|
// a bulk of AgentRuleVersion nodes.
|
|
type AgentRuleVersionUpsertBulk struct {
|
|
create *AgentRuleVersionCreateBulk
|
|
}
|
|
|
|
// UpdateNewValues updates the mutable fields using the new values that
|
|
// were set on create. Using this option is equivalent to using:
|
|
//
|
|
// client.AgentRuleVersion.Create().
|
|
// OnConflict(
|
|
// sql.ResolveWithNewValues(),
|
|
// sql.ResolveWith(func(u *sql.UpdateSet) {
|
|
// u.SetIgnore(agentruleversion.FieldID)
|
|
// }),
|
|
// ).
|
|
// Exec(ctx)
|
|
func (u *AgentRuleVersionUpsertBulk) UpdateNewValues() *AgentRuleVersionUpsertBulk {
|
|
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.ID(); exists {
|
|
s.SetIgnore(agentruleversion.FieldID)
|
|
}
|
|
}
|
|
}))
|
|
return u
|
|
}
|
|
|
|
// Ignore sets each column to itself in case of conflict.
|
|
// Using this option is equivalent to using:
|
|
//
|
|
// client.AgentRuleVersion.Create().
|
|
// OnConflict(sql.ResolveWithIgnore()).
|
|
// Exec(ctx)
|
|
func (u *AgentRuleVersionUpsertBulk) Ignore() *AgentRuleVersionUpsertBulk {
|
|
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 *AgentRuleVersionUpsertBulk) DoNothing() *AgentRuleVersionUpsertBulk {
|
|
u.create.conflict = append(u.create.conflict, sql.DoNothing())
|
|
return u
|
|
}
|
|
|
|
// Update allows overriding fields `UPDATE` values. See the AgentRuleVersionCreateBulk.OnConflict
|
|
// documentation for more info.
|
|
func (u *AgentRuleVersionUpsertBulk) Update(set func(*AgentRuleVersionUpsert)) *AgentRuleVersionUpsertBulk {
|
|
u.create.conflict = append(u.create.conflict, sql.ResolveWith(func(update *sql.UpdateSet) {
|
|
set(&AgentRuleVersionUpsert{UpdateSet: update})
|
|
}))
|
|
return u
|
|
}
|
|
|
|
// SetRuleID sets the "rule_id" field.
|
|
func (u *AgentRuleVersionUpsertBulk) SetRuleID(v uuid.UUID) *AgentRuleVersionUpsertBulk {
|
|
return u.Update(func(s *AgentRuleVersionUpsert) {
|
|
s.SetRuleID(v)
|
|
})
|
|
}
|
|
|
|
// UpdateRuleID sets the "rule_id" field to the value that was provided on create.
|
|
func (u *AgentRuleVersionUpsertBulk) UpdateRuleID() *AgentRuleVersionUpsertBulk {
|
|
return u.Update(func(s *AgentRuleVersionUpsert) {
|
|
s.UpdateRuleID()
|
|
})
|
|
}
|
|
|
|
// SetVersion sets the "version" field.
|
|
func (u *AgentRuleVersionUpsertBulk) SetVersion(v string) *AgentRuleVersionUpsertBulk {
|
|
return u.Update(func(s *AgentRuleVersionUpsert) {
|
|
s.SetVersion(v)
|
|
})
|
|
}
|
|
|
|
// UpdateVersion sets the "version" field to the value that was provided on create.
|
|
func (u *AgentRuleVersionUpsertBulk) UpdateVersion() *AgentRuleVersionUpsertBulk {
|
|
return u.Update(func(s *AgentRuleVersionUpsert) {
|
|
s.UpdateVersion()
|
|
})
|
|
}
|
|
|
|
// SetContent sets the "content" field.
|
|
func (u *AgentRuleVersionUpsertBulk) SetContent(v string) *AgentRuleVersionUpsertBulk {
|
|
return u.Update(func(s *AgentRuleVersionUpsert) {
|
|
s.SetContent(v)
|
|
})
|
|
}
|
|
|
|
// UpdateContent sets the "content" field to the value that was provided on create.
|
|
func (u *AgentRuleVersionUpsertBulk) UpdateContent() *AgentRuleVersionUpsertBulk {
|
|
return u.Update(func(s *AgentRuleVersionUpsert) {
|
|
s.UpdateContent()
|
|
})
|
|
}
|
|
|
|
// SetCreatedAt sets the "created_at" field.
|
|
func (u *AgentRuleVersionUpsertBulk) SetCreatedAt(v time.Time) *AgentRuleVersionUpsertBulk {
|
|
return u.Update(func(s *AgentRuleVersionUpsert) {
|
|
s.SetCreatedAt(v)
|
|
})
|
|
}
|
|
|
|
// UpdateCreatedAt sets the "created_at" field to the value that was provided on create.
|
|
func (u *AgentRuleVersionUpsertBulk) UpdateCreatedAt() *AgentRuleVersionUpsertBulk {
|
|
return u.Update(func(s *AgentRuleVersionUpsert) {
|
|
s.UpdateCreatedAt()
|
|
})
|
|
}
|
|
|
|
// Exec executes the query.
|
|
func (u *AgentRuleVersionUpsertBulk) 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("db: OnConflict was set for builder %d. Set it on the AgentRuleVersionCreateBulk instead", i)
|
|
}
|
|
}
|
|
if len(u.create.conflict) == 0 {
|
|
return errors.New("db: missing options for AgentRuleVersionCreateBulk.OnConflict")
|
|
}
|
|
return u.create.Exec(ctx)
|
|
}
|
|
|
|
// ExecX is like Exec, but panics if an error occurs.
|
|
func (u *AgentRuleVersionUpsertBulk) ExecX(ctx context.Context) {
|
|
if err := u.create.Exec(ctx); err != nil {
|
|
panic(err)
|
|
}
|
|
}
|