mirror of
https://github.com/chaitin/MonkeyCode.git
synced 2026-02-02 23:03:57 +08:00
1522 lines
42 KiB
Go
1522 lines
42 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/consts"
|
|
"github.com/chaitin/MonkeyCode/backend/db/model"
|
|
"github.com/chaitin/MonkeyCode/backend/db/record"
|
|
"github.com/chaitin/MonkeyCode/backend/db/user"
|
|
"github.com/google/uuid"
|
|
)
|
|
|
|
// RecordCreate is the builder for creating a Record entity.
|
|
type RecordCreate struct {
|
|
config
|
|
mutation *RecordMutation
|
|
hooks []Hook
|
|
conflict []sql.ConflictOption
|
|
}
|
|
|
|
// SetUserID sets the "user_id" field.
|
|
func (rc *RecordCreate) SetUserID(u uuid.UUID) *RecordCreate {
|
|
rc.mutation.SetUserID(u)
|
|
return rc
|
|
}
|
|
|
|
// SetNillableUserID sets the "user_id" field if the given value is not nil.
|
|
func (rc *RecordCreate) SetNillableUserID(u *uuid.UUID) *RecordCreate {
|
|
if u != nil {
|
|
rc.SetUserID(*u)
|
|
}
|
|
return rc
|
|
}
|
|
|
|
// SetModelID sets the "model_id" field.
|
|
func (rc *RecordCreate) SetModelID(u uuid.UUID) *RecordCreate {
|
|
rc.mutation.SetModelID(u)
|
|
return rc
|
|
}
|
|
|
|
// SetNillableModelID sets the "model_id" field if the given value is not nil.
|
|
func (rc *RecordCreate) SetNillableModelID(u *uuid.UUID) *RecordCreate {
|
|
if u != nil {
|
|
rc.SetModelID(*u)
|
|
}
|
|
return rc
|
|
}
|
|
|
|
// SetTaskID sets the "task_id" field.
|
|
func (rc *RecordCreate) SetTaskID(s string) *RecordCreate {
|
|
rc.mutation.SetTaskID(s)
|
|
return rc
|
|
}
|
|
|
|
// SetModelType sets the "model_type" field.
|
|
func (rc *RecordCreate) SetModelType(ct consts.ModelType) *RecordCreate {
|
|
rc.mutation.SetModelType(ct)
|
|
return rc
|
|
}
|
|
|
|
// SetNillableModelType sets the "model_type" field if the given value is not nil.
|
|
func (rc *RecordCreate) SetNillableModelType(ct *consts.ModelType) *RecordCreate {
|
|
if ct != nil {
|
|
rc.SetModelType(*ct)
|
|
}
|
|
return rc
|
|
}
|
|
|
|
// SetPrompt sets the "prompt" field.
|
|
func (rc *RecordCreate) SetPrompt(s string) *RecordCreate {
|
|
rc.mutation.SetPrompt(s)
|
|
return rc
|
|
}
|
|
|
|
// SetNillablePrompt sets the "prompt" field if the given value is not nil.
|
|
func (rc *RecordCreate) SetNillablePrompt(s *string) *RecordCreate {
|
|
if s != nil {
|
|
rc.SetPrompt(*s)
|
|
}
|
|
return rc
|
|
}
|
|
|
|
// SetCompletion sets the "completion" field.
|
|
func (rc *RecordCreate) SetCompletion(s string) *RecordCreate {
|
|
rc.mutation.SetCompletion(s)
|
|
return rc
|
|
}
|
|
|
|
// SetNillableCompletion sets the "completion" field if the given value is not nil.
|
|
func (rc *RecordCreate) SetNillableCompletion(s *string) *RecordCreate {
|
|
if s != nil {
|
|
rc.SetCompletion(*s)
|
|
}
|
|
return rc
|
|
}
|
|
|
|
// SetIsAccept sets the "is_accept" field.
|
|
func (rc *RecordCreate) SetIsAccept(b bool) *RecordCreate {
|
|
rc.mutation.SetIsAccept(b)
|
|
return rc
|
|
}
|
|
|
|
// SetNillableIsAccept sets the "is_accept" field if the given value is not nil.
|
|
func (rc *RecordCreate) SetNillableIsAccept(b *bool) *RecordCreate {
|
|
if b != nil {
|
|
rc.SetIsAccept(*b)
|
|
}
|
|
return rc
|
|
}
|
|
|
|
// SetProgramLanguage sets the "program_language" field.
|
|
func (rc *RecordCreate) SetProgramLanguage(s string) *RecordCreate {
|
|
rc.mutation.SetProgramLanguage(s)
|
|
return rc
|
|
}
|
|
|
|
// SetNillableProgramLanguage sets the "program_language" field if the given value is not nil.
|
|
func (rc *RecordCreate) SetNillableProgramLanguage(s *string) *RecordCreate {
|
|
if s != nil {
|
|
rc.SetProgramLanguage(*s)
|
|
}
|
|
return rc
|
|
}
|
|
|
|
// SetWorkMode sets the "work_mode" field.
|
|
func (rc *RecordCreate) SetWorkMode(s string) *RecordCreate {
|
|
rc.mutation.SetWorkMode(s)
|
|
return rc
|
|
}
|
|
|
|
// SetNillableWorkMode sets the "work_mode" field if the given value is not nil.
|
|
func (rc *RecordCreate) SetNillableWorkMode(s *string) *RecordCreate {
|
|
if s != nil {
|
|
rc.SetWorkMode(*s)
|
|
}
|
|
return rc
|
|
}
|
|
|
|
// SetCodeLines sets the "code_lines" field.
|
|
func (rc *RecordCreate) SetCodeLines(i int64) *RecordCreate {
|
|
rc.mutation.SetCodeLines(i)
|
|
return rc
|
|
}
|
|
|
|
// SetNillableCodeLines sets the "code_lines" field if the given value is not nil.
|
|
func (rc *RecordCreate) SetNillableCodeLines(i *int64) *RecordCreate {
|
|
if i != nil {
|
|
rc.SetCodeLines(*i)
|
|
}
|
|
return rc
|
|
}
|
|
|
|
// SetInputTokens sets the "input_tokens" field.
|
|
func (rc *RecordCreate) SetInputTokens(i int64) *RecordCreate {
|
|
rc.mutation.SetInputTokens(i)
|
|
return rc
|
|
}
|
|
|
|
// SetOutputTokens sets the "output_tokens" field.
|
|
func (rc *RecordCreate) SetOutputTokens(i int64) *RecordCreate {
|
|
rc.mutation.SetOutputTokens(i)
|
|
return rc
|
|
}
|
|
|
|
// SetCreatedAt sets the "created_at" field.
|
|
func (rc *RecordCreate) SetCreatedAt(t time.Time) *RecordCreate {
|
|
rc.mutation.SetCreatedAt(t)
|
|
return rc
|
|
}
|
|
|
|
// SetNillableCreatedAt sets the "created_at" field if the given value is not nil.
|
|
func (rc *RecordCreate) SetNillableCreatedAt(t *time.Time) *RecordCreate {
|
|
if t != nil {
|
|
rc.SetCreatedAt(*t)
|
|
}
|
|
return rc
|
|
}
|
|
|
|
// SetUpdatedAt sets the "updated_at" field.
|
|
func (rc *RecordCreate) SetUpdatedAt(t time.Time) *RecordCreate {
|
|
rc.mutation.SetUpdatedAt(t)
|
|
return rc
|
|
}
|
|
|
|
// SetNillableUpdatedAt sets the "updated_at" field if the given value is not nil.
|
|
func (rc *RecordCreate) SetNillableUpdatedAt(t *time.Time) *RecordCreate {
|
|
if t != nil {
|
|
rc.SetUpdatedAt(*t)
|
|
}
|
|
return rc
|
|
}
|
|
|
|
// SetID sets the "id" field.
|
|
func (rc *RecordCreate) SetID(u uuid.UUID) *RecordCreate {
|
|
rc.mutation.SetID(u)
|
|
return rc
|
|
}
|
|
|
|
// SetUser sets the "user" edge to the User entity.
|
|
func (rc *RecordCreate) SetUser(u *User) *RecordCreate {
|
|
return rc.SetUserID(u.ID)
|
|
}
|
|
|
|
// SetModel sets the "model" edge to the Model entity.
|
|
func (rc *RecordCreate) SetModel(m *Model) *RecordCreate {
|
|
return rc.SetModelID(m.ID)
|
|
}
|
|
|
|
// Mutation returns the RecordMutation object of the builder.
|
|
func (rc *RecordCreate) Mutation() *RecordMutation {
|
|
return rc.mutation
|
|
}
|
|
|
|
// Save creates the Record in the database.
|
|
func (rc *RecordCreate) Save(ctx context.Context) (*Record, error) {
|
|
rc.defaults()
|
|
return withHooks(ctx, rc.sqlSave, rc.mutation, rc.hooks)
|
|
}
|
|
|
|
// SaveX calls Save and panics if Save returns an error.
|
|
func (rc *RecordCreate) SaveX(ctx context.Context) *Record {
|
|
v, err := rc.Save(ctx)
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
return v
|
|
}
|
|
|
|
// Exec executes the query.
|
|
func (rc *RecordCreate) Exec(ctx context.Context) error {
|
|
_, err := rc.Save(ctx)
|
|
return err
|
|
}
|
|
|
|
// ExecX is like Exec, but panics if an error occurs.
|
|
func (rc *RecordCreate) ExecX(ctx context.Context) {
|
|
if err := rc.Exec(ctx); err != nil {
|
|
panic(err)
|
|
}
|
|
}
|
|
|
|
// defaults sets the default values of the builder before save.
|
|
func (rc *RecordCreate) defaults() {
|
|
if _, ok := rc.mutation.IsAccept(); !ok {
|
|
v := record.DefaultIsAccept
|
|
rc.mutation.SetIsAccept(v)
|
|
}
|
|
if _, ok := rc.mutation.CreatedAt(); !ok {
|
|
v := record.DefaultCreatedAt()
|
|
rc.mutation.SetCreatedAt(v)
|
|
}
|
|
if _, ok := rc.mutation.UpdatedAt(); !ok {
|
|
v := record.DefaultUpdatedAt()
|
|
rc.mutation.SetUpdatedAt(v)
|
|
}
|
|
}
|
|
|
|
// check runs all checks and user-defined validators on the builder.
|
|
func (rc *RecordCreate) check() error {
|
|
if _, ok := rc.mutation.TaskID(); !ok {
|
|
return &ValidationError{Name: "task_id", err: errors.New(`db: missing required field "Record.task_id"`)}
|
|
}
|
|
if _, ok := rc.mutation.IsAccept(); !ok {
|
|
return &ValidationError{Name: "is_accept", err: errors.New(`db: missing required field "Record.is_accept"`)}
|
|
}
|
|
if _, ok := rc.mutation.InputTokens(); !ok {
|
|
return &ValidationError{Name: "input_tokens", err: errors.New(`db: missing required field "Record.input_tokens"`)}
|
|
}
|
|
if _, ok := rc.mutation.OutputTokens(); !ok {
|
|
return &ValidationError{Name: "output_tokens", err: errors.New(`db: missing required field "Record.output_tokens"`)}
|
|
}
|
|
if _, ok := rc.mutation.CreatedAt(); !ok {
|
|
return &ValidationError{Name: "created_at", err: errors.New(`db: missing required field "Record.created_at"`)}
|
|
}
|
|
if _, ok := rc.mutation.UpdatedAt(); !ok {
|
|
return &ValidationError{Name: "updated_at", err: errors.New(`db: missing required field "Record.updated_at"`)}
|
|
}
|
|
return nil
|
|
}
|
|
|
|
func (rc *RecordCreate) sqlSave(ctx context.Context) (*Record, error) {
|
|
if err := rc.check(); err != nil {
|
|
return nil, err
|
|
}
|
|
_node, _spec := rc.createSpec()
|
|
if err := sqlgraph.CreateNode(ctx, rc.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
|
|
}
|
|
}
|
|
rc.mutation.id = &_node.ID
|
|
rc.mutation.done = true
|
|
return _node, nil
|
|
}
|
|
|
|
func (rc *RecordCreate) createSpec() (*Record, *sqlgraph.CreateSpec) {
|
|
var (
|
|
_node = &Record{config: rc.config}
|
|
_spec = sqlgraph.NewCreateSpec(record.Table, sqlgraph.NewFieldSpec(record.FieldID, field.TypeUUID))
|
|
)
|
|
_spec.OnConflict = rc.conflict
|
|
if id, ok := rc.mutation.ID(); ok {
|
|
_node.ID = id
|
|
_spec.ID.Value = &id
|
|
}
|
|
if value, ok := rc.mutation.TaskID(); ok {
|
|
_spec.SetField(record.FieldTaskID, field.TypeString, value)
|
|
_node.TaskID = value
|
|
}
|
|
if value, ok := rc.mutation.ModelType(); ok {
|
|
_spec.SetField(record.FieldModelType, field.TypeString, value)
|
|
_node.ModelType = value
|
|
}
|
|
if value, ok := rc.mutation.Prompt(); ok {
|
|
_spec.SetField(record.FieldPrompt, field.TypeString, value)
|
|
_node.Prompt = value
|
|
}
|
|
if value, ok := rc.mutation.Completion(); ok {
|
|
_spec.SetField(record.FieldCompletion, field.TypeString, value)
|
|
_node.Completion = value
|
|
}
|
|
if value, ok := rc.mutation.IsAccept(); ok {
|
|
_spec.SetField(record.FieldIsAccept, field.TypeBool, value)
|
|
_node.IsAccept = value
|
|
}
|
|
if value, ok := rc.mutation.ProgramLanguage(); ok {
|
|
_spec.SetField(record.FieldProgramLanguage, field.TypeString, value)
|
|
_node.ProgramLanguage = value
|
|
}
|
|
if value, ok := rc.mutation.WorkMode(); ok {
|
|
_spec.SetField(record.FieldWorkMode, field.TypeString, value)
|
|
_node.WorkMode = value
|
|
}
|
|
if value, ok := rc.mutation.CodeLines(); ok {
|
|
_spec.SetField(record.FieldCodeLines, field.TypeInt64, value)
|
|
_node.CodeLines = value
|
|
}
|
|
if value, ok := rc.mutation.InputTokens(); ok {
|
|
_spec.SetField(record.FieldInputTokens, field.TypeInt64, value)
|
|
_node.InputTokens = value
|
|
}
|
|
if value, ok := rc.mutation.OutputTokens(); ok {
|
|
_spec.SetField(record.FieldOutputTokens, field.TypeInt64, value)
|
|
_node.OutputTokens = value
|
|
}
|
|
if value, ok := rc.mutation.CreatedAt(); ok {
|
|
_spec.SetField(record.FieldCreatedAt, field.TypeTime, value)
|
|
_node.CreatedAt = value
|
|
}
|
|
if value, ok := rc.mutation.UpdatedAt(); ok {
|
|
_spec.SetField(record.FieldUpdatedAt, field.TypeTime, value)
|
|
_node.UpdatedAt = value
|
|
}
|
|
if nodes := rc.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)
|
|
}
|
|
_node.UserID = nodes[0]
|
|
_spec.Edges = append(_spec.Edges, edge)
|
|
}
|
|
if nodes := rc.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)
|
|
}
|
|
_node.ModelID = 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.Record.Create().
|
|
// SetUserID(v).
|
|
// OnConflict(
|
|
// // Update the row with the new values
|
|
// // the was proposed for insertion.
|
|
// sql.ResolveWithNewValues(),
|
|
// ).
|
|
// // Override some of the fields with custom
|
|
// // update values.
|
|
// Update(func(u *ent.RecordUpsert) {
|
|
// SetUserID(v+v).
|
|
// }).
|
|
// Exec(ctx)
|
|
func (rc *RecordCreate) OnConflict(opts ...sql.ConflictOption) *RecordUpsertOne {
|
|
rc.conflict = opts
|
|
return &RecordUpsertOne{
|
|
create: rc,
|
|
}
|
|
}
|
|
|
|
// OnConflictColumns calls `OnConflict` and configures the columns
|
|
// as conflict target. Using this option is equivalent to using:
|
|
//
|
|
// client.Record.Create().
|
|
// OnConflict(sql.ConflictColumns(columns...)).
|
|
// Exec(ctx)
|
|
func (rc *RecordCreate) OnConflictColumns(columns ...string) *RecordUpsertOne {
|
|
rc.conflict = append(rc.conflict, sql.ConflictColumns(columns...))
|
|
return &RecordUpsertOne{
|
|
create: rc,
|
|
}
|
|
}
|
|
|
|
type (
|
|
// RecordUpsertOne is the builder for "upsert"-ing
|
|
// one Record node.
|
|
RecordUpsertOne struct {
|
|
create *RecordCreate
|
|
}
|
|
|
|
// RecordUpsert is the "OnConflict" setter.
|
|
RecordUpsert struct {
|
|
*sql.UpdateSet
|
|
}
|
|
)
|
|
|
|
// SetUserID sets the "user_id" field.
|
|
func (u *RecordUpsert) SetUserID(v uuid.UUID) *RecordUpsert {
|
|
u.Set(record.FieldUserID, v)
|
|
return u
|
|
}
|
|
|
|
// UpdateUserID sets the "user_id" field to the value that was provided on create.
|
|
func (u *RecordUpsert) UpdateUserID() *RecordUpsert {
|
|
u.SetExcluded(record.FieldUserID)
|
|
return u
|
|
}
|
|
|
|
// ClearUserID clears the value of the "user_id" field.
|
|
func (u *RecordUpsert) ClearUserID() *RecordUpsert {
|
|
u.SetNull(record.FieldUserID)
|
|
return u
|
|
}
|
|
|
|
// SetModelID sets the "model_id" field.
|
|
func (u *RecordUpsert) SetModelID(v uuid.UUID) *RecordUpsert {
|
|
u.Set(record.FieldModelID, v)
|
|
return u
|
|
}
|
|
|
|
// UpdateModelID sets the "model_id" field to the value that was provided on create.
|
|
func (u *RecordUpsert) UpdateModelID() *RecordUpsert {
|
|
u.SetExcluded(record.FieldModelID)
|
|
return u
|
|
}
|
|
|
|
// ClearModelID clears the value of the "model_id" field.
|
|
func (u *RecordUpsert) ClearModelID() *RecordUpsert {
|
|
u.SetNull(record.FieldModelID)
|
|
return u
|
|
}
|
|
|
|
// SetTaskID sets the "task_id" field.
|
|
func (u *RecordUpsert) SetTaskID(v string) *RecordUpsert {
|
|
u.Set(record.FieldTaskID, v)
|
|
return u
|
|
}
|
|
|
|
// UpdateTaskID sets the "task_id" field to the value that was provided on create.
|
|
func (u *RecordUpsert) UpdateTaskID() *RecordUpsert {
|
|
u.SetExcluded(record.FieldTaskID)
|
|
return u
|
|
}
|
|
|
|
// SetModelType sets the "model_type" field.
|
|
func (u *RecordUpsert) SetModelType(v consts.ModelType) *RecordUpsert {
|
|
u.Set(record.FieldModelType, v)
|
|
return u
|
|
}
|
|
|
|
// UpdateModelType sets the "model_type" field to the value that was provided on create.
|
|
func (u *RecordUpsert) UpdateModelType() *RecordUpsert {
|
|
u.SetExcluded(record.FieldModelType)
|
|
return u
|
|
}
|
|
|
|
// ClearModelType clears the value of the "model_type" field.
|
|
func (u *RecordUpsert) ClearModelType() *RecordUpsert {
|
|
u.SetNull(record.FieldModelType)
|
|
return u
|
|
}
|
|
|
|
// SetPrompt sets the "prompt" field.
|
|
func (u *RecordUpsert) SetPrompt(v string) *RecordUpsert {
|
|
u.Set(record.FieldPrompt, v)
|
|
return u
|
|
}
|
|
|
|
// UpdatePrompt sets the "prompt" field to the value that was provided on create.
|
|
func (u *RecordUpsert) UpdatePrompt() *RecordUpsert {
|
|
u.SetExcluded(record.FieldPrompt)
|
|
return u
|
|
}
|
|
|
|
// ClearPrompt clears the value of the "prompt" field.
|
|
func (u *RecordUpsert) ClearPrompt() *RecordUpsert {
|
|
u.SetNull(record.FieldPrompt)
|
|
return u
|
|
}
|
|
|
|
// SetCompletion sets the "completion" field.
|
|
func (u *RecordUpsert) SetCompletion(v string) *RecordUpsert {
|
|
u.Set(record.FieldCompletion, v)
|
|
return u
|
|
}
|
|
|
|
// UpdateCompletion sets the "completion" field to the value that was provided on create.
|
|
func (u *RecordUpsert) UpdateCompletion() *RecordUpsert {
|
|
u.SetExcluded(record.FieldCompletion)
|
|
return u
|
|
}
|
|
|
|
// ClearCompletion clears the value of the "completion" field.
|
|
func (u *RecordUpsert) ClearCompletion() *RecordUpsert {
|
|
u.SetNull(record.FieldCompletion)
|
|
return u
|
|
}
|
|
|
|
// SetIsAccept sets the "is_accept" field.
|
|
func (u *RecordUpsert) SetIsAccept(v bool) *RecordUpsert {
|
|
u.Set(record.FieldIsAccept, v)
|
|
return u
|
|
}
|
|
|
|
// UpdateIsAccept sets the "is_accept" field to the value that was provided on create.
|
|
func (u *RecordUpsert) UpdateIsAccept() *RecordUpsert {
|
|
u.SetExcluded(record.FieldIsAccept)
|
|
return u
|
|
}
|
|
|
|
// SetProgramLanguage sets the "program_language" field.
|
|
func (u *RecordUpsert) SetProgramLanguage(v string) *RecordUpsert {
|
|
u.Set(record.FieldProgramLanguage, v)
|
|
return u
|
|
}
|
|
|
|
// UpdateProgramLanguage sets the "program_language" field to the value that was provided on create.
|
|
func (u *RecordUpsert) UpdateProgramLanguage() *RecordUpsert {
|
|
u.SetExcluded(record.FieldProgramLanguage)
|
|
return u
|
|
}
|
|
|
|
// ClearProgramLanguage clears the value of the "program_language" field.
|
|
func (u *RecordUpsert) ClearProgramLanguage() *RecordUpsert {
|
|
u.SetNull(record.FieldProgramLanguage)
|
|
return u
|
|
}
|
|
|
|
// SetWorkMode sets the "work_mode" field.
|
|
func (u *RecordUpsert) SetWorkMode(v string) *RecordUpsert {
|
|
u.Set(record.FieldWorkMode, v)
|
|
return u
|
|
}
|
|
|
|
// UpdateWorkMode sets the "work_mode" field to the value that was provided on create.
|
|
func (u *RecordUpsert) UpdateWorkMode() *RecordUpsert {
|
|
u.SetExcluded(record.FieldWorkMode)
|
|
return u
|
|
}
|
|
|
|
// ClearWorkMode clears the value of the "work_mode" field.
|
|
func (u *RecordUpsert) ClearWorkMode() *RecordUpsert {
|
|
u.SetNull(record.FieldWorkMode)
|
|
return u
|
|
}
|
|
|
|
// SetCodeLines sets the "code_lines" field.
|
|
func (u *RecordUpsert) SetCodeLines(v int64) *RecordUpsert {
|
|
u.Set(record.FieldCodeLines, v)
|
|
return u
|
|
}
|
|
|
|
// UpdateCodeLines sets the "code_lines" field to the value that was provided on create.
|
|
func (u *RecordUpsert) UpdateCodeLines() *RecordUpsert {
|
|
u.SetExcluded(record.FieldCodeLines)
|
|
return u
|
|
}
|
|
|
|
// AddCodeLines adds v to the "code_lines" field.
|
|
func (u *RecordUpsert) AddCodeLines(v int64) *RecordUpsert {
|
|
u.Add(record.FieldCodeLines, v)
|
|
return u
|
|
}
|
|
|
|
// ClearCodeLines clears the value of the "code_lines" field.
|
|
func (u *RecordUpsert) ClearCodeLines() *RecordUpsert {
|
|
u.SetNull(record.FieldCodeLines)
|
|
return u
|
|
}
|
|
|
|
// SetInputTokens sets the "input_tokens" field.
|
|
func (u *RecordUpsert) SetInputTokens(v int64) *RecordUpsert {
|
|
u.Set(record.FieldInputTokens, v)
|
|
return u
|
|
}
|
|
|
|
// UpdateInputTokens sets the "input_tokens" field to the value that was provided on create.
|
|
func (u *RecordUpsert) UpdateInputTokens() *RecordUpsert {
|
|
u.SetExcluded(record.FieldInputTokens)
|
|
return u
|
|
}
|
|
|
|
// AddInputTokens adds v to the "input_tokens" field.
|
|
func (u *RecordUpsert) AddInputTokens(v int64) *RecordUpsert {
|
|
u.Add(record.FieldInputTokens, v)
|
|
return u
|
|
}
|
|
|
|
// SetOutputTokens sets the "output_tokens" field.
|
|
func (u *RecordUpsert) SetOutputTokens(v int64) *RecordUpsert {
|
|
u.Set(record.FieldOutputTokens, v)
|
|
return u
|
|
}
|
|
|
|
// UpdateOutputTokens sets the "output_tokens" field to the value that was provided on create.
|
|
func (u *RecordUpsert) UpdateOutputTokens() *RecordUpsert {
|
|
u.SetExcluded(record.FieldOutputTokens)
|
|
return u
|
|
}
|
|
|
|
// AddOutputTokens adds v to the "output_tokens" field.
|
|
func (u *RecordUpsert) AddOutputTokens(v int64) *RecordUpsert {
|
|
u.Add(record.FieldOutputTokens, v)
|
|
return u
|
|
}
|
|
|
|
// SetCreatedAt sets the "created_at" field.
|
|
func (u *RecordUpsert) SetCreatedAt(v time.Time) *RecordUpsert {
|
|
u.Set(record.FieldCreatedAt, v)
|
|
return u
|
|
}
|
|
|
|
// UpdateCreatedAt sets the "created_at" field to the value that was provided on create.
|
|
func (u *RecordUpsert) UpdateCreatedAt() *RecordUpsert {
|
|
u.SetExcluded(record.FieldCreatedAt)
|
|
return u
|
|
}
|
|
|
|
// SetUpdatedAt sets the "updated_at" field.
|
|
func (u *RecordUpsert) SetUpdatedAt(v time.Time) *RecordUpsert {
|
|
u.Set(record.FieldUpdatedAt, v)
|
|
return u
|
|
}
|
|
|
|
// UpdateUpdatedAt sets the "updated_at" field to the value that was provided on create.
|
|
func (u *RecordUpsert) UpdateUpdatedAt() *RecordUpsert {
|
|
u.SetExcluded(record.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.Record.Create().
|
|
// OnConflict(
|
|
// sql.ResolveWithNewValues(),
|
|
// sql.ResolveWith(func(u *sql.UpdateSet) {
|
|
// u.SetIgnore(record.FieldID)
|
|
// }),
|
|
// ).
|
|
// Exec(ctx)
|
|
func (u *RecordUpsertOne) UpdateNewValues() *RecordUpsertOne {
|
|
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(record.FieldID)
|
|
}
|
|
}))
|
|
return u
|
|
}
|
|
|
|
// Ignore sets each column to itself in case of conflict.
|
|
// Using this option is equivalent to using:
|
|
//
|
|
// client.Record.Create().
|
|
// OnConflict(sql.ResolveWithIgnore()).
|
|
// Exec(ctx)
|
|
func (u *RecordUpsertOne) Ignore() *RecordUpsertOne {
|
|
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 *RecordUpsertOne) DoNothing() *RecordUpsertOne {
|
|
u.create.conflict = append(u.create.conflict, sql.DoNothing())
|
|
return u
|
|
}
|
|
|
|
// Update allows overriding fields `UPDATE` values. See the RecordCreate.OnConflict
|
|
// documentation for more info.
|
|
func (u *RecordUpsertOne) Update(set func(*RecordUpsert)) *RecordUpsertOne {
|
|
u.create.conflict = append(u.create.conflict, sql.ResolveWith(func(update *sql.UpdateSet) {
|
|
set(&RecordUpsert{UpdateSet: update})
|
|
}))
|
|
return u
|
|
}
|
|
|
|
// SetUserID sets the "user_id" field.
|
|
func (u *RecordUpsertOne) SetUserID(v uuid.UUID) *RecordUpsertOne {
|
|
return u.Update(func(s *RecordUpsert) {
|
|
s.SetUserID(v)
|
|
})
|
|
}
|
|
|
|
// UpdateUserID sets the "user_id" field to the value that was provided on create.
|
|
func (u *RecordUpsertOne) UpdateUserID() *RecordUpsertOne {
|
|
return u.Update(func(s *RecordUpsert) {
|
|
s.UpdateUserID()
|
|
})
|
|
}
|
|
|
|
// ClearUserID clears the value of the "user_id" field.
|
|
func (u *RecordUpsertOne) ClearUserID() *RecordUpsertOne {
|
|
return u.Update(func(s *RecordUpsert) {
|
|
s.ClearUserID()
|
|
})
|
|
}
|
|
|
|
// SetModelID sets the "model_id" field.
|
|
func (u *RecordUpsertOne) SetModelID(v uuid.UUID) *RecordUpsertOne {
|
|
return u.Update(func(s *RecordUpsert) {
|
|
s.SetModelID(v)
|
|
})
|
|
}
|
|
|
|
// UpdateModelID sets the "model_id" field to the value that was provided on create.
|
|
func (u *RecordUpsertOne) UpdateModelID() *RecordUpsertOne {
|
|
return u.Update(func(s *RecordUpsert) {
|
|
s.UpdateModelID()
|
|
})
|
|
}
|
|
|
|
// ClearModelID clears the value of the "model_id" field.
|
|
func (u *RecordUpsertOne) ClearModelID() *RecordUpsertOne {
|
|
return u.Update(func(s *RecordUpsert) {
|
|
s.ClearModelID()
|
|
})
|
|
}
|
|
|
|
// SetTaskID sets the "task_id" field.
|
|
func (u *RecordUpsertOne) SetTaskID(v string) *RecordUpsertOne {
|
|
return u.Update(func(s *RecordUpsert) {
|
|
s.SetTaskID(v)
|
|
})
|
|
}
|
|
|
|
// UpdateTaskID sets the "task_id" field to the value that was provided on create.
|
|
func (u *RecordUpsertOne) UpdateTaskID() *RecordUpsertOne {
|
|
return u.Update(func(s *RecordUpsert) {
|
|
s.UpdateTaskID()
|
|
})
|
|
}
|
|
|
|
// SetModelType sets the "model_type" field.
|
|
func (u *RecordUpsertOne) SetModelType(v consts.ModelType) *RecordUpsertOne {
|
|
return u.Update(func(s *RecordUpsert) {
|
|
s.SetModelType(v)
|
|
})
|
|
}
|
|
|
|
// UpdateModelType sets the "model_type" field to the value that was provided on create.
|
|
func (u *RecordUpsertOne) UpdateModelType() *RecordUpsertOne {
|
|
return u.Update(func(s *RecordUpsert) {
|
|
s.UpdateModelType()
|
|
})
|
|
}
|
|
|
|
// ClearModelType clears the value of the "model_type" field.
|
|
func (u *RecordUpsertOne) ClearModelType() *RecordUpsertOne {
|
|
return u.Update(func(s *RecordUpsert) {
|
|
s.ClearModelType()
|
|
})
|
|
}
|
|
|
|
// SetPrompt sets the "prompt" field.
|
|
func (u *RecordUpsertOne) SetPrompt(v string) *RecordUpsertOne {
|
|
return u.Update(func(s *RecordUpsert) {
|
|
s.SetPrompt(v)
|
|
})
|
|
}
|
|
|
|
// UpdatePrompt sets the "prompt" field to the value that was provided on create.
|
|
func (u *RecordUpsertOne) UpdatePrompt() *RecordUpsertOne {
|
|
return u.Update(func(s *RecordUpsert) {
|
|
s.UpdatePrompt()
|
|
})
|
|
}
|
|
|
|
// ClearPrompt clears the value of the "prompt" field.
|
|
func (u *RecordUpsertOne) ClearPrompt() *RecordUpsertOne {
|
|
return u.Update(func(s *RecordUpsert) {
|
|
s.ClearPrompt()
|
|
})
|
|
}
|
|
|
|
// SetCompletion sets the "completion" field.
|
|
func (u *RecordUpsertOne) SetCompletion(v string) *RecordUpsertOne {
|
|
return u.Update(func(s *RecordUpsert) {
|
|
s.SetCompletion(v)
|
|
})
|
|
}
|
|
|
|
// UpdateCompletion sets the "completion" field to the value that was provided on create.
|
|
func (u *RecordUpsertOne) UpdateCompletion() *RecordUpsertOne {
|
|
return u.Update(func(s *RecordUpsert) {
|
|
s.UpdateCompletion()
|
|
})
|
|
}
|
|
|
|
// ClearCompletion clears the value of the "completion" field.
|
|
func (u *RecordUpsertOne) ClearCompletion() *RecordUpsertOne {
|
|
return u.Update(func(s *RecordUpsert) {
|
|
s.ClearCompletion()
|
|
})
|
|
}
|
|
|
|
// SetIsAccept sets the "is_accept" field.
|
|
func (u *RecordUpsertOne) SetIsAccept(v bool) *RecordUpsertOne {
|
|
return u.Update(func(s *RecordUpsert) {
|
|
s.SetIsAccept(v)
|
|
})
|
|
}
|
|
|
|
// UpdateIsAccept sets the "is_accept" field to the value that was provided on create.
|
|
func (u *RecordUpsertOne) UpdateIsAccept() *RecordUpsertOne {
|
|
return u.Update(func(s *RecordUpsert) {
|
|
s.UpdateIsAccept()
|
|
})
|
|
}
|
|
|
|
// SetProgramLanguage sets the "program_language" field.
|
|
func (u *RecordUpsertOne) SetProgramLanguage(v string) *RecordUpsertOne {
|
|
return u.Update(func(s *RecordUpsert) {
|
|
s.SetProgramLanguage(v)
|
|
})
|
|
}
|
|
|
|
// UpdateProgramLanguage sets the "program_language" field to the value that was provided on create.
|
|
func (u *RecordUpsertOne) UpdateProgramLanguage() *RecordUpsertOne {
|
|
return u.Update(func(s *RecordUpsert) {
|
|
s.UpdateProgramLanguage()
|
|
})
|
|
}
|
|
|
|
// ClearProgramLanguage clears the value of the "program_language" field.
|
|
func (u *RecordUpsertOne) ClearProgramLanguage() *RecordUpsertOne {
|
|
return u.Update(func(s *RecordUpsert) {
|
|
s.ClearProgramLanguage()
|
|
})
|
|
}
|
|
|
|
// SetWorkMode sets the "work_mode" field.
|
|
func (u *RecordUpsertOne) SetWorkMode(v string) *RecordUpsertOne {
|
|
return u.Update(func(s *RecordUpsert) {
|
|
s.SetWorkMode(v)
|
|
})
|
|
}
|
|
|
|
// UpdateWorkMode sets the "work_mode" field to the value that was provided on create.
|
|
func (u *RecordUpsertOne) UpdateWorkMode() *RecordUpsertOne {
|
|
return u.Update(func(s *RecordUpsert) {
|
|
s.UpdateWorkMode()
|
|
})
|
|
}
|
|
|
|
// ClearWorkMode clears the value of the "work_mode" field.
|
|
func (u *RecordUpsertOne) ClearWorkMode() *RecordUpsertOne {
|
|
return u.Update(func(s *RecordUpsert) {
|
|
s.ClearWorkMode()
|
|
})
|
|
}
|
|
|
|
// SetCodeLines sets the "code_lines" field.
|
|
func (u *RecordUpsertOne) SetCodeLines(v int64) *RecordUpsertOne {
|
|
return u.Update(func(s *RecordUpsert) {
|
|
s.SetCodeLines(v)
|
|
})
|
|
}
|
|
|
|
// AddCodeLines adds v to the "code_lines" field.
|
|
func (u *RecordUpsertOne) AddCodeLines(v int64) *RecordUpsertOne {
|
|
return u.Update(func(s *RecordUpsert) {
|
|
s.AddCodeLines(v)
|
|
})
|
|
}
|
|
|
|
// UpdateCodeLines sets the "code_lines" field to the value that was provided on create.
|
|
func (u *RecordUpsertOne) UpdateCodeLines() *RecordUpsertOne {
|
|
return u.Update(func(s *RecordUpsert) {
|
|
s.UpdateCodeLines()
|
|
})
|
|
}
|
|
|
|
// ClearCodeLines clears the value of the "code_lines" field.
|
|
func (u *RecordUpsertOne) ClearCodeLines() *RecordUpsertOne {
|
|
return u.Update(func(s *RecordUpsert) {
|
|
s.ClearCodeLines()
|
|
})
|
|
}
|
|
|
|
// SetInputTokens sets the "input_tokens" field.
|
|
func (u *RecordUpsertOne) SetInputTokens(v int64) *RecordUpsertOne {
|
|
return u.Update(func(s *RecordUpsert) {
|
|
s.SetInputTokens(v)
|
|
})
|
|
}
|
|
|
|
// AddInputTokens adds v to the "input_tokens" field.
|
|
func (u *RecordUpsertOne) AddInputTokens(v int64) *RecordUpsertOne {
|
|
return u.Update(func(s *RecordUpsert) {
|
|
s.AddInputTokens(v)
|
|
})
|
|
}
|
|
|
|
// UpdateInputTokens sets the "input_tokens" field to the value that was provided on create.
|
|
func (u *RecordUpsertOne) UpdateInputTokens() *RecordUpsertOne {
|
|
return u.Update(func(s *RecordUpsert) {
|
|
s.UpdateInputTokens()
|
|
})
|
|
}
|
|
|
|
// SetOutputTokens sets the "output_tokens" field.
|
|
func (u *RecordUpsertOne) SetOutputTokens(v int64) *RecordUpsertOne {
|
|
return u.Update(func(s *RecordUpsert) {
|
|
s.SetOutputTokens(v)
|
|
})
|
|
}
|
|
|
|
// AddOutputTokens adds v to the "output_tokens" field.
|
|
func (u *RecordUpsertOne) AddOutputTokens(v int64) *RecordUpsertOne {
|
|
return u.Update(func(s *RecordUpsert) {
|
|
s.AddOutputTokens(v)
|
|
})
|
|
}
|
|
|
|
// UpdateOutputTokens sets the "output_tokens" field to the value that was provided on create.
|
|
func (u *RecordUpsertOne) UpdateOutputTokens() *RecordUpsertOne {
|
|
return u.Update(func(s *RecordUpsert) {
|
|
s.UpdateOutputTokens()
|
|
})
|
|
}
|
|
|
|
// SetCreatedAt sets the "created_at" field.
|
|
func (u *RecordUpsertOne) SetCreatedAt(v time.Time) *RecordUpsertOne {
|
|
return u.Update(func(s *RecordUpsert) {
|
|
s.SetCreatedAt(v)
|
|
})
|
|
}
|
|
|
|
// UpdateCreatedAt sets the "created_at" field to the value that was provided on create.
|
|
func (u *RecordUpsertOne) UpdateCreatedAt() *RecordUpsertOne {
|
|
return u.Update(func(s *RecordUpsert) {
|
|
s.UpdateCreatedAt()
|
|
})
|
|
}
|
|
|
|
// SetUpdatedAt sets the "updated_at" field.
|
|
func (u *RecordUpsertOne) SetUpdatedAt(v time.Time) *RecordUpsertOne {
|
|
return u.Update(func(s *RecordUpsert) {
|
|
s.SetUpdatedAt(v)
|
|
})
|
|
}
|
|
|
|
// UpdateUpdatedAt sets the "updated_at" field to the value that was provided on create.
|
|
func (u *RecordUpsertOne) UpdateUpdatedAt() *RecordUpsertOne {
|
|
return u.Update(func(s *RecordUpsert) {
|
|
s.UpdateUpdatedAt()
|
|
})
|
|
}
|
|
|
|
// Exec executes the query.
|
|
func (u *RecordUpsertOne) Exec(ctx context.Context) error {
|
|
if len(u.create.conflict) == 0 {
|
|
return errors.New("db: missing options for RecordCreate.OnConflict")
|
|
}
|
|
return u.create.Exec(ctx)
|
|
}
|
|
|
|
// ExecX is like Exec, but panics if an error occurs.
|
|
func (u *RecordUpsertOne) 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 *RecordUpsertOne) 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: RecordUpsertOne.ID is not supported by MySQL driver. Use RecordUpsertOne.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 *RecordUpsertOne) IDX(ctx context.Context) uuid.UUID {
|
|
id, err := u.ID(ctx)
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
return id
|
|
}
|
|
|
|
// RecordCreateBulk is the builder for creating many Record entities in bulk.
|
|
type RecordCreateBulk struct {
|
|
config
|
|
err error
|
|
builders []*RecordCreate
|
|
conflict []sql.ConflictOption
|
|
}
|
|
|
|
// Save creates the Record entities in the database.
|
|
func (rcb *RecordCreateBulk) Save(ctx context.Context) ([]*Record, error) {
|
|
if rcb.err != nil {
|
|
return nil, rcb.err
|
|
}
|
|
specs := make([]*sqlgraph.CreateSpec, len(rcb.builders))
|
|
nodes := make([]*Record, len(rcb.builders))
|
|
mutators := make([]Mutator, len(rcb.builders))
|
|
for i := range rcb.builders {
|
|
func(i int, root context.Context) {
|
|
builder := rcb.builders[i]
|
|
builder.defaults()
|
|
var mut Mutator = MutateFunc(func(ctx context.Context, m Mutation) (Value, error) {
|
|
mutation, ok := m.(*RecordMutation)
|
|
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, rcb.builders[i+1].mutation)
|
|
} else {
|
|
spec := &sqlgraph.BatchCreateSpec{Nodes: specs}
|
|
spec.OnConflict = rcb.conflict
|
|
// Invoke the actual operation on the latest mutation in the chain.
|
|
if err = sqlgraph.BatchCreate(ctx, rcb.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, rcb.builders[0].mutation); err != nil {
|
|
return nil, err
|
|
}
|
|
}
|
|
return nodes, nil
|
|
}
|
|
|
|
// SaveX is like Save, but panics if an error occurs.
|
|
func (rcb *RecordCreateBulk) SaveX(ctx context.Context) []*Record {
|
|
v, err := rcb.Save(ctx)
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
return v
|
|
}
|
|
|
|
// Exec executes the query.
|
|
func (rcb *RecordCreateBulk) Exec(ctx context.Context) error {
|
|
_, err := rcb.Save(ctx)
|
|
return err
|
|
}
|
|
|
|
// ExecX is like Exec, but panics if an error occurs.
|
|
func (rcb *RecordCreateBulk) ExecX(ctx context.Context) {
|
|
if err := rcb.Exec(ctx); err != nil {
|
|
panic(err)
|
|
}
|
|
}
|
|
|
|
// OnConflict allows configuring the `ON CONFLICT` / `ON DUPLICATE KEY` clause
|
|
// of the `INSERT` statement. For example:
|
|
//
|
|
// client.Record.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.RecordUpsert) {
|
|
// SetUserID(v+v).
|
|
// }).
|
|
// Exec(ctx)
|
|
func (rcb *RecordCreateBulk) OnConflict(opts ...sql.ConflictOption) *RecordUpsertBulk {
|
|
rcb.conflict = opts
|
|
return &RecordUpsertBulk{
|
|
create: rcb,
|
|
}
|
|
}
|
|
|
|
// OnConflictColumns calls `OnConflict` and configures the columns
|
|
// as conflict target. Using this option is equivalent to using:
|
|
//
|
|
// client.Record.Create().
|
|
// OnConflict(sql.ConflictColumns(columns...)).
|
|
// Exec(ctx)
|
|
func (rcb *RecordCreateBulk) OnConflictColumns(columns ...string) *RecordUpsertBulk {
|
|
rcb.conflict = append(rcb.conflict, sql.ConflictColumns(columns...))
|
|
return &RecordUpsertBulk{
|
|
create: rcb,
|
|
}
|
|
}
|
|
|
|
// RecordUpsertBulk is the builder for "upsert"-ing
|
|
// a bulk of Record nodes.
|
|
type RecordUpsertBulk struct {
|
|
create *RecordCreateBulk
|
|
}
|
|
|
|
// UpdateNewValues updates the mutable fields using the new values that
|
|
// were set on create. Using this option is equivalent to using:
|
|
//
|
|
// client.Record.Create().
|
|
// OnConflict(
|
|
// sql.ResolveWithNewValues(),
|
|
// sql.ResolveWith(func(u *sql.UpdateSet) {
|
|
// u.SetIgnore(record.FieldID)
|
|
// }),
|
|
// ).
|
|
// Exec(ctx)
|
|
func (u *RecordUpsertBulk) UpdateNewValues() *RecordUpsertBulk {
|
|
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(record.FieldID)
|
|
}
|
|
}
|
|
}))
|
|
return u
|
|
}
|
|
|
|
// Ignore sets each column to itself in case of conflict.
|
|
// Using this option is equivalent to using:
|
|
//
|
|
// client.Record.Create().
|
|
// OnConflict(sql.ResolveWithIgnore()).
|
|
// Exec(ctx)
|
|
func (u *RecordUpsertBulk) Ignore() *RecordUpsertBulk {
|
|
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 *RecordUpsertBulk) DoNothing() *RecordUpsertBulk {
|
|
u.create.conflict = append(u.create.conflict, sql.DoNothing())
|
|
return u
|
|
}
|
|
|
|
// Update allows overriding fields `UPDATE` values. See the RecordCreateBulk.OnConflict
|
|
// documentation for more info.
|
|
func (u *RecordUpsertBulk) Update(set func(*RecordUpsert)) *RecordUpsertBulk {
|
|
u.create.conflict = append(u.create.conflict, sql.ResolveWith(func(update *sql.UpdateSet) {
|
|
set(&RecordUpsert{UpdateSet: update})
|
|
}))
|
|
return u
|
|
}
|
|
|
|
// SetUserID sets the "user_id" field.
|
|
func (u *RecordUpsertBulk) SetUserID(v uuid.UUID) *RecordUpsertBulk {
|
|
return u.Update(func(s *RecordUpsert) {
|
|
s.SetUserID(v)
|
|
})
|
|
}
|
|
|
|
// UpdateUserID sets the "user_id" field to the value that was provided on create.
|
|
func (u *RecordUpsertBulk) UpdateUserID() *RecordUpsertBulk {
|
|
return u.Update(func(s *RecordUpsert) {
|
|
s.UpdateUserID()
|
|
})
|
|
}
|
|
|
|
// ClearUserID clears the value of the "user_id" field.
|
|
func (u *RecordUpsertBulk) ClearUserID() *RecordUpsertBulk {
|
|
return u.Update(func(s *RecordUpsert) {
|
|
s.ClearUserID()
|
|
})
|
|
}
|
|
|
|
// SetModelID sets the "model_id" field.
|
|
func (u *RecordUpsertBulk) SetModelID(v uuid.UUID) *RecordUpsertBulk {
|
|
return u.Update(func(s *RecordUpsert) {
|
|
s.SetModelID(v)
|
|
})
|
|
}
|
|
|
|
// UpdateModelID sets the "model_id" field to the value that was provided on create.
|
|
func (u *RecordUpsertBulk) UpdateModelID() *RecordUpsertBulk {
|
|
return u.Update(func(s *RecordUpsert) {
|
|
s.UpdateModelID()
|
|
})
|
|
}
|
|
|
|
// ClearModelID clears the value of the "model_id" field.
|
|
func (u *RecordUpsertBulk) ClearModelID() *RecordUpsertBulk {
|
|
return u.Update(func(s *RecordUpsert) {
|
|
s.ClearModelID()
|
|
})
|
|
}
|
|
|
|
// SetTaskID sets the "task_id" field.
|
|
func (u *RecordUpsertBulk) SetTaskID(v string) *RecordUpsertBulk {
|
|
return u.Update(func(s *RecordUpsert) {
|
|
s.SetTaskID(v)
|
|
})
|
|
}
|
|
|
|
// UpdateTaskID sets the "task_id" field to the value that was provided on create.
|
|
func (u *RecordUpsertBulk) UpdateTaskID() *RecordUpsertBulk {
|
|
return u.Update(func(s *RecordUpsert) {
|
|
s.UpdateTaskID()
|
|
})
|
|
}
|
|
|
|
// SetModelType sets the "model_type" field.
|
|
func (u *RecordUpsertBulk) SetModelType(v consts.ModelType) *RecordUpsertBulk {
|
|
return u.Update(func(s *RecordUpsert) {
|
|
s.SetModelType(v)
|
|
})
|
|
}
|
|
|
|
// UpdateModelType sets the "model_type" field to the value that was provided on create.
|
|
func (u *RecordUpsertBulk) UpdateModelType() *RecordUpsertBulk {
|
|
return u.Update(func(s *RecordUpsert) {
|
|
s.UpdateModelType()
|
|
})
|
|
}
|
|
|
|
// ClearModelType clears the value of the "model_type" field.
|
|
func (u *RecordUpsertBulk) ClearModelType() *RecordUpsertBulk {
|
|
return u.Update(func(s *RecordUpsert) {
|
|
s.ClearModelType()
|
|
})
|
|
}
|
|
|
|
// SetPrompt sets the "prompt" field.
|
|
func (u *RecordUpsertBulk) SetPrompt(v string) *RecordUpsertBulk {
|
|
return u.Update(func(s *RecordUpsert) {
|
|
s.SetPrompt(v)
|
|
})
|
|
}
|
|
|
|
// UpdatePrompt sets the "prompt" field to the value that was provided on create.
|
|
func (u *RecordUpsertBulk) UpdatePrompt() *RecordUpsertBulk {
|
|
return u.Update(func(s *RecordUpsert) {
|
|
s.UpdatePrompt()
|
|
})
|
|
}
|
|
|
|
// ClearPrompt clears the value of the "prompt" field.
|
|
func (u *RecordUpsertBulk) ClearPrompt() *RecordUpsertBulk {
|
|
return u.Update(func(s *RecordUpsert) {
|
|
s.ClearPrompt()
|
|
})
|
|
}
|
|
|
|
// SetCompletion sets the "completion" field.
|
|
func (u *RecordUpsertBulk) SetCompletion(v string) *RecordUpsertBulk {
|
|
return u.Update(func(s *RecordUpsert) {
|
|
s.SetCompletion(v)
|
|
})
|
|
}
|
|
|
|
// UpdateCompletion sets the "completion" field to the value that was provided on create.
|
|
func (u *RecordUpsertBulk) UpdateCompletion() *RecordUpsertBulk {
|
|
return u.Update(func(s *RecordUpsert) {
|
|
s.UpdateCompletion()
|
|
})
|
|
}
|
|
|
|
// ClearCompletion clears the value of the "completion" field.
|
|
func (u *RecordUpsertBulk) ClearCompletion() *RecordUpsertBulk {
|
|
return u.Update(func(s *RecordUpsert) {
|
|
s.ClearCompletion()
|
|
})
|
|
}
|
|
|
|
// SetIsAccept sets the "is_accept" field.
|
|
func (u *RecordUpsertBulk) SetIsAccept(v bool) *RecordUpsertBulk {
|
|
return u.Update(func(s *RecordUpsert) {
|
|
s.SetIsAccept(v)
|
|
})
|
|
}
|
|
|
|
// UpdateIsAccept sets the "is_accept" field to the value that was provided on create.
|
|
func (u *RecordUpsertBulk) UpdateIsAccept() *RecordUpsertBulk {
|
|
return u.Update(func(s *RecordUpsert) {
|
|
s.UpdateIsAccept()
|
|
})
|
|
}
|
|
|
|
// SetProgramLanguage sets the "program_language" field.
|
|
func (u *RecordUpsertBulk) SetProgramLanguage(v string) *RecordUpsertBulk {
|
|
return u.Update(func(s *RecordUpsert) {
|
|
s.SetProgramLanguage(v)
|
|
})
|
|
}
|
|
|
|
// UpdateProgramLanguage sets the "program_language" field to the value that was provided on create.
|
|
func (u *RecordUpsertBulk) UpdateProgramLanguage() *RecordUpsertBulk {
|
|
return u.Update(func(s *RecordUpsert) {
|
|
s.UpdateProgramLanguage()
|
|
})
|
|
}
|
|
|
|
// ClearProgramLanguage clears the value of the "program_language" field.
|
|
func (u *RecordUpsertBulk) ClearProgramLanguage() *RecordUpsertBulk {
|
|
return u.Update(func(s *RecordUpsert) {
|
|
s.ClearProgramLanguage()
|
|
})
|
|
}
|
|
|
|
// SetWorkMode sets the "work_mode" field.
|
|
func (u *RecordUpsertBulk) SetWorkMode(v string) *RecordUpsertBulk {
|
|
return u.Update(func(s *RecordUpsert) {
|
|
s.SetWorkMode(v)
|
|
})
|
|
}
|
|
|
|
// UpdateWorkMode sets the "work_mode" field to the value that was provided on create.
|
|
func (u *RecordUpsertBulk) UpdateWorkMode() *RecordUpsertBulk {
|
|
return u.Update(func(s *RecordUpsert) {
|
|
s.UpdateWorkMode()
|
|
})
|
|
}
|
|
|
|
// ClearWorkMode clears the value of the "work_mode" field.
|
|
func (u *RecordUpsertBulk) ClearWorkMode() *RecordUpsertBulk {
|
|
return u.Update(func(s *RecordUpsert) {
|
|
s.ClearWorkMode()
|
|
})
|
|
}
|
|
|
|
// SetCodeLines sets the "code_lines" field.
|
|
func (u *RecordUpsertBulk) SetCodeLines(v int64) *RecordUpsertBulk {
|
|
return u.Update(func(s *RecordUpsert) {
|
|
s.SetCodeLines(v)
|
|
})
|
|
}
|
|
|
|
// AddCodeLines adds v to the "code_lines" field.
|
|
func (u *RecordUpsertBulk) AddCodeLines(v int64) *RecordUpsertBulk {
|
|
return u.Update(func(s *RecordUpsert) {
|
|
s.AddCodeLines(v)
|
|
})
|
|
}
|
|
|
|
// UpdateCodeLines sets the "code_lines" field to the value that was provided on create.
|
|
func (u *RecordUpsertBulk) UpdateCodeLines() *RecordUpsertBulk {
|
|
return u.Update(func(s *RecordUpsert) {
|
|
s.UpdateCodeLines()
|
|
})
|
|
}
|
|
|
|
// ClearCodeLines clears the value of the "code_lines" field.
|
|
func (u *RecordUpsertBulk) ClearCodeLines() *RecordUpsertBulk {
|
|
return u.Update(func(s *RecordUpsert) {
|
|
s.ClearCodeLines()
|
|
})
|
|
}
|
|
|
|
// SetInputTokens sets the "input_tokens" field.
|
|
func (u *RecordUpsertBulk) SetInputTokens(v int64) *RecordUpsertBulk {
|
|
return u.Update(func(s *RecordUpsert) {
|
|
s.SetInputTokens(v)
|
|
})
|
|
}
|
|
|
|
// AddInputTokens adds v to the "input_tokens" field.
|
|
func (u *RecordUpsertBulk) AddInputTokens(v int64) *RecordUpsertBulk {
|
|
return u.Update(func(s *RecordUpsert) {
|
|
s.AddInputTokens(v)
|
|
})
|
|
}
|
|
|
|
// UpdateInputTokens sets the "input_tokens" field to the value that was provided on create.
|
|
func (u *RecordUpsertBulk) UpdateInputTokens() *RecordUpsertBulk {
|
|
return u.Update(func(s *RecordUpsert) {
|
|
s.UpdateInputTokens()
|
|
})
|
|
}
|
|
|
|
// SetOutputTokens sets the "output_tokens" field.
|
|
func (u *RecordUpsertBulk) SetOutputTokens(v int64) *RecordUpsertBulk {
|
|
return u.Update(func(s *RecordUpsert) {
|
|
s.SetOutputTokens(v)
|
|
})
|
|
}
|
|
|
|
// AddOutputTokens adds v to the "output_tokens" field.
|
|
func (u *RecordUpsertBulk) AddOutputTokens(v int64) *RecordUpsertBulk {
|
|
return u.Update(func(s *RecordUpsert) {
|
|
s.AddOutputTokens(v)
|
|
})
|
|
}
|
|
|
|
// UpdateOutputTokens sets the "output_tokens" field to the value that was provided on create.
|
|
func (u *RecordUpsertBulk) UpdateOutputTokens() *RecordUpsertBulk {
|
|
return u.Update(func(s *RecordUpsert) {
|
|
s.UpdateOutputTokens()
|
|
})
|
|
}
|
|
|
|
// SetCreatedAt sets the "created_at" field.
|
|
func (u *RecordUpsertBulk) SetCreatedAt(v time.Time) *RecordUpsertBulk {
|
|
return u.Update(func(s *RecordUpsert) {
|
|
s.SetCreatedAt(v)
|
|
})
|
|
}
|
|
|
|
// UpdateCreatedAt sets the "created_at" field to the value that was provided on create.
|
|
func (u *RecordUpsertBulk) UpdateCreatedAt() *RecordUpsertBulk {
|
|
return u.Update(func(s *RecordUpsert) {
|
|
s.UpdateCreatedAt()
|
|
})
|
|
}
|
|
|
|
// SetUpdatedAt sets the "updated_at" field.
|
|
func (u *RecordUpsertBulk) SetUpdatedAt(v time.Time) *RecordUpsertBulk {
|
|
return u.Update(func(s *RecordUpsert) {
|
|
s.SetUpdatedAt(v)
|
|
})
|
|
}
|
|
|
|
// UpdateUpdatedAt sets the "updated_at" field to the value that was provided on create.
|
|
func (u *RecordUpsertBulk) UpdateUpdatedAt() *RecordUpsertBulk {
|
|
return u.Update(func(s *RecordUpsert) {
|
|
s.UpdateUpdatedAt()
|
|
})
|
|
}
|
|
|
|
// Exec executes the query.
|
|
func (u *RecordUpsertBulk) 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 RecordCreateBulk instead", i)
|
|
}
|
|
}
|
|
if len(u.create.conflict) == 0 {
|
|
return errors.New("db: missing options for RecordCreateBulk.OnConflict")
|
|
}
|
|
return u.create.Exec(ctx)
|
|
}
|
|
|
|
// ExecX is like Exec, but panics if an error occurs.
|
|
func (u *RecordUpsertBulk) ExecX(ctx context.Context) {
|
|
if err := u.create.Exec(ctx); err != nil {
|
|
panic(err)
|
|
}
|
|
}
|