Files
MonkeyCode/backend/db/taskmodelswitch_create.go

1246 lines
39 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/task"
"github.com/chaitin/MonkeyCode/backend/db/taskmodelswitch"
"github.com/chaitin/MonkeyCode/backend/db/user"
"github.com/google/uuid"
)
// TaskModelSwitchCreate is the builder for creating a TaskModelSwitch entity.
type TaskModelSwitchCreate struct {
config
mutation *TaskModelSwitchMutation
hooks []Hook
conflict []sql.ConflictOption
}
// SetTaskID sets the "task_id" field.
func (_c *TaskModelSwitchCreate) SetTaskID(v uuid.UUID) *TaskModelSwitchCreate {
_c.mutation.SetTaskID(v)
return _c
}
// SetUserID sets the "user_id" field.
func (_c *TaskModelSwitchCreate) SetUserID(v uuid.UUID) *TaskModelSwitchCreate {
_c.mutation.SetUserID(v)
return _c
}
// SetFromModelID sets the "from_model_id" field.
func (_c *TaskModelSwitchCreate) SetFromModelID(v uuid.UUID) *TaskModelSwitchCreate {
_c.mutation.SetFromModelID(v)
return _c
}
// SetNillableFromModelID sets the "from_model_id" field if the given value is not nil.
func (_c *TaskModelSwitchCreate) SetNillableFromModelID(v *uuid.UUID) *TaskModelSwitchCreate {
if v != nil {
_c.SetFromModelID(*v)
}
return _c
}
// SetToModelID sets the "to_model_id" field.
func (_c *TaskModelSwitchCreate) SetToModelID(v uuid.UUID) *TaskModelSwitchCreate {
_c.mutation.SetToModelID(v)
return _c
}
// SetRequestID sets the "request_id" field.
func (_c *TaskModelSwitchCreate) SetRequestID(v string) *TaskModelSwitchCreate {
_c.mutation.SetRequestID(v)
return _c
}
// SetNillableRequestID sets the "request_id" field if the given value is not nil.
func (_c *TaskModelSwitchCreate) SetNillableRequestID(v *string) *TaskModelSwitchCreate {
if v != nil {
_c.SetRequestID(*v)
}
return _c
}
// SetLoadSession sets the "load_session" field.
func (_c *TaskModelSwitchCreate) SetLoadSession(v bool) *TaskModelSwitchCreate {
_c.mutation.SetLoadSession(v)
return _c
}
// SetNillableLoadSession sets the "load_session" field if the given value is not nil.
func (_c *TaskModelSwitchCreate) SetNillableLoadSession(v *bool) *TaskModelSwitchCreate {
if v != nil {
_c.SetLoadSession(*v)
}
return _c
}
// SetSuccess sets the "success" field.
func (_c *TaskModelSwitchCreate) SetSuccess(v bool) *TaskModelSwitchCreate {
_c.mutation.SetSuccess(v)
return _c
}
// SetNillableSuccess sets the "success" field if the given value is not nil.
func (_c *TaskModelSwitchCreate) SetNillableSuccess(v *bool) *TaskModelSwitchCreate {
if v != nil {
_c.SetSuccess(*v)
}
return _c
}
// SetMessage sets the "message" field.
func (_c *TaskModelSwitchCreate) SetMessage(v string) *TaskModelSwitchCreate {
_c.mutation.SetMessage(v)
return _c
}
// SetNillableMessage sets the "message" field if the given value is not nil.
func (_c *TaskModelSwitchCreate) SetNillableMessage(v *string) *TaskModelSwitchCreate {
if v != nil {
_c.SetMessage(*v)
}
return _c
}
// SetSessionID sets the "session_id" field.
func (_c *TaskModelSwitchCreate) SetSessionID(v string) *TaskModelSwitchCreate {
_c.mutation.SetSessionID(v)
return _c
}
// SetNillableSessionID sets the "session_id" field if the given value is not nil.
func (_c *TaskModelSwitchCreate) SetNillableSessionID(v *string) *TaskModelSwitchCreate {
if v != nil {
_c.SetSessionID(*v)
}
return _c
}
// SetCreatedAt sets the "created_at" field.
func (_c *TaskModelSwitchCreate) SetCreatedAt(v time.Time) *TaskModelSwitchCreate {
_c.mutation.SetCreatedAt(v)
return _c
}
// SetNillableCreatedAt sets the "created_at" field if the given value is not nil.
func (_c *TaskModelSwitchCreate) SetNillableCreatedAt(v *time.Time) *TaskModelSwitchCreate {
if v != nil {
_c.SetCreatedAt(*v)
}
return _c
}
// SetUpdatedAt sets the "updated_at" field.
func (_c *TaskModelSwitchCreate) SetUpdatedAt(v time.Time) *TaskModelSwitchCreate {
_c.mutation.SetUpdatedAt(v)
return _c
}
// SetNillableUpdatedAt sets the "updated_at" field if the given value is not nil.
func (_c *TaskModelSwitchCreate) SetNillableUpdatedAt(v *time.Time) *TaskModelSwitchCreate {
if v != nil {
_c.SetUpdatedAt(*v)
}
return _c
}
// SetID sets the "id" field.
func (_c *TaskModelSwitchCreate) SetID(v uuid.UUID) *TaskModelSwitchCreate {
_c.mutation.SetID(v)
return _c
}
// SetNillableID sets the "id" field if the given value is not nil.
func (_c *TaskModelSwitchCreate) SetNillableID(v *uuid.UUID) *TaskModelSwitchCreate {
if v != nil {
_c.SetID(*v)
}
return _c
}
// SetTask sets the "task" edge to the Task entity.
func (_c *TaskModelSwitchCreate) SetTask(v *Task) *TaskModelSwitchCreate {
return _c.SetTaskID(v.ID)
}
// SetUser sets the "user" edge to the User entity.
func (_c *TaskModelSwitchCreate) SetUser(v *User) *TaskModelSwitchCreate {
return _c.SetUserID(v.ID)
}
// SetFromModel sets the "from_model" edge to the Model entity.
func (_c *TaskModelSwitchCreate) SetFromModel(v *Model) *TaskModelSwitchCreate {
return _c.SetFromModelID(v.ID)
}
// SetToModel sets the "to_model" edge to the Model entity.
func (_c *TaskModelSwitchCreate) SetToModel(v *Model) *TaskModelSwitchCreate {
return _c.SetToModelID(v.ID)
}
// Mutation returns the TaskModelSwitchMutation object of the builder.
func (_c *TaskModelSwitchCreate) Mutation() *TaskModelSwitchMutation {
return _c.mutation
}
// Save creates the TaskModelSwitch in the database.
func (_c *TaskModelSwitchCreate) Save(ctx context.Context) (*TaskModelSwitch, error) {
_c.defaults()
return withHooks(ctx, _c.sqlSave, _c.mutation, _c.hooks)
}
// SaveX calls Save and panics if Save returns an error.
func (_c *TaskModelSwitchCreate) SaveX(ctx context.Context) *TaskModelSwitch {
v, err := _c.Save(ctx)
if err != nil {
panic(err)
}
return v
}
// Exec executes the query.
func (_c *TaskModelSwitchCreate) Exec(ctx context.Context) error {
_, err := _c.Save(ctx)
return err
}
// ExecX is like Exec, but panics if an error occurs.
func (_c *TaskModelSwitchCreate) 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 *TaskModelSwitchCreate) defaults() {
if _, ok := _c.mutation.RequestID(); !ok {
v := taskmodelswitch.DefaultRequestID
_c.mutation.SetRequestID(v)
}
if _, ok := _c.mutation.LoadSession(); !ok {
v := taskmodelswitch.DefaultLoadSession
_c.mutation.SetLoadSession(v)
}
if _, ok := _c.mutation.Message(); !ok {
v := taskmodelswitch.DefaultMessage
_c.mutation.SetMessage(v)
}
if _, ok := _c.mutation.SessionID(); !ok {
v := taskmodelswitch.DefaultSessionID
_c.mutation.SetSessionID(v)
}
if _, ok := _c.mutation.CreatedAt(); !ok {
v := taskmodelswitch.DefaultCreatedAt()
_c.mutation.SetCreatedAt(v)
}
if _, ok := _c.mutation.UpdatedAt(); !ok {
v := taskmodelswitch.DefaultUpdatedAt()
_c.mutation.SetUpdatedAt(v)
}
if _, ok := _c.mutation.ID(); !ok {
v := taskmodelswitch.DefaultID()
_c.mutation.SetID(v)
}
}
// check runs all checks and user-defined validators on the builder.
func (_c *TaskModelSwitchCreate) check() error {
if _, ok := _c.mutation.TaskID(); !ok {
return &ValidationError{Name: "task_id", err: errors.New(`db: missing required field "TaskModelSwitch.task_id"`)}
}
if _, ok := _c.mutation.UserID(); !ok {
return &ValidationError{Name: "user_id", err: errors.New(`db: missing required field "TaskModelSwitch.user_id"`)}
}
if _, ok := _c.mutation.ToModelID(); !ok {
return &ValidationError{Name: "to_model_id", err: errors.New(`db: missing required field "TaskModelSwitch.to_model_id"`)}
}
if _, ok := _c.mutation.RequestID(); !ok {
return &ValidationError{Name: "request_id", err: errors.New(`db: missing required field "TaskModelSwitch.request_id"`)}
}
if _, ok := _c.mutation.LoadSession(); !ok {
return &ValidationError{Name: "load_session", err: errors.New(`db: missing required field "TaskModelSwitch.load_session"`)}
}
if _, ok := _c.mutation.Message(); !ok {
return &ValidationError{Name: "message", err: errors.New(`db: missing required field "TaskModelSwitch.message"`)}
}
if _, ok := _c.mutation.SessionID(); !ok {
return &ValidationError{Name: "session_id", err: errors.New(`db: missing required field "TaskModelSwitch.session_id"`)}
}
if _, ok := _c.mutation.CreatedAt(); !ok {
return &ValidationError{Name: "created_at", err: errors.New(`db: missing required field "TaskModelSwitch.created_at"`)}
}
if _, ok := _c.mutation.UpdatedAt(); !ok {
return &ValidationError{Name: "updated_at", err: errors.New(`db: missing required field "TaskModelSwitch.updated_at"`)}
}
if len(_c.mutation.TaskIDs()) == 0 {
return &ValidationError{Name: "task", err: errors.New(`db: missing required edge "TaskModelSwitch.task"`)}
}
if len(_c.mutation.UserIDs()) == 0 {
return &ValidationError{Name: "user", err: errors.New(`db: missing required edge "TaskModelSwitch.user"`)}
}
if len(_c.mutation.ToModelIDs()) == 0 {
return &ValidationError{Name: "to_model", err: errors.New(`db: missing required edge "TaskModelSwitch.to_model"`)}
}
return nil
}
func (_c *TaskModelSwitchCreate) sqlSave(ctx context.Context) (*TaskModelSwitch, 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 *TaskModelSwitchCreate) createSpec() (*TaskModelSwitch, *sqlgraph.CreateSpec) {
var (
_node = &TaskModelSwitch{config: _c.config}
_spec = sqlgraph.NewCreateSpec(taskmodelswitch.Table, sqlgraph.NewFieldSpec(taskmodelswitch.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.RequestID(); ok {
_spec.SetField(taskmodelswitch.FieldRequestID, field.TypeString, value)
_node.RequestID = value
}
if value, ok := _c.mutation.LoadSession(); ok {
_spec.SetField(taskmodelswitch.FieldLoadSession, field.TypeBool, value)
_node.LoadSession = value
}
if value, ok := _c.mutation.Success(); ok {
_spec.SetField(taskmodelswitch.FieldSuccess, field.TypeBool, value)
_node.Success = &value
}
if value, ok := _c.mutation.Message(); ok {
_spec.SetField(taskmodelswitch.FieldMessage, field.TypeString, value)
_node.Message = value
}
if value, ok := _c.mutation.SessionID(); ok {
_spec.SetField(taskmodelswitch.FieldSessionID, field.TypeString, value)
_node.SessionID = value
}
if value, ok := _c.mutation.CreatedAt(); ok {
_spec.SetField(taskmodelswitch.FieldCreatedAt, field.TypeTime, value)
_node.CreatedAt = value
}
if value, ok := _c.mutation.UpdatedAt(); ok {
_spec.SetField(taskmodelswitch.FieldUpdatedAt, field.TypeTime, value)
_node.UpdatedAt = value
}
if nodes := _c.mutation.TaskIDs(); len(nodes) > 0 {
edge := &sqlgraph.EdgeSpec{
Rel: sqlgraph.M2O,
Inverse: true,
Table: taskmodelswitch.TaskTable,
Columns: []string{taskmodelswitch.TaskColumn},
Bidi: false,
Target: &sqlgraph.EdgeTarget{
IDSpec: sqlgraph.NewFieldSpec(task.FieldID, field.TypeUUID),
},
}
for _, k := range nodes {
edge.Target.Nodes = append(edge.Target.Nodes, k)
}
_node.TaskID = nodes[0]
_spec.Edges = append(_spec.Edges, edge)
}
if nodes := _c.mutation.UserIDs(); len(nodes) > 0 {
edge := &sqlgraph.EdgeSpec{
Rel: sqlgraph.M2O,
Inverse: true,
Table: taskmodelswitch.UserTable,
Columns: []string{taskmodelswitch.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.FromModelIDs(); len(nodes) > 0 {
edge := &sqlgraph.EdgeSpec{
Rel: sqlgraph.M2O,
Inverse: true,
Table: taskmodelswitch.FromModelTable,
Columns: []string{taskmodelswitch.FromModelColumn},
Bidi: false,
Target: &sqlgraph.EdgeTarget{
IDSpec: sqlgraph.NewFieldSpec(model.FieldID, field.TypeUUID),
},
}
for _, k := range nodes {
edge.Target.Nodes = append(edge.Target.Nodes, k)
}
_node.FromModelID = &nodes[0]
_spec.Edges = append(_spec.Edges, edge)
}
if nodes := _c.mutation.ToModelIDs(); len(nodes) > 0 {
edge := &sqlgraph.EdgeSpec{
Rel: sqlgraph.M2O,
Inverse: true,
Table: taskmodelswitch.ToModelTable,
Columns: []string{taskmodelswitch.ToModelColumn},
Bidi: false,
Target: &sqlgraph.EdgeTarget{
IDSpec: sqlgraph.NewFieldSpec(model.FieldID, field.TypeUUID),
},
}
for _, k := range nodes {
edge.Target.Nodes = append(edge.Target.Nodes, k)
}
_node.ToModelID = 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.TaskModelSwitch.Create().
// SetTaskID(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.TaskModelSwitchUpsert) {
// SetTaskID(v+v).
// }).
// Exec(ctx)
func (_c *TaskModelSwitchCreate) OnConflict(opts ...sql.ConflictOption) *TaskModelSwitchUpsertOne {
_c.conflict = opts
return &TaskModelSwitchUpsertOne{
create: _c,
}
}
// OnConflictColumns calls `OnConflict` and configures the columns
// as conflict target. Using this option is equivalent to using:
//
// client.TaskModelSwitch.Create().
// OnConflict(sql.ConflictColumns(columns...)).
// Exec(ctx)
func (_c *TaskModelSwitchCreate) OnConflictColumns(columns ...string) *TaskModelSwitchUpsertOne {
_c.conflict = append(_c.conflict, sql.ConflictColumns(columns...))
return &TaskModelSwitchUpsertOne{
create: _c,
}
}
type (
// TaskModelSwitchUpsertOne is the builder for "upsert"-ing
// one TaskModelSwitch node.
TaskModelSwitchUpsertOne struct {
create *TaskModelSwitchCreate
}
// TaskModelSwitchUpsert is the "OnConflict" setter.
TaskModelSwitchUpsert struct {
*sql.UpdateSet
}
)
// SetTaskID sets the "task_id" field.
func (u *TaskModelSwitchUpsert) SetTaskID(v uuid.UUID) *TaskModelSwitchUpsert {
u.Set(taskmodelswitch.FieldTaskID, v)
return u
}
// UpdateTaskID sets the "task_id" field to the value that was provided on create.
func (u *TaskModelSwitchUpsert) UpdateTaskID() *TaskModelSwitchUpsert {
u.SetExcluded(taskmodelswitch.FieldTaskID)
return u
}
// SetUserID sets the "user_id" field.
func (u *TaskModelSwitchUpsert) SetUserID(v uuid.UUID) *TaskModelSwitchUpsert {
u.Set(taskmodelswitch.FieldUserID, v)
return u
}
// UpdateUserID sets the "user_id" field to the value that was provided on create.
func (u *TaskModelSwitchUpsert) UpdateUserID() *TaskModelSwitchUpsert {
u.SetExcluded(taskmodelswitch.FieldUserID)
return u
}
// SetFromModelID sets the "from_model_id" field.
func (u *TaskModelSwitchUpsert) SetFromModelID(v uuid.UUID) *TaskModelSwitchUpsert {
u.Set(taskmodelswitch.FieldFromModelID, v)
return u
}
// UpdateFromModelID sets the "from_model_id" field to the value that was provided on create.
func (u *TaskModelSwitchUpsert) UpdateFromModelID() *TaskModelSwitchUpsert {
u.SetExcluded(taskmodelswitch.FieldFromModelID)
return u
}
// ClearFromModelID clears the value of the "from_model_id" field.
func (u *TaskModelSwitchUpsert) ClearFromModelID() *TaskModelSwitchUpsert {
u.SetNull(taskmodelswitch.FieldFromModelID)
return u
}
// SetToModelID sets the "to_model_id" field.
func (u *TaskModelSwitchUpsert) SetToModelID(v uuid.UUID) *TaskModelSwitchUpsert {
u.Set(taskmodelswitch.FieldToModelID, v)
return u
}
// UpdateToModelID sets the "to_model_id" field to the value that was provided on create.
func (u *TaskModelSwitchUpsert) UpdateToModelID() *TaskModelSwitchUpsert {
u.SetExcluded(taskmodelswitch.FieldToModelID)
return u
}
// SetRequestID sets the "request_id" field.
func (u *TaskModelSwitchUpsert) SetRequestID(v string) *TaskModelSwitchUpsert {
u.Set(taskmodelswitch.FieldRequestID, v)
return u
}
// UpdateRequestID sets the "request_id" field to the value that was provided on create.
func (u *TaskModelSwitchUpsert) UpdateRequestID() *TaskModelSwitchUpsert {
u.SetExcluded(taskmodelswitch.FieldRequestID)
return u
}
// SetLoadSession sets the "load_session" field.
func (u *TaskModelSwitchUpsert) SetLoadSession(v bool) *TaskModelSwitchUpsert {
u.Set(taskmodelswitch.FieldLoadSession, v)
return u
}
// UpdateLoadSession sets the "load_session" field to the value that was provided on create.
func (u *TaskModelSwitchUpsert) UpdateLoadSession() *TaskModelSwitchUpsert {
u.SetExcluded(taskmodelswitch.FieldLoadSession)
return u
}
// SetSuccess sets the "success" field.
func (u *TaskModelSwitchUpsert) SetSuccess(v bool) *TaskModelSwitchUpsert {
u.Set(taskmodelswitch.FieldSuccess, v)
return u
}
// UpdateSuccess sets the "success" field to the value that was provided on create.
func (u *TaskModelSwitchUpsert) UpdateSuccess() *TaskModelSwitchUpsert {
u.SetExcluded(taskmodelswitch.FieldSuccess)
return u
}
// ClearSuccess clears the value of the "success" field.
func (u *TaskModelSwitchUpsert) ClearSuccess() *TaskModelSwitchUpsert {
u.SetNull(taskmodelswitch.FieldSuccess)
return u
}
// SetMessage sets the "message" field.
func (u *TaskModelSwitchUpsert) SetMessage(v string) *TaskModelSwitchUpsert {
u.Set(taskmodelswitch.FieldMessage, v)
return u
}
// UpdateMessage sets the "message" field to the value that was provided on create.
func (u *TaskModelSwitchUpsert) UpdateMessage() *TaskModelSwitchUpsert {
u.SetExcluded(taskmodelswitch.FieldMessage)
return u
}
// SetSessionID sets the "session_id" field.
func (u *TaskModelSwitchUpsert) SetSessionID(v string) *TaskModelSwitchUpsert {
u.Set(taskmodelswitch.FieldSessionID, v)
return u
}
// UpdateSessionID sets the "session_id" field to the value that was provided on create.
func (u *TaskModelSwitchUpsert) UpdateSessionID() *TaskModelSwitchUpsert {
u.SetExcluded(taskmodelswitch.FieldSessionID)
return u
}
// SetCreatedAt sets the "created_at" field.
func (u *TaskModelSwitchUpsert) SetCreatedAt(v time.Time) *TaskModelSwitchUpsert {
u.Set(taskmodelswitch.FieldCreatedAt, v)
return u
}
// UpdateCreatedAt sets the "created_at" field to the value that was provided on create.
func (u *TaskModelSwitchUpsert) UpdateCreatedAt() *TaskModelSwitchUpsert {
u.SetExcluded(taskmodelswitch.FieldCreatedAt)
return u
}
// SetUpdatedAt sets the "updated_at" field.
func (u *TaskModelSwitchUpsert) SetUpdatedAt(v time.Time) *TaskModelSwitchUpsert {
u.Set(taskmodelswitch.FieldUpdatedAt, v)
return u
}
// UpdateUpdatedAt sets the "updated_at" field to the value that was provided on create.
func (u *TaskModelSwitchUpsert) UpdateUpdatedAt() *TaskModelSwitchUpsert {
u.SetExcluded(taskmodelswitch.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.TaskModelSwitch.Create().
// OnConflict(
// sql.ResolveWithNewValues(),
// sql.ResolveWith(func(u *sql.UpdateSet) {
// u.SetIgnore(taskmodelswitch.FieldID)
// }),
// ).
// Exec(ctx)
func (u *TaskModelSwitchUpsertOne) UpdateNewValues() *TaskModelSwitchUpsertOne {
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(taskmodelswitch.FieldID)
}
}))
return u
}
// Ignore sets each column to itself in case of conflict.
// Using this option is equivalent to using:
//
// client.TaskModelSwitch.Create().
// OnConflict(sql.ResolveWithIgnore()).
// Exec(ctx)
func (u *TaskModelSwitchUpsertOne) Ignore() *TaskModelSwitchUpsertOne {
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 *TaskModelSwitchUpsertOne) DoNothing() *TaskModelSwitchUpsertOne {
u.create.conflict = append(u.create.conflict, sql.DoNothing())
return u
}
// Update allows overriding fields `UPDATE` values. See the TaskModelSwitchCreate.OnConflict
// documentation for more info.
func (u *TaskModelSwitchUpsertOne) Update(set func(*TaskModelSwitchUpsert)) *TaskModelSwitchUpsertOne {
u.create.conflict = append(u.create.conflict, sql.ResolveWith(func(update *sql.UpdateSet) {
set(&TaskModelSwitchUpsert{UpdateSet: update})
}))
return u
}
// SetTaskID sets the "task_id" field.
func (u *TaskModelSwitchUpsertOne) SetTaskID(v uuid.UUID) *TaskModelSwitchUpsertOne {
return u.Update(func(s *TaskModelSwitchUpsert) {
s.SetTaskID(v)
})
}
// UpdateTaskID sets the "task_id" field to the value that was provided on create.
func (u *TaskModelSwitchUpsertOne) UpdateTaskID() *TaskModelSwitchUpsertOne {
return u.Update(func(s *TaskModelSwitchUpsert) {
s.UpdateTaskID()
})
}
// SetUserID sets the "user_id" field.
func (u *TaskModelSwitchUpsertOne) SetUserID(v uuid.UUID) *TaskModelSwitchUpsertOne {
return u.Update(func(s *TaskModelSwitchUpsert) {
s.SetUserID(v)
})
}
// UpdateUserID sets the "user_id" field to the value that was provided on create.
func (u *TaskModelSwitchUpsertOne) UpdateUserID() *TaskModelSwitchUpsertOne {
return u.Update(func(s *TaskModelSwitchUpsert) {
s.UpdateUserID()
})
}
// SetFromModelID sets the "from_model_id" field.
func (u *TaskModelSwitchUpsertOne) SetFromModelID(v uuid.UUID) *TaskModelSwitchUpsertOne {
return u.Update(func(s *TaskModelSwitchUpsert) {
s.SetFromModelID(v)
})
}
// UpdateFromModelID sets the "from_model_id" field to the value that was provided on create.
func (u *TaskModelSwitchUpsertOne) UpdateFromModelID() *TaskModelSwitchUpsertOne {
return u.Update(func(s *TaskModelSwitchUpsert) {
s.UpdateFromModelID()
})
}
// ClearFromModelID clears the value of the "from_model_id" field.
func (u *TaskModelSwitchUpsertOne) ClearFromModelID() *TaskModelSwitchUpsertOne {
return u.Update(func(s *TaskModelSwitchUpsert) {
s.ClearFromModelID()
})
}
// SetToModelID sets the "to_model_id" field.
func (u *TaskModelSwitchUpsertOne) SetToModelID(v uuid.UUID) *TaskModelSwitchUpsertOne {
return u.Update(func(s *TaskModelSwitchUpsert) {
s.SetToModelID(v)
})
}
// UpdateToModelID sets the "to_model_id" field to the value that was provided on create.
func (u *TaskModelSwitchUpsertOne) UpdateToModelID() *TaskModelSwitchUpsertOne {
return u.Update(func(s *TaskModelSwitchUpsert) {
s.UpdateToModelID()
})
}
// SetRequestID sets the "request_id" field.
func (u *TaskModelSwitchUpsertOne) SetRequestID(v string) *TaskModelSwitchUpsertOne {
return u.Update(func(s *TaskModelSwitchUpsert) {
s.SetRequestID(v)
})
}
// UpdateRequestID sets the "request_id" field to the value that was provided on create.
func (u *TaskModelSwitchUpsertOne) UpdateRequestID() *TaskModelSwitchUpsertOne {
return u.Update(func(s *TaskModelSwitchUpsert) {
s.UpdateRequestID()
})
}
// SetLoadSession sets the "load_session" field.
func (u *TaskModelSwitchUpsertOne) SetLoadSession(v bool) *TaskModelSwitchUpsertOne {
return u.Update(func(s *TaskModelSwitchUpsert) {
s.SetLoadSession(v)
})
}
// UpdateLoadSession sets the "load_session" field to the value that was provided on create.
func (u *TaskModelSwitchUpsertOne) UpdateLoadSession() *TaskModelSwitchUpsertOne {
return u.Update(func(s *TaskModelSwitchUpsert) {
s.UpdateLoadSession()
})
}
// SetSuccess sets the "success" field.
func (u *TaskModelSwitchUpsertOne) SetSuccess(v bool) *TaskModelSwitchUpsertOne {
return u.Update(func(s *TaskModelSwitchUpsert) {
s.SetSuccess(v)
})
}
// UpdateSuccess sets the "success" field to the value that was provided on create.
func (u *TaskModelSwitchUpsertOne) UpdateSuccess() *TaskModelSwitchUpsertOne {
return u.Update(func(s *TaskModelSwitchUpsert) {
s.UpdateSuccess()
})
}
// ClearSuccess clears the value of the "success" field.
func (u *TaskModelSwitchUpsertOne) ClearSuccess() *TaskModelSwitchUpsertOne {
return u.Update(func(s *TaskModelSwitchUpsert) {
s.ClearSuccess()
})
}
// SetMessage sets the "message" field.
func (u *TaskModelSwitchUpsertOne) SetMessage(v string) *TaskModelSwitchUpsertOne {
return u.Update(func(s *TaskModelSwitchUpsert) {
s.SetMessage(v)
})
}
// UpdateMessage sets the "message" field to the value that was provided on create.
func (u *TaskModelSwitchUpsertOne) UpdateMessage() *TaskModelSwitchUpsertOne {
return u.Update(func(s *TaskModelSwitchUpsert) {
s.UpdateMessage()
})
}
// SetSessionID sets the "session_id" field.
func (u *TaskModelSwitchUpsertOne) SetSessionID(v string) *TaskModelSwitchUpsertOne {
return u.Update(func(s *TaskModelSwitchUpsert) {
s.SetSessionID(v)
})
}
// UpdateSessionID sets the "session_id" field to the value that was provided on create.
func (u *TaskModelSwitchUpsertOne) UpdateSessionID() *TaskModelSwitchUpsertOne {
return u.Update(func(s *TaskModelSwitchUpsert) {
s.UpdateSessionID()
})
}
// SetCreatedAt sets the "created_at" field.
func (u *TaskModelSwitchUpsertOne) SetCreatedAt(v time.Time) *TaskModelSwitchUpsertOne {
return u.Update(func(s *TaskModelSwitchUpsert) {
s.SetCreatedAt(v)
})
}
// UpdateCreatedAt sets the "created_at" field to the value that was provided on create.
func (u *TaskModelSwitchUpsertOne) UpdateCreatedAt() *TaskModelSwitchUpsertOne {
return u.Update(func(s *TaskModelSwitchUpsert) {
s.UpdateCreatedAt()
})
}
// SetUpdatedAt sets the "updated_at" field.
func (u *TaskModelSwitchUpsertOne) SetUpdatedAt(v time.Time) *TaskModelSwitchUpsertOne {
return u.Update(func(s *TaskModelSwitchUpsert) {
s.SetUpdatedAt(v)
})
}
// UpdateUpdatedAt sets the "updated_at" field to the value that was provided on create.
func (u *TaskModelSwitchUpsertOne) UpdateUpdatedAt() *TaskModelSwitchUpsertOne {
return u.Update(func(s *TaskModelSwitchUpsert) {
s.UpdateUpdatedAt()
})
}
// Exec executes the query.
func (u *TaskModelSwitchUpsertOne) Exec(ctx context.Context) error {
if len(u.create.conflict) == 0 {
return errors.New("db: missing options for TaskModelSwitchCreate.OnConflict")
}
return u.create.Exec(ctx)
}
// ExecX is like Exec, but panics if an error occurs.
func (u *TaskModelSwitchUpsertOne) 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 *TaskModelSwitchUpsertOne) 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: TaskModelSwitchUpsertOne.ID is not supported by MySQL driver. Use TaskModelSwitchUpsertOne.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 *TaskModelSwitchUpsertOne) IDX(ctx context.Context) uuid.UUID {
id, err := u.ID(ctx)
if err != nil {
panic(err)
}
return id
}
// TaskModelSwitchCreateBulk is the builder for creating many TaskModelSwitch entities in bulk.
type TaskModelSwitchCreateBulk struct {
config
err error
builders []*TaskModelSwitchCreate
conflict []sql.ConflictOption
}
// Save creates the TaskModelSwitch entities in the database.
func (_c *TaskModelSwitchCreateBulk) Save(ctx context.Context) ([]*TaskModelSwitch, error) {
if _c.err != nil {
return nil, _c.err
}
specs := make([]*sqlgraph.CreateSpec, len(_c.builders))
nodes := make([]*TaskModelSwitch, 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.(*TaskModelSwitchMutation)
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 *TaskModelSwitchCreateBulk) SaveX(ctx context.Context) []*TaskModelSwitch {
v, err := _c.Save(ctx)
if err != nil {
panic(err)
}
return v
}
// Exec executes the query.
func (_c *TaskModelSwitchCreateBulk) Exec(ctx context.Context) error {
_, err := _c.Save(ctx)
return err
}
// ExecX is like Exec, but panics if an error occurs.
func (_c *TaskModelSwitchCreateBulk) 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.TaskModelSwitch.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.TaskModelSwitchUpsert) {
// SetTaskID(v+v).
// }).
// Exec(ctx)
func (_c *TaskModelSwitchCreateBulk) OnConflict(opts ...sql.ConflictOption) *TaskModelSwitchUpsertBulk {
_c.conflict = opts
return &TaskModelSwitchUpsertBulk{
create: _c,
}
}
// OnConflictColumns calls `OnConflict` and configures the columns
// as conflict target. Using this option is equivalent to using:
//
// client.TaskModelSwitch.Create().
// OnConflict(sql.ConflictColumns(columns...)).
// Exec(ctx)
func (_c *TaskModelSwitchCreateBulk) OnConflictColumns(columns ...string) *TaskModelSwitchUpsertBulk {
_c.conflict = append(_c.conflict, sql.ConflictColumns(columns...))
return &TaskModelSwitchUpsertBulk{
create: _c,
}
}
// TaskModelSwitchUpsertBulk is the builder for "upsert"-ing
// a bulk of TaskModelSwitch nodes.
type TaskModelSwitchUpsertBulk struct {
create *TaskModelSwitchCreateBulk
}
// UpdateNewValues updates the mutable fields using the new values that
// were set on create. Using this option is equivalent to using:
//
// client.TaskModelSwitch.Create().
// OnConflict(
// sql.ResolveWithNewValues(),
// sql.ResolveWith(func(u *sql.UpdateSet) {
// u.SetIgnore(taskmodelswitch.FieldID)
// }),
// ).
// Exec(ctx)
func (u *TaskModelSwitchUpsertBulk) UpdateNewValues() *TaskModelSwitchUpsertBulk {
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(taskmodelswitch.FieldID)
}
}
}))
return u
}
// Ignore sets each column to itself in case of conflict.
// Using this option is equivalent to using:
//
// client.TaskModelSwitch.Create().
// OnConflict(sql.ResolveWithIgnore()).
// Exec(ctx)
func (u *TaskModelSwitchUpsertBulk) Ignore() *TaskModelSwitchUpsertBulk {
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 *TaskModelSwitchUpsertBulk) DoNothing() *TaskModelSwitchUpsertBulk {
u.create.conflict = append(u.create.conflict, sql.DoNothing())
return u
}
// Update allows overriding fields `UPDATE` values. See the TaskModelSwitchCreateBulk.OnConflict
// documentation for more info.
func (u *TaskModelSwitchUpsertBulk) Update(set func(*TaskModelSwitchUpsert)) *TaskModelSwitchUpsertBulk {
u.create.conflict = append(u.create.conflict, sql.ResolveWith(func(update *sql.UpdateSet) {
set(&TaskModelSwitchUpsert{UpdateSet: update})
}))
return u
}
// SetTaskID sets the "task_id" field.
func (u *TaskModelSwitchUpsertBulk) SetTaskID(v uuid.UUID) *TaskModelSwitchUpsertBulk {
return u.Update(func(s *TaskModelSwitchUpsert) {
s.SetTaskID(v)
})
}
// UpdateTaskID sets the "task_id" field to the value that was provided on create.
func (u *TaskModelSwitchUpsertBulk) UpdateTaskID() *TaskModelSwitchUpsertBulk {
return u.Update(func(s *TaskModelSwitchUpsert) {
s.UpdateTaskID()
})
}
// SetUserID sets the "user_id" field.
func (u *TaskModelSwitchUpsertBulk) SetUserID(v uuid.UUID) *TaskModelSwitchUpsertBulk {
return u.Update(func(s *TaskModelSwitchUpsert) {
s.SetUserID(v)
})
}
// UpdateUserID sets the "user_id" field to the value that was provided on create.
func (u *TaskModelSwitchUpsertBulk) UpdateUserID() *TaskModelSwitchUpsertBulk {
return u.Update(func(s *TaskModelSwitchUpsert) {
s.UpdateUserID()
})
}
// SetFromModelID sets the "from_model_id" field.
func (u *TaskModelSwitchUpsertBulk) SetFromModelID(v uuid.UUID) *TaskModelSwitchUpsertBulk {
return u.Update(func(s *TaskModelSwitchUpsert) {
s.SetFromModelID(v)
})
}
// UpdateFromModelID sets the "from_model_id" field to the value that was provided on create.
func (u *TaskModelSwitchUpsertBulk) UpdateFromModelID() *TaskModelSwitchUpsertBulk {
return u.Update(func(s *TaskModelSwitchUpsert) {
s.UpdateFromModelID()
})
}
// ClearFromModelID clears the value of the "from_model_id" field.
func (u *TaskModelSwitchUpsertBulk) ClearFromModelID() *TaskModelSwitchUpsertBulk {
return u.Update(func(s *TaskModelSwitchUpsert) {
s.ClearFromModelID()
})
}
// SetToModelID sets the "to_model_id" field.
func (u *TaskModelSwitchUpsertBulk) SetToModelID(v uuid.UUID) *TaskModelSwitchUpsertBulk {
return u.Update(func(s *TaskModelSwitchUpsert) {
s.SetToModelID(v)
})
}
// UpdateToModelID sets the "to_model_id" field to the value that was provided on create.
func (u *TaskModelSwitchUpsertBulk) UpdateToModelID() *TaskModelSwitchUpsertBulk {
return u.Update(func(s *TaskModelSwitchUpsert) {
s.UpdateToModelID()
})
}
// SetRequestID sets the "request_id" field.
func (u *TaskModelSwitchUpsertBulk) SetRequestID(v string) *TaskModelSwitchUpsertBulk {
return u.Update(func(s *TaskModelSwitchUpsert) {
s.SetRequestID(v)
})
}
// UpdateRequestID sets the "request_id" field to the value that was provided on create.
func (u *TaskModelSwitchUpsertBulk) UpdateRequestID() *TaskModelSwitchUpsertBulk {
return u.Update(func(s *TaskModelSwitchUpsert) {
s.UpdateRequestID()
})
}
// SetLoadSession sets the "load_session" field.
func (u *TaskModelSwitchUpsertBulk) SetLoadSession(v bool) *TaskModelSwitchUpsertBulk {
return u.Update(func(s *TaskModelSwitchUpsert) {
s.SetLoadSession(v)
})
}
// UpdateLoadSession sets the "load_session" field to the value that was provided on create.
func (u *TaskModelSwitchUpsertBulk) UpdateLoadSession() *TaskModelSwitchUpsertBulk {
return u.Update(func(s *TaskModelSwitchUpsert) {
s.UpdateLoadSession()
})
}
// SetSuccess sets the "success" field.
func (u *TaskModelSwitchUpsertBulk) SetSuccess(v bool) *TaskModelSwitchUpsertBulk {
return u.Update(func(s *TaskModelSwitchUpsert) {
s.SetSuccess(v)
})
}
// UpdateSuccess sets the "success" field to the value that was provided on create.
func (u *TaskModelSwitchUpsertBulk) UpdateSuccess() *TaskModelSwitchUpsertBulk {
return u.Update(func(s *TaskModelSwitchUpsert) {
s.UpdateSuccess()
})
}
// ClearSuccess clears the value of the "success" field.
func (u *TaskModelSwitchUpsertBulk) ClearSuccess() *TaskModelSwitchUpsertBulk {
return u.Update(func(s *TaskModelSwitchUpsert) {
s.ClearSuccess()
})
}
// SetMessage sets the "message" field.
func (u *TaskModelSwitchUpsertBulk) SetMessage(v string) *TaskModelSwitchUpsertBulk {
return u.Update(func(s *TaskModelSwitchUpsert) {
s.SetMessage(v)
})
}
// UpdateMessage sets the "message" field to the value that was provided on create.
func (u *TaskModelSwitchUpsertBulk) UpdateMessage() *TaskModelSwitchUpsertBulk {
return u.Update(func(s *TaskModelSwitchUpsert) {
s.UpdateMessage()
})
}
// SetSessionID sets the "session_id" field.
func (u *TaskModelSwitchUpsertBulk) SetSessionID(v string) *TaskModelSwitchUpsertBulk {
return u.Update(func(s *TaskModelSwitchUpsert) {
s.SetSessionID(v)
})
}
// UpdateSessionID sets the "session_id" field to the value that was provided on create.
func (u *TaskModelSwitchUpsertBulk) UpdateSessionID() *TaskModelSwitchUpsertBulk {
return u.Update(func(s *TaskModelSwitchUpsert) {
s.UpdateSessionID()
})
}
// SetCreatedAt sets the "created_at" field.
func (u *TaskModelSwitchUpsertBulk) SetCreatedAt(v time.Time) *TaskModelSwitchUpsertBulk {
return u.Update(func(s *TaskModelSwitchUpsert) {
s.SetCreatedAt(v)
})
}
// UpdateCreatedAt sets the "created_at" field to the value that was provided on create.
func (u *TaskModelSwitchUpsertBulk) UpdateCreatedAt() *TaskModelSwitchUpsertBulk {
return u.Update(func(s *TaskModelSwitchUpsert) {
s.UpdateCreatedAt()
})
}
// SetUpdatedAt sets the "updated_at" field.
func (u *TaskModelSwitchUpsertBulk) SetUpdatedAt(v time.Time) *TaskModelSwitchUpsertBulk {
return u.Update(func(s *TaskModelSwitchUpsert) {
s.SetUpdatedAt(v)
})
}
// UpdateUpdatedAt sets the "updated_at" field to the value that was provided on create.
func (u *TaskModelSwitchUpsertBulk) UpdateUpdatedAt() *TaskModelSwitchUpsertBulk {
return u.Update(func(s *TaskModelSwitchUpsert) {
s.UpdateUpdatedAt()
})
}
// Exec executes the query.
func (u *TaskModelSwitchUpsertBulk) 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 TaskModelSwitchCreateBulk instead", i)
}
}
if len(u.create.conflict) == 0 {
return errors.New("db: missing options for TaskModelSwitchCreateBulk.OnConflict")
}
return u.create.Exec(ctx)
}
// ExecX is like Exec, but panics if an error occurs.
func (u *TaskModelSwitchUpsertBulk) ExecX(ctx context.Context) {
if err := u.create.Exec(ctx); err != nil {
panic(err)
}
}