mirror of
https://github.com/chaitin/MonkeyCode.git
synced 2026-11-24 21:29:00 +08:00
746 lines
23 KiB
Go
746 lines
23 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/mcpusertoolsetting"
|
|
"github.com/google/uuid"
|
|
)
|
|
|
|
// MCPUserToolSettingCreate is the builder for creating a MCPUserToolSetting entity.
|
|
type MCPUserToolSettingCreate struct {
|
|
config
|
|
mutation *MCPUserToolSettingMutation
|
|
hooks []Hook
|
|
conflict []sql.ConflictOption
|
|
}
|
|
|
|
// SetUserID sets the "user_id" field.
|
|
func (_c *MCPUserToolSettingCreate) SetUserID(v uuid.UUID) *MCPUserToolSettingCreate {
|
|
_c.mutation.SetUserID(v)
|
|
return _c
|
|
}
|
|
|
|
// SetToolID sets the "tool_id" field.
|
|
func (_c *MCPUserToolSettingCreate) SetToolID(v uuid.UUID) *MCPUserToolSettingCreate {
|
|
_c.mutation.SetToolID(v)
|
|
return _c
|
|
}
|
|
|
|
// SetEnabled sets the "enabled" field.
|
|
func (_c *MCPUserToolSettingCreate) SetEnabled(v bool) *MCPUserToolSettingCreate {
|
|
_c.mutation.SetEnabled(v)
|
|
return _c
|
|
}
|
|
|
|
// SetNillableEnabled sets the "enabled" field if the given value is not nil.
|
|
func (_c *MCPUserToolSettingCreate) SetNillableEnabled(v *bool) *MCPUserToolSettingCreate {
|
|
if v != nil {
|
|
_c.SetEnabled(*v)
|
|
}
|
|
return _c
|
|
}
|
|
|
|
// SetCreatedAt sets the "created_at" field.
|
|
func (_c *MCPUserToolSettingCreate) SetCreatedAt(v time.Time) *MCPUserToolSettingCreate {
|
|
_c.mutation.SetCreatedAt(v)
|
|
return _c
|
|
}
|
|
|
|
// SetNillableCreatedAt sets the "created_at" field if the given value is not nil.
|
|
func (_c *MCPUserToolSettingCreate) SetNillableCreatedAt(v *time.Time) *MCPUserToolSettingCreate {
|
|
if v != nil {
|
|
_c.SetCreatedAt(*v)
|
|
}
|
|
return _c
|
|
}
|
|
|
|
// SetUpdatedAt sets the "updated_at" field.
|
|
func (_c *MCPUserToolSettingCreate) SetUpdatedAt(v time.Time) *MCPUserToolSettingCreate {
|
|
_c.mutation.SetUpdatedAt(v)
|
|
return _c
|
|
}
|
|
|
|
// SetNillableUpdatedAt sets the "updated_at" field if the given value is not nil.
|
|
func (_c *MCPUserToolSettingCreate) SetNillableUpdatedAt(v *time.Time) *MCPUserToolSettingCreate {
|
|
if v != nil {
|
|
_c.SetUpdatedAt(*v)
|
|
}
|
|
return _c
|
|
}
|
|
|
|
// SetID sets the "id" field.
|
|
func (_c *MCPUserToolSettingCreate) SetID(v uuid.UUID) *MCPUserToolSettingCreate {
|
|
_c.mutation.SetID(v)
|
|
return _c
|
|
}
|
|
|
|
// Mutation returns the MCPUserToolSettingMutation object of the builder.
|
|
func (_c *MCPUserToolSettingCreate) Mutation() *MCPUserToolSettingMutation {
|
|
return _c.mutation
|
|
}
|
|
|
|
// Save creates the MCPUserToolSetting in the database.
|
|
func (_c *MCPUserToolSettingCreate) Save(ctx context.Context) (*MCPUserToolSetting, error) {
|
|
_c.defaults()
|
|
return withHooks(ctx, _c.sqlSave, _c.mutation, _c.hooks)
|
|
}
|
|
|
|
// SaveX calls Save and panics if Save returns an error.
|
|
func (_c *MCPUserToolSettingCreate) SaveX(ctx context.Context) *MCPUserToolSetting {
|
|
v, err := _c.Save(ctx)
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
return v
|
|
}
|
|
|
|
// Exec executes the query.
|
|
func (_c *MCPUserToolSettingCreate) Exec(ctx context.Context) error {
|
|
_, err := _c.Save(ctx)
|
|
return err
|
|
}
|
|
|
|
// ExecX is like Exec, but panics if an error occurs.
|
|
func (_c *MCPUserToolSettingCreate) 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 *MCPUserToolSettingCreate) defaults() {
|
|
if _, ok := _c.mutation.Enabled(); !ok {
|
|
v := mcpusertoolsetting.DefaultEnabled
|
|
_c.mutation.SetEnabled(v)
|
|
}
|
|
if _, ok := _c.mutation.CreatedAt(); !ok {
|
|
v := mcpusertoolsetting.DefaultCreatedAt()
|
|
_c.mutation.SetCreatedAt(v)
|
|
}
|
|
if _, ok := _c.mutation.UpdatedAt(); !ok {
|
|
v := mcpusertoolsetting.DefaultUpdatedAt()
|
|
_c.mutation.SetUpdatedAt(v)
|
|
}
|
|
}
|
|
|
|
// check runs all checks and user-defined validators on the builder.
|
|
func (_c *MCPUserToolSettingCreate) check() error {
|
|
if _, ok := _c.mutation.UserID(); !ok {
|
|
return &ValidationError{Name: "user_id", err: errors.New(`db: missing required field "MCPUserToolSetting.user_id"`)}
|
|
}
|
|
if _, ok := _c.mutation.ToolID(); !ok {
|
|
return &ValidationError{Name: "tool_id", err: errors.New(`db: missing required field "MCPUserToolSetting.tool_id"`)}
|
|
}
|
|
if _, ok := _c.mutation.Enabled(); !ok {
|
|
return &ValidationError{Name: "enabled", err: errors.New(`db: missing required field "MCPUserToolSetting.enabled"`)}
|
|
}
|
|
if _, ok := _c.mutation.CreatedAt(); !ok {
|
|
return &ValidationError{Name: "created_at", err: errors.New(`db: missing required field "MCPUserToolSetting.created_at"`)}
|
|
}
|
|
if _, ok := _c.mutation.UpdatedAt(); !ok {
|
|
return &ValidationError{Name: "updated_at", err: errors.New(`db: missing required field "MCPUserToolSetting.updated_at"`)}
|
|
}
|
|
return nil
|
|
}
|
|
|
|
func (_c *MCPUserToolSettingCreate) sqlSave(ctx context.Context) (*MCPUserToolSetting, 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 *MCPUserToolSettingCreate) createSpec() (*MCPUserToolSetting, *sqlgraph.CreateSpec) {
|
|
var (
|
|
_node = &MCPUserToolSetting{config: _c.config}
|
|
_spec = sqlgraph.NewCreateSpec(mcpusertoolsetting.Table, sqlgraph.NewFieldSpec(mcpusertoolsetting.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.UserID(); ok {
|
|
_spec.SetField(mcpusertoolsetting.FieldUserID, field.TypeUUID, value)
|
|
_node.UserID = value
|
|
}
|
|
if value, ok := _c.mutation.ToolID(); ok {
|
|
_spec.SetField(mcpusertoolsetting.FieldToolID, field.TypeUUID, value)
|
|
_node.ToolID = value
|
|
}
|
|
if value, ok := _c.mutation.Enabled(); ok {
|
|
_spec.SetField(mcpusertoolsetting.FieldEnabled, field.TypeBool, value)
|
|
_node.Enabled = value
|
|
}
|
|
if value, ok := _c.mutation.CreatedAt(); ok {
|
|
_spec.SetField(mcpusertoolsetting.FieldCreatedAt, field.TypeTime, value)
|
|
_node.CreatedAt = value
|
|
}
|
|
if value, ok := _c.mutation.UpdatedAt(); ok {
|
|
_spec.SetField(mcpusertoolsetting.FieldUpdatedAt, field.TypeTime, value)
|
|
_node.UpdatedAt = value
|
|
}
|
|
return _node, _spec
|
|
}
|
|
|
|
// OnConflict allows configuring the `ON CONFLICT` / `ON DUPLICATE KEY` clause
|
|
// of the `INSERT` statement. For example:
|
|
//
|
|
// client.MCPUserToolSetting.Create().
|
|
// SetUserID(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.MCPUserToolSettingUpsert) {
|
|
// SetUserID(v+v).
|
|
// }).
|
|
// Exec(ctx)
|
|
func (_c *MCPUserToolSettingCreate) OnConflict(opts ...sql.ConflictOption) *MCPUserToolSettingUpsertOne {
|
|
_c.conflict = opts
|
|
return &MCPUserToolSettingUpsertOne{
|
|
create: _c,
|
|
}
|
|
}
|
|
|
|
// OnConflictColumns calls `OnConflict` and configures the columns
|
|
// as conflict target. Using this option is equivalent to using:
|
|
//
|
|
// client.MCPUserToolSetting.Create().
|
|
// OnConflict(sql.ConflictColumns(columns...)).
|
|
// Exec(ctx)
|
|
func (_c *MCPUserToolSettingCreate) OnConflictColumns(columns ...string) *MCPUserToolSettingUpsertOne {
|
|
_c.conflict = append(_c.conflict, sql.ConflictColumns(columns...))
|
|
return &MCPUserToolSettingUpsertOne{
|
|
create: _c,
|
|
}
|
|
}
|
|
|
|
type (
|
|
// MCPUserToolSettingUpsertOne is the builder for "upsert"-ing
|
|
// one MCPUserToolSetting node.
|
|
MCPUserToolSettingUpsertOne struct {
|
|
create *MCPUserToolSettingCreate
|
|
}
|
|
|
|
// MCPUserToolSettingUpsert is the "OnConflict" setter.
|
|
MCPUserToolSettingUpsert struct {
|
|
*sql.UpdateSet
|
|
}
|
|
)
|
|
|
|
// SetUserID sets the "user_id" field.
|
|
func (u *MCPUserToolSettingUpsert) SetUserID(v uuid.UUID) *MCPUserToolSettingUpsert {
|
|
u.Set(mcpusertoolsetting.FieldUserID, v)
|
|
return u
|
|
}
|
|
|
|
// UpdateUserID sets the "user_id" field to the value that was provided on create.
|
|
func (u *MCPUserToolSettingUpsert) UpdateUserID() *MCPUserToolSettingUpsert {
|
|
u.SetExcluded(mcpusertoolsetting.FieldUserID)
|
|
return u
|
|
}
|
|
|
|
// SetToolID sets the "tool_id" field.
|
|
func (u *MCPUserToolSettingUpsert) SetToolID(v uuid.UUID) *MCPUserToolSettingUpsert {
|
|
u.Set(mcpusertoolsetting.FieldToolID, v)
|
|
return u
|
|
}
|
|
|
|
// UpdateToolID sets the "tool_id" field to the value that was provided on create.
|
|
func (u *MCPUserToolSettingUpsert) UpdateToolID() *MCPUserToolSettingUpsert {
|
|
u.SetExcluded(mcpusertoolsetting.FieldToolID)
|
|
return u
|
|
}
|
|
|
|
// SetEnabled sets the "enabled" field.
|
|
func (u *MCPUserToolSettingUpsert) SetEnabled(v bool) *MCPUserToolSettingUpsert {
|
|
u.Set(mcpusertoolsetting.FieldEnabled, v)
|
|
return u
|
|
}
|
|
|
|
// UpdateEnabled sets the "enabled" field to the value that was provided on create.
|
|
func (u *MCPUserToolSettingUpsert) UpdateEnabled() *MCPUserToolSettingUpsert {
|
|
u.SetExcluded(mcpusertoolsetting.FieldEnabled)
|
|
return u
|
|
}
|
|
|
|
// SetCreatedAt sets the "created_at" field.
|
|
func (u *MCPUserToolSettingUpsert) SetCreatedAt(v time.Time) *MCPUserToolSettingUpsert {
|
|
u.Set(mcpusertoolsetting.FieldCreatedAt, v)
|
|
return u
|
|
}
|
|
|
|
// UpdateCreatedAt sets the "created_at" field to the value that was provided on create.
|
|
func (u *MCPUserToolSettingUpsert) UpdateCreatedAt() *MCPUserToolSettingUpsert {
|
|
u.SetExcluded(mcpusertoolsetting.FieldCreatedAt)
|
|
return u
|
|
}
|
|
|
|
// SetUpdatedAt sets the "updated_at" field.
|
|
func (u *MCPUserToolSettingUpsert) SetUpdatedAt(v time.Time) *MCPUserToolSettingUpsert {
|
|
u.Set(mcpusertoolsetting.FieldUpdatedAt, v)
|
|
return u
|
|
}
|
|
|
|
// UpdateUpdatedAt sets the "updated_at" field to the value that was provided on create.
|
|
func (u *MCPUserToolSettingUpsert) UpdateUpdatedAt() *MCPUserToolSettingUpsert {
|
|
u.SetExcluded(mcpusertoolsetting.FieldUpdatedAt)
|
|
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.MCPUserToolSetting.Create().
|
|
// OnConflict(
|
|
// sql.ResolveWithNewValues(),
|
|
// sql.ResolveWith(func(u *sql.UpdateSet) {
|
|
// u.SetIgnore(mcpusertoolsetting.FieldID)
|
|
// }),
|
|
// ).
|
|
// Exec(ctx)
|
|
func (u *MCPUserToolSettingUpsertOne) UpdateNewValues() *MCPUserToolSettingUpsertOne {
|
|
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(mcpusertoolsetting.FieldID)
|
|
}
|
|
}))
|
|
return u
|
|
}
|
|
|
|
// Ignore sets each column to itself in case of conflict.
|
|
// Using this option is equivalent to using:
|
|
//
|
|
// client.MCPUserToolSetting.Create().
|
|
// OnConflict(sql.ResolveWithIgnore()).
|
|
// Exec(ctx)
|
|
func (u *MCPUserToolSettingUpsertOne) Ignore() *MCPUserToolSettingUpsertOne {
|
|
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 *MCPUserToolSettingUpsertOne) DoNothing() *MCPUserToolSettingUpsertOne {
|
|
u.create.conflict = append(u.create.conflict, sql.DoNothing())
|
|
return u
|
|
}
|
|
|
|
// Update allows overriding fields `UPDATE` values. See the MCPUserToolSettingCreate.OnConflict
|
|
// documentation for more info.
|
|
func (u *MCPUserToolSettingUpsertOne) Update(set func(*MCPUserToolSettingUpsert)) *MCPUserToolSettingUpsertOne {
|
|
u.create.conflict = append(u.create.conflict, sql.ResolveWith(func(update *sql.UpdateSet) {
|
|
set(&MCPUserToolSettingUpsert{UpdateSet: update})
|
|
}))
|
|
return u
|
|
}
|
|
|
|
// SetUserID sets the "user_id" field.
|
|
func (u *MCPUserToolSettingUpsertOne) SetUserID(v uuid.UUID) *MCPUserToolSettingUpsertOne {
|
|
return u.Update(func(s *MCPUserToolSettingUpsert) {
|
|
s.SetUserID(v)
|
|
})
|
|
}
|
|
|
|
// UpdateUserID sets the "user_id" field to the value that was provided on create.
|
|
func (u *MCPUserToolSettingUpsertOne) UpdateUserID() *MCPUserToolSettingUpsertOne {
|
|
return u.Update(func(s *MCPUserToolSettingUpsert) {
|
|
s.UpdateUserID()
|
|
})
|
|
}
|
|
|
|
// SetToolID sets the "tool_id" field.
|
|
func (u *MCPUserToolSettingUpsertOne) SetToolID(v uuid.UUID) *MCPUserToolSettingUpsertOne {
|
|
return u.Update(func(s *MCPUserToolSettingUpsert) {
|
|
s.SetToolID(v)
|
|
})
|
|
}
|
|
|
|
// UpdateToolID sets the "tool_id" field to the value that was provided on create.
|
|
func (u *MCPUserToolSettingUpsertOne) UpdateToolID() *MCPUserToolSettingUpsertOne {
|
|
return u.Update(func(s *MCPUserToolSettingUpsert) {
|
|
s.UpdateToolID()
|
|
})
|
|
}
|
|
|
|
// SetEnabled sets the "enabled" field.
|
|
func (u *MCPUserToolSettingUpsertOne) SetEnabled(v bool) *MCPUserToolSettingUpsertOne {
|
|
return u.Update(func(s *MCPUserToolSettingUpsert) {
|
|
s.SetEnabled(v)
|
|
})
|
|
}
|
|
|
|
// UpdateEnabled sets the "enabled" field to the value that was provided on create.
|
|
func (u *MCPUserToolSettingUpsertOne) UpdateEnabled() *MCPUserToolSettingUpsertOne {
|
|
return u.Update(func(s *MCPUserToolSettingUpsert) {
|
|
s.UpdateEnabled()
|
|
})
|
|
}
|
|
|
|
// SetCreatedAt sets the "created_at" field.
|
|
func (u *MCPUserToolSettingUpsertOne) SetCreatedAt(v time.Time) *MCPUserToolSettingUpsertOne {
|
|
return u.Update(func(s *MCPUserToolSettingUpsert) {
|
|
s.SetCreatedAt(v)
|
|
})
|
|
}
|
|
|
|
// UpdateCreatedAt sets the "created_at" field to the value that was provided on create.
|
|
func (u *MCPUserToolSettingUpsertOne) UpdateCreatedAt() *MCPUserToolSettingUpsertOne {
|
|
return u.Update(func(s *MCPUserToolSettingUpsert) {
|
|
s.UpdateCreatedAt()
|
|
})
|
|
}
|
|
|
|
// SetUpdatedAt sets the "updated_at" field.
|
|
func (u *MCPUserToolSettingUpsertOne) SetUpdatedAt(v time.Time) *MCPUserToolSettingUpsertOne {
|
|
return u.Update(func(s *MCPUserToolSettingUpsert) {
|
|
s.SetUpdatedAt(v)
|
|
})
|
|
}
|
|
|
|
// UpdateUpdatedAt sets the "updated_at" field to the value that was provided on create.
|
|
func (u *MCPUserToolSettingUpsertOne) UpdateUpdatedAt() *MCPUserToolSettingUpsertOne {
|
|
return u.Update(func(s *MCPUserToolSettingUpsert) {
|
|
s.UpdateUpdatedAt()
|
|
})
|
|
}
|
|
|
|
// Exec executes the query.
|
|
func (u *MCPUserToolSettingUpsertOne) Exec(ctx context.Context) error {
|
|
if len(u.create.conflict) == 0 {
|
|
return errors.New("db: missing options for MCPUserToolSettingCreate.OnConflict")
|
|
}
|
|
return u.create.Exec(ctx)
|
|
}
|
|
|
|
// ExecX is like Exec, but panics if an error occurs.
|
|
func (u *MCPUserToolSettingUpsertOne) 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 *MCPUserToolSettingUpsertOne) 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: MCPUserToolSettingUpsertOne.ID is not supported by MySQL driver. Use MCPUserToolSettingUpsertOne.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 *MCPUserToolSettingUpsertOne) IDX(ctx context.Context) uuid.UUID {
|
|
id, err := u.ID(ctx)
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
return id
|
|
}
|
|
|
|
// MCPUserToolSettingCreateBulk is the builder for creating many MCPUserToolSetting entities in bulk.
|
|
type MCPUserToolSettingCreateBulk struct {
|
|
config
|
|
err error
|
|
builders []*MCPUserToolSettingCreate
|
|
conflict []sql.ConflictOption
|
|
}
|
|
|
|
// Save creates the MCPUserToolSetting entities in the database.
|
|
func (_c *MCPUserToolSettingCreateBulk) Save(ctx context.Context) ([]*MCPUserToolSetting, error) {
|
|
if _c.err != nil {
|
|
return nil, _c.err
|
|
}
|
|
specs := make([]*sqlgraph.CreateSpec, len(_c.builders))
|
|
nodes := make([]*MCPUserToolSetting, 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.(*MCPUserToolSettingMutation)
|
|
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 *MCPUserToolSettingCreateBulk) SaveX(ctx context.Context) []*MCPUserToolSetting {
|
|
v, err := _c.Save(ctx)
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
return v
|
|
}
|
|
|
|
// Exec executes the query.
|
|
func (_c *MCPUserToolSettingCreateBulk) Exec(ctx context.Context) error {
|
|
_, err := _c.Save(ctx)
|
|
return err
|
|
}
|
|
|
|
// ExecX is like Exec, but panics if an error occurs.
|
|
func (_c *MCPUserToolSettingCreateBulk) 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.MCPUserToolSetting.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.MCPUserToolSettingUpsert) {
|
|
// SetUserID(v+v).
|
|
// }).
|
|
// Exec(ctx)
|
|
func (_c *MCPUserToolSettingCreateBulk) OnConflict(opts ...sql.ConflictOption) *MCPUserToolSettingUpsertBulk {
|
|
_c.conflict = opts
|
|
return &MCPUserToolSettingUpsertBulk{
|
|
create: _c,
|
|
}
|
|
}
|
|
|
|
// OnConflictColumns calls `OnConflict` and configures the columns
|
|
// as conflict target. Using this option is equivalent to using:
|
|
//
|
|
// client.MCPUserToolSetting.Create().
|
|
// OnConflict(sql.ConflictColumns(columns...)).
|
|
// Exec(ctx)
|
|
func (_c *MCPUserToolSettingCreateBulk) OnConflictColumns(columns ...string) *MCPUserToolSettingUpsertBulk {
|
|
_c.conflict = append(_c.conflict, sql.ConflictColumns(columns...))
|
|
return &MCPUserToolSettingUpsertBulk{
|
|
create: _c,
|
|
}
|
|
}
|
|
|
|
// MCPUserToolSettingUpsertBulk is the builder for "upsert"-ing
|
|
// a bulk of MCPUserToolSetting nodes.
|
|
type MCPUserToolSettingUpsertBulk struct {
|
|
create *MCPUserToolSettingCreateBulk
|
|
}
|
|
|
|
// UpdateNewValues updates the mutable fields using the new values that
|
|
// were set on create. Using this option is equivalent to using:
|
|
//
|
|
// client.MCPUserToolSetting.Create().
|
|
// OnConflict(
|
|
// sql.ResolveWithNewValues(),
|
|
// sql.ResolveWith(func(u *sql.UpdateSet) {
|
|
// u.SetIgnore(mcpusertoolsetting.FieldID)
|
|
// }),
|
|
// ).
|
|
// Exec(ctx)
|
|
func (u *MCPUserToolSettingUpsertBulk) UpdateNewValues() *MCPUserToolSettingUpsertBulk {
|
|
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(mcpusertoolsetting.FieldID)
|
|
}
|
|
}
|
|
}))
|
|
return u
|
|
}
|
|
|
|
// Ignore sets each column to itself in case of conflict.
|
|
// Using this option is equivalent to using:
|
|
//
|
|
// client.MCPUserToolSetting.Create().
|
|
// OnConflict(sql.ResolveWithIgnore()).
|
|
// Exec(ctx)
|
|
func (u *MCPUserToolSettingUpsertBulk) Ignore() *MCPUserToolSettingUpsertBulk {
|
|
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 *MCPUserToolSettingUpsertBulk) DoNothing() *MCPUserToolSettingUpsertBulk {
|
|
u.create.conflict = append(u.create.conflict, sql.DoNothing())
|
|
return u
|
|
}
|
|
|
|
// Update allows overriding fields `UPDATE` values. See the MCPUserToolSettingCreateBulk.OnConflict
|
|
// documentation for more info.
|
|
func (u *MCPUserToolSettingUpsertBulk) Update(set func(*MCPUserToolSettingUpsert)) *MCPUserToolSettingUpsertBulk {
|
|
u.create.conflict = append(u.create.conflict, sql.ResolveWith(func(update *sql.UpdateSet) {
|
|
set(&MCPUserToolSettingUpsert{UpdateSet: update})
|
|
}))
|
|
return u
|
|
}
|
|
|
|
// SetUserID sets the "user_id" field.
|
|
func (u *MCPUserToolSettingUpsertBulk) SetUserID(v uuid.UUID) *MCPUserToolSettingUpsertBulk {
|
|
return u.Update(func(s *MCPUserToolSettingUpsert) {
|
|
s.SetUserID(v)
|
|
})
|
|
}
|
|
|
|
// UpdateUserID sets the "user_id" field to the value that was provided on create.
|
|
func (u *MCPUserToolSettingUpsertBulk) UpdateUserID() *MCPUserToolSettingUpsertBulk {
|
|
return u.Update(func(s *MCPUserToolSettingUpsert) {
|
|
s.UpdateUserID()
|
|
})
|
|
}
|
|
|
|
// SetToolID sets the "tool_id" field.
|
|
func (u *MCPUserToolSettingUpsertBulk) SetToolID(v uuid.UUID) *MCPUserToolSettingUpsertBulk {
|
|
return u.Update(func(s *MCPUserToolSettingUpsert) {
|
|
s.SetToolID(v)
|
|
})
|
|
}
|
|
|
|
// UpdateToolID sets the "tool_id" field to the value that was provided on create.
|
|
func (u *MCPUserToolSettingUpsertBulk) UpdateToolID() *MCPUserToolSettingUpsertBulk {
|
|
return u.Update(func(s *MCPUserToolSettingUpsert) {
|
|
s.UpdateToolID()
|
|
})
|
|
}
|
|
|
|
// SetEnabled sets the "enabled" field.
|
|
func (u *MCPUserToolSettingUpsertBulk) SetEnabled(v bool) *MCPUserToolSettingUpsertBulk {
|
|
return u.Update(func(s *MCPUserToolSettingUpsert) {
|
|
s.SetEnabled(v)
|
|
})
|
|
}
|
|
|
|
// UpdateEnabled sets the "enabled" field to the value that was provided on create.
|
|
func (u *MCPUserToolSettingUpsertBulk) UpdateEnabled() *MCPUserToolSettingUpsertBulk {
|
|
return u.Update(func(s *MCPUserToolSettingUpsert) {
|
|
s.UpdateEnabled()
|
|
})
|
|
}
|
|
|
|
// SetCreatedAt sets the "created_at" field.
|
|
func (u *MCPUserToolSettingUpsertBulk) SetCreatedAt(v time.Time) *MCPUserToolSettingUpsertBulk {
|
|
return u.Update(func(s *MCPUserToolSettingUpsert) {
|
|
s.SetCreatedAt(v)
|
|
})
|
|
}
|
|
|
|
// UpdateCreatedAt sets the "created_at" field to the value that was provided on create.
|
|
func (u *MCPUserToolSettingUpsertBulk) UpdateCreatedAt() *MCPUserToolSettingUpsertBulk {
|
|
return u.Update(func(s *MCPUserToolSettingUpsert) {
|
|
s.UpdateCreatedAt()
|
|
})
|
|
}
|
|
|
|
// SetUpdatedAt sets the "updated_at" field.
|
|
func (u *MCPUserToolSettingUpsertBulk) SetUpdatedAt(v time.Time) *MCPUserToolSettingUpsertBulk {
|
|
return u.Update(func(s *MCPUserToolSettingUpsert) {
|
|
s.SetUpdatedAt(v)
|
|
})
|
|
}
|
|
|
|
// UpdateUpdatedAt sets the "updated_at" field to the value that was provided on create.
|
|
func (u *MCPUserToolSettingUpsertBulk) UpdateUpdatedAt() *MCPUserToolSettingUpsertBulk {
|
|
return u.Update(func(s *MCPUserToolSettingUpsert) {
|
|
s.UpdateUpdatedAt()
|
|
})
|
|
}
|
|
|
|
// Exec executes the query.
|
|
func (u *MCPUserToolSettingUpsertBulk) 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 MCPUserToolSettingCreateBulk instead", i)
|
|
}
|
|
}
|
|
if len(u.create.conflict) == 0 {
|
|
return errors.New("db: missing options for MCPUserToolSettingCreateBulk.OnConflict")
|
|
}
|
|
return u.create.Exec(ctx)
|
|
}
|
|
|
|
// ExecX is like Exec, but panics if an error occurs.
|
|
func (u *MCPUserToolSettingUpsertBulk) ExecX(ctx context.Context) {
|
|
if err := u.create.Exec(ctx); err != nil {
|
|
panic(err)
|
|
}
|
|
}
|