mirror of
https://github.com/chaitin/MonkeyCode.git
synced 2026-11-23 04:09:15 +08:00
943 lines
28 KiB
Go
943 lines
28 KiB
Go
// Code generated by ent, DO NOT EDIT.
|
|
|
|
package db
|
|
|
|
import (
|
|
"context"
|
|
"errors"
|
|
"fmt"
|
|
"time"
|
|
|
|
"entgo.io/ent/dialect"
|
|
"entgo.io/ent/dialect/sql"
|
|
"entgo.io/ent/dialect/sql/sqlgraph"
|
|
"entgo.io/ent/schema/field"
|
|
"github.com/chaitin/MonkeyCode/backend/db/model"
|
|
"github.com/chaitin/MonkeyCode/backend/db/modelpricing"
|
|
"github.com/google/uuid"
|
|
)
|
|
|
|
// ModelPricingCreate is the builder for creating a ModelPricing entity.
|
|
type ModelPricingCreate struct {
|
|
config
|
|
mutation *ModelPricingMutation
|
|
hooks []Hook
|
|
conflict []sql.ConflictOption
|
|
}
|
|
|
|
// SetModelID sets the "model_id" field.
|
|
func (_c *ModelPricingCreate) SetModelID(v uuid.UUID) *ModelPricingCreate {
|
|
_c.mutation.SetModelID(v)
|
|
return _c
|
|
}
|
|
|
|
// SetAccessLevel sets the "access_level" field.
|
|
func (_c *ModelPricingCreate) SetAccessLevel(v string) *ModelPricingCreate {
|
|
_c.mutation.SetAccessLevel(v)
|
|
return _c
|
|
}
|
|
|
|
// SetIsFree sets the "is_free" field.
|
|
func (_c *ModelPricingCreate) SetIsFree(v bool) *ModelPricingCreate {
|
|
_c.mutation.SetIsFree(v)
|
|
return _c
|
|
}
|
|
|
|
// SetNillableIsFree sets the "is_free" field if the given value is not nil.
|
|
func (_c *ModelPricingCreate) SetNillableIsFree(v *bool) *ModelPricingCreate {
|
|
if v != nil {
|
|
_c.SetIsFree(*v)
|
|
}
|
|
return _c
|
|
}
|
|
|
|
// SetInputPrice sets the "input_price" field.
|
|
func (_c *ModelPricingCreate) SetInputPrice(v int64) *ModelPricingCreate {
|
|
_c.mutation.SetInputPrice(v)
|
|
return _c
|
|
}
|
|
|
|
// SetNillableInputPrice sets the "input_price" field if the given value is not nil.
|
|
func (_c *ModelPricingCreate) SetNillableInputPrice(v *int64) *ModelPricingCreate {
|
|
if v != nil {
|
|
_c.SetInputPrice(*v)
|
|
}
|
|
return _c
|
|
}
|
|
|
|
// SetOutputPrice sets the "output_price" field.
|
|
func (_c *ModelPricingCreate) SetOutputPrice(v int64) *ModelPricingCreate {
|
|
_c.mutation.SetOutputPrice(v)
|
|
return _c
|
|
}
|
|
|
|
// SetNillableOutputPrice sets the "output_price" field if the given value is not nil.
|
|
func (_c *ModelPricingCreate) SetNillableOutputPrice(v *int64) *ModelPricingCreate {
|
|
if v != nil {
|
|
_c.SetOutputPrice(*v)
|
|
}
|
|
return _c
|
|
}
|
|
|
|
// SetCreatedAt sets the "created_at" field.
|
|
func (_c *ModelPricingCreate) SetCreatedAt(v time.Time) *ModelPricingCreate {
|
|
_c.mutation.SetCreatedAt(v)
|
|
return _c
|
|
}
|
|
|
|
// SetNillableCreatedAt sets the "created_at" field if the given value is not nil.
|
|
func (_c *ModelPricingCreate) SetNillableCreatedAt(v *time.Time) *ModelPricingCreate {
|
|
if v != nil {
|
|
_c.SetCreatedAt(*v)
|
|
}
|
|
return _c
|
|
}
|
|
|
|
// SetUpdatedAt sets the "updated_at" field.
|
|
func (_c *ModelPricingCreate) SetUpdatedAt(v time.Time) *ModelPricingCreate {
|
|
_c.mutation.SetUpdatedAt(v)
|
|
return _c
|
|
}
|
|
|
|
// SetNillableUpdatedAt sets the "updated_at" field if the given value is not nil.
|
|
func (_c *ModelPricingCreate) SetNillableUpdatedAt(v *time.Time) *ModelPricingCreate {
|
|
if v != nil {
|
|
_c.SetUpdatedAt(*v)
|
|
}
|
|
return _c
|
|
}
|
|
|
|
// SetID sets the "id" field.
|
|
func (_c *ModelPricingCreate) SetID(v uuid.UUID) *ModelPricingCreate {
|
|
_c.mutation.SetID(v)
|
|
return _c
|
|
}
|
|
|
|
// SetModel sets the "model" edge to the Model entity.
|
|
func (_c *ModelPricingCreate) SetModel(v *Model) *ModelPricingCreate {
|
|
return _c.SetModelID(v.ID)
|
|
}
|
|
|
|
// Mutation returns the ModelPricingMutation object of the builder.
|
|
func (_c *ModelPricingCreate) Mutation() *ModelPricingMutation {
|
|
return _c.mutation
|
|
}
|
|
|
|
// Save creates the ModelPricing in the database.
|
|
func (_c *ModelPricingCreate) Save(ctx context.Context) (*ModelPricing, error) {
|
|
_c.defaults()
|
|
return withHooks(ctx, _c.sqlSave, _c.mutation, _c.hooks)
|
|
}
|
|
|
|
// SaveX calls Save and panics if Save returns an error.
|
|
func (_c *ModelPricingCreate) SaveX(ctx context.Context) *ModelPricing {
|
|
v, err := _c.Save(ctx)
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
return v
|
|
}
|
|
|
|
// Exec executes the query.
|
|
func (_c *ModelPricingCreate) Exec(ctx context.Context) error {
|
|
_, err := _c.Save(ctx)
|
|
return err
|
|
}
|
|
|
|
// ExecX is like Exec, but panics if an error occurs.
|
|
func (_c *ModelPricingCreate) ExecX(ctx context.Context) {
|
|
if err := _c.Exec(ctx); err != nil {
|
|
panic(err)
|
|
}
|
|
}
|
|
|
|
// defaults sets the default values of the builder before save.
|
|
func (_c *ModelPricingCreate) defaults() {
|
|
if _, ok := _c.mutation.IsFree(); !ok {
|
|
v := modelpricing.DefaultIsFree
|
|
_c.mutation.SetIsFree(v)
|
|
}
|
|
if _, ok := _c.mutation.InputPrice(); !ok {
|
|
v := modelpricing.DefaultInputPrice
|
|
_c.mutation.SetInputPrice(v)
|
|
}
|
|
if _, ok := _c.mutation.OutputPrice(); !ok {
|
|
v := modelpricing.DefaultOutputPrice
|
|
_c.mutation.SetOutputPrice(v)
|
|
}
|
|
if _, ok := _c.mutation.CreatedAt(); !ok {
|
|
v := modelpricing.DefaultCreatedAt()
|
|
_c.mutation.SetCreatedAt(v)
|
|
}
|
|
if _, ok := _c.mutation.UpdatedAt(); !ok {
|
|
v := modelpricing.DefaultUpdatedAt()
|
|
_c.mutation.SetUpdatedAt(v)
|
|
}
|
|
}
|
|
|
|
// check runs all checks and user-defined validators on the builder.
|
|
func (_c *ModelPricingCreate) check() error {
|
|
if _, ok := _c.mutation.ModelID(); !ok {
|
|
return &ValidationError{Name: "model_id", err: errors.New(`db: missing required field "ModelPricing.model_id"`)}
|
|
}
|
|
if _, ok := _c.mutation.AccessLevel(); !ok {
|
|
return &ValidationError{Name: "access_level", err: errors.New(`db: missing required field "ModelPricing.access_level"`)}
|
|
}
|
|
if v, ok := _c.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 _, ok := _c.mutation.IsFree(); !ok {
|
|
return &ValidationError{Name: "is_free", err: errors.New(`db: missing required field "ModelPricing.is_free"`)}
|
|
}
|
|
if _, ok := _c.mutation.InputPrice(); !ok {
|
|
return &ValidationError{Name: "input_price", err: errors.New(`db: missing required field "ModelPricing.input_price"`)}
|
|
}
|
|
if _, ok := _c.mutation.OutputPrice(); !ok {
|
|
return &ValidationError{Name: "output_price", err: errors.New(`db: missing required field "ModelPricing.output_price"`)}
|
|
}
|
|
if _, ok := _c.mutation.CreatedAt(); !ok {
|
|
return &ValidationError{Name: "created_at", err: errors.New(`db: missing required field "ModelPricing.created_at"`)}
|
|
}
|
|
if _, ok := _c.mutation.UpdatedAt(); !ok {
|
|
return &ValidationError{Name: "updated_at", err: errors.New(`db: missing required field "ModelPricing.updated_at"`)}
|
|
}
|
|
if len(_c.mutation.ModelIDs()) == 0 {
|
|
return &ValidationError{Name: "model", err: errors.New(`db: missing required edge "ModelPricing.model"`)}
|
|
}
|
|
return nil
|
|
}
|
|
|
|
func (_c *ModelPricingCreate) sqlSave(ctx context.Context) (*ModelPricing, error) {
|
|
if err := _c.check(); err != nil {
|
|
return nil, err
|
|
}
|
|
_node, _spec := _c.createSpec()
|
|
if err := sqlgraph.CreateNode(ctx, _c.driver, _spec); err != nil {
|
|
if sqlgraph.IsConstraintError(err) {
|
|
err = &ConstraintError{msg: err.Error(), wrap: err}
|
|
}
|
|
return nil, err
|
|
}
|
|
if _spec.ID.Value != nil {
|
|
if id, ok := _spec.ID.Value.(*uuid.UUID); ok {
|
|
_node.ID = *id
|
|
} else if err := _node.ID.Scan(_spec.ID.Value); err != nil {
|
|
return nil, err
|
|
}
|
|
}
|
|
_c.mutation.id = &_node.ID
|
|
_c.mutation.done = true
|
|
return _node, nil
|
|
}
|
|
|
|
func (_c *ModelPricingCreate) createSpec() (*ModelPricing, *sqlgraph.CreateSpec) {
|
|
var (
|
|
_node = &ModelPricing{config: _c.config}
|
|
_spec = sqlgraph.NewCreateSpec(modelpricing.Table, sqlgraph.NewFieldSpec(modelpricing.FieldID, field.TypeUUID))
|
|
)
|
|
_spec.OnConflict = _c.conflict
|
|
if id, ok := _c.mutation.ID(); ok {
|
|
_node.ID = id
|
|
_spec.ID.Value = &id
|
|
}
|
|
if value, ok := _c.mutation.AccessLevel(); ok {
|
|
_spec.SetField(modelpricing.FieldAccessLevel, field.TypeString, value)
|
|
_node.AccessLevel = value
|
|
}
|
|
if value, ok := _c.mutation.IsFree(); ok {
|
|
_spec.SetField(modelpricing.FieldIsFree, field.TypeBool, value)
|
|
_node.IsFree = value
|
|
}
|
|
if value, ok := _c.mutation.InputPrice(); ok {
|
|
_spec.SetField(modelpricing.FieldInputPrice, field.TypeInt64, value)
|
|
_node.InputPrice = value
|
|
}
|
|
if value, ok := _c.mutation.OutputPrice(); ok {
|
|
_spec.SetField(modelpricing.FieldOutputPrice, field.TypeInt64, value)
|
|
_node.OutputPrice = value
|
|
}
|
|
if value, ok := _c.mutation.CreatedAt(); ok {
|
|
_spec.SetField(modelpricing.FieldCreatedAt, field.TypeTime, value)
|
|
_node.CreatedAt = value
|
|
}
|
|
if value, ok := _c.mutation.UpdatedAt(); ok {
|
|
_spec.SetField(modelpricing.FieldUpdatedAt, field.TypeTime, value)
|
|
_node.UpdatedAt = value
|
|
}
|
|
if nodes := _c.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)
|
|
}
|
|
_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.ModelPricing.Create().
|
|
// SetModelID(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.ModelPricingUpsert) {
|
|
// SetModelID(v+v).
|
|
// }).
|
|
// Exec(ctx)
|
|
func (_c *ModelPricingCreate) OnConflict(opts ...sql.ConflictOption) *ModelPricingUpsertOne {
|
|
_c.conflict = opts
|
|
return &ModelPricingUpsertOne{
|
|
create: _c,
|
|
}
|
|
}
|
|
|
|
// OnConflictColumns calls `OnConflict` and configures the columns
|
|
// as conflict target. Using this option is equivalent to using:
|
|
//
|
|
// client.ModelPricing.Create().
|
|
// OnConflict(sql.ConflictColumns(columns...)).
|
|
// Exec(ctx)
|
|
func (_c *ModelPricingCreate) OnConflictColumns(columns ...string) *ModelPricingUpsertOne {
|
|
_c.conflict = append(_c.conflict, sql.ConflictColumns(columns...))
|
|
return &ModelPricingUpsertOne{
|
|
create: _c,
|
|
}
|
|
}
|
|
|
|
type (
|
|
// ModelPricingUpsertOne is the builder for "upsert"-ing
|
|
// one ModelPricing node.
|
|
ModelPricingUpsertOne struct {
|
|
create *ModelPricingCreate
|
|
}
|
|
|
|
// ModelPricingUpsert is the "OnConflict" setter.
|
|
ModelPricingUpsert struct {
|
|
*sql.UpdateSet
|
|
}
|
|
)
|
|
|
|
// SetModelID sets the "model_id" field.
|
|
func (u *ModelPricingUpsert) SetModelID(v uuid.UUID) *ModelPricingUpsert {
|
|
u.Set(modelpricing.FieldModelID, v)
|
|
return u
|
|
}
|
|
|
|
// UpdateModelID sets the "model_id" field to the value that was provided on create.
|
|
func (u *ModelPricingUpsert) UpdateModelID() *ModelPricingUpsert {
|
|
u.SetExcluded(modelpricing.FieldModelID)
|
|
return u
|
|
}
|
|
|
|
// SetAccessLevel sets the "access_level" field.
|
|
func (u *ModelPricingUpsert) SetAccessLevel(v string) *ModelPricingUpsert {
|
|
u.Set(modelpricing.FieldAccessLevel, v)
|
|
return u
|
|
}
|
|
|
|
// UpdateAccessLevel sets the "access_level" field to the value that was provided on create.
|
|
func (u *ModelPricingUpsert) UpdateAccessLevel() *ModelPricingUpsert {
|
|
u.SetExcluded(modelpricing.FieldAccessLevel)
|
|
return u
|
|
}
|
|
|
|
// SetIsFree sets the "is_free" field.
|
|
func (u *ModelPricingUpsert) SetIsFree(v bool) *ModelPricingUpsert {
|
|
u.Set(modelpricing.FieldIsFree, v)
|
|
return u
|
|
}
|
|
|
|
// UpdateIsFree sets the "is_free" field to the value that was provided on create.
|
|
func (u *ModelPricingUpsert) UpdateIsFree() *ModelPricingUpsert {
|
|
u.SetExcluded(modelpricing.FieldIsFree)
|
|
return u
|
|
}
|
|
|
|
// SetInputPrice sets the "input_price" field.
|
|
func (u *ModelPricingUpsert) SetInputPrice(v int64) *ModelPricingUpsert {
|
|
u.Set(modelpricing.FieldInputPrice, v)
|
|
return u
|
|
}
|
|
|
|
// UpdateInputPrice sets the "input_price" field to the value that was provided on create.
|
|
func (u *ModelPricingUpsert) UpdateInputPrice() *ModelPricingUpsert {
|
|
u.SetExcluded(modelpricing.FieldInputPrice)
|
|
return u
|
|
}
|
|
|
|
// AddInputPrice adds v to the "input_price" field.
|
|
func (u *ModelPricingUpsert) AddInputPrice(v int64) *ModelPricingUpsert {
|
|
u.Add(modelpricing.FieldInputPrice, v)
|
|
return u
|
|
}
|
|
|
|
// SetOutputPrice sets the "output_price" field.
|
|
func (u *ModelPricingUpsert) SetOutputPrice(v int64) *ModelPricingUpsert {
|
|
u.Set(modelpricing.FieldOutputPrice, v)
|
|
return u
|
|
}
|
|
|
|
// UpdateOutputPrice sets the "output_price" field to the value that was provided on create.
|
|
func (u *ModelPricingUpsert) UpdateOutputPrice() *ModelPricingUpsert {
|
|
u.SetExcluded(modelpricing.FieldOutputPrice)
|
|
return u
|
|
}
|
|
|
|
// AddOutputPrice adds v to the "output_price" field.
|
|
func (u *ModelPricingUpsert) AddOutputPrice(v int64) *ModelPricingUpsert {
|
|
u.Add(modelpricing.FieldOutputPrice, v)
|
|
return u
|
|
}
|
|
|
|
// SetCreatedAt sets the "created_at" field.
|
|
func (u *ModelPricingUpsert) SetCreatedAt(v time.Time) *ModelPricingUpsert {
|
|
u.Set(modelpricing.FieldCreatedAt, v)
|
|
return u
|
|
}
|
|
|
|
// UpdateCreatedAt sets the "created_at" field to the value that was provided on create.
|
|
func (u *ModelPricingUpsert) UpdateCreatedAt() *ModelPricingUpsert {
|
|
u.SetExcluded(modelpricing.FieldCreatedAt)
|
|
return u
|
|
}
|
|
|
|
// SetUpdatedAt sets the "updated_at" field.
|
|
func (u *ModelPricingUpsert) SetUpdatedAt(v time.Time) *ModelPricingUpsert {
|
|
u.Set(modelpricing.FieldUpdatedAt, v)
|
|
return u
|
|
}
|
|
|
|
// UpdateUpdatedAt sets the "updated_at" field to the value that was provided on create.
|
|
func (u *ModelPricingUpsert) UpdateUpdatedAt() *ModelPricingUpsert {
|
|
u.SetExcluded(modelpricing.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.ModelPricing.Create().
|
|
// OnConflict(
|
|
// sql.ResolveWithNewValues(),
|
|
// sql.ResolveWith(func(u *sql.UpdateSet) {
|
|
// u.SetIgnore(modelpricing.FieldID)
|
|
// }),
|
|
// ).
|
|
// Exec(ctx)
|
|
func (u *ModelPricingUpsertOne) UpdateNewValues() *ModelPricingUpsertOne {
|
|
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(modelpricing.FieldID)
|
|
}
|
|
}))
|
|
return u
|
|
}
|
|
|
|
// Ignore sets each column to itself in case of conflict.
|
|
// Using this option is equivalent to using:
|
|
//
|
|
// client.ModelPricing.Create().
|
|
// OnConflict(sql.ResolveWithIgnore()).
|
|
// Exec(ctx)
|
|
func (u *ModelPricingUpsertOne) Ignore() *ModelPricingUpsertOne {
|
|
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 *ModelPricingUpsertOne) DoNothing() *ModelPricingUpsertOne {
|
|
u.create.conflict = append(u.create.conflict, sql.DoNothing())
|
|
return u
|
|
}
|
|
|
|
// Update allows overriding fields `UPDATE` values. See the ModelPricingCreate.OnConflict
|
|
// documentation for more info.
|
|
func (u *ModelPricingUpsertOne) Update(set func(*ModelPricingUpsert)) *ModelPricingUpsertOne {
|
|
u.create.conflict = append(u.create.conflict, sql.ResolveWith(func(update *sql.UpdateSet) {
|
|
set(&ModelPricingUpsert{UpdateSet: update})
|
|
}))
|
|
return u
|
|
}
|
|
|
|
// SetModelID sets the "model_id" field.
|
|
func (u *ModelPricingUpsertOne) SetModelID(v uuid.UUID) *ModelPricingUpsertOne {
|
|
return u.Update(func(s *ModelPricingUpsert) {
|
|
s.SetModelID(v)
|
|
})
|
|
}
|
|
|
|
// UpdateModelID sets the "model_id" field to the value that was provided on create.
|
|
func (u *ModelPricingUpsertOne) UpdateModelID() *ModelPricingUpsertOne {
|
|
return u.Update(func(s *ModelPricingUpsert) {
|
|
s.UpdateModelID()
|
|
})
|
|
}
|
|
|
|
// SetAccessLevel sets the "access_level" field.
|
|
func (u *ModelPricingUpsertOne) SetAccessLevel(v string) *ModelPricingUpsertOne {
|
|
return u.Update(func(s *ModelPricingUpsert) {
|
|
s.SetAccessLevel(v)
|
|
})
|
|
}
|
|
|
|
// UpdateAccessLevel sets the "access_level" field to the value that was provided on create.
|
|
func (u *ModelPricingUpsertOne) UpdateAccessLevel() *ModelPricingUpsertOne {
|
|
return u.Update(func(s *ModelPricingUpsert) {
|
|
s.UpdateAccessLevel()
|
|
})
|
|
}
|
|
|
|
// SetIsFree sets the "is_free" field.
|
|
func (u *ModelPricingUpsertOne) SetIsFree(v bool) *ModelPricingUpsertOne {
|
|
return u.Update(func(s *ModelPricingUpsert) {
|
|
s.SetIsFree(v)
|
|
})
|
|
}
|
|
|
|
// UpdateIsFree sets the "is_free" field to the value that was provided on create.
|
|
func (u *ModelPricingUpsertOne) UpdateIsFree() *ModelPricingUpsertOne {
|
|
return u.Update(func(s *ModelPricingUpsert) {
|
|
s.UpdateIsFree()
|
|
})
|
|
}
|
|
|
|
// SetInputPrice sets the "input_price" field.
|
|
func (u *ModelPricingUpsertOne) SetInputPrice(v int64) *ModelPricingUpsertOne {
|
|
return u.Update(func(s *ModelPricingUpsert) {
|
|
s.SetInputPrice(v)
|
|
})
|
|
}
|
|
|
|
// AddInputPrice adds v to the "input_price" field.
|
|
func (u *ModelPricingUpsertOne) AddInputPrice(v int64) *ModelPricingUpsertOne {
|
|
return u.Update(func(s *ModelPricingUpsert) {
|
|
s.AddInputPrice(v)
|
|
})
|
|
}
|
|
|
|
// UpdateInputPrice sets the "input_price" field to the value that was provided on create.
|
|
func (u *ModelPricingUpsertOne) UpdateInputPrice() *ModelPricingUpsertOne {
|
|
return u.Update(func(s *ModelPricingUpsert) {
|
|
s.UpdateInputPrice()
|
|
})
|
|
}
|
|
|
|
// SetOutputPrice sets the "output_price" field.
|
|
func (u *ModelPricingUpsertOne) SetOutputPrice(v int64) *ModelPricingUpsertOne {
|
|
return u.Update(func(s *ModelPricingUpsert) {
|
|
s.SetOutputPrice(v)
|
|
})
|
|
}
|
|
|
|
// AddOutputPrice adds v to the "output_price" field.
|
|
func (u *ModelPricingUpsertOne) AddOutputPrice(v int64) *ModelPricingUpsertOne {
|
|
return u.Update(func(s *ModelPricingUpsert) {
|
|
s.AddOutputPrice(v)
|
|
})
|
|
}
|
|
|
|
// UpdateOutputPrice sets the "output_price" field to the value that was provided on create.
|
|
func (u *ModelPricingUpsertOne) UpdateOutputPrice() *ModelPricingUpsertOne {
|
|
return u.Update(func(s *ModelPricingUpsert) {
|
|
s.UpdateOutputPrice()
|
|
})
|
|
}
|
|
|
|
// SetCreatedAt sets the "created_at" field.
|
|
func (u *ModelPricingUpsertOne) SetCreatedAt(v time.Time) *ModelPricingUpsertOne {
|
|
return u.Update(func(s *ModelPricingUpsert) {
|
|
s.SetCreatedAt(v)
|
|
})
|
|
}
|
|
|
|
// UpdateCreatedAt sets the "created_at" field to the value that was provided on create.
|
|
func (u *ModelPricingUpsertOne) UpdateCreatedAt() *ModelPricingUpsertOne {
|
|
return u.Update(func(s *ModelPricingUpsert) {
|
|
s.UpdateCreatedAt()
|
|
})
|
|
}
|
|
|
|
// SetUpdatedAt sets the "updated_at" field.
|
|
func (u *ModelPricingUpsertOne) SetUpdatedAt(v time.Time) *ModelPricingUpsertOne {
|
|
return u.Update(func(s *ModelPricingUpsert) {
|
|
s.SetUpdatedAt(v)
|
|
})
|
|
}
|
|
|
|
// UpdateUpdatedAt sets the "updated_at" field to the value that was provided on create.
|
|
func (u *ModelPricingUpsertOne) UpdateUpdatedAt() *ModelPricingUpsertOne {
|
|
return u.Update(func(s *ModelPricingUpsert) {
|
|
s.UpdateUpdatedAt()
|
|
})
|
|
}
|
|
|
|
// Exec executes the query.
|
|
func (u *ModelPricingUpsertOne) Exec(ctx context.Context) error {
|
|
if len(u.create.conflict) == 0 {
|
|
return errors.New("db: missing options for ModelPricingCreate.OnConflict")
|
|
}
|
|
return u.create.Exec(ctx)
|
|
}
|
|
|
|
// ExecX is like Exec, but panics if an error occurs.
|
|
func (u *ModelPricingUpsertOne) 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 *ModelPricingUpsertOne) 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: ModelPricingUpsertOne.ID is not supported by MySQL driver. Use ModelPricingUpsertOne.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 *ModelPricingUpsertOne) IDX(ctx context.Context) uuid.UUID {
|
|
id, err := u.ID(ctx)
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
return id
|
|
}
|
|
|
|
// ModelPricingCreateBulk is the builder for creating many ModelPricing entities in bulk.
|
|
type ModelPricingCreateBulk struct {
|
|
config
|
|
err error
|
|
builders []*ModelPricingCreate
|
|
conflict []sql.ConflictOption
|
|
}
|
|
|
|
// Save creates the ModelPricing entities in the database.
|
|
func (_c *ModelPricingCreateBulk) Save(ctx context.Context) ([]*ModelPricing, error) {
|
|
if _c.err != nil {
|
|
return nil, _c.err
|
|
}
|
|
specs := make([]*sqlgraph.CreateSpec, len(_c.builders))
|
|
nodes := make([]*ModelPricing, len(_c.builders))
|
|
mutators := make([]Mutator, len(_c.builders))
|
|
for i := range _c.builders {
|
|
func(i int, root context.Context) {
|
|
builder := _c.builders[i]
|
|
builder.defaults()
|
|
var mut Mutator = MutateFunc(func(ctx context.Context, m Mutation) (Value, error) {
|
|
mutation, ok := m.(*ModelPricingMutation)
|
|
if !ok {
|
|
return nil, fmt.Errorf("unexpected mutation type %T", m)
|
|
}
|
|
if err := builder.check(); err != nil {
|
|
return nil, err
|
|
}
|
|
builder.mutation = mutation
|
|
var err error
|
|
nodes[i], specs[i] = builder.createSpec()
|
|
if i < len(mutators)-1 {
|
|
_, err = mutators[i+1].Mutate(root, _c.builders[i+1].mutation)
|
|
} else {
|
|
spec := &sqlgraph.BatchCreateSpec{Nodes: specs}
|
|
spec.OnConflict = _c.conflict
|
|
// Invoke the actual operation on the latest mutation in the chain.
|
|
if err = sqlgraph.BatchCreate(ctx, _c.driver, spec); err != nil {
|
|
if sqlgraph.IsConstraintError(err) {
|
|
err = &ConstraintError{msg: err.Error(), wrap: err}
|
|
}
|
|
}
|
|
}
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
mutation.id = &nodes[i].ID
|
|
mutation.done = true
|
|
return nodes[i], nil
|
|
})
|
|
for i := len(builder.hooks) - 1; i >= 0; i-- {
|
|
mut = builder.hooks[i](mut)
|
|
}
|
|
mutators[i] = mut
|
|
}(i, ctx)
|
|
}
|
|
if len(mutators) > 0 {
|
|
if _, err := mutators[0].Mutate(ctx, _c.builders[0].mutation); err != nil {
|
|
return nil, err
|
|
}
|
|
}
|
|
return nodes, nil
|
|
}
|
|
|
|
// SaveX is like Save, but panics if an error occurs.
|
|
func (_c *ModelPricingCreateBulk) SaveX(ctx context.Context) []*ModelPricing {
|
|
v, err := _c.Save(ctx)
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
return v
|
|
}
|
|
|
|
// Exec executes the query.
|
|
func (_c *ModelPricingCreateBulk) Exec(ctx context.Context) error {
|
|
_, err := _c.Save(ctx)
|
|
return err
|
|
}
|
|
|
|
// ExecX is like Exec, but panics if an error occurs.
|
|
func (_c *ModelPricingCreateBulk) ExecX(ctx context.Context) {
|
|
if err := _c.Exec(ctx); err != nil {
|
|
panic(err)
|
|
}
|
|
}
|
|
|
|
// OnConflict allows configuring the `ON CONFLICT` / `ON DUPLICATE KEY` clause
|
|
// of the `INSERT` statement. For example:
|
|
//
|
|
// client.ModelPricing.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.ModelPricingUpsert) {
|
|
// SetModelID(v+v).
|
|
// }).
|
|
// Exec(ctx)
|
|
func (_c *ModelPricingCreateBulk) OnConflict(opts ...sql.ConflictOption) *ModelPricingUpsertBulk {
|
|
_c.conflict = opts
|
|
return &ModelPricingUpsertBulk{
|
|
create: _c,
|
|
}
|
|
}
|
|
|
|
// OnConflictColumns calls `OnConflict` and configures the columns
|
|
// as conflict target. Using this option is equivalent to using:
|
|
//
|
|
// client.ModelPricing.Create().
|
|
// OnConflict(sql.ConflictColumns(columns...)).
|
|
// Exec(ctx)
|
|
func (_c *ModelPricingCreateBulk) OnConflictColumns(columns ...string) *ModelPricingUpsertBulk {
|
|
_c.conflict = append(_c.conflict, sql.ConflictColumns(columns...))
|
|
return &ModelPricingUpsertBulk{
|
|
create: _c,
|
|
}
|
|
}
|
|
|
|
// ModelPricingUpsertBulk is the builder for "upsert"-ing
|
|
// a bulk of ModelPricing nodes.
|
|
type ModelPricingUpsertBulk struct {
|
|
create *ModelPricingCreateBulk
|
|
}
|
|
|
|
// UpdateNewValues updates the mutable fields using the new values that
|
|
// were set on create. Using this option is equivalent to using:
|
|
//
|
|
// client.ModelPricing.Create().
|
|
// OnConflict(
|
|
// sql.ResolveWithNewValues(),
|
|
// sql.ResolveWith(func(u *sql.UpdateSet) {
|
|
// u.SetIgnore(modelpricing.FieldID)
|
|
// }),
|
|
// ).
|
|
// Exec(ctx)
|
|
func (u *ModelPricingUpsertBulk) UpdateNewValues() *ModelPricingUpsertBulk {
|
|
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(modelpricing.FieldID)
|
|
}
|
|
}
|
|
}))
|
|
return u
|
|
}
|
|
|
|
// Ignore sets each column to itself in case of conflict.
|
|
// Using this option is equivalent to using:
|
|
//
|
|
// client.ModelPricing.Create().
|
|
// OnConflict(sql.ResolveWithIgnore()).
|
|
// Exec(ctx)
|
|
func (u *ModelPricingUpsertBulk) Ignore() *ModelPricingUpsertBulk {
|
|
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 *ModelPricingUpsertBulk) DoNothing() *ModelPricingUpsertBulk {
|
|
u.create.conflict = append(u.create.conflict, sql.DoNothing())
|
|
return u
|
|
}
|
|
|
|
// Update allows overriding fields `UPDATE` values. See the ModelPricingCreateBulk.OnConflict
|
|
// documentation for more info.
|
|
func (u *ModelPricingUpsertBulk) Update(set func(*ModelPricingUpsert)) *ModelPricingUpsertBulk {
|
|
u.create.conflict = append(u.create.conflict, sql.ResolveWith(func(update *sql.UpdateSet) {
|
|
set(&ModelPricingUpsert{UpdateSet: update})
|
|
}))
|
|
return u
|
|
}
|
|
|
|
// SetModelID sets the "model_id" field.
|
|
func (u *ModelPricingUpsertBulk) SetModelID(v uuid.UUID) *ModelPricingUpsertBulk {
|
|
return u.Update(func(s *ModelPricingUpsert) {
|
|
s.SetModelID(v)
|
|
})
|
|
}
|
|
|
|
// UpdateModelID sets the "model_id" field to the value that was provided on create.
|
|
func (u *ModelPricingUpsertBulk) UpdateModelID() *ModelPricingUpsertBulk {
|
|
return u.Update(func(s *ModelPricingUpsert) {
|
|
s.UpdateModelID()
|
|
})
|
|
}
|
|
|
|
// SetAccessLevel sets the "access_level" field.
|
|
func (u *ModelPricingUpsertBulk) SetAccessLevel(v string) *ModelPricingUpsertBulk {
|
|
return u.Update(func(s *ModelPricingUpsert) {
|
|
s.SetAccessLevel(v)
|
|
})
|
|
}
|
|
|
|
// UpdateAccessLevel sets the "access_level" field to the value that was provided on create.
|
|
func (u *ModelPricingUpsertBulk) UpdateAccessLevel() *ModelPricingUpsertBulk {
|
|
return u.Update(func(s *ModelPricingUpsert) {
|
|
s.UpdateAccessLevel()
|
|
})
|
|
}
|
|
|
|
// SetIsFree sets the "is_free" field.
|
|
func (u *ModelPricingUpsertBulk) SetIsFree(v bool) *ModelPricingUpsertBulk {
|
|
return u.Update(func(s *ModelPricingUpsert) {
|
|
s.SetIsFree(v)
|
|
})
|
|
}
|
|
|
|
// UpdateIsFree sets the "is_free" field to the value that was provided on create.
|
|
func (u *ModelPricingUpsertBulk) UpdateIsFree() *ModelPricingUpsertBulk {
|
|
return u.Update(func(s *ModelPricingUpsert) {
|
|
s.UpdateIsFree()
|
|
})
|
|
}
|
|
|
|
// SetInputPrice sets the "input_price" field.
|
|
func (u *ModelPricingUpsertBulk) SetInputPrice(v int64) *ModelPricingUpsertBulk {
|
|
return u.Update(func(s *ModelPricingUpsert) {
|
|
s.SetInputPrice(v)
|
|
})
|
|
}
|
|
|
|
// AddInputPrice adds v to the "input_price" field.
|
|
func (u *ModelPricingUpsertBulk) AddInputPrice(v int64) *ModelPricingUpsertBulk {
|
|
return u.Update(func(s *ModelPricingUpsert) {
|
|
s.AddInputPrice(v)
|
|
})
|
|
}
|
|
|
|
// UpdateInputPrice sets the "input_price" field to the value that was provided on create.
|
|
func (u *ModelPricingUpsertBulk) UpdateInputPrice() *ModelPricingUpsertBulk {
|
|
return u.Update(func(s *ModelPricingUpsert) {
|
|
s.UpdateInputPrice()
|
|
})
|
|
}
|
|
|
|
// SetOutputPrice sets the "output_price" field.
|
|
func (u *ModelPricingUpsertBulk) SetOutputPrice(v int64) *ModelPricingUpsertBulk {
|
|
return u.Update(func(s *ModelPricingUpsert) {
|
|
s.SetOutputPrice(v)
|
|
})
|
|
}
|
|
|
|
// AddOutputPrice adds v to the "output_price" field.
|
|
func (u *ModelPricingUpsertBulk) AddOutputPrice(v int64) *ModelPricingUpsertBulk {
|
|
return u.Update(func(s *ModelPricingUpsert) {
|
|
s.AddOutputPrice(v)
|
|
})
|
|
}
|
|
|
|
// UpdateOutputPrice sets the "output_price" field to the value that was provided on create.
|
|
func (u *ModelPricingUpsertBulk) UpdateOutputPrice() *ModelPricingUpsertBulk {
|
|
return u.Update(func(s *ModelPricingUpsert) {
|
|
s.UpdateOutputPrice()
|
|
})
|
|
}
|
|
|
|
// SetCreatedAt sets the "created_at" field.
|
|
func (u *ModelPricingUpsertBulk) SetCreatedAt(v time.Time) *ModelPricingUpsertBulk {
|
|
return u.Update(func(s *ModelPricingUpsert) {
|
|
s.SetCreatedAt(v)
|
|
})
|
|
}
|
|
|
|
// UpdateCreatedAt sets the "created_at" field to the value that was provided on create.
|
|
func (u *ModelPricingUpsertBulk) UpdateCreatedAt() *ModelPricingUpsertBulk {
|
|
return u.Update(func(s *ModelPricingUpsert) {
|
|
s.UpdateCreatedAt()
|
|
})
|
|
}
|
|
|
|
// SetUpdatedAt sets the "updated_at" field.
|
|
func (u *ModelPricingUpsertBulk) SetUpdatedAt(v time.Time) *ModelPricingUpsertBulk {
|
|
return u.Update(func(s *ModelPricingUpsert) {
|
|
s.SetUpdatedAt(v)
|
|
})
|
|
}
|
|
|
|
// UpdateUpdatedAt sets the "updated_at" field to the value that was provided on create.
|
|
func (u *ModelPricingUpsertBulk) UpdateUpdatedAt() *ModelPricingUpsertBulk {
|
|
return u.Update(func(s *ModelPricingUpsert) {
|
|
s.UpdateUpdatedAt()
|
|
})
|
|
}
|
|
|
|
// Exec executes the query.
|
|
func (u *ModelPricingUpsertBulk) 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 ModelPricingCreateBulk instead", i)
|
|
}
|
|
}
|
|
if len(u.create.conflict) == 0 {
|
|
return errors.New("db: missing options for ModelPricingCreateBulk.OnConflict")
|
|
}
|
|
return u.create.Exec(ctx)
|
|
}
|
|
|
|
// ExecX is like Exec, but panics if an error occurs.
|
|
func (u *ModelPricingUpsertBulk) ExecX(ctx context.Context) {
|
|
if err := u.create.Exec(ctx); err != nil {
|
|
panic(err)
|
|
}
|
|
}
|