Files
MonkeyCode/backend/db/modelpricing_update.go
2026-04-03 01:31:20 +08:00

581 lines
18 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/db/model"
"github.com/chaitin/MonkeyCode/backend/db/modelpricing"
"github.com/chaitin/MonkeyCode/backend/db/predicate"
"github.com/google/uuid"
)
// ModelPricingUpdate is the builder for updating ModelPricing entities.
type ModelPricingUpdate struct {
config
hooks []Hook
mutation *ModelPricingMutation
modifiers []func(*sql.UpdateBuilder)
}
// Where appends a list predicates to the ModelPricingUpdate builder.
func (_u *ModelPricingUpdate) Where(ps ...predicate.ModelPricing) *ModelPricingUpdate {
_u.mutation.Where(ps...)
return _u
}
// SetModelID sets the "model_id" field.
func (_u *ModelPricingUpdate) SetModelID(v uuid.UUID) *ModelPricingUpdate {
_u.mutation.SetModelID(v)
return _u
}
// SetNillableModelID sets the "model_id" field if the given value is not nil.
func (_u *ModelPricingUpdate) SetNillableModelID(v *uuid.UUID) *ModelPricingUpdate {
if v != nil {
_u.SetModelID(*v)
}
return _u
}
// SetAccessLevel sets the "access_level" field.
func (_u *ModelPricingUpdate) SetAccessLevel(v string) *ModelPricingUpdate {
_u.mutation.SetAccessLevel(v)
return _u
}
// SetNillableAccessLevel sets the "access_level" field if the given value is not nil.
func (_u *ModelPricingUpdate) SetNillableAccessLevel(v *string) *ModelPricingUpdate {
if v != nil {
_u.SetAccessLevel(*v)
}
return _u
}
// SetIsFree sets the "is_free" field.
func (_u *ModelPricingUpdate) SetIsFree(v bool) *ModelPricingUpdate {
_u.mutation.SetIsFree(v)
return _u
}
// SetNillableIsFree sets the "is_free" field if the given value is not nil.
func (_u *ModelPricingUpdate) SetNillableIsFree(v *bool) *ModelPricingUpdate {
if v != nil {
_u.SetIsFree(*v)
}
return _u
}
// SetInputPrice sets the "input_price" field.
func (_u *ModelPricingUpdate) SetInputPrice(v int64) *ModelPricingUpdate {
_u.mutation.ResetInputPrice()
_u.mutation.SetInputPrice(v)
return _u
}
// SetNillableInputPrice sets the "input_price" field if the given value is not nil.
func (_u *ModelPricingUpdate) SetNillableInputPrice(v *int64) *ModelPricingUpdate {
if v != nil {
_u.SetInputPrice(*v)
}
return _u
}
// AddInputPrice adds value to the "input_price" field.
func (_u *ModelPricingUpdate) AddInputPrice(v int64) *ModelPricingUpdate {
_u.mutation.AddInputPrice(v)
return _u
}
// SetOutputPrice sets the "output_price" field.
func (_u *ModelPricingUpdate) SetOutputPrice(v int64) *ModelPricingUpdate {
_u.mutation.ResetOutputPrice()
_u.mutation.SetOutputPrice(v)
return _u
}
// SetNillableOutputPrice sets the "output_price" field if the given value is not nil.
func (_u *ModelPricingUpdate) SetNillableOutputPrice(v *int64) *ModelPricingUpdate {
if v != nil {
_u.SetOutputPrice(*v)
}
return _u
}
// AddOutputPrice adds value to the "output_price" field.
func (_u *ModelPricingUpdate) AddOutputPrice(v int64) *ModelPricingUpdate {
_u.mutation.AddOutputPrice(v)
return _u
}
// SetCreatedAt sets the "created_at" field.
func (_u *ModelPricingUpdate) SetCreatedAt(v time.Time) *ModelPricingUpdate {
_u.mutation.SetCreatedAt(v)
return _u
}
// SetNillableCreatedAt sets the "created_at" field if the given value is not nil.
func (_u *ModelPricingUpdate) SetNillableCreatedAt(v *time.Time) *ModelPricingUpdate {
if v != nil {
_u.SetCreatedAt(*v)
}
return _u
}
// SetUpdatedAt sets the "updated_at" field.
func (_u *ModelPricingUpdate) SetUpdatedAt(v time.Time) *ModelPricingUpdate {
_u.mutation.SetUpdatedAt(v)
return _u
}
// SetModel sets the "model" edge to the Model entity.
func (_u *ModelPricingUpdate) SetModel(v *Model) *ModelPricingUpdate {
return _u.SetModelID(v.ID)
}
// Mutation returns the ModelPricingMutation object of the builder.
func (_u *ModelPricingUpdate) Mutation() *ModelPricingMutation {
return _u.mutation
}
// ClearModel clears the "model" edge to the Model entity.
func (_u *ModelPricingUpdate) ClearModel() *ModelPricingUpdate {
_u.mutation.ClearModel()
return _u
}
// Save executes the query and returns the number of nodes affected by the update operation.
func (_u *ModelPricingUpdate) Save(ctx context.Context) (int, error) {
_u.defaults()
return withHooks(ctx, _u.sqlSave, _u.mutation, _u.hooks)
}
// SaveX is like Save, but panics if an error occurs.
func (_u *ModelPricingUpdate) SaveX(ctx context.Context) int {
affected, err := _u.Save(ctx)
if err != nil {
panic(err)
}
return affected
}
// Exec executes the query.
func (_u *ModelPricingUpdate) Exec(ctx context.Context) error {
_, err := _u.Save(ctx)
return err
}
// ExecX is like Exec, but panics if an error occurs.
func (_u *ModelPricingUpdate) ExecX(ctx context.Context) {
if err := _u.Exec(ctx); err != nil {
panic(err)
}
}
// defaults sets the default values of the builder before save.
func (_u *ModelPricingUpdate) defaults() {
if _, ok := _u.mutation.UpdatedAt(); !ok {
v := modelpricing.UpdateDefaultUpdatedAt()
_u.mutation.SetUpdatedAt(v)
}
}
// check runs all checks and user-defined validators on the builder.
func (_u *ModelPricingUpdate) check() error {
if v, ok := _u.mutation.AccessLevel(); ok {
if err := modelpricing.AccessLevelValidator(v); err != nil {
return &ValidationError{Name: "access_level", err: fmt.Errorf(`db: validator failed for field "ModelPricing.access_level": %w`, err)}
}
}
if _u.mutation.ModelCleared() && len(_u.mutation.ModelIDs()) > 0 {
return errors.New(`db: clearing a required unique edge "ModelPricing.model"`)
}
return nil
}
// Modify adds a statement modifier for attaching custom logic to the UPDATE statement.
func (_u *ModelPricingUpdate) Modify(modifiers ...func(u *sql.UpdateBuilder)) *ModelPricingUpdate {
_u.modifiers = append(_u.modifiers, modifiers...)
return _u
}
func (_u *ModelPricingUpdate) sqlSave(ctx context.Context) (_node int, err error) {
if err := _u.check(); err != nil {
return _node, err
}
_spec := sqlgraph.NewUpdateSpec(modelpricing.Table, modelpricing.Columns, sqlgraph.NewFieldSpec(modelpricing.FieldID, field.TypeUUID))
if ps := _u.mutation.predicates; len(ps) > 0 {
_spec.Predicate = func(selector *sql.Selector) {
for i := range ps {
ps[i](selector)
}
}
}
if value, ok := _u.mutation.AccessLevel(); ok {
_spec.SetField(modelpricing.FieldAccessLevel, field.TypeString, value)
}
if value, ok := _u.mutation.IsFree(); ok {
_spec.SetField(modelpricing.FieldIsFree, field.TypeBool, value)
}
if value, ok := _u.mutation.InputPrice(); ok {
_spec.SetField(modelpricing.FieldInputPrice, field.TypeInt64, value)
}
if value, ok := _u.mutation.AddedInputPrice(); ok {
_spec.AddField(modelpricing.FieldInputPrice, field.TypeInt64, value)
}
if value, ok := _u.mutation.OutputPrice(); ok {
_spec.SetField(modelpricing.FieldOutputPrice, field.TypeInt64, value)
}
if value, ok := _u.mutation.AddedOutputPrice(); ok {
_spec.AddField(modelpricing.FieldOutputPrice, field.TypeInt64, value)
}
if value, ok := _u.mutation.CreatedAt(); ok {
_spec.SetField(modelpricing.FieldCreatedAt, field.TypeTime, value)
}
if value, ok := _u.mutation.UpdatedAt(); ok {
_spec.SetField(modelpricing.FieldUpdatedAt, field.TypeTime, value)
}
if _u.mutation.ModelCleared() {
edge := &sqlgraph.EdgeSpec{
Rel: sqlgraph.O2O,
Inverse: true,
Table: modelpricing.ModelTable,
Columns: []string{modelpricing.ModelColumn},
Bidi: false,
Target: &sqlgraph.EdgeTarget{
IDSpec: sqlgraph.NewFieldSpec(model.FieldID, field.TypeUUID),
},
}
_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
}
if nodes := _u.mutation.ModelIDs(); len(nodes) > 0 {
edge := &sqlgraph.EdgeSpec{
Rel: sqlgraph.O2O,
Inverse: true,
Table: modelpricing.ModelTable,
Columns: []string{modelpricing.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(_u.modifiers...)
if _node, err = sqlgraph.UpdateNodes(ctx, _u.driver, _spec); err != nil {
if _, ok := err.(*sqlgraph.NotFoundError); ok {
err = &NotFoundError{modelpricing.Label}
} else if sqlgraph.IsConstraintError(err) {
err = &ConstraintError{msg: err.Error(), wrap: err}
}
return 0, err
}
_u.mutation.done = true
return _node, nil
}
// ModelPricingUpdateOne is the builder for updating a single ModelPricing entity.
type ModelPricingUpdateOne struct {
config
fields []string
hooks []Hook
mutation *ModelPricingMutation
modifiers []func(*sql.UpdateBuilder)
}
// SetModelID sets the "model_id" field.
func (_u *ModelPricingUpdateOne) SetModelID(v uuid.UUID) *ModelPricingUpdateOne {
_u.mutation.SetModelID(v)
return _u
}
// SetNillableModelID sets the "model_id" field if the given value is not nil.
func (_u *ModelPricingUpdateOne) SetNillableModelID(v *uuid.UUID) *ModelPricingUpdateOne {
if v != nil {
_u.SetModelID(*v)
}
return _u
}
// SetAccessLevel sets the "access_level" field.
func (_u *ModelPricingUpdateOne) SetAccessLevel(v string) *ModelPricingUpdateOne {
_u.mutation.SetAccessLevel(v)
return _u
}
// SetNillableAccessLevel sets the "access_level" field if the given value is not nil.
func (_u *ModelPricingUpdateOne) SetNillableAccessLevel(v *string) *ModelPricingUpdateOne {
if v != nil {
_u.SetAccessLevel(*v)
}
return _u
}
// SetIsFree sets the "is_free" field.
func (_u *ModelPricingUpdateOne) SetIsFree(v bool) *ModelPricingUpdateOne {
_u.mutation.SetIsFree(v)
return _u
}
// SetNillableIsFree sets the "is_free" field if the given value is not nil.
func (_u *ModelPricingUpdateOne) SetNillableIsFree(v *bool) *ModelPricingUpdateOne {
if v != nil {
_u.SetIsFree(*v)
}
return _u
}
// SetInputPrice sets the "input_price" field.
func (_u *ModelPricingUpdateOne) SetInputPrice(v int64) *ModelPricingUpdateOne {
_u.mutation.ResetInputPrice()
_u.mutation.SetInputPrice(v)
return _u
}
// SetNillableInputPrice sets the "input_price" field if the given value is not nil.
func (_u *ModelPricingUpdateOne) SetNillableInputPrice(v *int64) *ModelPricingUpdateOne {
if v != nil {
_u.SetInputPrice(*v)
}
return _u
}
// AddInputPrice adds value to the "input_price" field.
func (_u *ModelPricingUpdateOne) AddInputPrice(v int64) *ModelPricingUpdateOne {
_u.mutation.AddInputPrice(v)
return _u
}
// SetOutputPrice sets the "output_price" field.
func (_u *ModelPricingUpdateOne) SetOutputPrice(v int64) *ModelPricingUpdateOne {
_u.mutation.ResetOutputPrice()
_u.mutation.SetOutputPrice(v)
return _u
}
// SetNillableOutputPrice sets the "output_price" field if the given value is not nil.
func (_u *ModelPricingUpdateOne) SetNillableOutputPrice(v *int64) *ModelPricingUpdateOne {
if v != nil {
_u.SetOutputPrice(*v)
}
return _u
}
// AddOutputPrice adds value to the "output_price" field.
func (_u *ModelPricingUpdateOne) AddOutputPrice(v int64) *ModelPricingUpdateOne {
_u.mutation.AddOutputPrice(v)
return _u
}
// SetCreatedAt sets the "created_at" field.
func (_u *ModelPricingUpdateOne) SetCreatedAt(v time.Time) *ModelPricingUpdateOne {
_u.mutation.SetCreatedAt(v)
return _u
}
// SetNillableCreatedAt sets the "created_at" field if the given value is not nil.
func (_u *ModelPricingUpdateOne) SetNillableCreatedAt(v *time.Time) *ModelPricingUpdateOne {
if v != nil {
_u.SetCreatedAt(*v)
}
return _u
}
// SetUpdatedAt sets the "updated_at" field.
func (_u *ModelPricingUpdateOne) SetUpdatedAt(v time.Time) *ModelPricingUpdateOne {
_u.mutation.SetUpdatedAt(v)
return _u
}
// SetModel sets the "model" edge to the Model entity.
func (_u *ModelPricingUpdateOne) SetModel(v *Model) *ModelPricingUpdateOne {
return _u.SetModelID(v.ID)
}
// Mutation returns the ModelPricingMutation object of the builder.
func (_u *ModelPricingUpdateOne) Mutation() *ModelPricingMutation {
return _u.mutation
}
// ClearModel clears the "model" edge to the Model entity.
func (_u *ModelPricingUpdateOne) ClearModel() *ModelPricingUpdateOne {
_u.mutation.ClearModel()
return _u
}
// Where appends a list predicates to the ModelPricingUpdate builder.
func (_u *ModelPricingUpdateOne) Where(ps ...predicate.ModelPricing) *ModelPricingUpdateOne {
_u.mutation.Where(ps...)
return _u
}
// Select allows selecting one or more fields (columns) of the returned entity.
// The default is selecting all fields defined in the entity schema.
func (_u *ModelPricingUpdateOne) Select(field string, fields ...string) *ModelPricingUpdateOne {
_u.fields = append([]string{field}, fields...)
return _u
}
// Save executes the query and returns the updated ModelPricing entity.
func (_u *ModelPricingUpdateOne) Save(ctx context.Context) (*ModelPricing, error) {
_u.defaults()
return withHooks(ctx, _u.sqlSave, _u.mutation, _u.hooks)
}
// SaveX is like Save, but panics if an error occurs.
func (_u *ModelPricingUpdateOne) SaveX(ctx context.Context) *ModelPricing {
node, err := _u.Save(ctx)
if err != nil {
panic(err)
}
return node
}
// Exec executes the query on the entity.
func (_u *ModelPricingUpdateOne) Exec(ctx context.Context) error {
_, err := _u.Save(ctx)
return err
}
// ExecX is like Exec, but panics if an error occurs.
func (_u *ModelPricingUpdateOne) ExecX(ctx context.Context) {
if err := _u.Exec(ctx); err != nil {
panic(err)
}
}
// defaults sets the default values of the builder before save.
func (_u *ModelPricingUpdateOne) defaults() {
if _, ok := _u.mutation.UpdatedAt(); !ok {
v := modelpricing.UpdateDefaultUpdatedAt()
_u.mutation.SetUpdatedAt(v)
}
}
// check runs all checks and user-defined validators on the builder.
func (_u *ModelPricingUpdateOne) check() error {
if v, ok := _u.mutation.AccessLevel(); ok {
if err := modelpricing.AccessLevelValidator(v); err != nil {
return &ValidationError{Name: "access_level", err: fmt.Errorf(`db: validator failed for field "ModelPricing.access_level": %w`, err)}
}
}
if _u.mutation.ModelCleared() && len(_u.mutation.ModelIDs()) > 0 {
return errors.New(`db: clearing a required unique edge "ModelPricing.model"`)
}
return nil
}
// Modify adds a statement modifier for attaching custom logic to the UPDATE statement.
func (_u *ModelPricingUpdateOne) Modify(modifiers ...func(u *sql.UpdateBuilder)) *ModelPricingUpdateOne {
_u.modifiers = append(_u.modifiers, modifiers...)
return _u
}
func (_u *ModelPricingUpdateOne) sqlSave(ctx context.Context) (_node *ModelPricing, err error) {
if err := _u.check(); err != nil {
return _node, err
}
_spec := sqlgraph.NewUpdateSpec(modelpricing.Table, modelpricing.Columns, sqlgraph.NewFieldSpec(modelpricing.FieldID, field.TypeUUID))
id, ok := _u.mutation.ID()
if !ok {
return nil, &ValidationError{Name: "id", err: errors.New(`db: missing "ModelPricing.id" for update`)}
}
_spec.Node.ID.Value = id
if fields := _u.fields; len(fields) > 0 {
_spec.Node.Columns = make([]string, 0, len(fields))
_spec.Node.Columns = append(_spec.Node.Columns, modelpricing.FieldID)
for _, f := range fields {
if !modelpricing.ValidColumn(f) {
return nil, &ValidationError{Name: f, err: fmt.Errorf("db: invalid field %q for query", f)}
}
if f != modelpricing.FieldID {
_spec.Node.Columns = append(_spec.Node.Columns, f)
}
}
}
if ps := _u.mutation.predicates; len(ps) > 0 {
_spec.Predicate = func(selector *sql.Selector) {
for i := range ps {
ps[i](selector)
}
}
}
if value, ok := _u.mutation.AccessLevel(); ok {
_spec.SetField(modelpricing.FieldAccessLevel, field.TypeString, value)
}
if value, ok := _u.mutation.IsFree(); ok {
_spec.SetField(modelpricing.FieldIsFree, field.TypeBool, value)
}
if value, ok := _u.mutation.InputPrice(); ok {
_spec.SetField(modelpricing.FieldInputPrice, field.TypeInt64, value)
}
if value, ok := _u.mutation.AddedInputPrice(); ok {
_spec.AddField(modelpricing.FieldInputPrice, field.TypeInt64, value)
}
if value, ok := _u.mutation.OutputPrice(); ok {
_spec.SetField(modelpricing.FieldOutputPrice, field.TypeInt64, value)
}
if value, ok := _u.mutation.AddedOutputPrice(); ok {
_spec.AddField(modelpricing.FieldOutputPrice, field.TypeInt64, value)
}
if value, ok := _u.mutation.CreatedAt(); ok {
_spec.SetField(modelpricing.FieldCreatedAt, field.TypeTime, value)
}
if value, ok := _u.mutation.UpdatedAt(); ok {
_spec.SetField(modelpricing.FieldUpdatedAt, field.TypeTime, value)
}
if _u.mutation.ModelCleared() {
edge := &sqlgraph.EdgeSpec{
Rel: sqlgraph.O2O,
Inverse: true,
Table: modelpricing.ModelTable,
Columns: []string{modelpricing.ModelColumn},
Bidi: false,
Target: &sqlgraph.EdgeTarget{
IDSpec: sqlgraph.NewFieldSpec(model.FieldID, field.TypeUUID),
},
}
_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
}
if nodes := _u.mutation.ModelIDs(); len(nodes) > 0 {
edge := &sqlgraph.EdgeSpec{
Rel: sqlgraph.O2O,
Inverse: true,
Table: modelpricing.ModelTable,
Columns: []string{modelpricing.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(_u.modifiers...)
_node = &ModelPricing{config: _u.config}
_spec.Assign = _node.assignValues
_spec.ScanValues = _node.scanValues
if err = sqlgraph.UpdateNode(ctx, _u.driver, _spec); err != nil {
if _, ok := err.(*sqlgraph.NotFoundError); ok {
err = &NotFoundError{modelpricing.Label}
} else if sqlgraph.IsConstraintError(err) {
err = &ConstraintError{msg: err.Error(), wrap: err}
}
return nil, err
}
_u.mutation.done = true
return _node, nil
}