mirror of
https://github.com/chaitin/MonkeyCode.git
synced 2026-02-03 15:23:30 +08:00
1015 lines
29 KiB
Go
1015 lines
29 KiB
Go
// Code generated by ent, DO NOT EDIT.
|
|
|
|
package db
|
|
|
|
import (
|
|
"context"
|
|
"errors"
|
|
"fmt"
|
|
"time"
|
|
|
|
"entgo.io/ent/dialect/sql"
|
|
"entgo.io/ent/dialect/sql/sqlgraph"
|
|
"entgo.io/ent/schema/field"
|
|
"github.com/chaitin/MonkeyCode/backend/consts"
|
|
"github.com/chaitin/MonkeyCode/backend/db/model"
|
|
"github.com/chaitin/MonkeyCode/backend/db/predicate"
|
|
"github.com/chaitin/MonkeyCode/backend/db/record"
|
|
"github.com/chaitin/MonkeyCode/backend/db/user"
|
|
"github.com/google/uuid"
|
|
)
|
|
|
|
// RecordUpdate is the builder for updating Record entities.
|
|
type RecordUpdate struct {
|
|
config
|
|
hooks []Hook
|
|
mutation *RecordMutation
|
|
modifiers []func(*sql.UpdateBuilder)
|
|
}
|
|
|
|
// Where appends a list predicates to the RecordUpdate builder.
|
|
func (ru *RecordUpdate) Where(ps ...predicate.Record) *RecordUpdate {
|
|
ru.mutation.Where(ps...)
|
|
return ru
|
|
}
|
|
|
|
// SetUserID sets the "user_id" field.
|
|
func (ru *RecordUpdate) SetUserID(u uuid.UUID) *RecordUpdate {
|
|
ru.mutation.SetUserID(u)
|
|
return ru
|
|
}
|
|
|
|
// SetNillableUserID sets the "user_id" field if the given value is not nil.
|
|
func (ru *RecordUpdate) SetNillableUserID(u *uuid.UUID) *RecordUpdate {
|
|
if u != nil {
|
|
ru.SetUserID(*u)
|
|
}
|
|
return ru
|
|
}
|
|
|
|
// ClearUserID clears the value of the "user_id" field.
|
|
func (ru *RecordUpdate) ClearUserID() *RecordUpdate {
|
|
ru.mutation.ClearUserID()
|
|
return ru
|
|
}
|
|
|
|
// SetModelID sets the "model_id" field.
|
|
func (ru *RecordUpdate) SetModelID(u uuid.UUID) *RecordUpdate {
|
|
ru.mutation.SetModelID(u)
|
|
return ru
|
|
}
|
|
|
|
// SetNillableModelID sets the "model_id" field if the given value is not nil.
|
|
func (ru *RecordUpdate) SetNillableModelID(u *uuid.UUID) *RecordUpdate {
|
|
if u != nil {
|
|
ru.SetModelID(*u)
|
|
}
|
|
return ru
|
|
}
|
|
|
|
// ClearModelID clears the value of the "model_id" field.
|
|
func (ru *RecordUpdate) ClearModelID() *RecordUpdate {
|
|
ru.mutation.ClearModelID()
|
|
return ru
|
|
}
|
|
|
|
// SetTaskID sets the "task_id" field.
|
|
func (ru *RecordUpdate) SetTaskID(s string) *RecordUpdate {
|
|
ru.mutation.SetTaskID(s)
|
|
return ru
|
|
}
|
|
|
|
// SetNillableTaskID sets the "task_id" field if the given value is not nil.
|
|
func (ru *RecordUpdate) SetNillableTaskID(s *string) *RecordUpdate {
|
|
if s != nil {
|
|
ru.SetTaskID(*s)
|
|
}
|
|
return ru
|
|
}
|
|
|
|
// SetModelType sets the "model_type" field.
|
|
func (ru *RecordUpdate) SetModelType(ct consts.ModelType) *RecordUpdate {
|
|
ru.mutation.SetModelType(ct)
|
|
return ru
|
|
}
|
|
|
|
// SetNillableModelType sets the "model_type" field if the given value is not nil.
|
|
func (ru *RecordUpdate) SetNillableModelType(ct *consts.ModelType) *RecordUpdate {
|
|
if ct != nil {
|
|
ru.SetModelType(*ct)
|
|
}
|
|
return ru
|
|
}
|
|
|
|
// ClearModelType clears the value of the "model_type" field.
|
|
func (ru *RecordUpdate) ClearModelType() *RecordUpdate {
|
|
ru.mutation.ClearModelType()
|
|
return ru
|
|
}
|
|
|
|
// SetPrompt sets the "prompt" field.
|
|
func (ru *RecordUpdate) SetPrompt(s string) *RecordUpdate {
|
|
ru.mutation.SetPrompt(s)
|
|
return ru
|
|
}
|
|
|
|
// SetNillablePrompt sets the "prompt" field if the given value is not nil.
|
|
func (ru *RecordUpdate) SetNillablePrompt(s *string) *RecordUpdate {
|
|
if s != nil {
|
|
ru.SetPrompt(*s)
|
|
}
|
|
return ru
|
|
}
|
|
|
|
// ClearPrompt clears the value of the "prompt" field.
|
|
func (ru *RecordUpdate) ClearPrompt() *RecordUpdate {
|
|
ru.mutation.ClearPrompt()
|
|
return ru
|
|
}
|
|
|
|
// SetCompletion sets the "completion" field.
|
|
func (ru *RecordUpdate) SetCompletion(s string) *RecordUpdate {
|
|
ru.mutation.SetCompletion(s)
|
|
return ru
|
|
}
|
|
|
|
// SetNillableCompletion sets the "completion" field if the given value is not nil.
|
|
func (ru *RecordUpdate) SetNillableCompletion(s *string) *RecordUpdate {
|
|
if s != nil {
|
|
ru.SetCompletion(*s)
|
|
}
|
|
return ru
|
|
}
|
|
|
|
// ClearCompletion clears the value of the "completion" field.
|
|
func (ru *RecordUpdate) ClearCompletion() *RecordUpdate {
|
|
ru.mutation.ClearCompletion()
|
|
return ru
|
|
}
|
|
|
|
// SetIsAccept sets the "is_accept" field.
|
|
func (ru *RecordUpdate) SetIsAccept(b bool) *RecordUpdate {
|
|
ru.mutation.SetIsAccept(b)
|
|
return ru
|
|
}
|
|
|
|
// SetNillableIsAccept sets the "is_accept" field if the given value is not nil.
|
|
func (ru *RecordUpdate) SetNillableIsAccept(b *bool) *RecordUpdate {
|
|
if b != nil {
|
|
ru.SetIsAccept(*b)
|
|
}
|
|
return ru
|
|
}
|
|
|
|
// SetProgramLanguage sets the "program_language" field.
|
|
func (ru *RecordUpdate) SetProgramLanguage(s string) *RecordUpdate {
|
|
ru.mutation.SetProgramLanguage(s)
|
|
return ru
|
|
}
|
|
|
|
// SetNillableProgramLanguage sets the "program_language" field if the given value is not nil.
|
|
func (ru *RecordUpdate) SetNillableProgramLanguage(s *string) *RecordUpdate {
|
|
if s != nil {
|
|
ru.SetProgramLanguage(*s)
|
|
}
|
|
return ru
|
|
}
|
|
|
|
// ClearProgramLanguage clears the value of the "program_language" field.
|
|
func (ru *RecordUpdate) ClearProgramLanguage() *RecordUpdate {
|
|
ru.mutation.ClearProgramLanguage()
|
|
return ru
|
|
}
|
|
|
|
// SetWorkMode sets the "work_mode" field.
|
|
func (ru *RecordUpdate) SetWorkMode(s string) *RecordUpdate {
|
|
ru.mutation.SetWorkMode(s)
|
|
return ru
|
|
}
|
|
|
|
// SetNillableWorkMode sets the "work_mode" field if the given value is not nil.
|
|
func (ru *RecordUpdate) SetNillableWorkMode(s *string) *RecordUpdate {
|
|
if s != nil {
|
|
ru.SetWorkMode(*s)
|
|
}
|
|
return ru
|
|
}
|
|
|
|
// ClearWorkMode clears the value of the "work_mode" field.
|
|
func (ru *RecordUpdate) ClearWorkMode() *RecordUpdate {
|
|
ru.mutation.ClearWorkMode()
|
|
return ru
|
|
}
|
|
|
|
// SetCodeLines sets the "code_lines" field.
|
|
func (ru *RecordUpdate) SetCodeLines(i int64) *RecordUpdate {
|
|
ru.mutation.ResetCodeLines()
|
|
ru.mutation.SetCodeLines(i)
|
|
return ru
|
|
}
|
|
|
|
// SetNillableCodeLines sets the "code_lines" field if the given value is not nil.
|
|
func (ru *RecordUpdate) SetNillableCodeLines(i *int64) *RecordUpdate {
|
|
if i != nil {
|
|
ru.SetCodeLines(*i)
|
|
}
|
|
return ru
|
|
}
|
|
|
|
// AddCodeLines adds i to the "code_lines" field.
|
|
func (ru *RecordUpdate) AddCodeLines(i int64) *RecordUpdate {
|
|
ru.mutation.AddCodeLines(i)
|
|
return ru
|
|
}
|
|
|
|
// ClearCodeLines clears the value of the "code_lines" field.
|
|
func (ru *RecordUpdate) ClearCodeLines() *RecordUpdate {
|
|
ru.mutation.ClearCodeLines()
|
|
return ru
|
|
}
|
|
|
|
// SetInputTokens sets the "input_tokens" field.
|
|
func (ru *RecordUpdate) SetInputTokens(i int64) *RecordUpdate {
|
|
ru.mutation.ResetInputTokens()
|
|
ru.mutation.SetInputTokens(i)
|
|
return ru
|
|
}
|
|
|
|
// SetNillableInputTokens sets the "input_tokens" field if the given value is not nil.
|
|
func (ru *RecordUpdate) SetNillableInputTokens(i *int64) *RecordUpdate {
|
|
if i != nil {
|
|
ru.SetInputTokens(*i)
|
|
}
|
|
return ru
|
|
}
|
|
|
|
// AddInputTokens adds i to the "input_tokens" field.
|
|
func (ru *RecordUpdate) AddInputTokens(i int64) *RecordUpdate {
|
|
ru.mutation.AddInputTokens(i)
|
|
return ru
|
|
}
|
|
|
|
// SetOutputTokens sets the "output_tokens" field.
|
|
func (ru *RecordUpdate) SetOutputTokens(i int64) *RecordUpdate {
|
|
ru.mutation.ResetOutputTokens()
|
|
ru.mutation.SetOutputTokens(i)
|
|
return ru
|
|
}
|
|
|
|
// SetNillableOutputTokens sets the "output_tokens" field if the given value is not nil.
|
|
func (ru *RecordUpdate) SetNillableOutputTokens(i *int64) *RecordUpdate {
|
|
if i != nil {
|
|
ru.SetOutputTokens(*i)
|
|
}
|
|
return ru
|
|
}
|
|
|
|
// AddOutputTokens adds i to the "output_tokens" field.
|
|
func (ru *RecordUpdate) AddOutputTokens(i int64) *RecordUpdate {
|
|
ru.mutation.AddOutputTokens(i)
|
|
return ru
|
|
}
|
|
|
|
// SetCreatedAt sets the "created_at" field.
|
|
func (ru *RecordUpdate) SetCreatedAt(t time.Time) *RecordUpdate {
|
|
ru.mutation.SetCreatedAt(t)
|
|
return ru
|
|
}
|
|
|
|
// SetNillableCreatedAt sets the "created_at" field if the given value is not nil.
|
|
func (ru *RecordUpdate) SetNillableCreatedAt(t *time.Time) *RecordUpdate {
|
|
if t != nil {
|
|
ru.SetCreatedAt(*t)
|
|
}
|
|
return ru
|
|
}
|
|
|
|
// SetUpdatedAt sets the "updated_at" field.
|
|
func (ru *RecordUpdate) SetUpdatedAt(t time.Time) *RecordUpdate {
|
|
ru.mutation.SetUpdatedAt(t)
|
|
return ru
|
|
}
|
|
|
|
// SetUser sets the "user" edge to the User entity.
|
|
func (ru *RecordUpdate) SetUser(u *User) *RecordUpdate {
|
|
return ru.SetUserID(u.ID)
|
|
}
|
|
|
|
// SetModel sets the "model" edge to the Model entity.
|
|
func (ru *RecordUpdate) SetModel(m *Model) *RecordUpdate {
|
|
return ru.SetModelID(m.ID)
|
|
}
|
|
|
|
// Mutation returns the RecordMutation object of the builder.
|
|
func (ru *RecordUpdate) Mutation() *RecordMutation {
|
|
return ru.mutation
|
|
}
|
|
|
|
// ClearUser clears the "user" edge to the User entity.
|
|
func (ru *RecordUpdate) ClearUser() *RecordUpdate {
|
|
ru.mutation.ClearUser()
|
|
return ru
|
|
}
|
|
|
|
// ClearModel clears the "model" edge to the Model entity.
|
|
func (ru *RecordUpdate) ClearModel() *RecordUpdate {
|
|
ru.mutation.ClearModel()
|
|
return ru
|
|
}
|
|
|
|
// Save executes the query and returns the number of nodes affected by the update operation.
|
|
func (ru *RecordUpdate) Save(ctx context.Context) (int, error) {
|
|
ru.defaults()
|
|
return withHooks(ctx, ru.sqlSave, ru.mutation, ru.hooks)
|
|
}
|
|
|
|
// SaveX is like Save, but panics if an error occurs.
|
|
func (ru *RecordUpdate) SaveX(ctx context.Context) int {
|
|
affected, err := ru.Save(ctx)
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
return affected
|
|
}
|
|
|
|
// Exec executes the query.
|
|
func (ru *RecordUpdate) Exec(ctx context.Context) error {
|
|
_, err := ru.Save(ctx)
|
|
return err
|
|
}
|
|
|
|
// ExecX is like Exec, but panics if an error occurs.
|
|
func (ru *RecordUpdate) ExecX(ctx context.Context) {
|
|
if err := ru.Exec(ctx); err != nil {
|
|
panic(err)
|
|
}
|
|
}
|
|
|
|
// defaults sets the default values of the builder before save.
|
|
func (ru *RecordUpdate) defaults() {
|
|
if _, ok := ru.mutation.UpdatedAt(); !ok {
|
|
v := record.UpdateDefaultUpdatedAt()
|
|
ru.mutation.SetUpdatedAt(v)
|
|
}
|
|
}
|
|
|
|
// Modify adds a statement modifier for attaching custom logic to the UPDATE statement.
|
|
func (ru *RecordUpdate) Modify(modifiers ...func(u *sql.UpdateBuilder)) *RecordUpdate {
|
|
ru.modifiers = append(ru.modifiers, modifiers...)
|
|
return ru
|
|
}
|
|
|
|
func (ru *RecordUpdate) sqlSave(ctx context.Context) (n int, err error) {
|
|
_spec := sqlgraph.NewUpdateSpec(record.Table, record.Columns, sqlgraph.NewFieldSpec(record.FieldID, field.TypeUUID))
|
|
if ps := ru.mutation.predicates; len(ps) > 0 {
|
|
_spec.Predicate = func(selector *sql.Selector) {
|
|
for i := range ps {
|
|
ps[i](selector)
|
|
}
|
|
}
|
|
}
|
|
if value, ok := ru.mutation.TaskID(); ok {
|
|
_spec.SetField(record.FieldTaskID, field.TypeString, value)
|
|
}
|
|
if value, ok := ru.mutation.ModelType(); ok {
|
|
_spec.SetField(record.FieldModelType, field.TypeString, value)
|
|
}
|
|
if ru.mutation.ModelTypeCleared() {
|
|
_spec.ClearField(record.FieldModelType, field.TypeString)
|
|
}
|
|
if value, ok := ru.mutation.Prompt(); ok {
|
|
_spec.SetField(record.FieldPrompt, field.TypeString, value)
|
|
}
|
|
if ru.mutation.PromptCleared() {
|
|
_spec.ClearField(record.FieldPrompt, field.TypeString)
|
|
}
|
|
if value, ok := ru.mutation.Completion(); ok {
|
|
_spec.SetField(record.FieldCompletion, field.TypeString, value)
|
|
}
|
|
if ru.mutation.CompletionCleared() {
|
|
_spec.ClearField(record.FieldCompletion, field.TypeString)
|
|
}
|
|
if value, ok := ru.mutation.IsAccept(); ok {
|
|
_spec.SetField(record.FieldIsAccept, field.TypeBool, value)
|
|
}
|
|
if value, ok := ru.mutation.ProgramLanguage(); ok {
|
|
_spec.SetField(record.FieldProgramLanguage, field.TypeString, value)
|
|
}
|
|
if ru.mutation.ProgramLanguageCleared() {
|
|
_spec.ClearField(record.FieldProgramLanguage, field.TypeString)
|
|
}
|
|
if value, ok := ru.mutation.WorkMode(); ok {
|
|
_spec.SetField(record.FieldWorkMode, field.TypeString, value)
|
|
}
|
|
if ru.mutation.WorkModeCleared() {
|
|
_spec.ClearField(record.FieldWorkMode, field.TypeString)
|
|
}
|
|
if value, ok := ru.mutation.CodeLines(); ok {
|
|
_spec.SetField(record.FieldCodeLines, field.TypeInt64, value)
|
|
}
|
|
if value, ok := ru.mutation.AddedCodeLines(); ok {
|
|
_spec.AddField(record.FieldCodeLines, field.TypeInt64, value)
|
|
}
|
|
if ru.mutation.CodeLinesCleared() {
|
|
_spec.ClearField(record.FieldCodeLines, field.TypeInt64)
|
|
}
|
|
if value, ok := ru.mutation.InputTokens(); ok {
|
|
_spec.SetField(record.FieldInputTokens, field.TypeInt64, value)
|
|
}
|
|
if value, ok := ru.mutation.AddedInputTokens(); ok {
|
|
_spec.AddField(record.FieldInputTokens, field.TypeInt64, value)
|
|
}
|
|
if value, ok := ru.mutation.OutputTokens(); ok {
|
|
_spec.SetField(record.FieldOutputTokens, field.TypeInt64, value)
|
|
}
|
|
if value, ok := ru.mutation.AddedOutputTokens(); ok {
|
|
_spec.AddField(record.FieldOutputTokens, field.TypeInt64, value)
|
|
}
|
|
if value, ok := ru.mutation.CreatedAt(); ok {
|
|
_spec.SetField(record.FieldCreatedAt, field.TypeTime, value)
|
|
}
|
|
if value, ok := ru.mutation.UpdatedAt(); ok {
|
|
_spec.SetField(record.FieldUpdatedAt, field.TypeTime, value)
|
|
}
|
|
if ru.mutation.UserCleared() {
|
|
edge := &sqlgraph.EdgeSpec{
|
|
Rel: sqlgraph.M2O,
|
|
Inverse: true,
|
|
Table: record.UserTable,
|
|
Columns: []string{record.UserColumn},
|
|
Bidi: false,
|
|
Target: &sqlgraph.EdgeTarget{
|
|
IDSpec: sqlgraph.NewFieldSpec(user.FieldID, field.TypeUUID),
|
|
},
|
|
}
|
|
_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
|
|
}
|
|
if nodes := ru.mutation.UserIDs(); len(nodes) > 0 {
|
|
edge := &sqlgraph.EdgeSpec{
|
|
Rel: sqlgraph.M2O,
|
|
Inverse: true,
|
|
Table: record.UserTable,
|
|
Columns: []string{record.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)
|
|
}
|
|
_spec.Edges.Add = append(_spec.Edges.Add, edge)
|
|
}
|
|
if ru.mutation.ModelCleared() {
|
|
edge := &sqlgraph.EdgeSpec{
|
|
Rel: sqlgraph.M2O,
|
|
Inverse: true,
|
|
Table: record.ModelTable,
|
|
Columns: []string{record.ModelColumn},
|
|
Bidi: false,
|
|
Target: &sqlgraph.EdgeTarget{
|
|
IDSpec: sqlgraph.NewFieldSpec(model.FieldID, field.TypeUUID),
|
|
},
|
|
}
|
|
_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
|
|
}
|
|
if nodes := ru.mutation.ModelIDs(); len(nodes) > 0 {
|
|
edge := &sqlgraph.EdgeSpec{
|
|
Rel: sqlgraph.M2O,
|
|
Inverse: true,
|
|
Table: record.ModelTable,
|
|
Columns: []string{record.ModelColumn},
|
|
Bidi: false,
|
|
Target: &sqlgraph.EdgeTarget{
|
|
IDSpec: sqlgraph.NewFieldSpec(model.FieldID, field.TypeUUID),
|
|
},
|
|
}
|
|
for _, k := range nodes {
|
|
edge.Target.Nodes = append(edge.Target.Nodes, k)
|
|
}
|
|
_spec.Edges.Add = append(_spec.Edges.Add, edge)
|
|
}
|
|
_spec.AddModifiers(ru.modifiers...)
|
|
if n, err = sqlgraph.UpdateNodes(ctx, ru.driver, _spec); err != nil {
|
|
if _, ok := err.(*sqlgraph.NotFoundError); ok {
|
|
err = &NotFoundError{record.Label}
|
|
} else if sqlgraph.IsConstraintError(err) {
|
|
err = &ConstraintError{msg: err.Error(), wrap: err}
|
|
}
|
|
return 0, err
|
|
}
|
|
ru.mutation.done = true
|
|
return n, nil
|
|
}
|
|
|
|
// RecordUpdateOne is the builder for updating a single Record entity.
|
|
type RecordUpdateOne struct {
|
|
config
|
|
fields []string
|
|
hooks []Hook
|
|
mutation *RecordMutation
|
|
modifiers []func(*sql.UpdateBuilder)
|
|
}
|
|
|
|
// SetUserID sets the "user_id" field.
|
|
func (ruo *RecordUpdateOne) SetUserID(u uuid.UUID) *RecordUpdateOne {
|
|
ruo.mutation.SetUserID(u)
|
|
return ruo
|
|
}
|
|
|
|
// SetNillableUserID sets the "user_id" field if the given value is not nil.
|
|
func (ruo *RecordUpdateOne) SetNillableUserID(u *uuid.UUID) *RecordUpdateOne {
|
|
if u != nil {
|
|
ruo.SetUserID(*u)
|
|
}
|
|
return ruo
|
|
}
|
|
|
|
// ClearUserID clears the value of the "user_id" field.
|
|
func (ruo *RecordUpdateOne) ClearUserID() *RecordUpdateOne {
|
|
ruo.mutation.ClearUserID()
|
|
return ruo
|
|
}
|
|
|
|
// SetModelID sets the "model_id" field.
|
|
func (ruo *RecordUpdateOne) SetModelID(u uuid.UUID) *RecordUpdateOne {
|
|
ruo.mutation.SetModelID(u)
|
|
return ruo
|
|
}
|
|
|
|
// SetNillableModelID sets the "model_id" field if the given value is not nil.
|
|
func (ruo *RecordUpdateOne) SetNillableModelID(u *uuid.UUID) *RecordUpdateOne {
|
|
if u != nil {
|
|
ruo.SetModelID(*u)
|
|
}
|
|
return ruo
|
|
}
|
|
|
|
// ClearModelID clears the value of the "model_id" field.
|
|
func (ruo *RecordUpdateOne) ClearModelID() *RecordUpdateOne {
|
|
ruo.mutation.ClearModelID()
|
|
return ruo
|
|
}
|
|
|
|
// SetTaskID sets the "task_id" field.
|
|
func (ruo *RecordUpdateOne) SetTaskID(s string) *RecordUpdateOne {
|
|
ruo.mutation.SetTaskID(s)
|
|
return ruo
|
|
}
|
|
|
|
// SetNillableTaskID sets the "task_id" field if the given value is not nil.
|
|
func (ruo *RecordUpdateOne) SetNillableTaskID(s *string) *RecordUpdateOne {
|
|
if s != nil {
|
|
ruo.SetTaskID(*s)
|
|
}
|
|
return ruo
|
|
}
|
|
|
|
// SetModelType sets the "model_type" field.
|
|
func (ruo *RecordUpdateOne) SetModelType(ct consts.ModelType) *RecordUpdateOne {
|
|
ruo.mutation.SetModelType(ct)
|
|
return ruo
|
|
}
|
|
|
|
// SetNillableModelType sets the "model_type" field if the given value is not nil.
|
|
func (ruo *RecordUpdateOne) SetNillableModelType(ct *consts.ModelType) *RecordUpdateOne {
|
|
if ct != nil {
|
|
ruo.SetModelType(*ct)
|
|
}
|
|
return ruo
|
|
}
|
|
|
|
// ClearModelType clears the value of the "model_type" field.
|
|
func (ruo *RecordUpdateOne) ClearModelType() *RecordUpdateOne {
|
|
ruo.mutation.ClearModelType()
|
|
return ruo
|
|
}
|
|
|
|
// SetPrompt sets the "prompt" field.
|
|
func (ruo *RecordUpdateOne) SetPrompt(s string) *RecordUpdateOne {
|
|
ruo.mutation.SetPrompt(s)
|
|
return ruo
|
|
}
|
|
|
|
// SetNillablePrompt sets the "prompt" field if the given value is not nil.
|
|
func (ruo *RecordUpdateOne) SetNillablePrompt(s *string) *RecordUpdateOne {
|
|
if s != nil {
|
|
ruo.SetPrompt(*s)
|
|
}
|
|
return ruo
|
|
}
|
|
|
|
// ClearPrompt clears the value of the "prompt" field.
|
|
func (ruo *RecordUpdateOne) ClearPrompt() *RecordUpdateOne {
|
|
ruo.mutation.ClearPrompt()
|
|
return ruo
|
|
}
|
|
|
|
// SetCompletion sets the "completion" field.
|
|
func (ruo *RecordUpdateOne) SetCompletion(s string) *RecordUpdateOne {
|
|
ruo.mutation.SetCompletion(s)
|
|
return ruo
|
|
}
|
|
|
|
// SetNillableCompletion sets the "completion" field if the given value is not nil.
|
|
func (ruo *RecordUpdateOne) SetNillableCompletion(s *string) *RecordUpdateOne {
|
|
if s != nil {
|
|
ruo.SetCompletion(*s)
|
|
}
|
|
return ruo
|
|
}
|
|
|
|
// ClearCompletion clears the value of the "completion" field.
|
|
func (ruo *RecordUpdateOne) ClearCompletion() *RecordUpdateOne {
|
|
ruo.mutation.ClearCompletion()
|
|
return ruo
|
|
}
|
|
|
|
// SetIsAccept sets the "is_accept" field.
|
|
func (ruo *RecordUpdateOne) SetIsAccept(b bool) *RecordUpdateOne {
|
|
ruo.mutation.SetIsAccept(b)
|
|
return ruo
|
|
}
|
|
|
|
// SetNillableIsAccept sets the "is_accept" field if the given value is not nil.
|
|
func (ruo *RecordUpdateOne) SetNillableIsAccept(b *bool) *RecordUpdateOne {
|
|
if b != nil {
|
|
ruo.SetIsAccept(*b)
|
|
}
|
|
return ruo
|
|
}
|
|
|
|
// SetProgramLanguage sets the "program_language" field.
|
|
func (ruo *RecordUpdateOne) SetProgramLanguage(s string) *RecordUpdateOne {
|
|
ruo.mutation.SetProgramLanguage(s)
|
|
return ruo
|
|
}
|
|
|
|
// SetNillableProgramLanguage sets the "program_language" field if the given value is not nil.
|
|
func (ruo *RecordUpdateOne) SetNillableProgramLanguage(s *string) *RecordUpdateOne {
|
|
if s != nil {
|
|
ruo.SetProgramLanguage(*s)
|
|
}
|
|
return ruo
|
|
}
|
|
|
|
// ClearProgramLanguage clears the value of the "program_language" field.
|
|
func (ruo *RecordUpdateOne) ClearProgramLanguage() *RecordUpdateOne {
|
|
ruo.mutation.ClearProgramLanguage()
|
|
return ruo
|
|
}
|
|
|
|
// SetWorkMode sets the "work_mode" field.
|
|
func (ruo *RecordUpdateOne) SetWorkMode(s string) *RecordUpdateOne {
|
|
ruo.mutation.SetWorkMode(s)
|
|
return ruo
|
|
}
|
|
|
|
// SetNillableWorkMode sets the "work_mode" field if the given value is not nil.
|
|
func (ruo *RecordUpdateOne) SetNillableWorkMode(s *string) *RecordUpdateOne {
|
|
if s != nil {
|
|
ruo.SetWorkMode(*s)
|
|
}
|
|
return ruo
|
|
}
|
|
|
|
// ClearWorkMode clears the value of the "work_mode" field.
|
|
func (ruo *RecordUpdateOne) ClearWorkMode() *RecordUpdateOne {
|
|
ruo.mutation.ClearWorkMode()
|
|
return ruo
|
|
}
|
|
|
|
// SetCodeLines sets the "code_lines" field.
|
|
func (ruo *RecordUpdateOne) SetCodeLines(i int64) *RecordUpdateOne {
|
|
ruo.mutation.ResetCodeLines()
|
|
ruo.mutation.SetCodeLines(i)
|
|
return ruo
|
|
}
|
|
|
|
// SetNillableCodeLines sets the "code_lines" field if the given value is not nil.
|
|
func (ruo *RecordUpdateOne) SetNillableCodeLines(i *int64) *RecordUpdateOne {
|
|
if i != nil {
|
|
ruo.SetCodeLines(*i)
|
|
}
|
|
return ruo
|
|
}
|
|
|
|
// AddCodeLines adds i to the "code_lines" field.
|
|
func (ruo *RecordUpdateOne) AddCodeLines(i int64) *RecordUpdateOne {
|
|
ruo.mutation.AddCodeLines(i)
|
|
return ruo
|
|
}
|
|
|
|
// ClearCodeLines clears the value of the "code_lines" field.
|
|
func (ruo *RecordUpdateOne) ClearCodeLines() *RecordUpdateOne {
|
|
ruo.mutation.ClearCodeLines()
|
|
return ruo
|
|
}
|
|
|
|
// SetInputTokens sets the "input_tokens" field.
|
|
func (ruo *RecordUpdateOne) SetInputTokens(i int64) *RecordUpdateOne {
|
|
ruo.mutation.ResetInputTokens()
|
|
ruo.mutation.SetInputTokens(i)
|
|
return ruo
|
|
}
|
|
|
|
// SetNillableInputTokens sets the "input_tokens" field if the given value is not nil.
|
|
func (ruo *RecordUpdateOne) SetNillableInputTokens(i *int64) *RecordUpdateOne {
|
|
if i != nil {
|
|
ruo.SetInputTokens(*i)
|
|
}
|
|
return ruo
|
|
}
|
|
|
|
// AddInputTokens adds i to the "input_tokens" field.
|
|
func (ruo *RecordUpdateOne) AddInputTokens(i int64) *RecordUpdateOne {
|
|
ruo.mutation.AddInputTokens(i)
|
|
return ruo
|
|
}
|
|
|
|
// SetOutputTokens sets the "output_tokens" field.
|
|
func (ruo *RecordUpdateOne) SetOutputTokens(i int64) *RecordUpdateOne {
|
|
ruo.mutation.ResetOutputTokens()
|
|
ruo.mutation.SetOutputTokens(i)
|
|
return ruo
|
|
}
|
|
|
|
// SetNillableOutputTokens sets the "output_tokens" field if the given value is not nil.
|
|
func (ruo *RecordUpdateOne) SetNillableOutputTokens(i *int64) *RecordUpdateOne {
|
|
if i != nil {
|
|
ruo.SetOutputTokens(*i)
|
|
}
|
|
return ruo
|
|
}
|
|
|
|
// AddOutputTokens adds i to the "output_tokens" field.
|
|
func (ruo *RecordUpdateOne) AddOutputTokens(i int64) *RecordUpdateOne {
|
|
ruo.mutation.AddOutputTokens(i)
|
|
return ruo
|
|
}
|
|
|
|
// SetCreatedAt sets the "created_at" field.
|
|
func (ruo *RecordUpdateOne) SetCreatedAt(t time.Time) *RecordUpdateOne {
|
|
ruo.mutation.SetCreatedAt(t)
|
|
return ruo
|
|
}
|
|
|
|
// SetNillableCreatedAt sets the "created_at" field if the given value is not nil.
|
|
func (ruo *RecordUpdateOne) SetNillableCreatedAt(t *time.Time) *RecordUpdateOne {
|
|
if t != nil {
|
|
ruo.SetCreatedAt(*t)
|
|
}
|
|
return ruo
|
|
}
|
|
|
|
// SetUpdatedAt sets the "updated_at" field.
|
|
func (ruo *RecordUpdateOne) SetUpdatedAt(t time.Time) *RecordUpdateOne {
|
|
ruo.mutation.SetUpdatedAt(t)
|
|
return ruo
|
|
}
|
|
|
|
// SetUser sets the "user" edge to the User entity.
|
|
func (ruo *RecordUpdateOne) SetUser(u *User) *RecordUpdateOne {
|
|
return ruo.SetUserID(u.ID)
|
|
}
|
|
|
|
// SetModel sets the "model" edge to the Model entity.
|
|
func (ruo *RecordUpdateOne) SetModel(m *Model) *RecordUpdateOne {
|
|
return ruo.SetModelID(m.ID)
|
|
}
|
|
|
|
// Mutation returns the RecordMutation object of the builder.
|
|
func (ruo *RecordUpdateOne) Mutation() *RecordMutation {
|
|
return ruo.mutation
|
|
}
|
|
|
|
// ClearUser clears the "user" edge to the User entity.
|
|
func (ruo *RecordUpdateOne) ClearUser() *RecordUpdateOne {
|
|
ruo.mutation.ClearUser()
|
|
return ruo
|
|
}
|
|
|
|
// ClearModel clears the "model" edge to the Model entity.
|
|
func (ruo *RecordUpdateOne) ClearModel() *RecordUpdateOne {
|
|
ruo.mutation.ClearModel()
|
|
return ruo
|
|
}
|
|
|
|
// Where appends a list predicates to the RecordUpdate builder.
|
|
func (ruo *RecordUpdateOne) Where(ps ...predicate.Record) *RecordUpdateOne {
|
|
ruo.mutation.Where(ps...)
|
|
return ruo
|
|
}
|
|
|
|
// Select allows selecting one or more fields (columns) of the returned entity.
|
|
// The default is selecting all fields defined in the entity schema.
|
|
func (ruo *RecordUpdateOne) Select(field string, fields ...string) *RecordUpdateOne {
|
|
ruo.fields = append([]string{field}, fields...)
|
|
return ruo
|
|
}
|
|
|
|
// Save executes the query and returns the updated Record entity.
|
|
func (ruo *RecordUpdateOne) Save(ctx context.Context) (*Record, error) {
|
|
ruo.defaults()
|
|
return withHooks(ctx, ruo.sqlSave, ruo.mutation, ruo.hooks)
|
|
}
|
|
|
|
// SaveX is like Save, but panics if an error occurs.
|
|
func (ruo *RecordUpdateOne) SaveX(ctx context.Context) *Record {
|
|
node, err := ruo.Save(ctx)
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
return node
|
|
}
|
|
|
|
// Exec executes the query on the entity.
|
|
func (ruo *RecordUpdateOne) Exec(ctx context.Context) error {
|
|
_, err := ruo.Save(ctx)
|
|
return err
|
|
}
|
|
|
|
// ExecX is like Exec, but panics if an error occurs.
|
|
func (ruo *RecordUpdateOne) ExecX(ctx context.Context) {
|
|
if err := ruo.Exec(ctx); err != nil {
|
|
panic(err)
|
|
}
|
|
}
|
|
|
|
// defaults sets the default values of the builder before save.
|
|
func (ruo *RecordUpdateOne) defaults() {
|
|
if _, ok := ruo.mutation.UpdatedAt(); !ok {
|
|
v := record.UpdateDefaultUpdatedAt()
|
|
ruo.mutation.SetUpdatedAt(v)
|
|
}
|
|
}
|
|
|
|
// Modify adds a statement modifier for attaching custom logic to the UPDATE statement.
|
|
func (ruo *RecordUpdateOne) Modify(modifiers ...func(u *sql.UpdateBuilder)) *RecordUpdateOne {
|
|
ruo.modifiers = append(ruo.modifiers, modifiers...)
|
|
return ruo
|
|
}
|
|
|
|
func (ruo *RecordUpdateOne) sqlSave(ctx context.Context) (_node *Record, err error) {
|
|
_spec := sqlgraph.NewUpdateSpec(record.Table, record.Columns, sqlgraph.NewFieldSpec(record.FieldID, field.TypeUUID))
|
|
id, ok := ruo.mutation.ID()
|
|
if !ok {
|
|
return nil, &ValidationError{Name: "id", err: errors.New(`db: missing "Record.id" for update`)}
|
|
}
|
|
_spec.Node.ID.Value = id
|
|
if fields := ruo.fields; len(fields) > 0 {
|
|
_spec.Node.Columns = make([]string, 0, len(fields))
|
|
_spec.Node.Columns = append(_spec.Node.Columns, record.FieldID)
|
|
for _, f := range fields {
|
|
if !record.ValidColumn(f) {
|
|
return nil, &ValidationError{Name: f, err: fmt.Errorf("db: invalid field %q for query", f)}
|
|
}
|
|
if f != record.FieldID {
|
|
_spec.Node.Columns = append(_spec.Node.Columns, f)
|
|
}
|
|
}
|
|
}
|
|
if ps := ruo.mutation.predicates; len(ps) > 0 {
|
|
_spec.Predicate = func(selector *sql.Selector) {
|
|
for i := range ps {
|
|
ps[i](selector)
|
|
}
|
|
}
|
|
}
|
|
if value, ok := ruo.mutation.TaskID(); ok {
|
|
_spec.SetField(record.FieldTaskID, field.TypeString, value)
|
|
}
|
|
if value, ok := ruo.mutation.ModelType(); ok {
|
|
_spec.SetField(record.FieldModelType, field.TypeString, value)
|
|
}
|
|
if ruo.mutation.ModelTypeCleared() {
|
|
_spec.ClearField(record.FieldModelType, field.TypeString)
|
|
}
|
|
if value, ok := ruo.mutation.Prompt(); ok {
|
|
_spec.SetField(record.FieldPrompt, field.TypeString, value)
|
|
}
|
|
if ruo.mutation.PromptCleared() {
|
|
_spec.ClearField(record.FieldPrompt, field.TypeString)
|
|
}
|
|
if value, ok := ruo.mutation.Completion(); ok {
|
|
_spec.SetField(record.FieldCompletion, field.TypeString, value)
|
|
}
|
|
if ruo.mutation.CompletionCleared() {
|
|
_spec.ClearField(record.FieldCompletion, field.TypeString)
|
|
}
|
|
if value, ok := ruo.mutation.IsAccept(); ok {
|
|
_spec.SetField(record.FieldIsAccept, field.TypeBool, value)
|
|
}
|
|
if value, ok := ruo.mutation.ProgramLanguage(); ok {
|
|
_spec.SetField(record.FieldProgramLanguage, field.TypeString, value)
|
|
}
|
|
if ruo.mutation.ProgramLanguageCleared() {
|
|
_spec.ClearField(record.FieldProgramLanguage, field.TypeString)
|
|
}
|
|
if value, ok := ruo.mutation.WorkMode(); ok {
|
|
_spec.SetField(record.FieldWorkMode, field.TypeString, value)
|
|
}
|
|
if ruo.mutation.WorkModeCleared() {
|
|
_spec.ClearField(record.FieldWorkMode, field.TypeString)
|
|
}
|
|
if value, ok := ruo.mutation.CodeLines(); ok {
|
|
_spec.SetField(record.FieldCodeLines, field.TypeInt64, value)
|
|
}
|
|
if value, ok := ruo.mutation.AddedCodeLines(); ok {
|
|
_spec.AddField(record.FieldCodeLines, field.TypeInt64, value)
|
|
}
|
|
if ruo.mutation.CodeLinesCleared() {
|
|
_spec.ClearField(record.FieldCodeLines, field.TypeInt64)
|
|
}
|
|
if value, ok := ruo.mutation.InputTokens(); ok {
|
|
_spec.SetField(record.FieldInputTokens, field.TypeInt64, value)
|
|
}
|
|
if value, ok := ruo.mutation.AddedInputTokens(); ok {
|
|
_spec.AddField(record.FieldInputTokens, field.TypeInt64, value)
|
|
}
|
|
if value, ok := ruo.mutation.OutputTokens(); ok {
|
|
_spec.SetField(record.FieldOutputTokens, field.TypeInt64, value)
|
|
}
|
|
if value, ok := ruo.mutation.AddedOutputTokens(); ok {
|
|
_spec.AddField(record.FieldOutputTokens, field.TypeInt64, value)
|
|
}
|
|
if value, ok := ruo.mutation.CreatedAt(); ok {
|
|
_spec.SetField(record.FieldCreatedAt, field.TypeTime, value)
|
|
}
|
|
if value, ok := ruo.mutation.UpdatedAt(); ok {
|
|
_spec.SetField(record.FieldUpdatedAt, field.TypeTime, value)
|
|
}
|
|
if ruo.mutation.UserCleared() {
|
|
edge := &sqlgraph.EdgeSpec{
|
|
Rel: sqlgraph.M2O,
|
|
Inverse: true,
|
|
Table: record.UserTable,
|
|
Columns: []string{record.UserColumn},
|
|
Bidi: false,
|
|
Target: &sqlgraph.EdgeTarget{
|
|
IDSpec: sqlgraph.NewFieldSpec(user.FieldID, field.TypeUUID),
|
|
},
|
|
}
|
|
_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
|
|
}
|
|
if nodes := ruo.mutation.UserIDs(); len(nodes) > 0 {
|
|
edge := &sqlgraph.EdgeSpec{
|
|
Rel: sqlgraph.M2O,
|
|
Inverse: true,
|
|
Table: record.UserTable,
|
|
Columns: []string{record.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)
|
|
}
|
|
_spec.Edges.Add = append(_spec.Edges.Add, edge)
|
|
}
|
|
if ruo.mutation.ModelCleared() {
|
|
edge := &sqlgraph.EdgeSpec{
|
|
Rel: sqlgraph.M2O,
|
|
Inverse: true,
|
|
Table: record.ModelTable,
|
|
Columns: []string{record.ModelColumn},
|
|
Bidi: false,
|
|
Target: &sqlgraph.EdgeTarget{
|
|
IDSpec: sqlgraph.NewFieldSpec(model.FieldID, field.TypeUUID),
|
|
},
|
|
}
|
|
_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
|
|
}
|
|
if nodes := ruo.mutation.ModelIDs(); len(nodes) > 0 {
|
|
edge := &sqlgraph.EdgeSpec{
|
|
Rel: sqlgraph.M2O,
|
|
Inverse: true,
|
|
Table: record.ModelTable,
|
|
Columns: []string{record.ModelColumn},
|
|
Bidi: false,
|
|
Target: &sqlgraph.EdgeTarget{
|
|
IDSpec: sqlgraph.NewFieldSpec(model.FieldID, field.TypeUUID),
|
|
},
|
|
}
|
|
for _, k := range nodes {
|
|
edge.Target.Nodes = append(edge.Target.Nodes, k)
|
|
}
|
|
_spec.Edges.Add = append(_spec.Edges.Add, edge)
|
|
}
|
|
_spec.AddModifiers(ruo.modifiers...)
|
|
_node = &Record{config: ruo.config}
|
|
_spec.Assign = _node.assignValues
|
|
_spec.ScanValues = _node.scanValues
|
|
if err = sqlgraph.UpdateNode(ctx, ruo.driver, _spec); err != nil {
|
|
if _, ok := err.(*sqlgraph.NotFoundError); ok {
|
|
err = &NotFoundError{record.Label}
|
|
} else if sqlgraph.IsConstraintError(err) {
|
|
err = &ConstraintError{msg: err.Error(), wrap: err}
|
|
}
|
|
return nil, err
|
|
}
|
|
ruo.mutation.done = true
|
|
return _node, nil
|
|
}
|