mirror of
https://github.com/chaitin/MonkeyCode.git
synced 2026-11-22 03:18:50 +08:00
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
798 lines
25 KiB
Go
798 lines
25 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/agentplugin"
|
|
"github.com/chaitin/MonkeyCode/backend/db/agentpluginversion"
|
|
"github.com/chaitin/MonkeyCode/backend/ent/types"
|
|
"github.com/google/uuid"
|
|
)
|
|
|
|
// AgentPluginVersionCreate is the builder for creating a AgentPluginVersion entity.
|
|
type AgentPluginVersionCreate struct {
|
|
config
|
|
mutation *AgentPluginVersionMutation
|
|
hooks []Hook
|
|
conflict []sql.ConflictOption
|
|
}
|
|
|
|
// SetResourceID sets the "resource_id" field.
|
|
func (_c *AgentPluginVersionCreate) SetResourceID(v uuid.UUID) *AgentPluginVersionCreate {
|
|
_c.mutation.SetResourceID(v)
|
|
return _c
|
|
}
|
|
|
|
// SetVersion sets the "version" field.
|
|
func (_c *AgentPluginVersionCreate) SetVersion(v string) *AgentPluginVersionCreate {
|
|
_c.mutation.SetVersion(v)
|
|
return _c
|
|
}
|
|
|
|
// SetS3Key sets the "s3_key" field.
|
|
func (_c *AgentPluginVersionCreate) SetS3Key(v string) *AgentPluginVersionCreate {
|
|
_c.mutation.SetS3Key(v)
|
|
return _c
|
|
}
|
|
|
|
// SetParsedMeta sets the "parsed_meta" field.
|
|
func (_c *AgentPluginVersionCreate) SetParsedMeta(v types.PluginParsedMeta) *AgentPluginVersionCreate {
|
|
_c.mutation.SetParsedMeta(v)
|
|
return _c
|
|
}
|
|
|
|
// SetNillableParsedMeta sets the "parsed_meta" field if the given value is not nil.
|
|
func (_c *AgentPluginVersionCreate) SetNillableParsedMeta(v *types.PluginParsedMeta) *AgentPluginVersionCreate {
|
|
if v != nil {
|
|
_c.SetParsedMeta(*v)
|
|
}
|
|
return _c
|
|
}
|
|
|
|
// SetCreatedAt sets the "created_at" field.
|
|
func (_c *AgentPluginVersionCreate) SetCreatedAt(v time.Time) *AgentPluginVersionCreate {
|
|
_c.mutation.SetCreatedAt(v)
|
|
return _c
|
|
}
|
|
|
|
// SetNillableCreatedAt sets the "created_at" field if the given value is not nil.
|
|
func (_c *AgentPluginVersionCreate) SetNillableCreatedAt(v *time.Time) *AgentPluginVersionCreate {
|
|
if v != nil {
|
|
_c.SetCreatedAt(*v)
|
|
}
|
|
return _c
|
|
}
|
|
|
|
// SetID sets the "id" field.
|
|
func (_c *AgentPluginVersionCreate) SetID(v uuid.UUID) *AgentPluginVersionCreate {
|
|
_c.mutation.SetID(v)
|
|
return _c
|
|
}
|
|
|
|
// SetNillableID sets the "id" field if the given value is not nil.
|
|
func (_c *AgentPluginVersionCreate) SetNillableID(v *uuid.UUID) *AgentPluginVersionCreate {
|
|
if v != nil {
|
|
_c.SetID(*v)
|
|
}
|
|
return _c
|
|
}
|
|
|
|
// SetPluginID sets the "plugin" edge to the AgentPlugin entity by ID.
|
|
func (_c *AgentPluginVersionCreate) SetPluginID(id uuid.UUID) *AgentPluginVersionCreate {
|
|
_c.mutation.SetPluginID(id)
|
|
return _c
|
|
}
|
|
|
|
// SetPlugin sets the "plugin" edge to the AgentPlugin entity.
|
|
func (_c *AgentPluginVersionCreate) SetPlugin(v *AgentPlugin) *AgentPluginVersionCreate {
|
|
return _c.SetPluginID(v.ID)
|
|
}
|
|
|
|
// Mutation returns the AgentPluginVersionMutation object of the builder.
|
|
func (_c *AgentPluginVersionCreate) Mutation() *AgentPluginVersionMutation {
|
|
return _c.mutation
|
|
}
|
|
|
|
// Save creates the AgentPluginVersion in the database.
|
|
func (_c *AgentPluginVersionCreate) Save(ctx context.Context) (*AgentPluginVersion, error) {
|
|
_c.defaults()
|
|
return withHooks(ctx, _c.sqlSave, _c.mutation, _c.hooks)
|
|
}
|
|
|
|
// SaveX calls Save and panics if Save returns an error.
|
|
func (_c *AgentPluginVersionCreate) SaveX(ctx context.Context) *AgentPluginVersion {
|
|
v, err := _c.Save(ctx)
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
return v
|
|
}
|
|
|
|
// Exec executes the query.
|
|
func (_c *AgentPluginVersionCreate) Exec(ctx context.Context) error {
|
|
_, err := _c.Save(ctx)
|
|
return err
|
|
}
|
|
|
|
// ExecX is like Exec, but panics if an error occurs.
|
|
func (_c *AgentPluginVersionCreate) 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 *AgentPluginVersionCreate) defaults() {
|
|
if _, ok := _c.mutation.CreatedAt(); !ok {
|
|
v := agentpluginversion.DefaultCreatedAt()
|
|
_c.mutation.SetCreatedAt(v)
|
|
}
|
|
if _, ok := _c.mutation.ID(); !ok {
|
|
v := agentpluginversion.DefaultID()
|
|
_c.mutation.SetID(v)
|
|
}
|
|
}
|
|
|
|
// check runs all checks and user-defined validators on the builder.
|
|
func (_c *AgentPluginVersionCreate) check() error {
|
|
if _, ok := _c.mutation.ResourceID(); !ok {
|
|
return &ValidationError{Name: "resource_id", err: errors.New(`db: missing required field "AgentPluginVersion.resource_id"`)}
|
|
}
|
|
if _, ok := _c.mutation.Version(); !ok {
|
|
return &ValidationError{Name: "version", err: errors.New(`db: missing required field "AgentPluginVersion.version"`)}
|
|
}
|
|
if v, ok := _c.mutation.Version(); ok {
|
|
if err := agentpluginversion.VersionValidator(v); err != nil {
|
|
return &ValidationError{Name: "version", err: fmt.Errorf(`db: validator failed for field "AgentPluginVersion.version": %w`, err)}
|
|
}
|
|
}
|
|
if _, ok := _c.mutation.S3Key(); !ok {
|
|
return &ValidationError{Name: "s3_key", err: errors.New(`db: missing required field "AgentPluginVersion.s3_key"`)}
|
|
}
|
|
if v, ok := _c.mutation.S3Key(); ok {
|
|
if err := agentpluginversion.S3KeyValidator(v); err != nil {
|
|
return &ValidationError{Name: "s3_key", err: fmt.Errorf(`db: validator failed for field "AgentPluginVersion.s3_key": %w`, err)}
|
|
}
|
|
}
|
|
if _, ok := _c.mutation.CreatedAt(); !ok {
|
|
return &ValidationError{Name: "created_at", err: errors.New(`db: missing required field "AgentPluginVersion.created_at"`)}
|
|
}
|
|
if len(_c.mutation.PluginIDs()) == 0 {
|
|
return &ValidationError{Name: "plugin", err: errors.New(`db: missing required edge "AgentPluginVersion.plugin"`)}
|
|
}
|
|
return nil
|
|
}
|
|
|
|
func (_c *AgentPluginVersionCreate) sqlSave(ctx context.Context) (*AgentPluginVersion, 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 *AgentPluginVersionCreate) createSpec() (*AgentPluginVersion, *sqlgraph.CreateSpec) {
|
|
var (
|
|
_node = &AgentPluginVersion{config: _c.config}
|
|
_spec = sqlgraph.NewCreateSpec(agentpluginversion.Table, sqlgraph.NewFieldSpec(agentpluginversion.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(agentpluginversion.FieldVersion, field.TypeString, value)
|
|
_node.Version = value
|
|
}
|
|
if value, ok := _c.mutation.S3Key(); ok {
|
|
_spec.SetField(agentpluginversion.FieldS3Key, field.TypeString, value)
|
|
_node.S3Key = value
|
|
}
|
|
if value, ok := _c.mutation.ParsedMeta(); ok {
|
|
_spec.SetField(agentpluginversion.FieldParsedMeta, field.TypeJSON, value)
|
|
_node.ParsedMeta = value
|
|
}
|
|
if value, ok := _c.mutation.CreatedAt(); ok {
|
|
_spec.SetField(agentpluginversion.FieldCreatedAt, field.TypeTime, value)
|
|
_node.CreatedAt = value
|
|
}
|
|
if nodes := _c.mutation.PluginIDs(); len(nodes) > 0 {
|
|
edge := &sqlgraph.EdgeSpec{
|
|
Rel: sqlgraph.M2O,
|
|
Inverse: true,
|
|
Table: agentpluginversion.PluginTable,
|
|
Columns: []string{agentpluginversion.PluginColumn},
|
|
Bidi: false,
|
|
Target: &sqlgraph.EdgeTarget{
|
|
IDSpec: sqlgraph.NewFieldSpec(agentplugin.FieldID, field.TypeUUID),
|
|
},
|
|
}
|
|
for _, k := range nodes {
|
|
edge.Target.Nodes = append(edge.Target.Nodes, k)
|
|
}
|
|
_node.ResourceID = 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.AgentPluginVersion.Create().
|
|
// SetResourceID(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.AgentPluginVersionUpsert) {
|
|
// SetResourceID(v+v).
|
|
// }).
|
|
// Exec(ctx)
|
|
func (_c *AgentPluginVersionCreate) OnConflict(opts ...sql.ConflictOption) *AgentPluginVersionUpsertOne {
|
|
_c.conflict = opts
|
|
return &AgentPluginVersionUpsertOne{
|
|
create: _c,
|
|
}
|
|
}
|
|
|
|
// OnConflictColumns calls `OnConflict` and configures the columns
|
|
// as conflict target. Using this option is equivalent to using:
|
|
//
|
|
// client.AgentPluginVersion.Create().
|
|
// OnConflict(sql.ConflictColumns(columns...)).
|
|
// Exec(ctx)
|
|
func (_c *AgentPluginVersionCreate) OnConflictColumns(columns ...string) *AgentPluginVersionUpsertOne {
|
|
_c.conflict = append(_c.conflict, sql.ConflictColumns(columns...))
|
|
return &AgentPluginVersionUpsertOne{
|
|
create: _c,
|
|
}
|
|
}
|
|
|
|
type (
|
|
// AgentPluginVersionUpsertOne is the builder for "upsert"-ing
|
|
// one AgentPluginVersion node.
|
|
AgentPluginVersionUpsertOne struct {
|
|
create *AgentPluginVersionCreate
|
|
}
|
|
|
|
// AgentPluginVersionUpsert is the "OnConflict" setter.
|
|
AgentPluginVersionUpsert struct {
|
|
*sql.UpdateSet
|
|
}
|
|
)
|
|
|
|
// SetResourceID sets the "resource_id" field.
|
|
func (u *AgentPluginVersionUpsert) SetResourceID(v uuid.UUID) *AgentPluginVersionUpsert {
|
|
u.Set(agentpluginversion.FieldResourceID, v)
|
|
return u
|
|
}
|
|
|
|
// UpdateResourceID sets the "resource_id" field to the value that was provided on create.
|
|
func (u *AgentPluginVersionUpsert) UpdateResourceID() *AgentPluginVersionUpsert {
|
|
u.SetExcluded(agentpluginversion.FieldResourceID)
|
|
return u
|
|
}
|
|
|
|
// SetVersion sets the "version" field.
|
|
func (u *AgentPluginVersionUpsert) SetVersion(v string) *AgentPluginVersionUpsert {
|
|
u.Set(agentpluginversion.FieldVersion, v)
|
|
return u
|
|
}
|
|
|
|
// UpdateVersion sets the "version" field to the value that was provided on create.
|
|
func (u *AgentPluginVersionUpsert) UpdateVersion() *AgentPluginVersionUpsert {
|
|
u.SetExcluded(agentpluginversion.FieldVersion)
|
|
return u
|
|
}
|
|
|
|
// SetS3Key sets the "s3_key" field.
|
|
func (u *AgentPluginVersionUpsert) SetS3Key(v string) *AgentPluginVersionUpsert {
|
|
u.Set(agentpluginversion.FieldS3Key, v)
|
|
return u
|
|
}
|
|
|
|
// UpdateS3Key sets the "s3_key" field to the value that was provided on create.
|
|
func (u *AgentPluginVersionUpsert) UpdateS3Key() *AgentPluginVersionUpsert {
|
|
u.SetExcluded(agentpluginversion.FieldS3Key)
|
|
return u
|
|
}
|
|
|
|
// SetParsedMeta sets the "parsed_meta" field.
|
|
func (u *AgentPluginVersionUpsert) SetParsedMeta(v types.PluginParsedMeta) *AgentPluginVersionUpsert {
|
|
u.Set(agentpluginversion.FieldParsedMeta, v)
|
|
return u
|
|
}
|
|
|
|
// UpdateParsedMeta sets the "parsed_meta" field to the value that was provided on create.
|
|
func (u *AgentPluginVersionUpsert) UpdateParsedMeta() *AgentPluginVersionUpsert {
|
|
u.SetExcluded(agentpluginversion.FieldParsedMeta)
|
|
return u
|
|
}
|
|
|
|
// ClearParsedMeta clears the value of the "parsed_meta" field.
|
|
func (u *AgentPluginVersionUpsert) ClearParsedMeta() *AgentPluginVersionUpsert {
|
|
u.SetNull(agentpluginversion.FieldParsedMeta)
|
|
return u
|
|
}
|
|
|
|
// SetCreatedAt sets the "created_at" field.
|
|
func (u *AgentPluginVersionUpsert) SetCreatedAt(v time.Time) *AgentPluginVersionUpsert {
|
|
u.Set(agentpluginversion.FieldCreatedAt, v)
|
|
return u
|
|
}
|
|
|
|
// UpdateCreatedAt sets the "created_at" field to the value that was provided on create.
|
|
func (u *AgentPluginVersionUpsert) UpdateCreatedAt() *AgentPluginVersionUpsert {
|
|
u.SetExcluded(agentpluginversion.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.AgentPluginVersion.Create().
|
|
// OnConflict(
|
|
// sql.ResolveWithNewValues(),
|
|
// sql.ResolveWith(func(u *sql.UpdateSet) {
|
|
// u.SetIgnore(agentpluginversion.FieldID)
|
|
// }),
|
|
// ).
|
|
// Exec(ctx)
|
|
func (u *AgentPluginVersionUpsertOne) UpdateNewValues() *AgentPluginVersionUpsertOne {
|
|
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(agentpluginversion.FieldID)
|
|
}
|
|
}))
|
|
return u
|
|
}
|
|
|
|
// Ignore sets each column to itself in case of conflict.
|
|
// Using this option is equivalent to using:
|
|
//
|
|
// client.AgentPluginVersion.Create().
|
|
// OnConflict(sql.ResolveWithIgnore()).
|
|
// Exec(ctx)
|
|
func (u *AgentPluginVersionUpsertOne) Ignore() *AgentPluginVersionUpsertOne {
|
|
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 *AgentPluginVersionUpsertOne) DoNothing() *AgentPluginVersionUpsertOne {
|
|
u.create.conflict = append(u.create.conflict, sql.DoNothing())
|
|
return u
|
|
}
|
|
|
|
// Update allows overriding fields `UPDATE` values. See the AgentPluginVersionCreate.OnConflict
|
|
// documentation for more info.
|
|
func (u *AgentPluginVersionUpsertOne) Update(set func(*AgentPluginVersionUpsert)) *AgentPluginVersionUpsertOne {
|
|
u.create.conflict = append(u.create.conflict, sql.ResolveWith(func(update *sql.UpdateSet) {
|
|
set(&AgentPluginVersionUpsert{UpdateSet: update})
|
|
}))
|
|
return u
|
|
}
|
|
|
|
// SetResourceID sets the "resource_id" field.
|
|
func (u *AgentPluginVersionUpsertOne) SetResourceID(v uuid.UUID) *AgentPluginVersionUpsertOne {
|
|
return u.Update(func(s *AgentPluginVersionUpsert) {
|
|
s.SetResourceID(v)
|
|
})
|
|
}
|
|
|
|
// UpdateResourceID sets the "resource_id" field to the value that was provided on create.
|
|
func (u *AgentPluginVersionUpsertOne) UpdateResourceID() *AgentPluginVersionUpsertOne {
|
|
return u.Update(func(s *AgentPluginVersionUpsert) {
|
|
s.UpdateResourceID()
|
|
})
|
|
}
|
|
|
|
// SetVersion sets the "version" field.
|
|
func (u *AgentPluginVersionUpsertOne) SetVersion(v string) *AgentPluginVersionUpsertOne {
|
|
return u.Update(func(s *AgentPluginVersionUpsert) {
|
|
s.SetVersion(v)
|
|
})
|
|
}
|
|
|
|
// UpdateVersion sets the "version" field to the value that was provided on create.
|
|
func (u *AgentPluginVersionUpsertOne) UpdateVersion() *AgentPluginVersionUpsertOne {
|
|
return u.Update(func(s *AgentPluginVersionUpsert) {
|
|
s.UpdateVersion()
|
|
})
|
|
}
|
|
|
|
// SetS3Key sets the "s3_key" field.
|
|
func (u *AgentPluginVersionUpsertOne) SetS3Key(v string) *AgentPluginVersionUpsertOne {
|
|
return u.Update(func(s *AgentPluginVersionUpsert) {
|
|
s.SetS3Key(v)
|
|
})
|
|
}
|
|
|
|
// UpdateS3Key sets the "s3_key" field to the value that was provided on create.
|
|
func (u *AgentPluginVersionUpsertOne) UpdateS3Key() *AgentPluginVersionUpsertOne {
|
|
return u.Update(func(s *AgentPluginVersionUpsert) {
|
|
s.UpdateS3Key()
|
|
})
|
|
}
|
|
|
|
// SetParsedMeta sets the "parsed_meta" field.
|
|
func (u *AgentPluginVersionUpsertOne) SetParsedMeta(v types.PluginParsedMeta) *AgentPluginVersionUpsertOne {
|
|
return u.Update(func(s *AgentPluginVersionUpsert) {
|
|
s.SetParsedMeta(v)
|
|
})
|
|
}
|
|
|
|
// UpdateParsedMeta sets the "parsed_meta" field to the value that was provided on create.
|
|
func (u *AgentPluginVersionUpsertOne) UpdateParsedMeta() *AgentPluginVersionUpsertOne {
|
|
return u.Update(func(s *AgentPluginVersionUpsert) {
|
|
s.UpdateParsedMeta()
|
|
})
|
|
}
|
|
|
|
// ClearParsedMeta clears the value of the "parsed_meta" field.
|
|
func (u *AgentPluginVersionUpsertOne) ClearParsedMeta() *AgentPluginVersionUpsertOne {
|
|
return u.Update(func(s *AgentPluginVersionUpsert) {
|
|
s.ClearParsedMeta()
|
|
})
|
|
}
|
|
|
|
// SetCreatedAt sets the "created_at" field.
|
|
func (u *AgentPluginVersionUpsertOne) SetCreatedAt(v time.Time) *AgentPluginVersionUpsertOne {
|
|
return u.Update(func(s *AgentPluginVersionUpsert) {
|
|
s.SetCreatedAt(v)
|
|
})
|
|
}
|
|
|
|
// UpdateCreatedAt sets the "created_at" field to the value that was provided on create.
|
|
func (u *AgentPluginVersionUpsertOne) UpdateCreatedAt() *AgentPluginVersionUpsertOne {
|
|
return u.Update(func(s *AgentPluginVersionUpsert) {
|
|
s.UpdateCreatedAt()
|
|
})
|
|
}
|
|
|
|
// Exec executes the query.
|
|
func (u *AgentPluginVersionUpsertOne) Exec(ctx context.Context) error {
|
|
if len(u.create.conflict) == 0 {
|
|
return errors.New("db: missing options for AgentPluginVersionCreate.OnConflict")
|
|
}
|
|
return u.create.Exec(ctx)
|
|
}
|
|
|
|
// ExecX is like Exec, but panics if an error occurs.
|
|
func (u *AgentPluginVersionUpsertOne) 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 *AgentPluginVersionUpsertOne) 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: AgentPluginVersionUpsertOne.ID is not supported by MySQL driver. Use AgentPluginVersionUpsertOne.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 *AgentPluginVersionUpsertOne) IDX(ctx context.Context) uuid.UUID {
|
|
id, err := u.ID(ctx)
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
return id
|
|
}
|
|
|
|
// AgentPluginVersionCreateBulk is the builder for creating many AgentPluginVersion entities in bulk.
|
|
type AgentPluginVersionCreateBulk struct {
|
|
config
|
|
err error
|
|
builders []*AgentPluginVersionCreate
|
|
conflict []sql.ConflictOption
|
|
}
|
|
|
|
// Save creates the AgentPluginVersion entities in the database.
|
|
func (_c *AgentPluginVersionCreateBulk) Save(ctx context.Context) ([]*AgentPluginVersion, error) {
|
|
if _c.err != nil {
|
|
return nil, _c.err
|
|
}
|
|
specs := make([]*sqlgraph.CreateSpec, len(_c.builders))
|
|
nodes := make([]*AgentPluginVersion, 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.(*AgentPluginVersionMutation)
|
|
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 *AgentPluginVersionCreateBulk) SaveX(ctx context.Context) []*AgentPluginVersion {
|
|
v, err := _c.Save(ctx)
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
return v
|
|
}
|
|
|
|
// Exec executes the query.
|
|
func (_c *AgentPluginVersionCreateBulk) Exec(ctx context.Context) error {
|
|
_, err := _c.Save(ctx)
|
|
return err
|
|
}
|
|
|
|
// ExecX is like Exec, but panics if an error occurs.
|
|
func (_c *AgentPluginVersionCreateBulk) 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.AgentPluginVersion.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.AgentPluginVersionUpsert) {
|
|
// SetResourceID(v+v).
|
|
// }).
|
|
// Exec(ctx)
|
|
func (_c *AgentPluginVersionCreateBulk) OnConflict(opts ...sql.ConflictOption) *AgentPluginVersionUpsertBulk {
|
|
_c.conflict = opts
|
|
return &AgentPluginVersionUpsertBulk{
|
|
create: _c,
|
|
}
|
|
}
|
|
|
|
// OnConflictColumns calls `OnConflict` and configures the columns
|
|
// as conflict target. Using this option is equivalent to using:
|
|
//
|
|
// client.AgentPluginVersion.Create().
|
|
// OnConflict(sql.ConflictColumns(columns...)).
|
|
// Exec(ctx)
|
|
func (_c *AgentPluginVersionCreateBulk) OnConflictColumns(columns ...string) *AgentPluginVersionUpsertBulk {
|
|
_c.conflict = append(_c.conflict, sql.ConflictColumns(columns...))
|
|
return &AgentPluginVersionUpsertBulk{
|
|
create: _c,
|
|
}
|
|
}
|
|
|
|
// AgentPluginVersionUpsertBulk is the builder for "upsert"-ing
|
|
// a bulk of AgentPluginVersion nodes.
|
|
type AgentPluginVersionUpsertBulk struct {
|
|
create *AgentPluginVersionCreateBulk
|
|
}
|
|
|
|
// UpdateNewValues updates the mutable fields using the new values that
|
|
// were set on create. Using this option is equivalent to using:
|
|
//
|
|
// client.AgentPluginVersion.Create().
|
|
// OnConflict(
|
|
// sql.ResolveWithNewValues(),
|
|
// sql.ResolveWith(func(u *sql.UpdateSet) {
|
|
// u.SetIgnore(agentpluginversion.FieldID)
|
|
// }),
|
|
// ).
|
|
// Exec(ctx)
|
|
func (u *AgentPluginVersionUpsertBulk) UpdateNewValues() *AgentPluginVersionUpsertBulk {
|
|
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(agentpluginversion.FieldID)
|
|
}
|
|
}
|
|
}))
|
|
return u
|
|
}
|
|
|
|
// Ignore sets each column to itself in case of conflict.
|
|
// Using this option is equivalent to using:
|
|
//
|
|
// client.AgentPluginVersion.Create().
|
|
// OnConflict(sql.ResolveWithIgnore()).
|
|
// Exec(ctx)
|
|
func (u *AgentPluginVersionUpsertBulk) Ignore() *AgentPluginVersionUpsertBulk {
|
|
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 *AgentPluginVersionUpsertBulk) DoNothing() *AgentPluginVersionUpsertBulk {
|
|
u.create.conflict = append(u.create.conflict, sql.DoNothing())
|
|
return u
|
|
}
|
|
|
|
// Update allows overriding fields `UPDATE` values. See the AgentPluginVersionCreateBulk.OnConflict
|
|
// documentation for more info.
|
|
func (u *AgentPluginVersionUpsertBulk) Update(set func(*AgentPluginVersionUpsert)) *AgentPluginVersionUpsertBulk {
|
|
u.create.conflict = append(u.create.conflict, sql.ResolveWith(func(update *sql.UpdateSet) {
|
|
set(&AgentPluginVersionUpsert{UpdateSet: update})
|
|
}))
|
|
return u
|
|
}
|
|
|
|
// SetResourceID sets the "resource_id" field.
|
|
func (u *AgentPluginVersionUpsertBulk) SetResourceID(v uuid.UUID) *AgentPluginVersionUpsertBulk {
|
|
return u.Update(func(s *AgentPluginVersionUpsert) {
|
|
s.SetResourceID(v)
|
|
})
|
|
}
|
|
|
|
// UpdateResourceID sets the "resource_id" field to the value that was provided on create.
|
|
func (u *AgentPluginVersionUpsertBulk) UpdateResourceID() *AgentPluginVersionUpsertBulk {
|
|
return u.Update(func(s *AgentPluginVersionUpsert) {
|
|
s.UpdateResourceID()
|
|
})
|
|
}
|
|
|
|
// SetVersion sets the "version" field.
|
|
func (u *AgentPluginVersionUpsertBulk) SetVersion(v string) *AgentPluginVersionUpsertBulk {
|
|
return u.Update(func(s *AgentPluginVersionUpsert) {
|
|
s.SetVersion(v)
|
|
})
|
|
}
|
|
|
|
// UpdateVersion sets the "version" field to the value that was provided on create.
|
|
func (u *AgentPluginVersionUpsertBulk) UpdateVersion() *AgentPluginVersionUpsertBulk {
|
|
return u.Update(func(s *AgentPluginVersionUpsert) {
|
|
s.UpdateVersion()
|
|
})
|
|
}
|
|
|
|
// SetS3Key sets the "s3_key" field.
|
|
func (u *AgentPluginVersionUpsertBulk) SetS3Key(v string) *AgentPluginVersionUpsertBulk {
|
|
return u.Update(func(s *AgentPluginVersionUpsert) {
|
|
s.SetS3Key(v)
|
|
})
|
|
}
|
|
|
|
// UpdateS3Key sets the "s3_key" field to the value that was provided on create.
|
|
func (u *AgentPluginVersionUpsertBulk) UpdateS3Key() *AgentPluginVersionUpsertBulk {
|
|
return u.Update(func(s *AgentPluginVersionUpsert) {
|
|
s.UpdateS3Key()
|
|
})
|
|
}
|
|
|
|
// SetParsedMeta sets the "parsed_meta" field.
|
|
func (u *AgentPluginVersionUpsertBulk) SetParsedMeta(v types.PluginParsedMeta) *AgentPluginVersionUpsertBulk {
|
|
return u.Update(func(s *AgentPluginVersionUpsert) {
|
|
s.SetParsedMeta(v)
|
|
})
|
|
}
|
|
|
|
// UpdateParsedMeta sets the "parsed_meta" field to the value that was provided on create.
|
|
func (u *AgentPluginVersionUpsertBulk) UpdateParsedMeta() *AgentPluginVersionUpsertBulk {
|
|
return u.Update(func(s *AgentPluginVersionUpsert) {
|
|
s.UpdateParsedMeta()
|
|
})
|
|
}
|
|
|
|
// ClearParsedMeta clears the value of the "parsed_meta" field.
|
|
func (u *AgentPluginVersionUpsertBulk) ClearParsedMeta() *AgentPluginVersionUpsertBulk {
|
|
return u.Update(func(s *AgentPluginVersionUpsert) {
|
|
s.ClearParsedMeta()
|
|
})
|
|
}
|
|
|
|
// SetCreatedAt sets the "created_at" field.
|
|
func (u *AgentPluginVersionUpsertBulk) SetCreatedAt(v time.Time) *AgentPluginVersionUpsertBulk {
|
|
return u.Update(func(s *AgentPluginVersionUpsert) {
|
|
s.SetCreatedAt(v)
|
|
})
|
|
}
|
|
|
|
// UpdateCreatedAt sets the "created_at" field to the value that was provided on create.
|
|
func (u *AgentPluginVersionUpsertBulk) UpdateCreatedAt() *AgentPluginVersionUpsertBulk {
|
|
return u.Update(func(s *AgentPluginVersionUpsert) {
|
|
s.UpdateCreatedAt()
|
|
})
|
|
}
|
|
|
|
// Exec executes the query.
|
|
func (u *AgentPluginVersionUpsertBulk) 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 AgentPluginVersionCreateBulk instead", i)
|
|
}
|
|
}
|
|
if len(u.create.conflict) == 0 {
|
|
return errors.New("db: missing options for AgentPluginVersionCreateBulk.OnConflict")
|
|
}
|
|
return u.create.Exec(ctx)
|
|
}
|
|
|
|
// ExecX is like Exec, but panics if an error occurs.
|
|
func (u *AgentPluginVersionUpsertBulk) ExecX(ctx context.Context) {
|
|
if err := u.create.Exec(ctx); err != nil {
|
|
panic(err)
|
|
}
|
|
}
|