You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
cloudreve/ent/sku_create.go

1394 lines
36 KiB

// Code generated by ent, DO NOT EDIT.
package ent
import (
"context"
"errors"
"fmt"
"time"
"entgo.io/ent/dialect/sql"
"entgo.io/ent/dialect/sql/sqlgraph"
"entgo.io/ent/schema/field"
"github.com/cloudreve/Cloudreve/v4/ent/sku"
)
// SkuCreate is the builder for creating a Sku entity.
type SkuCreate struct {
config
mutation *SkuMutation
hooks []Hook
conflict []sql.ConflictOption
}
// SetCreatedAt sets the "created_at" field.
func (sc *SkuCreate) SetCreatedAt(t time.Time) *SkuCreate {
sc.mutation.SetCreatedAt(t)
return sc
}
// SetNillableCreatedAt sets the "created_at" field if the given value is not nil.
func (sc *SkuCreate) SetNillableCreatedAt(t *time.Time) *SkuCreate {
if t != nil {
sc.SetCreatedAt(*t)
}
return sc
}
// SetUpdatedAt sets the "updated_at" field.
func (sc *SkuCreate) SetUpdatedAt(t time.Time) *SkuCreate {
sc.mutation.SetUpdatedAt(t)
return sc
}
// SetNillableUpdatedAt sets the "updated_at" field if the given value is not nil.
func (sc *SkuCreate) SetNillableUpdatedAt(t *time.Time) *SkuCreate {
if t != nil {
sc.SetUpdatedAt(*t)
}
return sc
}
// SetDeletedAt sets the "deleted_at" field.
func (sc *SkuCreate) SetDeletedAt(t time.Time) *SkuCreate {
sc.mutation.SetDeletedAt(t)
return sc
}
// SetNillableDeletedAt sets the "deleted_at" field if the given value is not nil.
func (sc *SkuCreate) SetNillableDeletedAt(t *time.Time) *SkuCreate {
if t != nil {
sc.SetDeletedAt(*t)
}
return sc
}
// SetName sets the "name" field.
func (sc *SkuCreate) SetName(s string) *SkuCreate {
sc.mutation.SetName(s)
return sc
}
// SetType sets the "type" field.
func (sc *SkuCreate) SetType(s sku.Type) *SkuCreate {
sc.mutation.SetType(s)
return sc
}
// SetAmount sets the "amount" field.
func (sc *SkuCreate) SetAmount(i int64) *SkuCreate {
sc.mutation.SetAmount(i)
return sc
}
// SetDuration sets the "duration" field.
func (sc *SkuCreate) SetDuration(i int64) *SkuCreate {
sc.mutation.SetDuration(i)
return sc
}
// SetNillableDuration sets the "duration" field if the given value is not nil.
func (sc *SkuCreate) SetNillableDuration(i *int64) *SkuCreate {
if i != nil {
sc.SetDuration(*i)
}
return sc
}
// SetPrice sets the "price" field.
func (sc *SkuCreate) SetPrice(i int64) *SkuCreate {
sc.mutation.SetPrice(i)
return sc
}
// SetNillablePrice sets the "price" field if the given value is not nil.
func (sc *SkuCreate) SetNillablePrice(i *int64) *SkuCreate {
if i != nil {
sc.SetPrice(*i)
}
return sc
}
// SetPoints sets the "points" field.
func (sc *SkuCreate) SetPoints(i int64) *SkuCreate {
sc.mutation.SetPoints(i)
return sc
}
// SetNillablePoints sets the "points" field if the given value is not nil.
func (sc *SkuCreate) SetNillablePoints(i *int64) *SkuCreate {
if i != nil {
sc.SetPoints(*i)
}
return sc
}
// SetLabel sets the "label" field.
func (sc *SkuCreate) SetLabel(s string) *SkuCreate {
sc.mutation.SetLabel(s)
return sc
}
// SetNillableLabel sets the "label" field if the given value is not nil.
func (sc *SkuCreate) SetNillableLabel(s *string) *SkuCreate {
if s != nil {
sc.SetLabel(*s)
}
return sc
}
// SetDes sets the "des" field.
func (sc *SkuCreate) SetDes(s string) *SkuCreate {
sc.mutation.SetDes(s)
return sc
}
// SetNillableDes sets the "des" field if the given value is not nil.
func (sc *SkuCreate) SetNillableDes(s *string) *SkuCreate {
if s != nil {
sc.SetDes(*s)
}
return sc
}
// SetEnabled sets the "enabled" field.
func (sc *SkuCreate) SetEnabled(b bool) *SkuCreate {
sc.mutation.SetEnabled(b)
return sc
}
// SetNillableEnabled sets the "enabled" field if the given value is not nil.
func (sc *SkuCreate) SetNillableEnabled(b *bool) *SkuCreate {
if b != nil {
sc.SetEnabled(*b)
}
return sc
}
// SetWeight sets the "weight" field.
func (sc *SkuCreate) SetWeight(i int) *SkuCreate {
sc.mutation.SetWeight(i)
return sc
}
// SetNillableWeight sets the "weight" field if the given value is not nil.
func (sc *SkuCreate) SetNillableWeight(i *int) *SkuCreate {
if i != nil {
sc.SetWeight(*i)
}
return sc
}
// Mutation returns the SkuMutation object of the builder.
func (sc *SkuCreate) Mutation() *SkuMutation {
return sc.mutation
}
// Save creates the Sku in the database.
func (sc *SkuCreate) Save(ctx context.Context) (*Sku, error) {
if err := sc.defaults(); err != nil {
return nil, err
}
return withHooks(ctx, sc.sqlSave, sc.mutation, sc.hooks)
}
// SaveX calls Save and panics if Save returns an error.
func (sc *SkuCreate) SaveX(ctx context.Context) *Sku {
v, err := sc.Save(ctx)
if err != nil {
panic(err)
}
return v
}
// Exec executes the query.
func (sc *SkuCreate) Exec(ctx context.Context) error {
_, err := sc.Save(ctx)
return err
}
// ExecX is like Exec, but panics if an error occurs.
func (sc *SkuCreate) ExecX(ctx context.Context) {
if err := sc.Exec(ctx); err != nil {
panic(err)
}
}
// defaults sets the default values of the builder before save.
func (sc *SkuCreate) defaults() error {
if _, ok := sc.mutation.CreatedAt(); !ok {
if sku.DefaultCreatedAt == nil {
return fmt.Errorf("ent: uninitialized sku.DefaultCreatedAt (forgotten import ent/runtime?)")
}
v := sku.DefaultCreatedAt()
sc.mutation.SetCreatedAt(v)
}
if _, ok := sc.mutation.UpdatedAt(); !ok {
if sku.DefaultUpdatedAt == nil {
return fmt.Errorf("ent: uninitialized sku.DefaultUpdatedAt (forgotten import ent/runtime?)")
}
v := sku.DefaultUpdatedAt()
sc.mutation.SetUpdatedAt(v)
}
if _, ok := sc.mutation.Enabled(); !ok {
v := sku.DefaultEnabled
sc.mutation.SetEnabled(v)
}
if _, ok := sc.mutation.Weight(); !ok {
v := sku.DefaultWeight
sc.mutation.SetWeight(v)
}
return nil
}
// check runs all checks and user-defined validators on the builder.
func (sc *SkuCreate) check() error {
if _, ok := sc.mutation.CreatedAt(); !ok {
return &ValidationError{Name: "created_at", err: errors.New(`ent: missing required field "Sku.created_at"`)}
}
if _, ok := sc.mutation.UpdatedAt(); !ok {
return &ValidationError{Name: "updated_at", err: errors.New(`ent: missing required field "Sku.updated_at"`)}
}
if _, ok := sc.mutation.Name(); !ok {
return &ValidationError{Name: "name", err: errors.New(`ent: missing required field "Sku.name"`)}
}
if _, ok := sc.mutation.GetType(); !ok {
return &ValidationError{Name: "type", err: errors.New(`ent: missing required field "Sku.type"`)}
}
if v, ok := sc.mutation.GetType(); ok {
if err := sku.TypeValidator(v); err != nil {
return &ValidationError{Name: "type", err: fmt.Errorf(`ent: validator failed for field "Sku.type": %w`, err)}
}
}
if _, ok := sc.mutation.Amount(); !ok {
return &ValidationError{Name: "amount", err: errors.New(`ent: missing required field "Sku.amount"`)}
}
if _, ok := sc.mutation.Enabled(); !ok {
return &ValidationError{Name: "enabled", err: errors.New(`ent: missing required field "Sku.enabled"`)}
}
if _, ok := sc.mutation.Weight(); !ok {
return &ValidationError{Name: "weight", err: errors.New(`ent: missing required field "Sku.weight"`)}
}
return nil
}
func (sc *SkuCreate) sqlSave(ctx context.Context) (*Sku, error) {
if err := sc.check(); err != nil {
return nil, err
}
_node, _spec := sc.createSpec()
if err := sqlgraph.CreateNode(ctx, sc.driver, _spec); err != nil {
if sqlgraph.IsConstraintError(err) {
err = &ConstraintError{msg: err.Error(), wrap: err}
}
return nil, err
}
id := _spec.ID.Value.(int64)
_node.ID = int(id)
sc.mutation.id = &_node.ID
sc.mutation.done = true
return _node, nil
}
func (sc *SkuCreate) createSpec() (*Sku, *sqlgraph.CreateSpec) {
var (
_node = &Sku{config: sc.config}
_spec = sqlgraph.NewCreateSpec(sku.Table, sqlgraph.NewFieldSpec(sku.FieldID, field.TypeInt))
)
if id, ok := sc.mutation.ID(); ok {
_node.ID = id
id64 := int64(id)
_spec.ID.Value = id64
}
_spec.OnConflict = sc.conflict
if value, ok := sc.mutation.CreatedAt(); ok {
_spec.SetField(sku.FieldCreatedAt, field.TypeTime, value)
_node.CreatedAt = value
}
if value, ok := sc.mutation.UpdatedAt(); ok {
_spec.SetField(sku.FieldUpdatedAt, field.TypeTime, value)
_node.UpdatedAt = value
}
if value, ok := sc.mutation.DeletedAt(); ok {
_spec.SetField(sku.FieldDeletedAt, field.TypeTime, value)
_node.DeletedAt = &value
}
if value, ok := sc.mutation.Name(); ok {
_spec.SetField(sku.FieldName, field.TypeString, value)
_node.Name = value
}
if value, ok := sc.mutation.GetType(); ok {
_spec.SetField(sku.FieldType, field.TypeEnum, value)
_node.Type = value
}
if value, ok := sc.mutation.Amount(); ok {
_spec.SetField(sku.FieldAmount, field.TypeInt64, value)
_node.Amount = value
}
if value, ok := sc.mutation.Duration(); ok {
_spec.SetField(sku.FieldDuration, field.TypeInt64, value)
_node.Duration = value
}
if value, ok := sc.mutation.Price(); ok {
_spec.SetField(sku.FieldPrice, field.TypeInt64, value)
_node.Price = value
}
if value, ok := sc.mutation.Points(); ok {
_spec.SetField(sku.FieldPoints, field.TypeInt64, value)
_node.Points = &value
}
if value, ok := sc.mutation.Label(); ok {
_spec.SetField(sku.FieldLabel, field.TypeString, value)
_node.Label = value
}
if value, ok := sc.mutation.Des(); ok {
_spec.SetField(sku.FieldDes, field.TypeString, value)
_node.Des = value
}
if value, ok := sc.mutation.Enabled(); ok {
_spec.SetField(sku.FieldEnabled, field.TypeBool, value)
_node.Enabled = value
}
if value, ok := sc.mutation.Weight(); ok {
_spec.SetField(sku.FieldWeight, field.TypeInt, value)
_node.Weight = value
}
return _node, _spec
}
// OnConflict allows configuring the `ON CONFLICT` / `ON DUPLICATE KEY` clause
// of the `INSERT` statement. For example:
//
// client.Sku.Create().
// SetCreatedAt(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.SkuUpsert) {
// SetCreatedAt(v+v).
// }).
// Exec(ctx)
func (sc *SkuCreate) OnConflict(opts ...sql.ConflictOption) *SkuUpsertOne {
sc.conflict = opts
return &SkuUpsertOne{
create: sc,
}
}
// OnConflictColumns calls `OnConflict` and configures the columns
// as conflict target. Using this option is equivalent to using:
//
// client.Sku.Create().
// OnConflict(sql.ConflictColumns(columns...)).
// Exec(ctx)
func (sc *SkuCreate) OnConflictColumns(columns ...string) *SkuUpsertOne {
sc.conflict = append(sc.conflict, sql.ConflictColumns(columns...))
return &SkuUpsertOne{
create: sc,
}
}
type (
// SkuUpsertOne is the builder for "upsert"-ing
// one Sku node.
SkuUpsertOne struct {
create *SkuCreate
}
// SkuUpsert is the "OnConflict" setter.
SkuUpsert struct {
*sql.UpdateSet
}
)
// SetUpdatedAt sets the "updated_at" field.
func (u *SkuUpsert) SetUpdatedAt(v time.Time) *SkuUpsert {
u.Set(sku.FieldUpdatedAt, v)
return u
}
// UpdateUpdatedAt sets the "updated_at" field to the value that was provided on create.
func (u *SkuUpsert) UpdateUpdatedAt() *SkuUpsert {
u.SetExcluded(sku.FieldUpdatedAt)
return u
}
// SetDeletedAt sets the "deleted_at" field.
func (u *SkuUpsert) SetDeletedAt(v time.Time) *SkuUpsert {
u.Set(sku.FieldDeletedAt, v)
return u
}
// UpdateDeletedAt sets the "deleted_at" field to the value that was provided on create.
func (u *SkuUpsert) UpdateDeletedAt() *SkuUpsert {
u.SetExcluded(sku.FieldDeletedAt)
return u
}
// ClearDeletedAt clears the value of the "deleted_at" field.
func (u *SkuUpsert) ClearDeletedAt() *SkuUpsert {
u.SetNull(sku.FieldDeletedAt)
return u
}
// SetName sets the "name" field.
func (u *SkuUpsert) SetName(v string) *SkuUpsert {
u.Set(sku.FieldName, v)
return u
}
// UpdateName sets the "name" field to the value that was provided on create.
func (u *SkuUpsert) UpdateName() *SkuUpsert {
u.SetExcluded(sku.FieldName)
return u
}
// SetType sets the "type" field.
func (u *SkuUpsert) SetType(v sku.Type) *SkuUpsert {
u.Set(sku.FieldType, v)
return u
}
// UpdateType sets the "type" field to the value that was provided on create.
func (u *SkuUpsert) UpdateType() *SkuUpsert {
u.SetExcluded(sku.FieldType)
return u
}
// SetAmount sets the "amount" field.
func (u *SkuUpsert) SetAmount(v int64) *SkuUpsert {
u.Set(sku.FieldAmount, v)
return u
}
// UpdateAmount sets the "amount" field to the value that was provided on create.
func (u *SkuUpsert) UpdateAmount() *SkuUpsert {
u.SetExcluded(sku.FieldAmount)
return u
}
// AddAmount adds v to the "amount" field.
func (u *SkuUpsert) AddAmount(v int64) *SkuUpsert {
u.Add(sku.FieldAmount, v)
return u
}
// SetDuration sets the "duration" field.
func (u *SkuUpsert) SetDuration(v int64) *SkuUpsert {
u.Set(sku.FieldDuration, v)
return u
}
// UpdateDuration sets the "duration" field to the value that was provided on create.
func (u *SkuUpsert) UpdateDuration() *SkuUpsert {
u.SetExcluded(sku.FieldDuration)
return u
}
// AddDuration adds v to the "duration" field.
func (u *SkuUpsert) AddDuration(v int64) *SkuUpsert {
u.Add(sku.FieldDuration, v)
return u
}
// ClearDuration clears the value of the "duration" field.
func (u *SkuUpsert) ClearDuration() *SkuUpsert {
u.SetNull(sku.FieldDuration)
return u
}
// SetPrice sets the "price" field.
func (u *SkuUpsert) SetPrice(v int64) *SkuUpsert {
u.Set(sku.FieldPrice, v)
return u
}
// UpdatePrice sets the "price" field to the value that was provided on create.
func (u *SkuUpsert) UpdatePrice() *SkuUpsert {
u.SetExcluded(sku.FieldPrice)
return u
}
// AddPrice adds v to the "price" field.
func (u *SkuUpsert) AddPrice(v int64) *SkuUpsert {
u.Add(sku.FieldPrice, v)
return u
}
// ClearPrice clears the value of the "price" field.
func (u *SkuUpsert) ClearPrice() *SkuUpsert {
u.SetNull(sku.FieldPrice)
return u
}
// SetPoints sets the "points" field.
func (u *SkuUpsert) SetPoints(v int64) *SkuUpsert {
u.Set(sku.FieldPoints, v)
return u
}
// UpdatePoints sets the "points" field to the value that was provided on create.
func (u *SkuUpsert) UpdatePoints() *SkuUpsert {
u.SetExcluded(sku.FieldPoints)
return u
}
// AddPoints adds v to the "points" field.
func (u *SkuUpsert) AddPoints(v int64) *SkuUpsert {
u.Add(sku.FieldPoints, v)
return u
}
// ClearPoints clears the value of the "points" field.
func (u *SkuUpsert) ClearPoints() *SkuUpsert {
u.SetNull(sku.FieldPoints)
return u
}
// SetLabel sets the "label" field.
func (u *SkuUpsert) SetLabel(v string) *SkuUpsert {
u.Set(sku.FieldLabel, v)
return u
}
// UpdateLabel sets the "label" field to the value that was provided on create.
func (u *SkuUpsert) UpdateLabel() *SkuUpsert {
u.SetExcluded(sku.FieldLabel)
return u
}
// ClearLabel clears the value of the "label" field.
func (u *SkuUpsert) ClearLabel() *SkuUpsert {
u.SetNull(sku.FieldLabel)
return u
}
// SetDes sets the "des" field.
func (u *SkuUpsert) SetDes(v string) *SkuUpsert {
u.Set(sku.FieldDes, v)
return u
}
// UpdateDes sets the "des" field to the value that was provided on create.
func (u *SkuUpsert) UpdateDes() *SkuUpsert {
u.SetExcluded(sku.FieldDes)
return u
}
// ClearDes clears the value of the "des" field.
func (u *SkuUpsert) ClearDes() *SkuUpsert {
u.SetNull(sku.FieldDes)
return u
}
// SetEnabled sets the "enabled" field.
func (u *SkuUpsert) SetEnabled(v bool) *SkuUpsert {
u.Set(sku.FieldEnabled, v)
return u
}
// UpdateEnabled sets the "enabled" field to the value that was provided on create.
func (u *SkuUpsert) UpdateEnabled() *SkuUpsert {
u.SetExcluded(sku.FieldEnabled)
return u
}
// SetWeight sets the "weight" field.
func (u *SkuUpsert) SetWeight(v int) *SkuUpsert {
u.Set(sku.FieldWeight, v)
return u
}
// UpdateWeight sets the "weight" field to the value that was provided on create.
func (u *SkuUpsert) UpdateWeight() *SkuUpsert {
u.SetExcluded(sku.FieldWeight)
return u
}
// AddWeight adds v to the "weight" field.
func (u *SkuUpsert) AddWeight(v int) *SkuUpsert {
u.Add(sku.FieldWeight, v)
return u
}
// UpdateNewValues updates the mutable fields using the new values that were set on create.
// Using this option is equivalent to using:
//
// client.Sku.Create().
// OnConflict(
// sql.ResolveWithNewValues(),
// ).
// Exec(ctx)
func (u *SkuUpsertOne) UpdateNewValues() *SkuUpsertOne {
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.CreatedAt(); exists {
s.SetIgnore(sku.FieldCreatedAt)
}
}))
return u
}
// Ignore sets each column to itself in case of conflict.
// Using this option is equivalent to using:
//
// client.Sku.Create().
// OnConflict(sql.ResolveWithIgnore()).
// Exec(ctx)
func (u *SkuUpsertOne) Ignore() *SkuUpsertOne {
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 *SkuUpsertOne) DoNothing() *SkuUpsertOne {
u.create.conflict = append(u.create.conflict, sql.DoNothing())
return u
}
// Update allows overriding fields `UPDATE` values. See the SkuCreate.OnConflict
// documentation for more info.
func (u *SkuUpsertOne) Update(set func(*SkuUpsert)) *SkuUpsertOne {
u.create.conflict = append(u.create.conflict, sql.ResolveWith(func(update *sql.UpdateSet) {
set(&SkuUpsert{UpdateSet: update})
}))
return u
}
// SetUpdatedAt sets the "updated_at" field.
func (u *SkuUpsertOne) SetUpdatedAt(v time.Time) *SkuUpsertOne {
return u.Update(func(s *SkuUpsert) {
s.SetUpdatedAt(v)
})
}
// UpdateUpdatedAt sets the "updated_at" field to the value that was provided on create.
func (u *SkuUpsertOne) UpdateUpdatedAt() *SkuUpsertOne {
return u.Update(func(s *SkuUpsert) {
s.UpdateUpdatedAt()
})
}
// SetDeletedAt sets the "deleted_at" field.
func (u *SkuUpsertOne) SetDeletedAt(v time.Time) *SkuUpsertOne {
return u.Update(func(s *SkuUpsert) {
s.SetDeletedAt(v)
})
}
// UpdateDeletedAt sets the "deleted_at" field to the value that was provided on create.
func (u *SkuUpsertOne) UpdateDeletedAt() *SkuUpsertOne {
return u.Update(func(s *SkuUpsert) {
s.UpdateDeletedAt()
})
}
// ClearDeletedAt clears the value of the "deleted_at" field.
func (u *SkuUpsertOne) ClearDeletedAt() *SkuUpsertOne {
return u.Update(func(s *SkuUpsert) {
s.ClearDeletedAt()
})
}
// SetName sets the "name" field.
func (u *SkuUpsertOne) SetName(v string) *SkuUpsertOne {
return u.Update(func(s *SkuUpsert) {
s.SetName(v)
})
}
// UpdateName sets the "name" field to the value that was provided on create.
func (u *SkuUpsertOne) UpdateName() *SkuUpsertOne {
return u.Update(func(s *SkuUpsert) {
s.UpdateName()
})
}
// SetType sets the "type" field.
func (u *SkuUpsertOne) SetType(v sku.Type) *SkuUpsertOne {
return u.Update(func(s *SkuUpsert) {
s.SetType(v)
})
}
// UpdateType sets the "type" field to the value that was provided on create.
func (u *SkuUpsertOne) UpdateType() *SkuUpsertOne {
return u.Update(func(s *SkuUpsert) {
s.UpdateType()
})
}
// SetAmount sets the "amount" field.
func (u *SkuUpsertOne) SetAmount(v int64) *SkuUpsertOne {
return u.Update(func(s *SkuUpsert) {
s.SetAmount(v)
})
}
// AddAmount adds v to the "amount" field.
func (u *SkuUpsertOne) AddAmount(v int64) *SkuUpsertOne {
return u.Update(func(s *SkuUpsert) {
s.AddAmount(v)
})
}
// UpdateAmount sets the "amount" field to the value that was provided on create.
func (u *SkuUpsertOne) UpdateAmount() *SkuUpsertOne {
return u.Update(func(s *SkuUpsert) {
s.UpdateAmount()
})
}
// SetDuration sets the "duration" field.
func (u *SkuUpsertOne) SetDuration(v int64) *SkuUpsertOne {
return u.Update(func(s *SkuUpsert) {
s.SetDuration(v)
})
}
// AddDuration adds v to the "duration" field.
func (u *SkuUpsertOne) AddDuration(v int64) *SkuUpsertOne {
return u.Update(func(s *SkuUpsert) {
s.AddDuration(v)
})
}
// UpdateDuration sets the "duration" field to the value that was provided on create.
func (u *SkuUpsertOne) UpdateDuration() *SkuUpsertOne {
return u.Update(func(s *SkuUpsert) {
s.UpdateDuration()
})
}
// ClearDuration clears the value of the "duration" field.
func (u *SkuUpsertOne) ClearDuration() *SkuUpsertOne {
return u.Update(func(s *SkuUpsert) {
s.ClearDuration()
})
}
// SetPrice sets the "price" field.
func (u *SkuUpsertOne) SetPrice(v int64) *SkuUpsertOne {
return u.Update(func(s *SkuUpsert) {
s.SetPrice(v)
})
}
// AddPrice adds v to the "price" field.
func (u *SkuUpsertOne) AddPrice(v int64) *SkuUpsertOne {
return u.Update(func(s *SkuUpsert) {
s.AddPrice(v)
})
}
// UpdatePrice sets the "price" field to the value that was provided on create.
func (u *SkuUpsertOne) UpdatePrice() *SkuUpsertOne {
return u.Update(func(s *SkuUpsert) {
s.UpdatePrice()
})
}
// ClearPrice clears the value of the "price" field.
func (u *SkuUpsertOne) ClearPrice() *SkuUpsertOne {
return u.Update(func(s *SkuUpsert) {
s.ClearPrice()
})
}
// SetPoints sets the "points" field.
func (u *SkuUpsertOne) SetPoints(v int64) *SkuUpsertOne {
return u.Update(func(s *SkuUpsert) {
s.SetPoints(v)
})
}
// AddPoints adds v to the "points" field.
func (u *SkuUpsertOne) AddPoints(v int64) *SkuUpsertOne {
return u.Update(func(s *SkuUpsert) {
s.AddPoints(v)
})
}
// UpdatePoints sets the "points" field to the value that was provided on create.
func (u *SkuUpsertOne) UpdatePoints() *SkuUpsertOne {
return u.Update(func(s *SkuUpsert) {
s.UpdatePoints()
})
}
// ClearPoints clears the value of the "points" field.
func (u *SkuUpsertOne) ClearPoints() *SkuUpsertOne {
return u.Update(func(s *SkuUpsert) {
s.ClearPoints()
})
}
// SetLabel sets the "label" field.
func (u *SkuUpsertOne) SetLabel(v string) *SkuUpsertOne {
return u.Update(func(s *SkuUpsert) {
s.SetLabel(v)
})
}
// UpdateLabel sets the "label" field to the value that was provided on create.
func (u *SkuUpsertOne) UpdateLabel() *SkuUpsertOne {
return u.Update(func(s *SkuUpsert) {
s.UpdateLabel()
})
}
// ClearLabel clears the value of the "label" field.
func (u *SkuUpsertOne) ClearLabel() *SkuUpsertOne {
return u.Update(func(s *SkuUpsert) {
s.ClearLabel()
})
}
// SetDes sets the "des" field.
func (u *SkuUpsertOne) SetDes(v string) *SkuUpsertOne {
return u.Update(func(s *SkuUpsert) {
s.SetDes(v)
})
}
// UpdateDes sets the "des" field to the value that was provided on create.
func (u *SkuUpsertOne) UpdateDes() *SkuUpsertOne {
return u.Update(func(s *SkuUpsert) {
s.UpdateDes()
})
}
// ClearDes clears the value of the "des" field.
func (u *SkuUpsertOne) ClearDes() *SkuUpsertOne {
return u.Update(func(s *SkuUpsert) {
s.ClearDes()
})
}
// SetEnabled sets the "enabled" field.
func (u *SkuUpsertOne) SetEnabled(v bool) *SkuUpsertOne {
return u.Update(func(s *SkuUpsert) {
s.SetEnabled(v)
})
}
// UpdateEnabled sets the "enabled" field to the value that was provided on create.
func (u *SkuUpsertOne) UpdateEnabled() *SkuUpsertOne {
return u.Update(func(s *SkuUpsert) {
s.UpdateEnabled()
})
}
// SetWeight sets the "weight" field.
func (u *SkuUpsertOne) SetWeight(v int) *SkuUpsertOne {
return u.Update(func(s *SkuUpsert) {
s.SetWeight(v)
})
}
// AddWeight adds v to the "weight" field.
func (u *SkuUpsertOne) AddWeight(v int) *SkuUpsertOne {
return u.Update(func(s *SkuUpsert) {
s.AddWeight(v)
})
}
// UpdateWeight sets the "weight" field to the value that was provided on create.
func (u *SkuUpsertOne) UpdateWeight() *SkuUpsertOne {
return u.Update(func(s *SkuUpsert) {
s.UpdateWeight()
})
}
// Exec executes the query.
func (u *SkuUpsertOne) Exec(ctx context.Context) error {
if len(u.create.conflict) == 0 {
return errors.New("ent: missing options for SkuCreate.OnConflict")
}
return u.create.Exec(ctx)
}
// ExecX is like Exec, but panics if an error occurs.
func (u *SkuUpsertOne) 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 *SkuUpsertOne) ID(ctx context.Context) (id int, err error) {
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 *SkuUpsertOne) IDX(ctx context.Context) int {
id, err := u.ID(ctx)
if err != nil {
panic(err)
}
return id
}
func (m *SkuCreate) SetRawID(t int) *SkuCreate {
m.mutation.SetRawID(t)
return m
}
// SkuCreateBulk is the builder for creating many Sku entities in bulk.
type SkuCreateBulk struct {
config
err error
builders []*SkuCreate
conflict []sql.ConflictOption
}
// Save creates the Sku entities in the database.
func (scb *SkuCreateBulk) Save(ctx context.Context) ([]*Sku, error) {
if scb.err != nil {
return nil, scb.err
}
specs := make([]*sqlgraph.CreateSpec, len(scb.builders))
nodes := make([]*Sku, len(scb.builders))
mutators := make([]Mutator, len(scb.builders))
for i := range scb.builders {
func(i int, root context.Context) {
builder := scb.builders[i]
builder.defaults()
var mut Mutator = MutateFunc(func(ctx context.Context, m Mutation) (Value, error) {
mutation, ok := m.(*SkuMutation)
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, scb.builders[i+1].mutation)
} else {
spec := &sqlgraph.BatchCreateSpec{Nodes: specs}
spec.OnConflict = scb.conflict
// Invoke the actual operation on the latest mutation in the chain.
if err = sqlgraph.BatchCreate(ctx, scb.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
if specs[i].ID.Value != nil {
id := specs[i].ID.Value.(int64)
nodes[i].ID = int(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, scb.builders[0].mutation); err != nil {
return nil, err
}
}
return nodes, nil
}
// SaveX is like Save, but panics if an error occurs.
func (scb *SkuCreateBulk) SaveX(ctx context.Context) []*Sku {
v, err := scb.Save(ctx)
if err != nil {
panic(err)
}
return v
}
// Exec executes the query.
func (scb *SkuCreateBulk) Exec(ctx context.Context) error {
_, err := scb.Save(ctx)
return err
}
// ExecX is like Exec, but panics if an error occurs.
func (scb *SkuCreateBulk) ExecX(ctx context.Context) {
if err := scb.Exec(ctx); err != nil {
panic(err)
}
}
// OnConflict allows configuring the `ON CONFLICT` / `ON DUPLICATE KEY` clause
// of the `INSERT` statement. For example:
//
// client.Sku.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.SkuUpsert) {
// SetCreatedAt(v+v).
// }).
// Exec(ctx)
func (scb *SkuCreateBulk) OnConflict(opts ...sql.ConflictOption) *SkuUpsertBulk {
scb.conflict = opts
return &SkuUpsertBulk{
create: scb,
}
}
// OnConflictColumns calls `OnConflict` and configures the columns
// as conflict target. Using this option is equivalent to using:
//
// client.Sku.Create().
// OnConflict(sql.ConflictColumns(columns...)).
// Exec(ctx)
func (scb *SkuCreateBulk) OnConflictColumns(columns ...string) *SkuUpsertBulk {
scb.conflict = append(scb.conflict, sql.ConflictColumns(columns...))
return &SkuUpsertBulk{
create: scb,
}
}
// SkuUpsertBulk is the builder for "upsert"-ing
// a bulk of Sku nodes.
type SkuUpsertBulk struct {
create *SkuCreateBulk
}
// UpdateNewValues updates the mutable fields using the new values that
// were set on create. Using this option is equivalent to using:
//
// client.Sku.Create().
// OnConflict(
// sql.ResolveWithNewValues(),
// ).
// Exec(ctx)
func (u *SkuUpsertBulk) UpdateNewValues() *SkuUpsertBulk {
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.CreatedAt(); exists {
s.SetIgnore(sku.FieldCreatedAt)
}
}
}))
return u
}
// Ignore sets each column to itself in case of conflict.
// Using this option is equivalent to using:
//
// client.Sku.Create().
// OnConflict(sql.ResolveWithIgnore()).
// Exec(ctx)
func (u *SkuUpsertBulk) Ignore() *SkuUpsertBulk {
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 *SkuUpsertBulk) DoNothing() *SkuUpsertBulk {
u.create.conflict = append(u.create.conflict, sql.DoNothing())
return u
}
// Update allows overriding fields `UPDATE` values. See the SkuCreateBulk.OnConflict
// documentation for more info.
func (u *SkuUpsertBulk) Update(set func(*SkuUpsert)) *SkuUpsertBulk {
u.create.conflict = append(u.create.conflict, sql.ResolveWith(func(update *sql.UpdateSet) {
set(&SkuUpsert{UpdateSet: update})
}))
return u
}
// SetUpdatedAt sets the "updated_at" field.
func (u *SkuUpsertBulk) SetUpdatedAt(v time.Time) *SkuUpsertBulk {
return u.Update(func(s *SkuUpsert) {
s.SetUpdatedAt(v)
})
}
// UpdateUpdatedAt sets the "updated_at" field to the value that was provided on create.
func (u *SkuUpsertBulk) UpdateUpdatedAt() *SkuUpsertBulk {
return u.Update(func(s *SkuUpsert) {
s.UpdateUpdatedAt()
})
}
// SetDeletedAt sets the "deleted_at" field.
func (u *SkuUpsertBulk) SetDeletedAt(v time.Time) *SkuUpsertBulk {
return u.Update(func(s *SkuUpsert) {
s.SetDeletedAt(v)
})
}
// UpdateDeletedAt sets the "deleted_at" field to the value that was provided on create.
func (u *SkuUpsertBulk) UpdateDeletedAt() *SkuUpsertBulk {
return u.Update(func(s *SkuUpsert) {
s.UpdateDeletedAt()
})
}
// ClearDeletedAt clears the value of the "deleted_at" field.
func (u *SkuUpsertBulk) ClearDeletedAt() *SkuUpsertBulk {
return u.Update(func(s *SkuUpsert) {
s.ClearDeletedAt()
})
}
// SetName sets the "name" field.
func (u *SkuUpsertBulk) SetName(v string) *SkuUpsertBulk {
return u.Update(func(s *SkuUpsert) {
s.SetName(v)
})
}
// UpdateName sets the "name" field to the value that was provided on create.
func (u *SkuUpsertBulk) UpdateName() *SkuUpsertBulk {
return u.Update(func(s *SkuUpsert) {
s.UpdateName()
})
}
// SetType sets the "type" field.
func (u *SkuUpsertBulk) SetType(v sku.Type) *SkuUpsertBulk {
return u.Update(func(s *SkuUpsert) {
s.SetType(v)
})
}
// UpdateType sets the "type" field to the value that was provided on create.
func (u *SkuUpsertBulk) UpdateType() *SkuUpsertBulk {
return u.Update(func(s *SkuUpsert) {
s.UpdateType()
})
}
// SetAmount sets the "amount" field.
func (u *SkuUpsertBulk) SetAmount(v int64) *SkuUpsertBulk {
return u.Update(func(s *SkuUpsert) {
s.SetAmount(v)
})
}
// AddAmount adds v to the "amount" field.
func (u *SkuUpsertBulk) AddAmount(v int64) *SkuUpsertBulk {
return u.Update(func(s *SkuUpsert) {
s.AddAmount(v)
})
}
// UpdateAmount sets the "amount" field to the value that was provided on create.
func (u *SkuUpsertBulk) UpdateAmount() *SkuUpsertBulk {
return u.Update(func(s *SkuUpsert) {
s.UpdateAmount()
})
}
// SetDuration sets the "duration" field.
func (u *SkuUpsertBulk) SetDuration(v int64) *SkuUpsertBulk {
return u.Update(func(s *SkuUpsert) {
s.SetDuration(v)
})
}
// AddDuration adds v to the "duration" field.
func (u *SkuUpsertBulk) AddDuration(v int64) *SkuUpsertBulk {
return u.Update(func(s *SkuUpsert) {
s.AddDuration(v)
})
}
// UpdateDuration sets the "duration" field to the value that was provided on create.
func (u *SkuUpsertBulk) UpdateDuration() *SkuUpsertBulk {
return u.Update(func(s *SkuUpsert) {
s.UpdateDuration()
})
}
// ClearDuration clears the value of the "duration" field.
func (u *SkuUpsertBulk) ClearDuration() *SkuUpsertBulk {
return u.Update(func(s *SkuUpsert) {
s.ClearDuration()
})
}
// SetPrice sets the "price" field.
func (u *SkuUpsertBulk) SetPrice(v int64) *SkuUpsertBulk {
return u.Update(func(s *SkuUpsert) {
s.SetPrice(v)
})
}
// AddPrice adds v to the "price" field.
func (u *SkuUpsertBulk) AddPrice(v int64) *SkuUpsertBulk {
return u.Update(func(s *SkuUpsert) {
s.AddPrice(v)
})
}
// UpdatePrice sets the "price" field to the value that was provided on create.
func (u *SkuUpsertBulk) UpdatePrice() *SkuUpsertBulk {
return u.Update(func(s *SkuUpsert) {
s.UpdatePrice()
})
}
// ClearPrice clears the value of the "price" field.
func (u *SkuUpsertBulk) ClearPrice() *SkuUpsertBulk {
return u.Update(func(s *SkuUpsert) {
s.ClearPrice()
})
}
// SetPoints sets the "points" field.
func (u *SkuUpsertBulk) SetPoints(v int64) *SkuUpsertBulk {
return u.Update(func(s *SkuUpsert) {
s.SetPoints(v)
})
}
// AddPoints adds v to the "points" field.
func (u *SkuUpsertBulk) AddPoints(v int64) *SkuUpsertBulk {
return u.Update(func(s *SkuUpsert) {
s.AddPoints(v)
})
}
// UpdatePoints sets the "points" field to the value that was provided on create.
func (u *SkuUpsertBulk) UpdatePoints() *SkuUpsertBulk {
return u.Update(func(s *SkuUpsert) {
s.UpdatePoints()
})
}
// ClearPoints clears the value of the "points" field.
func (u *SkuUpsertBulk) ClearPoints() *SkuUpsertBulk {
return u.Update(func(s *SkuUpsert) {
s.ClearPoints()
})
}
// SetLabel sets the "label" field.
func (u *SkuUpsertBulk) SetLabel(v string) *SkuUpsertBulk {
return u.Update(func(s *SkuUpsert) {
s.SetLabel(v)
})
}
// UpdateLabel sets the "label" field to the value that was provided on create.
func (u *SkuUpsertBulk) UpdateLabel() *SkuUpsertBulk {
return u.Update(func(s *SkuUpsert) {
s.UpdateLabel()
})
}
// ClearLabel clears the value of the "label" field.
func (u *SkuUpsertBulk) ClearLabel() *SkuUpsertBulk {
return u.Update(func(s *SkuUpsert) {
s.ClearLabel()
})
}
// SetDes sets the "des" field.
func (u *SkuUpsertBulk) SetDes(v string) *SkuUpsertBulk {
return u.Update(func(s *SkuUpsert) {
s.SetDes(v)
})
}
// UpdateDes sets the "des" field to the value that was provided on create.
func (u *SkuUpsertBulk) UpdateDes() *SkuUpsertBulk {
return u.Update(func(s *SkuUpsert) {
s.UpdateDes()
})
}
// ClearDes clears the value of the "des" field.
func (u *SkuUpsertBulk) ClearDes() *SkuUpsertBulk {
return u.Update(func(s *SkuUpsert) {
s.ClearDes()
})
}
// SetEnabled sets the "enabled" field.
func (u *SkuUpsertBulk) SetEnabled(v bool) *SkuUpsertBulk {
return u.Update(func(s *SkuUpsert) {
s.SetEnabled(v)
})
}
// UpdateEnabled sets the "enabled" field to the value that was provided on create.
func (u *SkuUpsertBulk) UpdateEnabled() *SkuUpsertBulk {
return u.Update(func(s *SkuUpsert) {
s.UpdateEnabled()
})
}
// SetWeight sets the "weight" field.
func (u *SkuUpsertBulk) SetWeight(v int) *SkuUpsertBulk {
return u.Update(func(s *SkuUpsert) {
s.SetWeight(v)
})
}
// AddWeight adds v to the "weight" field.
func (u *SkuUpsertBulk) AddWeight(v int) *SkuUpsertBulk {
return u.Update(func(s *SkuUpsert) {
s.AddWeight(v)
})
}
// UpdateWeight sets the "weight" field to the value that was provided on create.
func (u *SkuUpsertBulk) UpdateWeight() *SkuUpsertBulk {
return u.Update(func(s *SkuUpsert) {
s.UpdateWeight()
})
}
// Exec executes the query.
func (u *SkuUpsertBulk) 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("ent: OnConflict was set for builder %d. Set it on the SkuCreateBulk instead", i)
}
}
if len(u.create.conflict) == 0 {
return errors.New("ent: missing options for SkuCreateBulk.OnConflict")
}
return u.create.Exec(ctx)
}
// ExecX is like Exec, but panics if an error occurs.
func (u *SkuUpsertBulk) ExecX(ctx context.Context) {
if err := u.create.Exec(ctx); err != nil {
panic(err)
}
}