mirror of
https://github.com/chaitin/MonkeyCode.git
synced 2026-11-22 19:39:31 +08:00
2108 lines
60 KiB
Go
2108 lines
60 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/model"
|
|
"github.com/chaitin/MonkeyCode/backend/db/modelapikey"
|
|
"github.com/chaitin/MonkeyCode/backend/db/modelpricing"
|
|
"github.com/chaitin/MonkeyCode/backend/db/projecttask"
|
|
"github.com/chaitin/MonkeyCode/backend/db/taskmodelswitch"
|
|
"github.com/chaitin/MonkeyCode/backend/db/team"
|
|
"github.com/chaitin/MonkeyCode/backend/db/teamgroup"
|
|
"github.com/chaitin/MonkeyCode/backend/db/teamgroupmodel"
|
|
"github.com/chaitin/MonkeyCode/backend/db/teammodel"
|
|
"github.com/chaitin/MonkeyCode/backend/db/user"
|
|
"github.com/chaitin/MonkeyCode/backend/db/virtualmachine"
|
|
"github.com/google/uuid"
|
|
)
|
|
|
|
// ModelCreate is the builder for creating a Model entity.
|
|
type ModelCreate struct {
|
|
config
|
|
mutation *ModelMutation
|
|
hooks []Hook
|
|
conflict []sql.ConflictOption
|
|
}
|
|
|
|
// SetDeletedAt sets the "deleted_at" field.
|
|
func (_c *ModelCreate) SetDeletedAt(v time.Time) *ModelCreate {
|
|
_c.mutation.SetDeletedAt(v)
|
|
return _c
|
|
}
|
|
|
|
// SetNillableDeletedAt sets the "deleted_at" field if the given value is not nil.
|
|
func (_c *ModelCreate) SetNillableDeletedAt(v *time.Time) *ModelCreate {
|
|
if v != nil {
|
|
_c.SetDeletedAt(*v)
|
|
}
|
|
return _c
|
|
}
|
|
|
|
// SetUserID sets the "user_id" field.
|
|
func (_c *ModelCreate) SetUserID(v uuid.UUID) *ModelCreate {
|
|
_c.mutation.SetUserID(v)
|
|
return _c
|
|
}
|
|
|
|
// SetProvider sets the "provider" field.
|
|
func (_c *ModelCreate) SetProvider(v string) *ModelCreate {
|
|
_c.mutation.SetProvider(v)
|
|
return _c
|
|
}
|
|
|
|
// SetAPIKey sets the "api_key" field.
|
|
func (_c *ModelCreate) SetAPIKey(v string) *ModelCreate {
|
|
_c.mutation.SetAPIKey(v)
|
|
return _c
|
|
}
|
|
|
|
// SetBaseURL sets the "base_url" field.
|
|
func (_c *ModelCreate) SetBaseURL(v string) *ModelCreate {
|
|
_c.mutation.SetBaseURL(v)
|
|
return _c
|
|
}
|
|
|
|
// SetModel sets the "model" field.
|
|
func (_c *ModelCreate) SetModel(v string) *ModelCreate {
|
|
_c.mutation.SetModel(v)
|
|
return _c
|
|
}
|
|
|
|
// SetRemark sets the "remark" field.
|
|
func (_c *ModelCreate) SetRemark(v string) *ModelCreate {
|
|
_c.mutation.SetRemark(v)
|
|
return _c
|
|
}
|
|
|
|
// SetNillableRemark sets the "remark" field if the given value is not nil.
|
|
func (_c *ModelCreate) SetNillableRemark(v *string) *ModelCreate {
|
|
if v != nil {
|
|
_c.SetRemark(*v)
|
|
}
|
|
return _c
|
|
}
|
|
|
|
// SetTemperature sets the "temperature" field.
|
|
func (_c *ModelCreate) SetTemperature(v float64) *ModelCreate {
|
|
_c.mutation.SetTemperature(v)
|
|
return _c
|
|
}
|
|
|
|
// SetNillableTemperature sets the "temperature" field if the given value is not nil.
|
|
func (_c *ModelCreate) SetNillableTemperature(v *float64) *ModelCreate {
|
|
if v != nil {
|
|
_c.SetTemperature(*v)
|
|
}
|
|
return _c
|
|
}
|
|
|
|
// SetInterfaceType sets the "interface_type" field.
|
|
func (_c *ModelCreate) SetInterfaceType(v string) *ModelCreate {
|
|
_c.mutation.SetInterfaceType(v)
|
|
return _c
|
|
}
|
|
|
|
// SetNillableInterfaceType sets the "interface_type" field if the given value is not nil.
|
|
func (_c *ModelCreate) SetNillableInterfaceType(v *string) *ModelCreate {
|
|
if v != nil {
|
|
_c.SetInterfaceType(*v)
|
|
}
|
|
return _c
|
|
}
|
|
|
|
// SetWeight sets the "weight" field.
|
|
func (_c *ModelCreate) SetWeight(v int) *ModelCreate {
|
|
_c.mutation.SetWeight(v)
|
|
return _c
|
|
}
|
|
|
|
// SetNillableWeight sets the "weight" field if the given value is not nil.
|
|
func (_c *ModelCreate) SetNillableWeight(v *int) *ModelCreate {
|
|
if v != nil {
|
|
_c.SetWeight(*v)
|
|
}
|
|
return _c
|
|
}
|
|
|
|
// SetThinkingEnabled sets the "thinking_enabled" field.
|
|
func (_c *ModelCreate) SetThinkingEnabled(v bool) *ModelCreate {
|
|
_c.mutation.SetThinkingEnabled(v)
|
|
return _c
|
|
}
|
|
|
|
// SetNillableThinkingEnabled sets the "thinking_enabled" field if the given value is not nil.
|
|
func (_c *ModelCreate) SetNillableThinkingEnabled(v *bool) *ModelCreate {
|
|
if v != nil {
|
|
_c.SetThinkingEnabled(*v)
|
|
}
|
|
return _c
|
|
}
|
|
|
|
// SetContextLimit sets the "context_limit" field.
|
|
func (_c *ModelCreate) SetContextLimit(v int) *ModelCreate {
|
|
_c.mutation.SetContextLimit(v)
|
|
return _c
|
|
}
|
|
|
|
// SetNillableContextLimit sets the "context_limit" field if the given value is not nil.
|
|
func (_c *ModelCreate) SetNillableContextLimit(v *int) *ModelCreate {
|
|
if v != nil {
|
|
_c.SetContextLimit(*v)
|
|
}
|
|
return _c
|
|
}
|
|
|
|
// SetOutputLimit sets the "output_limit" field.
|
|
func (_c *ModelCreate) SetOutputLimit(v int) *ModelCreate {
|
|
_c.mutation.SetOutputLimit(v)
|
|
return _c
|
|
}
|
|
|
|
// SetNillableOutputLimit sets the "output_limit" field if the given value is not nil.
|
|
func (_c *ModelCreate) SetNillableOutputLimit(v *int) *ModelCreate {
|
|
if v != nil {
|
|
_c.SetOutputLimit(*v)
|
|
}
|
|
return _c
|
|
}
|
|
|
|
// SetLastCheckAt sets the "last_check_at" field.
|
|
func (_c *ModelCreate) SetLastCheckAt(v time.Time) *ModelCreate {
|
|
_c.mutation.SetLastCheckAt(v)
|
|
return _c
|
|
}
|
|
|
|
// SetNillableLastCheckAt sets the "last_check_at" field if the given value is not nil.
|
|
func (_c *ModelCreate) SetNillableLastCheckAt(v *time.Time) *ModelCreate {
|
|
if v != nil {
|
|
_c.SetLastCheckAt(*v)
|
|
}
|
|
return _c
|
|
}
|
|
|
|
// SetLastCheckSuccess sets the "last_check_success" field.
|
|
func (_c *ModelCreate) SetLastCheckSuccess(v bool) *ModelCreate {
|
|
_c.mutation.SetLastCheckSuccess(v)
|
|
return _c
|
|
}
|
|
|
|
// SetNillableLastCheckSuccess sets the "last_check_success" field if the given value is not nil.
|
|
func (_c *ModelCreate) SetNillableLastCheckSuccess(v *bool) *ModelCreate {
|
|
if v != nil {
|
|
_c.SetLastCheckSuccess(*v)
|
|
}
|
|
return _c
|
|
}
|
|
|
|
// SetLastCheckError sets the "last_check_error" field.
|
|
func (_c *ModelCreate) SetLastCheckError(v string) *ModelCreate {
|
|
_c.mutation.SetLastCheckError(v)
|
|
return _c
|
|
}
|
|
|
|
// SetNillableLastCheckError sets the "last_check_error" field if the given value is not nil.
|
|
func (_c *ModelCreate) SetNillableLastCheckError(v *string) *ModelCreate {
|
|
if v != nil {
|
|
_c.SetLastCheckError(*v)
|
|
}
|
|
return _c
|
|
}
|
|
|
|
// SetCreatedAt sets the "created_at" field.
|
|
func (_c *ModelCreate) SetCreatedAt(v time.Time) *ModelCreate {
|
|
_c.mutation.SetCreatedAt(v)
|
|
return _c
|
|
}
|
|
|
|
// SetNillableCreatedAt sets the "created_at" field if the given value is not nil.
|
|
func (_c *ModelCreate) SetNillableCreatedAt(v *time.Time) *ModelCreate {
|
|
if v != nil {
|
|
_c.SetCreatedAt(*v)
|
|
}
|
|
return _c
|
|
}
|
|
|
|
// SetUpdatedAt sets the "updated_at" field.
|
|
func (_c *ModelCreate) SetUpdatedAt(v time.Time) *ModelCreate {
|
|
_c.mutation.SetUpdatedAt(v)
|
|
return _c
|
|
}
|
|
|
|
// SetNillableUpdatedAt sets the "updated_at" field if the given value is not nil.
|
|
func (_c *ModelCreate) SetNillableUpdatedAt(v *time.Time) *ModelCreate {
|
|
if v != nil {
|
|
_c.SetUpdatedAt(*v)
|
|
}
|
|
return _c
|
|
}
|
|
|
|
// SetID sets the "id" field.
|
|
func (_c *ModelCreate) SetID(v uuid.UUID) *ModelCreate {
|
|
_c.mutation.SetID(v)
|
|
return _c
|
|
}
|
|
|
|
// SetUser sets the "user" edge to the User entity.
|
|
func (_c *ModelCreate) SetUser(v *User) *ModelCreate {
|
|
return _c.SetUserID(v.ID)
|
|
}
|
|
|
|
// AddTeamIDs adds the "teams" edge to the Team entity by IDs.
|
|
func (_c *ModelCreate) AddTeamIDs(ids ...uuid.UUID) *ModelCreate {
|
|
_c.mutation.AddTeamIDs(ids...)
|
|
return _c
|
|
}
|
|
|
|
// AddTeams adds the "teams" edges to the Team entity.
|
|
func (_c *ModelCreate) AddTeams(v ...*Team) *ModelCreate {
|
|
ids := make([]uuid.UUID, len(v))
|
|
for i := range v {
|
|
ids[i] = v[i].ID
|
|
}
|
|
return _c.AddTeamIDs(ids...)
|
|
}
|
|
|
|
// AddGroupIDs adds the "groups" edge to the TeamGroup entity by IDs.
|
|
func (_c *ModelCreate) AddGroupIDs(ids ...uuid.UUID) *ModelCreate {
|
|
_c.mutation.AddGroupIDs(ids...)
|
|
return _c
|
|
}
|
|
|
|
// AddGroups adds the "groups" edges to the TeamGroup entity.
|
|
func (_c *ModelCreate) AddGroups(v ...*TeamGroup) *ModelCreate {
|
|
ids := make([]uuid.UUID, len(v))
|
|
for i := range v {
|
|
ids[i] = v[i].ID
|
|
}
|
|
return _c.AddGroupIDs(ids...)
|
|
}
|
|
|
|
// AddVMIDs adds the "vms" edge to the VirtualMachine entity by IDs.
|
|
func (_c *ModelCreate) AddVMIDs(ids ...string) *ModelCreate {
|
|
_c.mutation.AddVMIDs(ids...)
|
|
return _c
|
|
}
|
|
|
|
// AddVms adds the "vms" edges to the VirtualMachine entity.
|
|
func (_c *ModelCreate) AddVms(v ...*VirtualMachine) *ModelCreate {
|
|
ids := make([]string, len(v))
|
|
for i := range v {
|
|
ids[i] = v[i].ID
|
|
}
|
|
return _c.AddVMIDs(ids...)
|
|
}
|
|
|
|
// AddProjectTaskIDs adds the "project_tasks" edge to the ProjectTask entity by IDs.
|
|
func (_c *ModelCreate) AddProjectTaskIDs(ids ...uuid.UUID) *ModelCreate {
|
|
_c.mutation.AddProjectTaskIDs(ids...)
|
|
return _c
|
|
}
|
|
|
|
// AddProjectTasks adds the "project_tasks" edges to the ProjectTask entity.
|
|
func (_c *ModelCreate) AddProjectTasks(v ...*ProjectTask) *ModelCreate {
|
|
ids := make([]uuid.UUID, len(v))
|
|
for i := range v {
|
|
ids[i] = v[i].ID
|
|
}
|
|
return _c.AddProjectTaskIDs(ids...)
|
|
}
|
|
|
|
// SetPricingID sets the "pricing" edge to the ModelPricing entity by ID.
|
|
func (_c *ModelCreate) SetPricingID(id uuid.UUID) *ModelCreate {
|
|
_c.mutation.SetPricingID(id)
|
|
return _c
|
|
}
|
|
|
|
// SetNillablePricingID sets the "pricing" edge to the ModelPricing entity by ID if the given value is not nil.
|
|
func (_c *ModelCreate) SetNillablePricingID(id *uuid.UUID) *ModelCreate {
|
|
if id != nil {
|
|
_c = _c.SetPricingID(*id)
|
|
}
|
|
return _c
|
|
}
|
|
|
|
// SetPricing sets the "pricing" edge to the ModelPricing entity.
|
|
func (_c *ModelCreate) SetPricing(v *ModelPricing) *ModelCreate {
|
|
return _c.SetPricingID(v.ID)
|
|
}
|
|
|
|
// AddApikeyIDs adds the "apikeys" edge to the ModelApiKey entity by IDs.
|
|
func (_c *ModelCreate) AddApikeyIDs(ids ...uuid.UUID) *ModelCreate {
|
|
_c.mutation.AddApikeyIDs(ids...)
|
|
return _c
|
|
}
|
|
|
|
// AddApikeys adds the "apikeys" edges to the ModelApiKey entity.
|
|
func (_c *ModelCreate) AddApikeys(v ...*ModelApiKey) *ModelCreate {
|
|
ids := make([]uuid.UUID, len(v))
|
|
for i := range v {
|
|
ids[i] = v[i].ID
|
|
}
|
|
return _c.AddApikeyIDs(ids...)
|
|
}
|
|
|
|
// AddSwitchesFromIDs adds the "switches_from" edge to the TaskModelSwitch entity by IDs.
|
|
func (_c *ModelCreate) AddSwitchesFromIDs(ids ...uuid.UUID) *ModelCreate {
|
|
_c.mutation.AddSwitchesFromIDs(ids...)
|
|
return _c
|
|
}
|
|
|
|
// AddSwitchesFrom adds the "switches_from" edges to the TaskModelSwitch entity.
|
|
func (_c *ModelCreate) AddSwitchesFrom(v ...*TaskModelSwitch) *ModelCreate {
|
|
ids := make([]uuid.UUID, len(v))
|
|
for i := range v {
|
|
ids[i] = v[i].ID
|
|
}
|
|
return _c.AddSwitchesFromIDs(ids...)
|
|
}
|
|
|
|
// AddSwitchesToIDs adds the "switches_to" edge to the TaskModelSwitch entity by IDs.
|
|
func (_c *ModelCreate) AddSwitchesToIDs(ids ...uuid.UUID) *ModelCreate {
|
|
_c.mutation.AddSwitchesToIDs(ids...)
|
|
return _c
|
|
}
|
|
|
|
// AddSwitchesTo adds the "switches_to" edges to the TaskModelSwitch entity.
|
|
func (_c *ModelCreate) AddSwitchesTo(v ...*TaskModelSwitch) *ModelCreate {
|
|
ids := make([]uuid.UUID, len(v))
|
|
for i := range v {
|
|
ids[i] = v[i].ID
|
|
}
|
|
return _c.AddSwitchesToIDs(ids...)
|
|
}
|
|
|
|
// AddTeamModelIDs adds the "team_models" edge to the TeamModel entity by IDs.
|
|
func (_c *ModelCreate) AddTeamModelIDs(ids ...uuid.UUID) *ModelCreate {
|
|
_c.mutation.AddTeamModelIDs(ids...)
|
|
return _c
|
|
}
|
|
|
|
// AddTeamModels adds the "team_models" edges to the TeamModel entity.
|
|
func (_c *ModelCreate) AddTeamModels(v ...*TeamModel) *ModelCreate {
|
|
ids := make([]uuid.UUID, len(v))
|
|
for i := range v {
|
|
ids[i] = v[i].ID
|
|
}
|
|
return _c.AddTeamModelIDs(ids...)
|
|
}
|
|
|
|
// AddTeamGroupModelIDs adds the "team_group_models" edge to the TeamGroupModel entity by IDs.
|
|
func (_c *ModelCreate) AddTeamGroupModelIDs(ids ...uuid.UUID) *ModelCreate {
|
|
_c.mutation.AddTeamGroupModelIDs(ids...)
|
|
return _c
|
|
}
|
|
|
|
// AddTeamGroupModels adds the "team_group_models" edges to the TeamGroupModel entity.
|
|
func (_c *ModelCreate) AddTeamGroupModels(v ...*TeamGroupModel) *ModelCreate {
|
|
ids := make([]uuid.UUID, len(v))
|
|
for i := range v {
|
|
ids[i] = v[i].ID
|
|
}
|
|
return _c.AddTeamGroupModelIDs(ids...)
|
|
}
|
|
|
|
// Mutation returns the ModelMutation object of the builder.
|
|
func (_c *ModelCreate) Mutation() *ModelMutation {
|
|
return _c.mutation
|
|
}
|
|
|
|
// Save creates the Model in the database.
|
|
func (_c *ModelCreate) Save(ctx context.Context) (*Model, 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 *ModelCreate) SaveX(ctx context.Context) *Model {
|
|
v, err := _c.Save(ctx)
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
return v
|
|
}
|
|
|
|
// Exec executes the query.
|
|
func (_c *ModelCreate) Exec(ctx context.Context) error {
|
|
_, err := _c.Save(ctx)
|
|
return err
|
|
}
|
|
|
|
// ExecX is like Exec, but panics if an error occurs.
|
|
func (_c *ModelCreate) 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 *ModelCreate) defaults() error {
|
|
if _, ok := _c.mutation.Weight(); !ok {
|
|
v := model.DefaultWeight
|
|
_c.mutation.SetWeight(v)
|
|
}
|
|
if _, ok := _c.mutation.ThinkingEnabled(); !ok {
|
|
v := model.DefaultThinkingEnabled
|
|
_c.mutation.SetThinkingEnabled(v)
|
|
}
|
|
if _, ok := _c.mutation.ContextLimit(); !ok {
|
|
v := model.DefaultContextLimit
|
|
_c.mutation.SetContextLimit(v)
|
|
}
|
|
if _, ok := _c.mutation.OutputLimit(); !ok {
|
|
v := model.DefaultOutputLimit
|
|
_c.mutation.SetOutputLimit(v)
|
|
}
|
|
if _, ok := _c.mutation.CreatedAt(); !ok {
|
|
if model.DefaultCreatedAt == nil {
|
|
return fmt.Errorf("db: uninitialized model.DefaultCreatedAt (forgotten import db/runtime?)")
|
|
}
|
|
v := model.DefaultCreatedAt()
|
|
_c.mutation.SetCreatedAt(v)
|
|
}
|
|
if _, ok := _c.mutation.UpdatedAt(); !ok {
|
|
if model.DefaultUpdatedAt == nil {
|
|
return fmt.Errorf("db: uninitialized model.DefaultUpdatedAt (forgotten import db/runtime?)")
|
|
}
|
|
v := model.DefaultUpdatedAt()
|
|
_c.mutation.SetUpdatedAt(v)
|
|
}
|
|
return nil
|
|
}
|
|
|
|
// check runs all checks and user-defined validators on the builder.
|
|
func (_c *ModelCreate) check() error {
|
|
if _, ok := _c.mutation.UserID(); !ok {
|
|
return &ValidationError{Name: "user_id", err: errors.New(`db: missing required field "Model.user_id"`)}
|
|
}
|
|
if _, ok := _c.mutation.Provider(); !ok {
|
|
return &ValidationError{Name: "provider", err: errors.New(`db: missing required field "Model.provider"`)}
|
|
}
|
|
if v, ok := _c.mutation.Provider(); ok {
|
|
if err := model.ProviderValidator(v); err != nil {
|
|
return &ValidationError{Name: "provider", err: fmt.Errorf(`db: validator failed for field "Model.provider": %w`, err)}
|
|
}
|
|
}
|
|
if _, ok := _c.mutation.APIKey(); !ok {
|
|
return &ValidationError{Name: "api_key", err: errors.New(`db: missing required field "Model.api_key"`)}
|
|
}
|
|
if v, ok := _c.mutation.APIKey(); ok {
|
|
if err := model.APIKeyValidator(v); err != nil {
|
|
return &ValidationError{Name: "api_key", err: fmt.Errorf(`db: validator failed for field "Model.api_key": %w`, err)}
|
|
}
|
|
}
|
|
if _, ok := _c.mutation.BaseURL(); !ok {
|
|
return &ValidationError{Name: "base_url", err: errors.New(`db: missing required field "Model.base_url"`)}
|
|
}
|
|
if v, ok := _c.mutation.BaseURL(); ok {
|
|
if err := model.BaseURLValidator(v); err != nil {
|
|
return &ValidationError{Name: "base_url", err: fmt.Errorf(`db: validator failed for field "Model.base_url": %w`, err)}
|
|
}
|
|
}
|
|
if _, ok := _c.mutation.Model(); !ok {
|
|
return &ValidationError{Name: "model", err: errors.New(`db: missing required field "Model.model"`)}
|
|
}
|
|
if v, ok := _c.mutation.Model(); ok {
|
|
if err := model.ModelValidator(v); err != nil {
|
|
return &ValidationError{Name: "model", err: fmt.Errorf(`db: validator failed for field "Model.model": %w`, err)}
|
|
}
|
|
}
|
|
if _, ok := _c.mutation.Weight(); !ok {
|
|
return &ValidationError{Name: "weight", err: errors.New(`db: missing required field "Model.weight"`)}
|
|
}
|
|
if _, ok := _c.mutation.ThinkingEnabled(); !ok {
|
|
return &ValidationError{Name: "thinking_enabled", err: errors.New(`db: missing required field "Model.thinking_enabled"`)}
|
|
}
|
|
if _, ok := _c.mutation.ContextLimit(); !ok {
|
|
return &ValidationError{Name: "context_limit", err: errors.New(`db: missing required field "Model.context_limit"`)}
|
|
}
|
|
if _, ok := _c.mutation.OutputLimit(); !ok {
|
|
return &ValidationError{Name: "output_limit", err: errors.New(`db: missing required field "Model.output_limit"`)}
|
|
}
|
|
if _, ok := _c.mutation.CreatedAt(); !ok {
|
|
return &ValidationError{Name: "created_at", err: errors.New(`db: missing required field "Model.created_at"`)}
|
|
}
|
|
if _, ok := _c.mutation.UpdatedAt(); !ok {
|
|
return &ValidationError{Name: "updated_at", err: errors.New(`db: missing required field "Model.updated_at"`)}
|
|
}
|
|
if len(_c.mutation.UserIDs()) == 0 {
|
|
return &ValidationError{Name: "user", err: errors.New(`db: missing required edge "Model.user"`)}
|
|
}
|
|
return nil
|
|
}
|
|
|
|
func (_c *ModelCreate) sqlSave(ctx context.Context) (*Model, 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 *ModelCreate) createSpec() (*Model, *sqlgraph.CreateSpec) {
|
|
var (
|
|
_node = &Model{config: _c.config}
|
|
_spec = sqlgraph.NewCreateSpec(model.Table, sqlgraph.NewFieldSpec(model.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.DeletedAt(); ok {
|
|
_spec.SetField(model.FieldDeletedAt, field.TypeTime, value)
|
|
_node.DeletedAt = value
|
|
}
|
|
if value, ok := _c.mutation.Provider(); ok {
|
|
_spec.SetField(model.FieldProvider, field.TypeString, value)
|
|
_node.Provider = value
|
|
}
|
|
if value, ok := _c.mutation.APIKey(); ok {
|
|
_spec.SetField(model.FieldAPIKey, field.TypeString, value)
|
|
_node.APIKey = value
|
|
}
|
|
if value, ok := _c.mutation.BaseURL(); ok {
|
|
_spec.SetField(model.FieldBaseURL, field.TypeString, value)
|
|
_node.BaseURL = value
|
|
}
|
|
if value, ok := _c.mutation.Model(); ok {
|
|
_spec.SetField(model.FieldModel, field.TypeString, value)
|
|
_node.Model = value
|
|
}
|
|
if value, ok := _c.mutation.Remark(); ok {
|
|
_spec.SetField(model.FieldRemark, field.TypeString, value)
|
|
_node.Remark = value
|
|
}
|
|
if value, ok := _c.mutation.Temperature(); ok {
|
|
_spec.SetField(model.FieldTemperature, field.TypeFloat64, value)
|
|
_node.Temperature = value
|
|
}
|
|
if value, ok := _c.mutation.InterfaceType(); ok {
|
|
_spec.SetField(model.FieldInterfaceType, field.TypeString, value)
|
|
_node.InterfaceType = value
|
|
}
|
|
if value, ok := _c.mutation.Weight(); ok {
|
|
_spec.SetField(model.FieldWeight, field.TypeInt, value)
|
|
_node.Weight = value
|
|
}
|
|
if value, ok := _c.mutation.ThinkingEnabled(); ok {
|
|
_spec.SetField(model.FieldThinkingEnabled, field.TypeBool, value)
|
|
_node.ThinkingEnabled = value
|
|
}
|
|
if value, ok := _c.mutation.ContextLimit(); ok {
|
|
_spec.SetField(model.FieldContextLimit, field.TypeInt, value)
|
|
_node.ContextLimit = value
|
|
}
|
|
if value, ok := _c.mutation.OutputLimit(); ok {
|
|
_spec.SetField(model.FieldOutputLimit, field.TypeInt, value)
|
|
_node.OutputLimit = value
|
|
}
|
|
if value, ok := _c.mutation.LastCheckAt(); ok {
|
|
_spec.SetField(model.FieldLastCheckAt, field.TypeTime, value)
|
|
_node.LastCheckAt = value
|
|
}
|
|
if value, ok := _c.mutation.LastCheckSuccess(); ok {
|
|
_spec.SetField(model.FieldLastCheckSuccess, field.TypeBool, value)
|
|
_node.LastCheckSuccess = value
|
|
}
|
|
if value, ok := _c.mutation.LastCheckError(); ok {
|
|
_spec.SetField(model.FieldLastCheckError, field.TypeString, value)
|
|
_node.LastCheckError = value
|
|
}
|
|
if value, ok := _c.mutation.CreatedAt(); ok {
|
|
_spec.SetField(model.FieldCreatedAt, field.TypeTime, value)
|
|
_node.CreatedAt = value
|
|
}
|
|
if value, ok := _c.mutation.UpdatedAt(); ok {
|
|
_spec.SetField(model.FieldUpdatedAt, field.TypeTime, value)
|
|
_node.UpdatedAt = value
|
|
}
|
|
if nodes := _c.mutation.UserIDs(); len(nodes) > 0 {
|
|
edge := &sqlgraph.EdgeSpec{
|
|
Rel: sqlgraph.M2O,
|
|
Inverse: true,
|
|
Table: model.UserTable,
|
|
Columns: []string{model.UserColumn},
|
|
Bidi: false,
|
|
Target: &sqlgraph.EdgeTarget{
|
|
IDSpec: sqlgraph.NewFieldSpec(user.FieldID, field.TypeUUID),
|
|
},
|
|
}
|
|
for _, k := range nodes {
|
|
edge.Target.Nodes = append(edge.Target.Nodes, k)
|
|
}
|
|
_node.UserID = nodes[0]
|
|
_spec.Edges = append(_spec.Edges, edge)
|
|
}
|
|
if nodes := _c.mutation.TeamsIDs(); len(nodes) > 0 {
|
|
edge := &sqlgraph.EdgeSpec{
|
|
Rel: sqlgraph.M2M,
|
|
Inverse: true,
|
|
Table: model.TeamsTable,
|
|
Columns: model.TeamsPrimaryKey,
|
|
Bidi: false,
|
|
Target: &sqlgraph.EdgeTarget{
|
|
IDSpec: sqlgraph.NewFieldSpec(team.FieldID, field.TypeUUID),
|
|
},
|
|
}
|
|
for _, k := range nodes {
|
|
edge.Target.Nodes = append(edge.Target.Nodes, k)
|
|
}
|
|
createE := &TeamModelCreate{config: _c.config, mutation: newTeamModelMutation(_c.config, OpCreate)}
|
|
createE.defaults()
|
|
_, specE := createE.createSpec()
|
|
edge.Target.Fields = specE.Fields
|
|
_spec.Edges = append(_spec.Edges, edge)
|
|
}
|
|
if nodes := _c.mutation.GroupsIDs(); len(nodes) > 0 {
|
|
edge := &sqlgraph.EdgeSpec{
|
|
Rel: sqlgraph.M2M,
|
|
Inverse: true,
|
|
Table: model.GroupsTable,
|
|
Columns: model.GroupsPrimaryKey,
|
|
Bidi: false,
|
|
Target: &sqlgraph.EdgeTarget{
|
|
IDSpec: sqlgraph.NewFieldSpec(teamgroup.FieldID, field.TypeUUID),
|
|
},
|
|
}
|
|
for _, k := range nodes {
|
|
edge.Target.Nodes = append(edge.Target.Nodes, k)
|
|
}
|
|
createE := &TeamGroupModelCreate{config: _c.config, mutation: newTeamGroupModelMutation(_c.config, OpCreate)}
|
|
createE.defaults()
|
|
_, specE := createE.createSpec()
|
|
edge.Target.Fields = specE.Fields
|
|
_spec.Edges = append(_spec.Edges, edge)
|
|
}
|
|
if nodes := _c.mutation.VmsIDs(); len(nodes) > 0 {
|
|
edge := &sqlgraph.EdgeSpec{
|
|
Rel: sqlgraph.O2M,
|
|
Inverse: false,
|
|
Table: model.VmsTable,
|
|
Columns: []string{model.VmsColumn},
|
|
Bidi: false,
|
|
Target: &sqlgraph.EdgeTarget{
|
|
IDSpec: sqlgraph.NewFieldSpec(virtualmachine.FieldID, field.TypeString),
|
|
},
|
|
}
|
|
for _, k := range nodes {
|
|
edge.Target.Nodes = append(edge.Target.Nodes, k)
|
|
}
|
|
_spec.Edges = append(_spec.Edges, edge)
|
|
}
|
|
if nodes := _c.mutation.ProjectTasksIDs(); len(nodes) > 0 {
|
|
edge := &sqlgraph.EdgeSpec{
|
|
Rel: sqlgraph.O2M,
|
|
Inverse: false,
|
|
Table: model.ProjectTasksTable,
|
|
Columns: []string{model.ProjectTasksColumn},
|
|
Bidi: false,
|
|
Target: &sqlgraph.EdgeTarget{
|
|
IDSpec: sqlgraph.NewFieldSpec(projecttask.FieldID, field.TypeUUID),
|
|
},
|
|
}
|
|
for _, k := range nodes {
|
|
edge.Target.Nodes = append(edge.Target.Nodes, k)
|
|
}
|
|
_spec.Edges = append(_spec.Edges, edge)
|
|
}
|
|
if nodes := _c.mutation.PricingIDs(); len(nodes) > 0 {
|
|
edge := &sqlgraph.EdgeSpec{
|
|
Rel: sqlgraph.O2O,
|
|
Inverse: false,
|
|
Table: model.PricingTable,
|
|
Columns: []string{model.PricingColumn},
|
|
Bidi: false,
|
|
Target: &sqlgraph.EdgeTarget{
|
|
IDSpec: sqlgraph.NewFieldSpec(modelpricing.FieldID, field.TypeUUID),
|
|
},
|
|
}
|
|
for _, k := range nodes {
|
|
edge.Target.Nodes = append(edge.Target.Nodes, k)
|
|
}
|
|
_spec.Edges = append(_spec.Edges, edge)
|
|
}
|
|
if nodes := _c.mutation.ApikeysIDs(); len(nodes) > 0 {
|
|
edge := &sqlgraph.EdgeSpec{
|
|
Rel: sqlgraph.O2M,
|
|
Inverse: false,
|
|
Table: model.ApikeysTable,
|
|
Columns: []string{model.ApikeysColumn},
|
|
Bidi: false,
|
|
Target: &sqlgraph.EdgeTarget{
|
|
IDSpec: sqlgraph.NewFieldSpec(modelapikey.FieldID, field.TypeUUID),
|
|
},
|
|
}
|
|
for _, k := range nodes {
|
|
edge.Target.Nodes = append(edge.Target.Nodes, k)
|
|
}
|
|
_spec.Edges = append(_spec.Edges, edge)
|
|
}
|
|
if nodes := _c.mutation.SwitchesFromIDs(); len(nodes) > 0 {
|
|
edge := &sqlgraph.EdgeSpec{
|
|
Rel: sqlgraph.O2M,
|
|
Inverse: false,
|
|
Table: model.SwitchesFromTable,
|
|
Columns: []string{model.SwitchesFromColumn},
|
|
Bidi: false,
|
|
Target: &sqlgraph.EdgeTarget{
|
|
IDSpec: sqlgraph.NewFieldSpec(taskmodelswitch.FieldID, field.TypeUUID),
|
|
},
|
|
}
|
|
for _, k := range nodes {
|
|
edge.Target.Nodes = append(edge.Target.Nodes, k)
|
|
}
|
|
_spec.Edges = append(_spec.Edges, edge)
|
|
}
|
|
if nodes := _c.mutation.SwitchesToIDs(); len(nodes) > 0 {
|
|
edge := &sqlgraph.EdgeSpec{
|
|
Rel: sqlgraph.O2M,
|
|
Inverse: false,
|
|
Table: model.SwitchesToTable,
|
|
Columns: []string{model.SwitchesToColumn},
|
|
Bidi: false,
|
|
Target: &sqlgraph.EdgeTarget{
|
|
IDSpec: sqlgraph.NewFieldSpec(taskmodelswitch.FieldID, field.TypeUUID),
|
|
},
|
|
}
|
|
for _, k := range nodes {
|
|
edge.Target.Nodes = append(edge.Target.Nodes, k)
|
|
}
|
|
_spec.Edges = append(_spec.Edges, edge)
|
|
}
|
|
if nodes := _c.mutation.TeamModelsIDs(); len(nodes) > 0 {
|
|
edge := &sqlgraph.EdgeSpec{
|
|
Rel: sqlgraph.O2M,
|
|
Inverse: true,
|
|
Table: model.TeamModelsTable,
|
|
Columns: []string{model.TeamModelsColumn},
|
|
Bidi: false,
|
|
Target: &sqlgraph.EdgeTarget{
|
|
IDSpec: sqlgraph.NewFieldSpec(teammodel.FieldID, field.TypeUUID),
|
|
},
|
|
}
|
|
for _, k := range nodes {
|
|
edge.Target.Nodes = append(edge.Target.Nodes, k)
|
|
}
|
|
_spec.Edges = append(_spec.Edges, edge)
|
|
}
|
|
if nodes := _c.mutation.TeamGroupModelsIDs(); len(nodes) > 0 {
|
|
edge := &sqlgraph.EdgeSpec{
|
|
Rel: sqlgraph.O2M,
|
|
Inverse: true,
|
|
Table: model.TeamGroupModelsTable,
|
|
Columns: []string{model.TeamGroupModelsColumn},
|
|
Bidi: false,
|
|
Target: &sqlgraph.EdgeTarget{
|
|
IDSpec: sqlgraph.NewFieldSpec(teamgroupmodel.FieldID, field.TypeUUID),
|
|
},
|
|
}
|
|
for _, k := range nodes {
|
|
edge.Target.Nodes = append(edge.Target.Nodes, k)
|
|
}
|
|
_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.Model.Create().
|
|
// SetDeletedAt(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.ModelUpsert) {
|
|
// SetDeletedAt(v+v).
|
|
// }).
|
|
// Exec(ctx)
|
|
func (_c *ModelCreate) OnConflict(opts ...sql.ConflictOption) *ModelUpsertOne {
|
|
_c.conflict = opts
|
|
return &ModelUpsertOne{
|
|
create: _c,
|
|
}
|
|
}
|
|
|
|
// OnConflictColumns calls `OnConflict` and configures the columns
|
|
// as conflict target. Using this option is equivalent to using:
|
|
//
|
|
// client.Model.Create().
|
|
// OnConflict(sql.ConflictColumns(columns...)).
|
|
// Exec(ctx)
|
|
func (_c *ModelCreate) OnConflictColumns(columns ...string) *ModelUpsertOne {
|
|
_c.conflict = append(_c.conflict, sql.ConflictColumns(columns...))
|
|
return &ModelUpsertOne{
|
|
create: _c,
|
|
}
|
|
}
|
|
|
|
type (
|
|
// ModelUpsertOne is the builder for "upsert"-ing
|
|
// one Model node.
|
|
ModelUpsertOne struct {
|
|
create *ModelCreate
|
|
}
|
|
|
|
// ModelUpsert is the "OnConflict" setter.
|
|
ModelUpsert struct {
|
|
*sql.UpdateSet
|
|
}
|
|
)
|
|
|
|
// SetDeletedAt sets the "deleted_at" field.
|
|
func (u *ModelUpsert) SetDeletedAt(v time.Time) *ModelUpsert {
|
|
u.Set(model.FieldDeletedAt, v)
|
|
return u
|
|
}
|
|
|
|
// UpdateDeletedAt sets the "deleted_at" field to the value that was provided on create.
|
|
func (u *ModelUpsert) UpdateDeletedAt() *ModelUpsert {
|
|
u.SetExcluded(model.FieldDeletedAt)
|
|
return u
|
|
}
|
|
|
|
// ClearDeletedAt clears the value of the "deleted_at" field.
|
|
func (u *ModelUpsert) ClearDeletedAt() *ModelUpsert {
|
|
u.SetNull(model.FieldDeletedAt)
|
|
return u
|
|
}
|
|
|
|
// SetUserID sets the "user_id" field.
|
|
func (u *ModelUpsert) SetUserID(v uuid.UUID) *ModelUpsert {
|
|
u.Set(model.FieldUserID, v)
|
|
return u
|
|
}
|
|
|
|
// UpdateUserID sets the "user_id" field to the value that was provided on create.
|
|
func (u *ModelUpsert) UpdateUserID() *ModelUpsert {
|
|
u.SetExcluded(model.FieldUserID)
|
|
return u
|
|
}
|
|
|
|
// SetProvider sets the "provider" field.
|
|
func (u *ModelUpsert) SetProvider(v string) *ModelUpsert {
|
|
u.Set(model.FieldProvider, v)
|
|
return u
|
|
}
|
|
|
|
// UpdateProvider sets the "provider" field to the value that was provided on create.
|
|
func (u *ModelUpsert) UpdateProvider() *ModelUpsert {
|
|
u.SetExcluded(model.FieldProvider)
|
|
return u
|
|
}
|
|
|
|
// SetAPIKey sets the "api_key" field.
|
|
func (u *ModelUpsert) SetAPIKey(v string) *ModelUpsert {
|
|
u.Set(model.FieldAPIKey, v)
|
|
return u
|
|
}
|
|
|
|
// UpdateAPIKey sets the "api_key" field to the value that was provided on create.
|
|
func (u *ModelUpsert) UpdateAPIKey() *ModelUpsert {
|
|
u.SetExcluded(model.FieldAPIKey)
|
|
return u
|
|
}
|
|
|
|
// SetBaseURL sets the "base_url" field.
|
|
func (u *ModelUpsert) SetBaseURL(v string) *ModelUpsert {
|
|
u.Set(model.FieldBaseURL, v)
|
|
return u
|
|
}
|
|
|
|
// UpdateBaseURL sets the "base_url" field to the value that was provided on create.
|
|
func (u *ModelUpsert) UpdateBaseURL() *ModelUpsert {
|
|
u.SetExcluded(model.FieldBaseURL)
|
|
return u
|
|
}
|
|
|
|
// SetModel sets the "model" field.
|
|
func (u *ModelUpsert) SetModel(v string) *ModelUpsert {
|
|
u.Set(model.FieldModel, v)
|
|
return u
|
|
}
|
|
|
|
// UpdateModel sets the "model" field to the value that was provided on create.
|
|
func (u *ModelUpsert) UpdateModel() *ModelUpsert {
|
|
u.SetExcluded(model.FieldModel)
|
|
return u
|
|
}
|
|
|
|
// SetRemark sets the "remark" field.
|
|
func (u *ModelUpsert) SetRemark(v string) *ModelUpsert {
|
|
u.Set(model.FieldRemark, v)
|
|
return u
|
|
}
|
|
|
|
// UpdateRemark sets the "remark" field to the value that was provided on create.
|
|
func (u *ModelUpsert) UpdateRemark() *ModelUpsert {
|
|
u.SetExcluded(model.FieldRemark)
|
|
return u
|
|
}
|
|
|
|
// ClearRemark clears the value of the "remark" field.
|
|
func (u *ModelUpsert) ClearRemark() *ModelUpsert {
|
|
u.SetNull(model.FieldRemark)
|
|
return u
|
|
}
|
|
|
|
// SetTemperature sets the "temperature" field.
|
|
func (u *ModelUpsert) SetTemperature(v float64) *ModelUpsert {
|
|
u.Set(model.FieldTemperature, v)
|
|
return u
|
|
}
|
|
|
|
// UpdateTemperature sets the "temperature" field to the value that was provided on create.
|
|
func (u *ModelUpsert) UpdateTemperature() *ModelUpsert {
|
|
u.SetExcluded(model.FieldTemperature)
|
|
return u
|
|
}
|
|
|
|
// AddTemperature adds v to the "temperature" field.
|
|
func (u *ModelUpsert) AddTemperature(v float64) *ModelUpsert {
|
|
u.Add(model.FieldTemperature, v)
|
|
return u
|
|
}
|
|
|
|
// ClearTemperature clears the value of the "temperature" field.
|
|
func (u *ModelUpsert) ClearTemperature() *ModelUpsert {
|
|
u.SetNull(model.FieldTemperature)
|
|
return u
|
|
}
|
|
|
|
// SetInterfaceType sets the "interface_type" field.
|
|
func (u *ModelUpsert) SetInterfaceType(v string) *ModelUpsert {
|
|
u.Set(model.FieldInterfaceType, v)
|
|
return u
|
|
}
|
|
|
|
// UpdateInterfaceType sets the "interface_type" field to the value that was provided on create.
|
|
func (u *ModelUpsert) UpdateInterfaceType() *ModelUpsert {
|
|
u.SetExcluded(model.FieldInterfaceType)
|
|
return u
|
|
}
|
|
|
|
// ClearInterfaceType clears the value of the "interface_type" field.
|
|
func (u *ModelUpsert) ClearInterfaceType() *ModelUpsert {
|
|
u.SetNull(model.FieldInterfaceType)
|
|
return u
|
|
}
|
|
|
|
// SetWeight sets the "weight" field.
|
|
func (u *ModelUpsert) SetWeight(v int) *ModelUpsert {
|
|
u.Set(model.FieldWeight, v)
|
|
return u
|
|
}
|
|
|
|
// UpdateWeight sets the "weight" field to the value that was provided on create.
|
|
func (u *ModelUpsert) UpdateWeight() *ModelUpsert {
|
|
u.SetExcluded(model.FieldWeight)
|
|
return u
|
|
}
|
|
|
|
// AddWeight adds v to the "weight" field.
|
|
func (u *ModelUpsert) AddWeight(v int) *ModelUpsert {
|
|
u.Add(model.FieldWeight, v)
|
|
return u
|
|
}
|
|
|
|
// SetThinkingEnabled sets the "thinking_enabled" field.
|
|
func (u *ModelUpsert) SetThinkingEnabled(v bool) *ModelUpsert {
|
|
u.Set(model.FieldThinkingEnabled, v)
|
|
return u
|
|
}
|
|
|
|
// UpdateThinkingEnabled sets the "thinking_enabled" field to the value that was provided on create.
|
|
func (u *ModelUpsert) UpdateThinkingEnabled() *ModelUpsert {
|
|
u.SetExcluded(model.FieldThinkingEnabled)
|
|
return u
|
|
}
|
|
|
|
// SetContextLimit sets the "context_limit" field.
|
|
func (u *ModelUpsert) SetContextLimit(v int) *ModelUpsert {
|
|
u.Set(model.FieldContextLimit, v)
|
|
return u
|
|
}
|
|
|
|
// UpdateContextLimit sets the "context_limit" field to the value that was provided on create.
|
|
func (u *ModelUpsert) UpdateContextLimit() *ModelUpsert {
|
|
u.SetExcluded(model.FieldContextLimit)
|
|
return u
|
|
}
|
|
|
|
// AddContextLimit adds v to the "context_limit" field.
|
|
func (u *ModelUpsert) AddContextLimit(v int) *ModelUpsert {
|
|
u.Add(model.FieldContextLimit, v)
|
|
return u
|
|
}
|
|
|
|
// SetOutputLimit sets the "output_limit" field.
|
|
func (u *ModelUpsert) SetOutputLimit(v int) *ModelUpsert {
|
|
u.Set(model.FieldOutputLimit, v)
|
|
return u
|
|
}
|
|
|
|
// UpdateOutputLimit sets the "output_limit" field to the value that was provided on create.
|
|
func (u *ModelUpsert) UpdateOutputLimit() *ModelUpsert {
|
|
u.SetExcluded(model.FieldOutputLimit)
|
|
return u
|
|
}
|
|
|
|
// AddOutputLimit adds v to the "output_limit" field.
|
|
func (u *ModelUpsert) AddOutputLimit(v int) *ModelUpsert {
|
|
u.Add(model.FieldOutputLimit, v)
|
|
return u
|
|
}
|
|
|
|
// SetLastCheckAt sets the "last_check_at" field.
|
|
func (u *ModelUpsert) SetLastCheckAt(v time.Time) *ModelUpsert {
|
|
u.Set(model.FieldLastCheckAt, v)
|
|
return u
|
|
}
|
|
|
|
// UpdateLastCheckAt sets the "last_check_at" field to the value that was provided on create.
|
|
func (u *ModelUpsert) UpdateLastCheckAt() *ModelUpsert {
|
|
u.SetExcluded(model.FieldLastCheckAt)
|
|
return u
|
|
}
|
|
|
|
// ClearLastCheckAt clears the value of the "last_check_at" field.
|
|
func (u *ModelUpsert) ClearLastCheckAt() *ModelUpsert {
|
|
u.SetNull(model.FieldLastCheckAt)
|
|
return u
|
|
}
|
|
|
|
// SetLastCheckSuccess sets the "last_check_success" field.
|
|
func (u *ModelUpsert) SetLastCheckSuccess(v bool) *ModelUpsert {
|
|
u.Set(model.FieldLastCheckSuccess, v)
|
|
return u
|
|
}
|
|
|
|
// UpdateLastCheckSuccess sets the "last_check_success" field to the value that was provided on create.
|
|
func (u *ModelUpsert) UpdateLastCheckSuccess() *ModelUpsert {
|
|
u.SetExcluded(model.FieldLastCheckSuccess)
|
|
return u
|
|
}
|
|
|
|
// ClearLastCheckSuccess clears the value of the "last_check_success" field.
|
|
func (u *ModelUpsert) ClearLastCheckSuccess() *ModelUpsert {
|
|
u.SetNull(model.FieldLastCheckSuccess)
|
|
return u
|
|
}
|
|
|
|
// SetLastCheckError sets the "last_check_error" field.
|
|
func (u *ModelUpsert) SetLastCheckError(v string) *ModelUpsert {
|
|
u.Set(model.FieldLastCheckError, v)
|
|
return u
|
|
}
|
|
|
|
// UpdateLastCheckError sets the "last_check_error" field to the value that was provided on create.
|
|
func (u *ModelUpsert) UpdateLastCheckError() *ModelUpsert {
|
|
u.SetExcluded(model.FieldLastCheckError)
|
|
return u
|
|
}
|
|
|
|
// ClearLastCheckError clears the value of the "last_check_error" field.
|
|
func (u *ModelUpsert) ClearLastCheckError() *ModelUpsert {
|
|
u.SetNull(model.FieldLastCheckError)
|
|
return u
|
|
}
|
|
|
|
// SetCreatedAt sets the "created_at" field.
|
|
func (u *ModelUpsert) SetCreatedAt(v time.Time) *ModelUpsert {
|
|
u.Set(model.FieldCreatedAt, v)
|
|
return u
|
|
}
|
|
|
|
// UpdateCreatedAt sets the "created_at" field to the value that was provided on create.
|
|
func (u *ModelUpsert) UpdateCreatedAt() *ModelUpsert {
|
|
u.SetExcluded(model.FieldCreatedAt)
|
|
return u
|
|
}
|
|
|
|
// SetUpdatedAt sets the "updated_at" field.
|
|
func (u *ModelUpsert) SetUpdatedAt(v time.Time) *ModelUpsert {
|
|
u.Set(model.FieldUpdatedAt, v)
|
|
return u
|
|
}
|
|
|
|
// UpdateUpdatedAt sets the "updated_at" field to the value that was provided on create.
|
|
func (u *ModelUpsert) UpdateUpdatedAt() *ModelUpsert {
|
|
u.SetExcluded(model.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.Model.Create().
|
|
// OnConflict(
|
|
// sql.ResolveWithNewValues(),
|
|
// sql.ResolveWith(func(u *sql.UpdateSet) {
|
|
// u.SetIgnore(model.FieldID)
|
|
// }),
|
|
// ).
|
|
// Exec(ctx)
|
|
func (u *ModelUpsertOne) UpdateNewValues() *ModelUpsertOne {
|
|
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(model.FieldID)
|
|
}
|
|
}))
|
|
return u
|
|
}
|
|
|
|
// Ignore sets each column to itself in case of conflict.
|
|
// Using this option is equivalent to using:
|
|
//
|
|
// client.Model.Create().
|
|
// OnConflict(sql.ResolveWithIgnore()).
|
|
// Exec(ctx)
|
|
func (u *ModelUpsertOne) Ignore() *ModelUpsertOne {
|
|
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 *ModelUpsertOne) DoNothing() *ModelUpsertOne {
|
|
u.create.conflict = append(u.create.conflict, sql.DoNothing())
|
|
return u
|
|
}
|
|
|
|
// Update allows overriding fields `UPDATE` values. See the ModelCreate.OnConflict
|
|
// documentation for more info.
|
|
func (u *ModelUpsertOne) Update(set func(*ModelUpsert)) *ModelUpsertOne {
|
|
u.create.conflict = append(u.create.conflict, sql.ResolveWith(func(update *sql.UpdateSet) {
|
|
set(&ModelUpsert{UpdateSet: update})
|
|
}))
|
|
return u
|
|
}
|
|
|
|
// SetDeletedAt sets the "deleted_at" field.
|
|
func (u *ModelUpsertOne) SetDeletedAt(v time.Time) *ModelUpsertOne {
|
|
return u.Update(func(s *ModelUpsert) {
|
|
s.SetDeletedAt(v)
|
|
})
|
|
}
|
|
|
|
// UpdateDeletedAt sets the "deleted_at" field to the value that was provided on create.
|
|
func (u *ModelUpsertOne) UpdateDeletedAt() *ModelUpsertOne {
|
|
return u.Update(func(s *ModelUpsert) {
|
|
s.UpdateDeletedAt()
|
|
})
|
|
}
|
|
|
|
// ClearDeletedAt clears the value of the "deleted_at" field.
|
|
func (u *ModelUpsertOne) ClearDeletedAt() *ModelUpsertOne {
|
|
return u.Update(func(s *ModelUpsert) {
|
|
s.ClearDeletedAt()
|
|
})
|
|
}
|
|
|
|
// SetUserID sets the "user_id" field.
|
|
func (u *ModelUpsertOne) SetUserID(v uuid.UUID) *ModelUpsertOne {
|
|
return u.Update(func(s *ModelUpsert) {
|
|
s.SetUserID(v)
|
|
})
|
|
}
|
|
|
|
// UpdateUserID sets the "user_id" field to the value that was provided on create.
|
|
func (u *ModelUpsertOne) UpdateUserID() *ModelUpsertOne {
|
|
return u.Update(func(s *ModelUpsert) {
|
|
s.UpdateUserID()
|
|
})
|
|
}
|
|
|
|
// SetProvider sets the "provider" field.
|
|
func (u *ModelUpsertOne) SetProvider(v string) *ModelUpsertOne {
|
|
return u.Update(func(s *ModelUpsert) {
|
|
s.SetProvider(v)
|
|
})
|
|
}
|
|
|
|
// UpdateProvider sets the "provider" field to the value that was provided on create.
|
|
func (u *ModelUpsertOne) UpdateProvider() *ModelUpsertOne {
|
|
return u.Update(func(s *ModelUpsert) {
|
|
s.UpdateProvider()
|
|
})
|
|
}
|
|
|
|
// SetAPIKey sets the "api_key" field.
|
|
func (u *ModelUpsertOne) SetAPIKey(v string) *ModelUpsertOne {
|
|
return u.Update(func(s *ModelUpsert) {
|
|
s.SetAPIKey(v)
|
|
})
|
|
}
|
|
|
|
// UpdateAPIKey sets the "api_key" field to the value that was provided on create.
|
|
func (u *ModelUpsertOne) UpdateAPIKey() *ModelUpsertOne {
|
|
return u.Update(func(s *ModelUpsert) {
|
|
s.UpdateAPIKey()
|
|
})
|
|
}
|
|
|
|
// SetBaseURL sets the "base_url" field.
|
|
func (u *ModelUpsertOne) SetBaseURL(v string) *ModelUpsertOne {
|
|
return u.Update(func(s *ModelUpsert) {
|
|
s.SetBaseURL(v)
|
|
})
|
|
}
|
|
|
|
// UpdateBaseURL sets the "base_url" field to the value that was provided on create.
|
|
func (u *ModelUpsertOne) UpdateBaseURL() *ModelUpsertOne {
|
|
return u.Update(func(s *ModelUpsert) {
|
|
s.UpdateBaseURL()
|
|
})
|
|
}
|
|
|
|
// SetModel sets the "model" field.
|
|
func (u *ModelUpsertOne) SetModel(v string) *ModelUpsertOne {
|
|
return u.Update(func(s *ModelUpsert) {
|
|
s.SetModel(v)
|
|
})
|
|
}
|
|
|
|
// UpdateModel sets the "model" field to the value that was provided on create.
|
|
func (u *ModelUpsertOne) UpdateModel() *ModelUpsertOne {
|
|
return u.Update(func(s *ModelUpsert) {
|
|
s.UpdateModel()
|
|
})
|
|
}
|
|
|
|
// SetRemark sets the "remark" field.
|
|
func (u *ModelUpsertOne) SetRemark(v string) *ModelUpsertOne {
|
|
return u.Update(func(s *ModelUpsert) {
|
|
s.SetRemark(v)
|
|
})
|
|
}
|
|
|
|
// UpdateRemark sets the "remark" field to the value that was provided on create.
|
|
func (u *ModelUpsertOne) UpdateRemark() *ModelUpsertOne {
|
|
return u.Update(func(s *ModelUpsert) {
|
|
s.UpdateRemark()
|
|
})
|
|
}
|
|
|
|
// ClearRemark clears the value of the "remark" field.
|
|
func (u *ModelUpsertOne) ClearRemark() *ModelUpsertOne {
|
|
return u.Update(func(s *ModelUpsert) {
|
|
s.ClearRemark()
|
|
})
|
|
}
|
|
|
|
// SetTemperature sets the "temperature" field.
|
|
func (u *ModelUpsertOne) SetTemperature(v float64) *ModelUpsertOne {
|
|
return u.Update(func(s *ModelUpsert) {
|
|
s.SetTemperature(v)
|
|
})
|
|
}
|
|
|
|
// AddTemperature adds v to the "temperature" field.
|
|
func (u *ModelUpsertOne) AddTemperature(v float64) *ModelUpsertOne {
|
|
return u.Update(func(s *ModelUpsert) {
|
|
s.AddTemperature(v)
|
|
})
|
|
}
|
|
|
|
// UpdateTemperature sets the "temperature" field to the value that was provided on create.
|
|
func (u *ModelUpsertOne) UpdateTemperature() *ModelUpsertOne {
|
|
return u.Update(func(s *ModelUpsert) {
|
|
s.UpdateTemperature()
|
|
})
|
|
}
|
|
|
|
// ClearTemperature clears the value of the "temperature" field.
|
|
func (u *ModelUpsertOne) ClearTemperature() *ModelUpsertOne {
|
|
return u.Update(func(s *ModelUpsert) {
|
|
s.ClearTemperature()
|
|
})
|
|
}
|
|
|
|
// SetInterfaceType sets the "interface_type" field.
|
|
func (u *ModelUpsertOne) SetInterfaceType(v string) *ModelUpsertOne {
|
|
return u.Update(func(s *ModelUpsert) {
|
|
s.SetInterfaceType(v)
|
|
})
|
|
}
|
|
|
|
// UpdateInterfaceType sets the "interface_type" field to the value that was provided on create.
|
|
func (u *ModelUpsertOne) UpdateInterfaceType() *ModelUpsertOne {
|
|
return u.Update(func(s *ModelUpsert) {
|
|
s.UpdateInterfaceType()
|
|
})
|
|
}
|
|
|
|
// ClearInterfaceType clears the value of the "interface_type" field.
|
|
func (u *ModelUpsertOne) ClearInterfaceType() *ModelUpsertOne {
|
|
return u.Update(func(s *ModelUpsert) {
|
|
s.ClearInterfaceType()
|
|
})
|
|
}
|
|
|
|
// SetWeight sets the "weight" field.
|
|
func (u *ModelUpsertOne) SetWeight(v int) *ModelUpsertOne {
|
|
return u.Update(func(s *ModelUpsert) {
|
|
s.SetWeight(v)
|
|
})
|
|
}
|
|
|
|
// AddWeight adds v to the "weight" field.
|
|
func (u *ModelUpsertOne) AddWeight(v int) *ModelUpsertOne {
|
|
return u.Update(func(s *ModelUpsert) {
|
|
s.AddWeight(v)
|
|
})
|
|
}
|
|
|
|
// UpdateWeight sets the "weight" field to the value that was provided on create.
|
|
func (u *ModelUpsertOne) UpdateWeight() *ModelUpsertOne {
|
|
return u.Update(func(s *ModelUpsert) {
|
|
s.UpdateWeight()
|
|
})
|
|
}
|
|
|
|
// SetThinkingEnabled sets the "thinking_enabled" field.
|
|
func (u *ModelUpsertOne) SetThinkingEnabled(v bool) *ModelUpsertOne {
|
|
return u.Update(func(s *ModelUpsert) {
|
|
s.SetThinkingEnabled(v)
|
|
})
|
|
}
|
|
|
|
// UpdateThinkingEnabled sets the "thinking_enabled" field to the value that was provided on create.
|
|
func (u *ModelUpsertOne) UpdateThinkingEnabled() *ModelUpsertOne {
|
|
return u.Update(func(s *ModelUpsert) {
|
|
s.UpdateThinkingEnabled()
|
|
})
|
|
}
|
|
|
|
// SetContextLimit sets the "context_limit" field.
|
|
func (u *ModelUpsertOne) SetContextLimit(v int) *ModelUpsertOne {
|
|
return u.Update(func(s *ModelUpsert) {
|
|
s.SetContextLimit(v)
|
|
})
|
|
}
|
|
|
|
// AddContextLimit adds v to the "context_limit" field.
|
|
func (u *ModelUpsertOne) AddContextLimit(v int) *ModelUpsertOne {
|
|
return u.Update(func(s *ModelUpsert) {
|
|
s.AddContextLimit(v)
|
|
})
|
|
}
|
|
|
|
// UpdateContextLimit sets the "context_limit" field to the value that was provided on create.
|
|
func (u *ModelUpsertOne) UpdateContextLimit() *ModelUpsertOne {
|
|
return u.Update(func(s *ModelUpsert) {
|
|
s.UpdateContextLimit()
|
|
})
|
|
}
|
|
|
|
// SetOutputLimit sets the "output_limit" field.
|
|
func (u *ModelUpsertOne) SetOutputLimit(v int) *ModelUpsertOne {
|
|
return u.Update(func(s *ModelUpsert) {
|
|
s.SetOutputLimit(v)
|
|
})
|
|
}
|
|
|
|
// AddOutputLimit adds v to the "output_limit" field.
|
|
func (u *ModelUpsertOne) AddOutputLimit(v int) *ModelUpsertOne {
|
|
return u.Update(func(s *ModelUpsert) {
|
|
s.AddOutputLimit(v)
|
|
})
|
|
}
|
|
|
|
// UpdateOutputLimit sets the "output_limit" field to the value that was provided on create.
|
|
func (u *ModelUpsertOne) UpdateOutputLimit() *ModelUpsertOne {
|
|
return u.Update(func(s *ModelUpsert) {
|
|
s.UpdateOutputLimit()
|
|
})
|
|
}
|
|
|
|
// SetLastCheckAt sets the "last_check_at" field.
|
|
func (u *ModelUpsertOne) SetLastCheckAt(v time.Time) *ModelUpsertOne {
|
|
return u.Update(func(s *ModelUpsert) {
|
|
s.SetLastCheckAt(v)
|
|
})
|
|
}
|
|
|
|
// UpdateLastCheckAt sets the "last_check_at" field to the value that was provided on create.
|
|
func (u *ModelUpsertOne) UpdateLastCheckAt() *ModelUpsertOne {
|
|
return u.Update(func(s *ModelUpsert) {
|
|
s.UpdateLastCheckAt()
|
|
})
|
|
}
|
|
|
|
// ClearLastCheckAt clears the value of the "last_check_at" field.
|
|
func (u *ModelUpsertOne) ClearLastCheckAt() *ModelUpsertOne {
|
|
return u.Update(func(s *ModelUpsert) {
|
|
s.ClearLastCheckAt()
|
|
})
|
|
}
|
|
|
|
// SetLastCheckSuccess sets the "last_check_success" field.
|
|
func (u *ModelUpsertOne) SetLastCheckSuccess(v bool) *ModelUpsertOne {
|
|
return u.Update(func(s *ModelUpsert) {
|
|
s.SetLastCheckSuccess(v)
|
|
})
|
|
}
|
|
|
|
// UpdateLastCheckSuccess sets the "last_check_success" field to the value that was provided on create.
|
|
func (u *ModelUpsertOne) UpdateLastCheckSuccess() *ModelUpsertOne {
|
|
return u.Update(func(s *ModelUpsert) {
|
|
s.UpdateLastCheckSuccess()
|
|
})
|
|
}
|
|
|
|
// ClearLastCheckSuccess clears the value of the "last_check_success" field.
|
|
func (u *ModelUpsertOne) ClearLastCheckSuccess() *ModelUpsertOne {
|
|
return u.Update(func(s *ModelUpsert) {
|
|
s.ClearLastCheckSuccess()
|
|
})
|
|
}
|
|
|
|
// SetLastCheckError sets the "last_check_error" field.
|
|
func (u *ModelUpsertOne) SetLastCheckError(v string) *ModelUpsertOne {
|
|
return u.Update(func(s *ModelUpsert) {
|
|
s.SetLastCheckError(v)
|
|
})
|
|
}
|
|
|
|
// UpdateLastCheckError sets the "last_check_error" field to the value that was provided on create.
|
|
func (u *ModelUpsertOne) UpdateLastCheckError() *ModelUpsertOne {
|
|
return u.Update(func(s *ModelUpsert) {
|
|
s.UpdateLastCheckError()
|
|
})
|
|
}
|
|
|
|
// ClearLastCheckError clears the value of the "last_check_error" field.
|
|
func (u *ModelUpsertOne) ClearLastCheckError() *ModelUpsertOne {
|
|
return u.Update(func(s *ModelUpsert) {
|
|
s.ClearLastCheckError()
|
|
})
|
|
}
|
|
|
|
// SetCreatedAt sets the "created_at" field.
|
|
func (u *ModelUpsertOne) SetCreatedAt(v time.Time) *ModelUpsertOne {
|
|
return u.Update(func(s *ModelUpsert) {
|
|
s.SetCreatedAt(v)
|
|
})
|
|
}
|
|
|
|
// UpdateCreatedAt sets the "created_at" field to the value that was provided on create.
|
|
func (u *ModelUpsertOne) UpdateCreatedAt() *ModelUpsertOne {
|
|
return u.Update(func(s *ModelUpsert) {
|
|
s.UpdateCreatedAt()
|
|
})
|
|
}
|
|
|
|
// SetUpdatedAt sets the "updated_at" field.
|
|
func (u *ModelUpsertOne) SetUpdatedAt(v time.Time) *ModelUpsertOne {
|
|
return u.Update(func(s *ModelUpsert) {
|
|
s.SetUpdatedAt(v)
|
|
})
|
|
}
|
|
|
|
// UpdateUpdatedAt sets the "updated_at" field to the value that was provided on create.
|
|
func (u *ModelUpsertOne) UpdateUpdatedAt() *ModelUpsertOne {
|
|
return u.Update(func(s *ModelUpsert) {
|
|
s.UpdateUpdatedAt()
|
|
})
|
|
}
|
|
|
|
// Exec executes the query.
|
|
func (u *ModelUpsertOne) Exec(ctx context.Context) error {
|
|
if len(u.create.conflict) == 0 {
|
|
return errors.New("db: missing options for ModelCreate.OnConflict")
|
|
}
|
|
return u.create.Exec(ctx)
|
|
}
|
|
|
|
// ExecX is like Exec, but panics if an error occurs.
|
|
func (u *ModelUpsertOne) 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 *ModelUpsertOne) 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: ModelUpsertOne.ID is not supported by MySQL driver. Use ModelUpsertOne.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 *ModelUpsertOne) IDX(ctx context.Context) uuid.UUID {
|
|
id, err := u.ID(ctx)
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
return id
|
|
}
|
|
|
|
// ModelCreateBulk is the builder for creating many Model entities in bulk.
|
|
type ModelCreateBulk struct {
|
|
config
|
|
err error
|
|
builders []*ModelCreate
|
|
conflict []sql.ConflictOption
|
|
}
|
|
|
|
// Save creates the Model entities in the database.
|
|
func (_c *ModelCreateBulk) Save(ctx context.Context) ([]*Model, error) {
|
|
if _c.err != nil {
|
|
return nil, _c.err
|
|
}
|
|
specs := make([]*sqlgraph.CreateSpec, len(_c.builders))
|
|
nodes := make([]*Model, 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.(*ModelMutation)
|
|
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 *ModelCreateBulk) SaveX(ctx context.Context) []*Model {
|
|
v, err := _c.Save(ctx)
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
return v
|
|
}
|
|
|
|
// Exec executes the query.
|
|
func (_c *ModelCreateBulk) Exec(ctx context.Context) error {
|
|
_, err := _c.Save(ctx)
|
|
return err
|
|
}
|
|
|
|
// ExecX is like Exec, but panics if an error occurs.
|
|
func (_c *ModelCreateBulk) 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.Model.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.ModelUpsert) {
|
|
// SetDeletedAt(v+v).
|
|
// }).
|
|
// Exec(ctx)
|
|
func (_c *ModelCreateBulk) OnConflict(opts ...sql.ConflictOption) *ModelUpsertBulk {
|
|
_c.conflict = opts
|
|
return &ModelUpsertBulk{
|
|
create: _c,
|
|
}
|
|
}
|
|
|
|
// OnConflictColumns calls `OnConflict` and configures the columns
|
|
// as conflict target. Using this option is equivalent to using:
|
|
//
|
|
// client.Model.Create().
|
|
// OnConflict(sql.ConflictColumns(columns...)).
|
|
// Exec(ctx)
|
|
func (_c *ModelCreateBulk) OnConflictColumns(columns ...string) *ModelUpsertBulk {
|
|
_c.conflict = append(_c.conflict, sql.ConflictColumns(columns...))
|
|
return &ModelUpsertBulk{
|
|
create: _c,
|
|
}
|
|
}
|
|
|
|
// ModelUpsertBulk is the builder for "upsert"-ing
|
|
// a bulk of Model nodes.
|
|
type ModelUpsertBulk struct {
|
|
create *ModelCreateBulk
|
|
}
|
|
|
|
// UpdateNewValues updates the mutable fields using the new values that
|
|
// were set on create. Using this option is equivalent to using:
|
|
//
|
|
// client.Model.Create().
|
|
// OnConflict(
|
|
// sql.ResolveWithNewValues(),
|
|
// sql.ResolveWith(func(u *sql.UpdateSet) {
|
|
// u.SetIgnore(model.FieldID)
|
|
// }),
|
|
// ).
|
|
// Exec(ctx)
|
|
func (u *ModelUpsertBulk) UpdateNewValues() *ModelUpsertBulk {
|
|
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(model.FieldID)
|
|
}
|
|
}
|
|
}))
|
|
return u
|
|
}
|
|
|
|
// Ignore sets each column to itself in case of conflict.
|
|
// Using this option is equivalent to using:
|
|
//
|
|
// client.Model.Create().
|
|
// OnConflict(sql.ResolveWithIgnore()).
|
|
// Exec(ctx)
|
|
func (u *ModelUpsertBulk) Ignore() *ModelUpsertBulk {
|
|
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 *ModelUpsertBulk) DoNothing() *ModelUpsertBulk {
|
|
u.create.conflict = append(u.create.conflict, sql.DoNothing())
|
|
return u
|
|
}
|
|
|
|
// Update allows overriding fields `UPDATE` values. See the ModelCreateBulk.OnConflict
|
|
// documentation for more info.
|
|
func (u *ModelUpsertBulk) Update(set func(*ModelUpsert)) *ModelUpsertBulk {
|
|
u.create.conflict = append(u.create.conflict, sql.ResolveWith(func(update *sql.UpdateSet) {
|
|
set(&ModelUpsert{UpdateSet: update})
|
|
}))
|
|
return u
|
|
}
|
|
|
|
// SetDeletedAt sets the "deleted_at" field.
|
|
func (u *ModelUpsertBulk) SetDeletedAt(v time.Time) *ModelUpsertBulk {
|
|
return u.Update(func(s *ModelUpsert) {
|
|
s.SetDeletedAt(v)
|
|
})
|
|
}
|
|
|
|
// UpdateDeletedAt sets the "deleted_at" field to the value that was provided on create.
|
|
func (u *ModelUpsertBulk) UpdateDeletedAt() *ModelUpsertBulk {
|
|
return u.Update(func(s *ModelUpsert) {
|
|
s.UpdateDeletedAt()
|
|
})
|
|
}
|
|
|
|
// ClearDeletedAt clears the value of the "deleted_at" field.
|
|
func (u *ModelUpsertBulk) ClearDeletedAt() *ModelUpsertBulk {
|
|
return u.Update(func(s *ModelUpsert) {
|
|
s.ClearDeletedAt()
|
|
})
|
|
}
|
|
|
|
// SetUserID sets the "user_id" field.
|
|
func (u *ModelUpsertBulk) SetUserID(v uuid.UUID) *ModelUpsertBulk {
|
|
return u.Update(func(s *ModelUpsert) {
|
|
s.SetUserID(v)
|
|
})
|
|
}
|
|
|
|
// UpdateUserID sets the "user_id" field to the value that was provided on create.
|
|
func (u *ModelUpsertBulk) UpdateUserID() *ModelUpsertBulk {
|
|
return u.Update(func(s *ModelUpsert) {
|
|
s.UpdateUserID()
|
|
})
|
|
}
|
|
|
|
// SetProvider sets the "provider" field.
|
|
func (u *ModelUpsertBulk) SetProvider(v string) *ModelUpsertBulk {
|
|
return u.Update(func(s *ModelUpsert) {
|
|
s.SetProvider(v)
|
|
})
|
|
}
|
|
|
|
// UpdateProvider sets the "provider" field to the value that was provided on create.
|
|
func (u *ModelUpsertBulk) UpdateProvider() *ModelUpsertBulk {
|
|
return u.Update(func(s *ModelUpsert) {
|
|
s.UpdateProvider()
|
|
})
|
|
}
|
|
|
|
// SetAPIKey sets the "api_key" field.
|
|
func (u *ModelUpsertBulk) SetAPIKey(v string) *ModelUpsertBulk {
|
|
return u.Update(func(s *ModelUpsert) {
|
|
s.SetAPIKey(v)
|
|
})
|
|
}
|
|
|
|
// UpdateAPIKey sets the "api_key" field to the value that was provided on create.
|
|
func (u *ModelUpsertBulk) UpdateAPIKey() *ModelUpsertBulk {
|
|
return u.Update(func(s *ModelUpsert) {
|
|
s.UpdateAPIKey()
|
|
})
|
|
}
|
|
|
|
// SetBaseURL sets the "base_url" field.
|
|
func (u *ModelUpsertBulk) SetBaseURL(v string) *ModelUpsertBulk {
|
|
return u.Update(func(s *ModelUpsert) {
|
|
s.SetBaseURL(v)
|
|
})
|
|
}
|
|
|
|
// UpdateBaseURL sets the "base_url" field to the value that was provided on create.
|
|
func (u *ModelUpsertBulk) UpdateBaseURL() *ModelUpsertBulk {
|
|
return u.Update(func(s *ModelUpsert) {
|
|
s.UpdateBaseURL()
|
|
})
|
|
}
|
|
|
|
// SetModel sets the "model" field.
|
|
func (u *ModelUpsertBulk) SetModel(v string) *ModelUpsertBulk {
|
|
return u.Update(func(s *ModelUpsert) {
|
|
s.SetModel(v)
|
|
})
|
|
}
|
|
|
|
// UpdateModel sets the "model" field to the value that was provided on create.
|
|
func (u *ModelUpsertBulk) UpdateModel() *ModelUpsertBulk {
|
|
return u.Update(func(s *ModelUpsert) {
|
|
s.UpdateModel()
|
|
})
|
|
}
|
|
|
|
// SetRemark sets the "remark" field.
|
|
func (u *ModelUpsertBulk) SetRemark(v string) *ModelUpsertBulk {
|
|
return u.Update(func(s *ModelUpsert) {
|
|
s.SetRemark(v)
|
|
})
|
|
}
|
|
|
|
// UpdateRemark sets the "remark" field to the value that was provided on create.
|
|
func (u *ModelUpsertBulk) UpdateRemark() *ModelUpsertBulk {
|
|
return u.Update(func(s *ModelUpsert) {
|
|
s.UpdateRemark()
|
|
})
|
|
}
|
|
|
|
// ClearRemark clears the value of the "remark" field.
|
|
func (u *ModelUpsertBulk) ClearRemark() *ModelUpsertBulk {
|
|
return u.Update(func(s *ModelUpsert) {
|
|
s.ClearRemark()
|
|
})
|
|
}
|
|
|
|
// SetTemperature sets the "temperature" field.
|
|
func (u *ModelUpsertBulk) SetTemperature(v float64) *ModelUpsertBulk {
|
|
return u.Update(func(s *ModelUpsert) {
|
|
s.SetTemperature(v)
|
|
})
|
|
}
|
|
|
|
// AddTemperature adds v to the "temperature" field.
|
|
func (u *ModelUpsertBulk) AddTemperature(v float64) *ModelUpsertBulk {
|
|
return u.Update(func(s *ModelUpsert) {
|
|
s.AddTemperature(v)
|
|
})
|
|
}
|
|
|
|
// UpdateTemperature sets the "temperature" field to the value that was provided on create.
|
|
func (u *ModelUpsertBulk) UpdateTemperature() *ModelUpsertBulk {
|
|
return u.Update(func(s *ModelUpsert) {
|
|
s.UpdateTemperature()
|
|
})
|
|
}
|
|
|
|
// ClearTemperature clears the value of the "temperature" field.
|
|
func (u *ModelUpsertBulk) ClearTemperature() *ModelUpsertBulk {
|
|
return u.Update(func(s *ModelUpsert) {
|
|
s.ClearTemperature()
|
|
})
|
|
}
|
|
|
|
// SetInterfaceType sets the "interface_type" field.
|
|
func (u *ModelUpsertBulk) SetInterfaceType(v string) *ModelUpsertBulk {
|
|
return u.Update(func(s *ModelUpsert) {
|
|
s.SetInterfaceType(v)
|
|
})
|
|
}
|
|
|
|
// UpdateInterfaceType sets the "interface_type" field to the value that was provided on create.
|
|
func (u *ModelUpsertBulk) UpdateInterfaceType() *ModelUpsertBulk {
|
|
return u.Update(func(s *ModelUpsert) {
|
|
s.UpdateInterfaceType()
|
|
})
|
|
}
|
|
|
|
// ClearInterfaceType clears the value of the "interface_type" field.
|
|
func (u *ModelUpsertBulk) ClearInterfaceType() *ModelUpsertBulk {
|
|
return u.Update(func(s *ModelUpsert) {
|
|
s.ClearInterfaceType()
|
|
})
|
|
}
|
|
|
|
// SetWeight sets the "weight" field.
|
|
func (u *ModelUpsertBulk) SetWeight(v int) *ModelUpsertBulk {
|
|
return u.Update(func(s *ModelUpsert) {
|
|
s.SetWeight(v)
|
|
})
|
|
}
|
|
|
|
// AddWeight adds v to the "weight" field.
|
|
func (u *ModelUpsertBulk) AddWeight(v int) *ModelUpsertBulk {
|
|
return u.Update(func(s *ModelUpsert) {
|
|
s.AddWeight(v)
|
|
})
|
|
}
|
|
|
|
// UpdateWeight sets the "weight" field to the value that was provided on create.
|
|
func (u *ModelUpsertBulk) UpdateWeight() *ModelUpsertBulk {
|
|
return u.Update(func(s *ModelUpsert) {
|
|
s.UpdateWeight()
|
|
})
|
|
}
|
|
|
|
// SetThinkingEnabled sets the "thinking_enabled" field.
|
|
func (u *ModelUpsertBulk) SetThinkingEnabled(v bool) *ModelUpsertBulk {
|
|
return u.Update(func(s *ModelUpsert) {
|
|
s.SetThinkingEnabled(v)
|
|
})
|
|
}
|
|
|
|
// UpdateThinkingEnabled sets the "thinking_enabled" field to the value that was provided on create.
|
|
func (u *ModelUpsertBulk) UpdateThinkingEnabled() *ModelUpsertBulk {
|
|
return u.Update(func(s *ModelUpsert) {
|
|
s.UpdateThinkingEnabled()
|
|
})
|
|
}
|
|
|
|
// SetContextLimit sets the "context_limit" field.
|
|
func (u *ModelUpsertBulk) SetContextLimit(v int) *ModelUpsertBulk {
|
|
return u.Update(func(s *ModelUpsert) {
|
|
s.SetContextLimit(v)
|
|
})
|
|
}
|
|
|
|
// AddContextLimit adds v to the "context_limit" field.
|
|
func (u *ModelUpsertBulk) AddContextLimit(v int) *ModelUpsertBulk {
|
|
return u.Update(func(s *ModelUpsert) {
|
|
s.AddContextLimit(v)
|
|
})
|
|
}
|
|
|
|
// UpdateContextLimit sets the "context_limit" field to the value that was provided on create.
|
|
func (u *ModelUpsertBulk) UpdateContextLimit() *ModelUpsertBulk {
|
|
return u.Update(func(s *ModelUpsert) {
|
|
s.UpdateContextLimit()
|
|
})
|
|
}
|
|
|
|
// SetOutputLimit sets the "output_limit" field.
|
|
func (u *ModelUpsertBulk) SetOutputLimit(v int) *ModelUpsertBulk {
|
|
return u.Update(func(s *ModelUpsert) {
|
|
s.SetOutputLimit(v)
|
|
})
|
|
}
|
|
|
|
// AddOutputLimit adds v to the "output_limit" field.
|
|
func (u *ModelUpsertBulk) AddOutputLimit(v int) *ModelUpsertBulk {
|
|
return u.Update(func(s *ModelUpsert) {
|
|
s.AddOutputLimit(v)
|
|
})
|
|
}
|
|
|
|
// UpdateOutputLimit sets the "output_limit" field to the value that was provided on create.
|
|
func (u *ModelUpsertBulk) UpdateOutputLimit() *ModelUpsertBulk {
|
|
return u.Update(func(s *ModelUpsert) {
|
|
s.UpdateOutputLimit()
|
|
})
|
|
}
|
|
|
|
// SetLastCheckAt sets the "last_check_at" field.
|
|
func (u *ModelUpsertBulk) SetLastCheckAt(v time.Time) *ModelUpsertBulk {
|
|
return u.Update(func(s *ModelUpsert) {
|
|
s.SetLastCheckAt(v)
|
|
})
|
|
}
|
|
|
|
// UpdateLastCheckAt sets the "last_check_at" field to the value that was provided on create.
|
|
func (u *ModelUpsertBulk) UpdateLastCheckAt() *ModelUpsertBulk {
|
|
return u.Update(func(s *ModelUpsert) {
|
|
s.UpdateLastCheckAt()
|
|
})
|
|
}
|
|
|
|
// ClearLastCheckAt clears the value of the "last_check_at" field.
|
|
func (u *ModelUpsertBulk) ClearLastCheckAt() *ModelUpsertBulk {
|
|
return u.Update(func(s *ModelUpsert) {
|
|
s.ClearLastCheckAt()
|
|
})
|
|
}
|
|
|
|
// SetLastCheckSuccess sets the "last_check_success" field.
|
|
func (u *ModelUpsertBulk) SetLastCheckSuccess(v bool) *ModelUpsertBulk {
|
|
return u.Update(func(s *ModelUpsert) {
|
|
s.SetLastCheckSuccess(v)
|
|
})
|
|
}
|
|
|
|
// UpdateLastCheckSuccess sets the "last_check_success" field to the value that was provided on create.
|
|
func (u *ModelUpsertBulk) UpdateLastCheckSuccess() *ModelUpsertBulk {
|
|
return u.Update(func(s *ModelUpsert) {
|
|
s.UpdateLastCheckSuccess()
|
|
})
|
|
}
|
|
|
|
// ClearLastCheckSuccess clears the value of the "last_check_success" field.
|
|
func (u *ModelUpsertBulk) ClearLastCheckSuccess() *ModelUpsertBulk {
|
|
return u.Update(func(s *ModelUpsert) {
|
|
s.ClearLastCheckSuccess()
|
|
})
|
|
}
|
|
|
|
// SetLastCheckError sets the "last_check_error" field.
|
|
func (u *ModelUpsertBulk) SetLastCheckError(v string) *ModelUpsertBulk {
|
|
return u.Update(func(s *ModelUpsert) {
|
|
s.SetLastCheckError(v)
|
|
})
|
|
}
|
|
|
|
// UpdateLastCheckError sets the "last_check_error" field to the value that was provided on create.
|
|
func (u *ModelUpsertBulk) UpdateLastCheckError() *ModelUpsertBulk {
|
|
return u.Update(func(s *ModelUpsert) {
|
|
s.UpdateLastCheckError()
|
|
})
|
|
}
|
|
|
|
// ClearLastCheckError clears the value of the "last_check_error" field.
|
|
func (u *ModelUpsertBulk) ClearLastCheckError() *ModelUpsertBulk {
|
|
return u.Update(func(s *ModelUpsert) {
|
|
s.ClearLastCheckError()
|
|
})
|
|
}
|
|
|
|
// SetCreatedAt sets the "created_at" field.
|
|
func (u *ModelUpsertBulk) SetCreatedAt(v time.Time) *ModelUpsertBulk {
|
|
return u.Update(func(s *ModelUpsert) {
|
|
s.SetCreatedAt(v)
|
|
})
|
|
}
|
|
|
|
// UpdateCreatedAt sets the "created_at" field to the value that was provided on create.
|
|
func (u *ModelUpsertBulk) UpdateCreatedAt() *ModelUpsertBulk {
|
|
return u.Update(func(s *ModelUpsert) {
|
|
s.UpdateCreatedAt()
|
|
})
|
|
}
|
|
|
|
// SetUpdatedAt sets the "updated_at" field.
|
|
func (u *ModelUpsertBulk) SetUpdatedAt(v time.Time) *ModelUpsertBulk {
|
|
return u.Update(func(s *ModelUpsert) {
|
|
s.SetUpdatedAt(v)
|
|
})
|
|
}
|
|
|
|
// UpdateUpdatedAt sets the "updated_at" field to the value that was provided on create.
|
|
func (u *ModelUpsertBulk) UpdateUpdatedAt() *ModelUpsertBulk {
|
|
return u.Update(func(s *ModelUpsert) {
|
|
s.UpdateUpdatedAt()
|
|
})
|
|
}
|
|
|
|
// Exec executes the query.
|
|
func (u *ModelUpsertBulk) 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 ModelCreateBulk instead", i)
|
|
}
|
|
}
|
|
if len(u.create.conflict) == 0 {
|
|
return errors.New("db: missing options for ModelCreateBulk.OnConflict")
|
|
}
|
|
return u.create.Exec(ctx)
|
|
}
|
|
|
|
// ExecX is like Exec, but panics if an error occurs.
|
|
func (u *ModelUpsertBulk) ExecX(ctx context.Context) {
|
|
if err := u.create.Exec(ctx); err != nil {
|
|
panic(err)
|
|
}
|
|
}
|