Add a full payment and subscription system supporting EasyPay (Alipay/WeChat), Stripe, and direct Alipay/WeChat Pay providers with multi-instance load balancing.
1318 lines
42 KiB
Go
1318 lines
42 KiB
Go
// 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/Wei-Shaw/sub2api/ent/subscriptionplan"
|
|
)
|
|
|
|
// SubscriptionPlanCreate is the builder for creating a SubscriptionPlan entity.
|
|
type SubscriptionPlanCreate struct {
|
|
config
|
|
mutation *SubscriptionPlanMutation
|
|
hooks []Hook
|
|
conflict []sql.ConflictOption
|
|
}
|
|
|
|
// SetGroupID sets the "group_id" field.
|
|
func (_c *SubscriptionPlanCreate) SetGroupID(v int64) *SubscriptionPlanCreate {
|
|
_c.mutation.SetGroupID(v)
|
|
return _c
|
|
}
|
|
|
|
// SetName sets the "name" field.
|
|
func (_c *SubscriptionPlanCreate) SetName(v string) *SubscriptionPlanCreate {
|
|
_c.mutation.SetName(v)
|
|
return _c
|
|
}
|
|
|
|
// SetDescription sets the "description" field.
|
|
func (_c *SubscriptionPlanCreate) SetDescription(v string) *SubscriptionPlanCreate {
|
|
_c.mutation.SetDescription(v)
|
|
return _c
|
|
}
|
|
|
|
// SetNillableDescription sets the "description" field if the given value is not nil.
|
|
func (_c *SubscriptionPlanCreate) SetNillableDescription(v *string) *SubscriptionPlanCreate {
|
|
if v != nil {
|
|
_c.SetDescription(*v)
|
|
}
|
|
return _c
|
|
}
|
|
|
|
// SetPrice sets the "price" field.
|
|
func (_c *SubscriptionPlanCreate) SetPrice(v float64) *SubscriptionPlanCreate {
|
|
_c.mutation.SetPrice(v)
|
|
return _c
|
|
}
|
|
|
|
// SetOriginalPrice sets the "original_price" field.
|
|
func (_c *SubscriptionPlanCreate) SetOriginalPrice(v float64) *SubscriptionPlanCreate {
|
|
_c.mutation.SetOriginalPrice(v)
|
|
return _c
|
|
}
|
|
|
|
// SetNillableOriginalPrice sets the "original_price" field if the given value is not nil.
|
|
func (_c *SubscriptionPlanCreate) SetNillableOriginalPrice(v *float64) *SubscriptionPlanCreate {
|
|
if v != nil {
|
|
_c.SetOriginalPrice(*v)
|
|
}
|
|
return _c
|
|
}
|
|
|
|
// SetValidityDays sets the "validity_days" field.
|
|
func (_c *SubscriptionPlanCreate) SetValidityDays(v int) *SubscriptionPlanCreate {
|
|
_c.mutation.SetValidityDays(v)
|
|
return _c
|
|
}
|
|
|
|
// SetNillableValidityDays sets the "validity_days" field if the given value is not nil.
|
|
func (_c *SubscriptionPlanCreate) SetNillableValidityDays(v *int) *SubscriptionPlanCreate {
|
|
if v != nil {
|
|
_c.SetValidityDays(*v)
|
|
}
|
|
return _c
|
|
}
|
|
|
|
// SetValidityUnit sets the "validity_unit" field.
|
|
func (_c *SubscriptionPlanCreate) SetValidityUnit(v string) *SubscriptionPlanCreate {
|
|
_c.mutation.SetValidityUnit(v)
|
|
return _c
|
|
}
|
|
|
|
// SetNillableValidityUnit sets the "validity_unit" field if the given value is not nil.
|
|
func (_c *SubscriptionPlanCreate) SetNillableValidityUnit(v *string) *SubscriptionPlanCreate {
|
|
if v != nil {
|
|
_c.SetValidityUnit(*v)
|
|
}
|
|
return _c
|
|
}
|
|
|
|
// SetFeatures sets the "features" field.
|
|
func (_c *SubscriptionPlanCreate) SetFeatures(v string) *SubscriptionPlanCreate {
|
|
_c.mutation.SetFeatures(v)
|
|
return _c
|
|
}
|
|
|
|
// SetNillableFeatures sets the "features" field if the given value is not nil.
|
|
func (_c *SubscriptionPlanCreate) SetNillableFeatures(v *string) *SubscriptionPlanCreate {
|
|
if v != nil {
|
|
_c.SetFeatures(*v)
|
|
}
|
|
return _c
|
|
}
|
|
|
|
// SetProductName sets the "product_name" field.
|
|
func (_c *SubscriptionPlanCreate) SetProductName(v string) *SubscriptionPlanCreate {
|
|
_c.mutation.SetProductName(v)
|
|
return _c
|
|
}
|
|
|
|
// SetNillableProductName sets the "product_name" field if the given value is not nil.
|
|
func (_c *SubscriptionPlanCreate) SetNillableProductName(v *string) *SubscriptionPlanCreate {
|
|
if v != nil {
|
|
_c.SetProductName(*v)
|
|
}
|
|
return _c
|
|
}
|
|
|
|
// SetForSale sets the "for_sale" field.
|
|
func (_c *SubscriptionPlanCreate) SetForSale(v bool) *SubscriptionPlanCreate {
|
|
_c.mutation.SetForSale(v)
|
|
return _c
|
|
}
|
|
|
|
// SetNillableForSale sets the "for_sale" field if the given value is not nil.
|
|
func (_c *SubscriptionPlanCreate) SetNillableForSale(v *bool) *SubscriptionPlanCreate {
|
|
if v != nil {
|
|
_c.SetForSale(*v)
|
|
}
|
|
return _c
|
|
}
|
|
|
|
// SetSortOrder sets the "sort_order" field.
|
|
func (_c *SubscriptionPlanCreate) SetSortOrder(v int) *SubscriptionPlanCreate {
|
|
_c.mutation.SetSortOrder(v)
|
|
return _c
|
|
}
|
|
|
|
// SetNillableSortOrder sets the "sort_order" field if the given value is not nil.
|
|
func (_c *SubscriptionPlanCreate) SetNillableSortOrder(v *int) *SubscriptionPlanCreate {
|
|
if v != nil {
|
|
_c.SetSortOrder(*v)
|
|
}
|
|
return _c
|
|
}
|
|
|
|
// SetCreatedAt sets the "created_at" field.
|
|
func (_c *SubscriptionPlanCreate) SetCreatedAt(v time.Time) *SubscriptionPlanCreate {
|
|
_c.mutation.SetCreatedAt(v)
|
|
return _c
|
|
}
|
|
|
|
// SetNillableCreatedAt sets the "created_at" field if the given value is not nil.
|
|
func (_c *SubscriptionPlanCreate) SetNillableCreatedAt(v *time.Time) *SubscriptionPlanCreate {
|
|
if v != nil {
|
|
_c.SetCreatedAt(*v)
|
|
}
|
|
return _c
|
|
}
|
|
|
|
// SetUpdatedAt sets the "updated_at" field.
|
|
func (_c *SubscriptionPlanCreate) SetUpdatedAt(v time.Time) *SubscriptionPlanCreate {
|
|
_c.mutation.SetUpdatedAt(v)
|
|
return _c
|
|
}
|
|
|
|
// SetNillableUpdatedAt sets the "updated_at" field if the given value is not nil.
|
|
func (_c *SubscriptionPlanCreate) SetNillableUpdatedAt(v *time.Time) *SubscriptionPlanCreate {
|
|
if v != nil {
|
|
_c.SetUpdatedAt(*v)
|
|
}
|
|
return _c
|
|
}
|
|
|
|
// Mutation returns the SubscriptionPlanMutation object of the builder.
|
|
func (_c *SubscriptionPlanCreate) Mutation() *SubscriptionPlanMutation {
|
|
return _c.mutation
|
|
}
|
|
|
|
// Save creates the SubscriptionPlan in the database.
|
|
func (_c *SubscriptionPlanCreate) Save(ctx context.Context) (*SubscriptionPlan, error) {
|
|
_c.defaults()
|
|
return withHooks(ctx, _c.sqlSave, _c.mutation, _c.hooks)
|
|
}
|
|
|
|
// SaveX calls Save and panics if Save returns an error.
|
|
func (_c *SubscriptionPlanCreate) SaveX(ctx context.Context) *SubscriptionPlan {
|
|
v, err := _c.Save(ctx)
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
return v
|
|
}
|
|
|
|
// Exec executes the query.
|
|
func (_c *SubscriptionPlanCreate) Exec(ctx context.Context) error {
|
|
_, err := _c.Save(ctx)
|
|
return err
|
|
}
|
|
|
|
// ExecX is like Exec, but panics if an error occurs.
|
|
func (_c *SubscriptionPlanCreate) 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 *SubscriptionPlanCreate) defaults() {
|
|
if _, ok := _c.mutation.Description(); !ok {
|
|
v := subscriptionplan.DefaultDescription
|
|
_c.mutation.SetDescription(v)
|
|
}
|
|
if _, ok := _c.mutation.ValidityDays(); !ok {
|
|
v := subscriptionplan.DefaultValidityDays
|
|
_c.mutation.SetValidityDays(v)
|
|
}
|
|
if _, ok := _c.mutation.ValidityUnit(); !ok {
|
|
v := subscriptionplan.DefaultValidityUnit
|
|
_c.mutation.SetValidityUnit(v)
|
|
}
|
|
if _, ok := _c.mutation.Features(); !ok {
|
|
v := subscriptionplan.DefaultFeatures
|
|
_c.mutation.SetFeatures(v)
|
|
}
|
|
if _, ok := _c.mutation.ProductName(); !ok {
|
|
v := subscriptionplan.DefaultProductName
|
|
_c.mutation.SetProductName(v)
|
|
}
|
|
if _, ok := _c.mutation.ForSale(); !ok {
|
|
v := subscriptionplan.DefaultForSale
|
|
_c.mutation.SetForSale(v)
|
|
}
|
|
if _, ok := _c.mutation.SortOrder(); !ok {
|
|
v := subscriptionplan.DefaultSortOrder
|
|
_c.mutation.SetSortOrder(v)
|
|
}
|
|
if _, ok := _c.mutation.CreatedAt(); !ok {
|
|
v := subscriptionplan.DefaultCreatedAt()
|
|
_c.mutation.SetCreatedAt(v)
|
|
}
|
|
if _, ok := _c.mutation.UpdatedAt(); !ok {
|
|
v := subscriptionplan.DefaultUpdatedAt()
|
|
_c.mutation.SetUpdatedAt(v)
|
|
}
|
|
}
|
|
|
|
// check runs all checks and user-defined validators on the builder.
|
|
func (_c *SubscriptionPlanCreate) check() error {
|
|
if _, ok := _c.mutation.GroupID(); !ok {
|
|
return &ValidationError{Name: "group_id", err: errors.New(`ent: missing required field "SubscriptionPlan.group_id"`)}
|
|
}
|
|
if _, ok := _c.mutation.Name(); !ok {
|
|
return &ValidationError{Name: "name", err: errors.New(`ent: missing required field "SubscriptionPlan.name"`)}
|
|
}
|
|
if v, ok := _c.mutation.Name(); ok {
|
|
if err := subscriptionplan.NameValidator(v); err != nil {
|
|
return &ValidationError{Name: "name", err: fmt.Errorf(`ent: validator failed for field "SubscriptionPlan.name": %w`, err)}
|
|
}
|
|
}
|
|
if _, ok := _c.mutation.Description(); !ok {
|
|
return &ValidationError{Name: "description", err: errors.New(`ent: missing required field "SubscriptionPlan.description"`)}
|
|
}
|
|
if _, ok := _c.mutation.Price(); !ok {
|
|
return &ValidationError{Name: "price", err: errors.New(`ent: missing required field "SubscriptionPlan.price"`)}
|
|
}
|
|
if _, ok := _c.mutation.ValidityDays(); !ok {
|
|
return &ValidationError{Name: "validity_days", err: errors.New(`ent: missing required field "SubscriptionPlan.validity_days"`)}
|
|
}
|
|
if _, ok := _c.mutation.ValidityUnit(); !ok {
|
|
return &ValidationError{Name: "validity_unit", err: errors.New(`ent: missing required field "SubscriptionPlan.validity_unit"`)}
|
|
}
|
|
if v, ok := _c.mutation.ValidityUnit(); ok {
|
|
if err := subscriptionplan.ValidityUnitValidator(v); err != nil {
|
|
return &ValidationError{Name: "validity_unit", err: fmt.Errorf(`ent: validator failed for field "SubscriptionPlan.validity_unit": %w`, err)}
|
|
}
|
|
}
|
|
if _, ok := _c.mutation.Features(); !ok {
|
|
return &ValidationError{Name: "features", err: errors.New(`ent: missing required field "SubscriptionPlan.features"`)}
|
|
}
|
|
if _, ok := _c.mutation.ProductName(); !ok {
|
|
return &ValidationError{Name: "product_name", err: errors.New(`ent: missing required field "SubscriptionPlan.product_name"`)}
|
|
}
|
|
if v, ok := _c.mutation.ProductName(); ok {
|
|
if err := subscriptionplan.ProductNameValidator(v); err != nil {
|
|
return &ValidationError{Name: "product_name", err: fmt.Errorf(`ent: validator failed for field "SubscriptionPlan.product_name": %w`, err)}
|
|
}
|
|
}
|
|
if _, ok := _c.mutation.ForSale(); !ok {
|
|
return &ValidationError{Name: "for_sale", err: errors.New(`ent: missing required field "SubscriptionPlan.for_sale"`)}
|
|
}
|
|
if _, ok := _c.mutation.SortOrder(); !ok {
|
|
return &ValidationError{Name: "sort_order", err: errors.New(`ent: missing required field "SubscriptionPlan.sort_order"`)}
|
|
}
|
|
if _, ok := _c.mutation.CreatedAt(); !ok {
|
|
return &ValidationError{Name: "created_at", err: errors.New(`ent: missing required field "SubscriptionPlan.created_at"`)}
|
|
}
|
|
if _, ok := _c.mutation.UpdatedAt(); !ok {
|
|
return &ValidationError{Name: "updated_at", err: errors.New(`ent: missing required field "SubscriptionPlan.updated_at"`)}
|
|
}
|
|
return nil
|
|
}
|
|
|
|
func (_c *SubscriptionPlanCreate) sqlSave(ctx context.Context) (*SubscriptionPlan, 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
|
|
}
|
|
id := _spec.ID.Value.(int64)
|
|
_node.ID = int64(id)
|
|
_c.mutation.id = &_node.ID
|
|
_c.mutation.done = true
|
|
return _node, nil
|
|
}
|
|
|
|
func (_c *SubscriptionPlanCreate) createSpec() (*SubscriptionPlan, *sqlgraph.CreateSpec) {
|
|
var (
|
|
_node = &SubscriptionPlan{config: _c.config}
|
|
_spec = sqlgraph.NewCreateSpec(subscriptionplan.Table, sqlgraph.NewFieldSpec(subscriptionplan.FieldID, field.TypeInt64))
|
|
)
|
|
_spec.OnConflict = _c.conflict
|
|
if value, ok := _c.mutation.GroupID(); ok {
|
|
_spec.SetField(subscriptionplan.FieldGroupID, field.TypeInt64, value)
|
|
_node.GroupID = value
|
|
}
|
|
if value, ok := _c.mutation.Name(); ok {
|
|
_spec.SetField(subscriptionplan.FieldName, field.TypeString, value)
|
|
_node.Name = value
|
|
}
|
|
if value, ok := _c.mutation.Description(); ok {
|
|
_spec.SetField(subscriptionplan.FieldDescription, field.TypeString, value)
|
|
_node.Description = value
|
|
}
|
|
if value, ok := _c.mutation.Price(); ok {
|
|
_spec.SetField(subscriptionplan.FieldPrice, field.TypeFloat64, value)
|
|
_node.Price = value
|
|
}
|
|
if value, ok := _c.mutation.OriginalPrice(); ok {
|
|
_spec.SetField(subscriptionplan.FieldOriginalPrice, field.TypeFloat64, value)
|
|
_node.OriginalPrice = &value
|
|
}
|
|
if value, ok := _c.mutation.ValidityDays(); ok {
|
|
_spec.SetField(subscriptionplan.FieldValidityDays, field.TypeInt, value)
|
|
_node.ValidityDays = value
|
|
}
|
|
if value, ok := _c.mutation.ValidityUnit(); ok {
|
|
_spec.SetField(subscriptionplan.FieldValidityUnit, field.TypeString, value)
|
|
_node.ValidityUnit = value
|
|
}
|
|
if value, ok := _c.mutation.Features(); ok {
|
|
_spec.SetField(subscriptionplan.FieldFeatures, field.TypeString, value)
|
|
_node.Features = value
|
|
}
|
|
if value, ok := _c.mutation.ProductName(); ok {
|
|
_spec.SetField(subscriptionplan.FieldProductName, field.TypeString, value)
|
|
_node.ProductName = value
|
|
}
|
|
if value, ok := _c.mutation.ForSale(); ok {
|
|
_spec.SetField(subscriptionplan.FieldForSale, field.TypeBool, value)
|
|
_node.ForSale = value
|
|
}
|
|
if value, ok := _c.mutation.SortOrder(); ok {
|
|
_spec.SetField(subscriptionplan.FieldSortOrder, field.TypeInt, value)
|
|
_node.SortOrder = value
|
|
}
|
|
if value, ok := _c.mutation.CreatedAt(); ok {
|
|
_spec.SetField(subscriptionplan.FieldCreatedAt, field.TypeTime, value)
|
|
_node.CreatedAt = value
|
|
}
|
|
if value, ok := _c.mutation.UpdatedAt(); ok {
|
|
_spec.SetField(subscriptionplan.FieldUpdatedAt, field.TypeTime, value)
|
|
_node.UpdatedAt = value
|
|
}
|
|
return _node, _spec
|
|
}
|
|
|
|
// OnConflict allows configuring the `ON CONFLICT` / `ON DUPLICATE KEY` clause
|
|
// of the `INSERT` statement. For example:
|
|
//
|
|
// client.SubscriptionPlan.Create().
|
|
// SetGroupID(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.SubscriptionPlanUpsert) {
|
|
// SetGroupID(v+v).
|
|
// }).
|
|
// Exec(ctx)
|
|
func (_c *SubscriptionPlanCreate) OnConflict(opts ...sql.ConflictOption) *SubscriptionPlanUpsertOne {
|
|
_c.conflict = opts
|
|
return &SubscriptionPlanUpsertOne{
|
|
create: _c,
|
|
}
|
|
}
|
|
|
|
// OnConflictColumns calls `OnConflict` and configures the columns
|
|
// as conflict target. Using this option is equivalent to using:
|
|
//
|
|
// client.SubscriptionPlan.Create().
|
|
// OnConflict(sql.ConflictColumns(columns...)).
|
|
// Exec(ctx)
|
|
func (_c *SubscriptionPlanCreate) OnConflictColumns(columns ...string) *SubscriptionPlanUpsertOne {
|
|
_c.conflict = append(_c.conflict, sql.ConflictColumns(columns...))
|
|
return &SubscriptionPlanUpsertOne{
|
|
create: _c,
|
|
}
|
|
}
|
|
|
|
type (
|
|
// SubscriptionPlanUpsertOne is the builder for "upsert"-ing
|
|
// one SubscriptionPlan node.
|
|
SubscriptionPlanUpsertOne struct {
|
|
create *SubscriptionPlanCreate
|
|
}
|
|
|
|
// SubscriptionPlanUpsert is the "OnConflict" setter.
|
|
SubscriptionPlanUpsert struct {
|
|
*sql.UpdateSet
|
|
}
|
|
)
|
|
|
|
// SetGroupID sets the "group_id" field.
|
|
func (u *SubscriptionPlanUpsert) SetGroupID(v int64) *SubscriptionPlanUpsert {
|
|
u.Set(subscriptionplan.FieldGroupID, v)
|
|
return u
|
|
}
|
|
|
|
// UpdateGroupID sets the "group_id" field to the value that was provided on create.
|
|
func (u *SubscriptionPlanUpsert) UpdateGroupID() *SubscriptionPlanUpsert {
|
|
u.SetExcluded(subscriptionplan.FieldGroupID)
|
|
return u
|
|
}
|
|
|
|
// AddGroupID adds v to the "group_id" field.
|
|
func (u *SubscriptionPlanUpsert) AddGroupID(v int64) *SubscriptionPlanUpsert {
|
|
u.Add(subscriptionplan.FieldGroupID, v)
|
|
return u
|
|
}
|
|
|
|
// SetName sets the "name" field.
|
|
func (u *SubscriptionPlanUpsert) SetName(v string) *SubscriptionPlanUpsert {
|
|
u.Set(subscriptionplan.FieldName, v)
|
|
return u
|
|
}
|
|
|
|
// UpdateName sets the "name" field to the value that was provided on create.
|
|
func (u *SubscriptionPlanUpsert) UpdateName() *SubscriptionPlanUpsert {
|
|
u.SetExcluded(subscriptionplan.FieldName)
|
|
return u
|
|
}
|
|
|
|
// SetDescription sets the "description" field.
|
|
func (u *SubscriptionPlanUpsert) SetDescription(v string) *SubscriptionPlanUpsert {
|
|
u.Set(subscriptionplan.FieldDescription, v)
|
|
return u
|
|
}
|
|
|
|
// UpdateDescription sets the "description" field to the value that was provided on create.
|
|
func (u *SubscriptionPlanUpsert) UpdateDescription() *SubscriptionPlanUpsert {
|
|
u.SetExcluded(subscriptionplan.FieldDescription)
|
|
return u
|
|
}
|
|
|
|
// SetPrice sets the "price" field.
|
|
func (u *SubscriptionPlanUpsert) SetPrice(v float64) *SubscriptionPlanUpsert {
|
|
u.Set(subscriptionplan.FieldPrice, v)
|
|
return u
|
|
}
|
|
|
|
// UpdatePrice sets the "price" field to the value that was provided on create.
|
|
func (u *SubscriptionPlanUpsert) UpdatePrice() *SubscriptionPlanUpsert {
|
|
u.SetExcluded(subscriptionplan.FieldPrice)
|
|
return u
|
|
}
|
|
|
|
// AddPrice adds v to the "price" field.
|
|
func (u *SubscriptionPlanUpsert) AddPrice(v float64) *SubscriptionPlanUpsert {
|
|
u.Add(subscriptionplan.FieldPrice, v)
|
|
return u
|
|
}
|
|
|
|
// SetOriginalPrice sets the "original_price" field.
|
|
func (u *SubscriptionPlanUpsert) SetOriginalPrice(v float64) *SubscriptionPlanUpsert {
|
|
u.Set(subscriptionplan.FieldOriginalPrice, v)
|
|
return u
|
|
}
|
|
|
|
// UpdateOriginalPrice sets the "original_price" field to the value that was provided on create.
|
|
func (u *SubscriptionPlanUpsert) UpdateOriginalPrice() *SubscriptionPlanUpsert {
|
|
u.SetExcluded(subscriptionplan.FieldOriginalPrice)
|
|
return u
|
|
}
|
|
|
|
// AddOriginalPrice adds v to the "original_price" field.
|
|
func (u *SubscriptionPlanUpsert) AddOriginalPrice(v float64) *SubscriptionPlanUpsert {
|
|
u.Add(subscriptionplan.FieldOriginalPrice, v)
|
|
return u
|
|
}
|
|
|
|
// ClearOriginalPrice clears the value of the "original_price" field.
|
|
func (u *SubscriptionPlanUpsert) ClearOriginalPrice() *SubscriptionPlanUpsert {
|
|
u.SetNull(subscriptionplan.FieldOriginalPrice)
|
|
return u
|
|
}
|
|
|
|
// SetValidityDays sets the "validity_days" field.
|
|
func (u *SubscriptionPlanUpsert) SetValidityDays(v int) *SubscriptionPlanUpsert {
|
|
u.Set(subscriptionplan.FieldValidityDays, v)
|
|
return u
|
|
}
|
|
|
|
// UpdateValidityDays sets the "validity_days" field to the value that was provided on create.
|
|
func (u *SubscriptionPlanUpsert) UpdateValidityDays() *SubscriptionPlanUpsert {
|
|
u.SetExcluded(subscriptionplan.FieldValidityDays)
|
|
return u
|
|
}
|
|
|
|
// AddValidityDays adds v to the "validity_days" field.
|
|
func (u *SubscriptionPlanUpsert) AddValidityDays(v int) *SubscriptionPlanUpsert {
|
|
u.Add(subscriptionplan.FieldValidityDays, v)
|
|
return u
|
|
}
|
|
|
|
// SetValidityUnit sets the "validity_unit" field.
|
|
func (u *SubscriptionPlanUpsert) SetValidityUnit(v string) *SubscriptionPlanUpsert {
|
|
u.Set(subscriptionplan.FieldValidityUnit, v)
|
|
return u
|
|
}
|
|
|
|
// UpdateValidityUnit sets the "validity_unit" field to the value that was provided on create.
|
|
func (u *SubscriptionPlanUpsert) UpdateValidityUnit() *SubscriptionPlanUpsert {
|
|
u.SetExcluded(subscriptionplan.FieldValidityUnit)
|
|
return u
|
|
}
|
|
|
|
// SetFeatures sets the "features" field.
|
|
func (u *SubscriptionPlanUpsert) SetFeatures(v string) *SubscriptionPlanUpsert {
|
|
u.Set(subscriptionplan.FieldFeatures, v)
|
|
return u
|
|
}
|
|
|
|
// UpdateFeatures sets the "features" field to the value that was provided on create.
|
|
func (u *SubscriptionPlanUpsert) UpdateFeatures() *SubscriptionPlanUpsert {
|
|
u.SetExcluded(subscriptionplan.FieldFeatures)
|
|
return u
|
|
}
|
|
|
|
// SetProductName sets the "product_name" field.
|
|
func (u *SubscriptionPlanUpsert) SetProductName(v string) *SubscriptionPlanUpsert {
|
|
u.Set(subscriptionplan.FieldProductName, v)
|
|
return u
|
|
}
|
|
|
|
// UpdateProductName sets the "product_name" field to the value that was provided on create.
|
|
func (u *SubscriptionPlanUpsert) UpdateProductName() *SubscriptionPlanUpsert {
|
|
u.SetExcluded(subscriptionplan.FieldProductName)
|
|
return u
|
|
}
|
|
|
|
// SetForSale sets the "for_sale" field.
|
|
func (u *SubscriptionPlanUpsert) SetForSale(v bool) *SubscriptionPlanUpsert {
|
|
u.Set(subscriptionplan.FieldForSale, v)
|
|
return u
|
|
}
|
|
|
|
// UpdateForSale sets the "for_sale" field to the value that was provided on create.
|
|
func (u *SubscriptionPlanUpsert) UpdateForSale() *SubscriptionPlanUpsert {
|
|
u.SetExcluded(subscriptionplan.FieldForSale)
|
|
return u
|
|
}
|
|
|
|
// SetSortOrder sets the "sort_order" field.
|
|
func (u *SubscriptionPlanUpsert) SetSortOrder(v int) *SubscriptionPlanUpsert {
|
|
u.Set(subscriptionplan.FieldSortOrder, v)
|
|
return u
|
|
}
|
|
|
|
// UpdateSortOrder sets the "sort_order" field to the value that was provided on create.
|
|
func (u *SubscriptionPlanUpsert) UpdateSortOrder() *SubscriptionPlanUpsert {
|
|
u.SetExcluded(subscriptionplan.FieldSortOrder)
|
|
return u
|
|
}
|
|
|
|
// AddSortOrder adds v to the "sort_order" field.
|
|
func (u *SubscriptionPlanUpsert) AddSortOrder(v int) *SubscriptionPlanUpsert {
|
|
u.Add(subscriptionplan.FieldSortOrder, v)
|
|
return u
|
|
}
|
|
|
|
// SetUpdatedAt sets the "updated_at" field.
|
|
func (u *SubscriptionPlanUpsert) SetUpdatedAt(v time.Time) *SubscriptionPlanUpsert {
|
|
u.Set(subscriptionplan.FieldUpdatedAt, v)
|
|
return u
|
|
}
|
|
|
|
// UpdateUpdatedAt sets the "updated_at" field to the value that was provided on create.
|
|
func (u *SubscriptionPlanUpsert) UpdateUpdatedAt() *SubscriptionPlanUpsert {
|
|
u.SetExcluded(subscriptionplan.FieldUpdatedAt)
|
|
return u
|
|
}
|
|
|
|
// UpdateNewValues updates the mutable fields using the new values that were set on create.
|
|
// Using this option is equivalent to using:
|
|
//
|
|
// client.SubscriptionPlan.Create().
|
|
// OnConflict(
|
|
// sql.ResolveWithNewValues(),
|
|
// ).
|
|
// Exec(ctx)
|
|
func (u *SubscriptionPlanUpsertOne) UpdateNewValues() *SubscriptionPlanUpsertOne {
|
|
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(subscriptionplan.FieldCreatedAt)
|
|
}
|
|
}))
|
|
return u
|
|
}
|
|
|
|
// Ignore sets each column to itself in case of conflict.
|
|
// Using this option is equivalent to using:
|
|
//
|
|
// client.SubscriptionPlan.Create().
|
|
// OnConflict(sql.ResolveWithIgnore()).
|
|
// Exec(ctx)
|
|
func (u *SubscriptionPlanUpsertOne) Ignore() *SubscriptionPlanUpsertOne {
|
|
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 *SubscriptionPlanUpsertOne) DoNothing() *SubscriptionPlanUpsertOne {
|
|
u.create.conflict = append(u.create.conflict, sql.DoNothing())
|
|
return u
|
|
}
|
|
|
|
// Update allows overriding fields `UPDATE` values. See the SubscriptionPlanCreate.OnConflict
|
|
// documentation for more info.
|
|
func (u *SubscriptionPlanUpsertOne) Update(set func(*SubscriptionPlanUpsert)) *SubscriptionPlanUpsertOne {
|
|
u.create.conflict = append(u.create.conflict, sql.ResolveWith(func(update *sql.UpdateSet) {
|
|
set(&SubscriptionPlanUpsert{UpdateSet: update})
|
|
}))
|
|
return u
|
|
}
|
|
|
|
// SetGroupID sets the "group_id" field.
|
|
func (u *SubscriptionPlanUpsertOne) SetGroupID(v int64) *SubscriptionPlanUpsertOne {
|
|
return u.Update(func(s *SubscriptionPlanUpsert) {
|
|
s.SetGroupID(v)
|
|
})
|
|
}
|
|
|
|
// AddGroupID adds v to the "group_id" field.
|
|
func (u *SubscriptionPlanUpsertOne) AddGroupID(v int64) *SubscriptionPlanUpsertOne {
|
|
return u.Update(func(s *SubscriptionPlanUpsert) {
|
|
s.AddGroupID(v)
|
|
})
|
|
}
|
|
|
|
// UpdateGroupID sets the "group_id" field to the value that was provided on create.
|
|
func (u *SubscriptionPlanUpsertOne) UpdateGroupID() *SubscriptionPlanUpsertOne {
|
|
return u.Update(func(s *SubscriptionPlanUpsert) {
|
|
s.UpdateGroupID()
|
|
})
|
|
}
|
|
|
|
// SetName sets the "name" field.
|
|
func (u *SubscriptionPlanUpsertOne) SetName(v string) *SubscriptionPlanUpsertOne {
|
|
return u.Update(func(s *SubscriptionPlanUpsert) {
|
|
s.SetName(v)
|
|
})
|
|
}
|
|
|
|
// UpdateName sets the "name" field to the value that was provided on create.
|
|
func (u *SubscriptionPlanUpsertOne) UpdateName() *SubscriptionPlanUpsertOne {
|
|
return u.Update(func(s *SubscriptionPlanUpsert) {
|
|
s.UpdateName()
|
|
})
|
|
}
|
|
|
|
// SetDescription sets the "description" field.
|
|
func (u *SubscriptionPlanUpsertOne) SetDescription(v string) *SubscriptionPlanUpsertOne {
|
|
return u.Update(func(s *SubscriptionPlanUpsert) {
|
|
s.SetDescription(v)
|
|
})
|
|
}
|
|
|
|
// UpdateDescription sets the "description" field to the value that was provided on create.
|
|
func (u *SubscriptionPlanUpsertOne) UpdateDescription() *SubscriptionPlanUpsertOne {
|
|
return u.Update(func(s *SubscriptionPlanUpsert) {
|
|
s.UpdateDescription()
|
|
})
|
|
}
|
|
|
|
// SetPrice sets the "price" field.
|
|
func (u *SubscriptionPlanUpsertOne) SetPrice(v float64) *SubscriptionPlanUpsertOne {
|
|
return u.Update(func(s *SubscriptionPlanUpsert) {
|
|
s.SetPrice(v)
|
|
})
|
|
}
|
|
|
|
// AddPrice adds v to the "price" field.
|
|
func (u *SubscriptionPlanUpsertOne) AddPrice(v float64) *SubscriptionPlanUpsertOne {
|
|
return u.Update(func(s *SubscriptionPlanUpsert) {
|
|
s.AddPrice(v)
|
|
})
|
|
}
|
|
|
|
// UpdatePrice sets the "price" field to the value that was provided on create.
|
|
func (u *SubscriptionPlanUpsertOne) UpdatePrice() *SubscriptionPlanUpsertOne {
|
|
return u.Update(func(s *SubscriptionPlanUpsert) {
|
|
s.UpdatePrice()
|
|
})
|
|
}
|
|
|
|
// SetOriginalPrice sets the "original_price" field.
|
|
func (u *SubscriptionPlanUpsertOne) SetOriginalPrice(v float64) *SubscriptionPlanUpsertOne {
|
|
return u.Update(func(s *SubscriptionPlanUpsert) {
|
|
s.SetOriginalPrice(v)
|
|
})
|
|
}
|
|
|
|
// AddOriginalPrice adds v to the "original_price" field.
|
|
func (u *SubscriptionPlanUpsertOne) AddOriginalPrice(v float64) *SubscriptionPlanUpsertOne {
|
|
return u.Update(func(s *SubscriptionPlanUpsert) {
|
|
s.AddOriginalPrice(v)
|
|
})
|
|
}
|
|
|
|
// UpdateOriginalPrice sets the "original_price" field to the value that was provided on create.
|
|
func (u *SubscriptionPlanUpsertOne) UpdateOriginalPrice() *SubscriptionPlanUpsertOne {
|
|
return u.Update(func(s *SubscriptionPlanUpsert) {
|
|
s.UpdateOriginalPrice()
|
|
})
|
|
}
|
|
|
|
// ClearOriginalPrice clears the value of the "original_price" field.
|
|
func (u *SubscriptionPlanUpsertOne) ClearOriginalPrice() *SubscriptionPlanUpsertOne {
|
|
return u.Update(func(s *SubscriptionPlanUpsert) {
|
|
s.ClearOriginalPrice()
|
|
})
|
|
}
|
|
|
|
// SetValidityDays sets the "validity_days" field.
|
|
func (u *SubscriptionPlanUpsertOne) SetValidityDays(v int) *SubscriptionPlanUpsertOne {
|
|
return u.Update(func(s *SubscriptionPlanUpsert) {
|
|
s.SetValidityDays(v)
|
|
})
|
|
}
|
|
|
|
// AddValidityDays adds v to the "validity_days" field.
|
|
func (u *SubscriptionPlanUpsertOne) AddValidityDays(v int) *SubscriptionPlanUpsertOne {
|
|
return u.Update(func(s *SubscriptionPlanUpsert) {
|
|
s.AddValidityDays(v)
|
|
})
|
|
}
|
|
|
|
// UpdateValidityDays sets the "validity_days" field to the value that was provided on create.
|
|
func (u *SubscriptionPlanUpsertOne) UpdateValidityDays() *SubscriptionPlanUpsertOne {
|
|
return u.Update(func(s *SubscriptionPlanUpsert) {
|
|
s.UpdateValidityDays()
|
|
})
|
|
}
|
|
|
|
// SetValidityUnit sets the "validity_unit" field.
|
|
func (u *SubscriptionPlanUpsertOne) SetValidityUnit(v string) *SubscriptionPlanUpsertOne {
|
|
return u.Update(func(s *SubscriptionPlanUpsert) {
|
|
s.SetValidityUnit(v)
|
|
})
|
|
}
|
|
|
|
// UpdateValidityUnit sets the "validity_unit" field to the value that was provided on create.
|
|
func (u *SubscriptionPlanUpsertOne) UpdateValidityUnit() *SubscriptionPlanUpsertOne {
|
|
return u.Update(func(s *SubscriptionPlanUpsert) {
|
|
s.UpdateValidityUnit()
|
|
})
|
|
}
|
|
|
|
// SetFeatures sets the "features" field.
|
|
func (u *SubscriptionPlanUpsertOne) SetFeatures(v string) *SubscriptionPlanUpsertOne {
|
|
return u.Update(func(s *SubscriptionPlanUpsert) {
|
|
s.SetFeatures(v)
|
|
})
|
|
}
|
|
|
|
// UpdateFeatures sets the "features" field to the value that was provided on create.
|
|
func (u *SubscriptionPlanUpsertOne) UpdateFeatures() *SubscriptionPlanUpsertOne {
|
|
return u.Update(func(s *SubscriptionPlanUpsert) {
|
|
s.UpdateFeatures()
|
|
})
|
|
}
|
|
|
|
// SetProductName sets the "product_name" field.
|
|
func (u *SubscriptionPlanUpsertOne) SetProductName(v string) *SubscriptionPlanUpsertOne {
|
|
return u.Update(func(s *SubscriptionPlanUpsert) {
|
|
s.SetProductName(v)
|
|
})
|
|
}
|
|
|
|
// UpdateProductName sets the "product_name" field to the value that was provided on create.
|
|
func (u *SubscriptionPlanUpsertOne) UpdateProductName() *SubscriptionPlanUpsertOne {
|
|
return u.Update(func(s *SubscriptionPlanUpsert) {
|
|
s.UpdateProductName()
|
|
})
|
|
}
|
|
|
|
// SetForSale sets the "for_sale" field.
|
|
func (u *SubscriptionPlanUpsertOne) SetForSale(v bool) *SubscriptionPlanUpsertOne {
|
|
return u.Update(func(s *SubscriptionPlanUpsert) {
|
|
s.SetForSale(v)
|
|
})
|
|
}
|
|
|
|
// UpdateForSale sets the "for_sale" field to the value that was provided on create.
|
|
func (u *SubscriptionPlanUpsertOne) UpdateForSale() *SubscriptionPlanUpsertOne {
|
|
return u.Update(func(s *SubscriptionPlanUpsert) {
|
|
s.UpdateForSale()
|
|
})
|
|
}
|
|
|
|
// SetSortOrder sets the "sort_order" field.
|
|
func (u *SubscriptionPlanUpsertOne) SetSortOrder(v int) *SubscriptionPlanUpsertOne {
|
|
return u.Update(func(s *SubscriptionPlanUpsert) {
|
|
s.SetSortOrder(v)
|
|
})
|
|
}
|
|
|
|
// AddSortOrder adds v to the "sort_order" field.
|
|
func (u *SubscriptionPlanUpsertOne) AddSortOrder(v int) *SubscriptionPlanUpsertOne {
|
|
return u.Update(func(s *SubscriptionPlanUpsert) {
|
|
s.AddSortOrder(v)
|
|
})
|
|
}
|
|
|
|
// UpdateSortOrder sets the "sort_order" field to the value that was provided on create.
|
|
func (u *SubscriptionPlanUpsertOne) UpdateSortOrder() *SubscriptionPlanUpsertOne {
|
|
return u.Update(func(s *SubscriptionPlanUpsert) {
|
|
s.UpdateSortOrder()
|
|
})
|
|
}
|
|
|
|
// SetUpdatedAt sets the "updated_at" field.
|
|
func (u *SubscriptionPlanUpsertOne) SetUpdatedAt(v time.Time) *SubscriptionPlanUpsertOne {
|
|
return u.Update(func(s *SubscriptionPlanUpsert) {
|
|
s.SetUpdatedAt(v)
|
|
})
|
|
}
|
|
|
|
// UpdateUpdatedAt sets the "updated_at" field to the value that was provided on create.
|
|
func (u *SubscriptionPlanUpsertOne) UpdateUpdatedAt() *SubscriptionPlanUpsertOne {
|
|
return u.Update(func(s *SubscriptionPlanUpsert) {
|
|
s.UpdateUpdatedAt()
|
|
})
|
|
}
|
|
|
|
// Exec executes the query.
|
|
func (u *SubscriptionPlanUpsertOne) Exec(ctx context.Context) error {
|
|
if len(u.create.conflict) == 0 {
|
|
return errors.New("ent: missing options for SubscriptionPlanCreate.OnConflict")
|
|
}
|
|
return u.create.Exec(ctx)
|
|
}
|
|
|
|
// ExecX is like Exec, but panics if an error occurs.
|
|
func (u *SubscriptionPlanUpsertOne) 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 *SubscriptionPlanUpsertOne) ID(ctx context.Context) (id int64, 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 *SubscriptionPlanUpsertOne) IDX(ctx context.Context) int64 {
|
|
id, err := u.ID(ctx)
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
return id
|
|
}
|
|
|
|
// SubscriptionPlanCreateBulk is the builder for creating many SubscriptionPlan entities in bulk.
|
|
type SubscriptionPlanCreateBulk struct {
|
|
config
|
|
err error
|
|
builders []*SubscriptionPlanCreate
|
|
conflict []sql.ConflictOption
|
|
}
|
|
|
|
// Save creates the SubscriptionPlan entities in the database.
|
|
func (_c *SubscriptionPlanCreateBulk) Save(ctx context.Context) ([]*SubscriptionPlan, error) {
|
|
if _c.err != nil {
|
|
return nil, _c.err
|
|
}
|
|
specs := make([]*sqlgraph.CreateSpec, len(_c.builders))
|
|
nodes := make([]*SubscriptionPlan, 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.(*SubscriptionPlanMutation)
|
|
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
|
|
if specs[i].ID.Value != nil {
|
|
id := specs[i].ID.Value.(int64)
|
|
nodes[i].ID = int64(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 *SubscriptionPlanCreateBulk) SaveX(ctx context.Context) []*SubscriptionPlan {
|
|
v, err := _c.Save(ctx)
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
return v
|
|
}
|
|
|
|
// Exec executes the query.
|
|
func (_c *SubscriptionPlanCreateBulk) Exec(ctx context.Context) error {
|
|
_, err := _c.Save(ctx)
|
|
return err
|
|
}
|
|
|
|
// ExecX is like Exec, but panics if an error occurs.
|
|
func (_c *SubscriptionPlanCreateBulk) 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.SubscriptionPlan.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.SubscriptionPlanUpsert) {
|
|
// SetGroupID(v+v).
|
|
// }).
|
|
// Exec(ctx)
|
|
func (_c *SubscriptionPlanCreateBulk) OnConflict(opts ...sql.ConflictOption) *SubscriptionPlanUpsertBulk {
|
|
_c.conflict = opts
|
|
return &SubscriptionPlanUpsertBulk{
|
|
create: _c,
|
|
}
|
|
}
|
|
|
|
// OnConflictColumns calls `OnConflict` and configures the columns
|
|
// as conflict target. Using this option is equivalent to using:
|
|
//
|
|
// client.SubscriptionPlan.Create().
|
|
// OnConflict(sql.ConflictColumns(columns...)).
|
|
// Exec(ctx)
|
|
func (_c *SubscriptionPlanCreateBulk) OnConflictColumns(columns ...string) *SubscriptionPlanUpsertBulk {
|
|
_c.conflict = append(_c.conflict, sql.ConflictColumns(columns...))
|
|
return &SubscriptionPlanUpsertBulk{
|
|
create: _c,
|
|
}
|
|
}
|
|
|
|
// SubscriptionPlanUpsertBulk is the builder for "upsert"-ing
|
|
// a bulk of SubscriptionPlan nodes.
|
|
type SubscriptionPlanUpsertBulk struct {
|
|
create *SubscriptionPlanCreateBulk
|
|
}
|
|
|
|
// UpdateNewValues updates the mutable fields using the new values that
|
|
// were set on create. Using this option is equivalent to using:
|
|
//
|
|
// client.SubscriptionPlan.Create().
|
|
// OnConflict(
|
|
// sql.ResolveWithNewValues(),
|
|
// ).
|
|
// Exec(ctx)
|
|
func (u *SubscriptionPlanUpsertBulk) UpdateNewValues() *SubscriptionPlanUpsertBulk {
|
|
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(subscriptionplan.FieldCreatedAt)
|
|
}
|
|
}
|
|
}))
|
|
return u
|
|
}
|
|
|
|
// Ignore sets each column to itself in case of conflict.
|
|
// Using this option is equivalent to using:
|
|
//
|
|
// client.SubscriptionPlan.Create().
|
|
// OnConflict(sql.ResolveWithIgnore()).
|
|
// Exec(ctx)
|
|
func (u *SubscriptionPlanUpsertBulk) Ignore() *SubscriptionPlanUpsertBulk {
|
|
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 *SubscriptionPlanUpsertBulk) DoNothing() *SubscriptionPlanUpsertBulk {
|
|
u.create.conflict = append(u.create.conflict, sql.DoNothing())
|
|
return u
|
|
}
|
|
|
|
// Update allows overriding fields `UPDATE` values. See the SubscriptionPlanCreateBulk.OnConflict
|
|
// documentation for more info.
|
|
func (u *SubscriptionPlanUpsertBulk) Update(set func(*SubscriptionPlanUpsert)) *SubscriptionPlanUpsertBulk {
|
|
u.create.conflict = append(u.create.conflict, sql.ResolveWith(func(update *sql.UpdateSet) {
|
|
set(&SubscriptionPlanUpsert{UpdateSet: update})
|
|
}))
|
|
return u
|
|
}
|
|
|
|
// SetGroupID sets the "group_id" field.
|
|
func (u *SubscriptionPlanUpsertBulk) SetGroupID(v int64) *SubscriptionPlanUpsertBulk {
|
|
return u.Update(func(s *SubscriptionPlanUpsert) {
|
|
s.SetGroupID(v)
|
|
})
|
|
}
|
|
|
|
// AddGroupID adds v to the "group_id" field.
|
|
func (u *SubscriptionPlanUpsertBulk) AddGroupID(v int64) *SubscriptionPlanUpsertBulk {
|
|
return u.Update(func(s *SubscriptionPlanUpsert) {
|
|
s.AddGroupID(v)
|
|
})
|
|
}
|
|
|
|
// UpdateGroupID sets the "group_id" field to the value that was provided on create.
|
|
func (u *SubscriptionPlanUpsertBulk) UpdateGroupID() *SubscriptionPlanUpsertBulk {
|
|
return u.Update(func(s *SubscriptionPlanUpsert) {
|
|
s.UpdateGroupID()
|
|
})
|
|
}
|
|
|
|
// SetName sets the "name" field.
|
|
func (u *SubscriptionPlanUpsertBulk) SetName(v string) *SubscriptionPlanUpsertBulk {
|
|
return u.Update(func(s *SubscriptionPlanUpsert) {
|
|
s.SetName(v)
|
|
})
|
|
}
|
|
|
|
// UpdateName sets the "name" field to the value that was provided on create.
|
|
func (u *SubscriptionPlanUpsertBulk) UpdateName() *SubscriptionPlanUpsertBulk {
|
|
return u.Update(func(s *SubscriptionPlanUpsert) {
|
|
s.UpdateName()
|
|
})
|
|
}
|
|
|
|
// SetDescription sets the "description" field.
|
|
func (u *SubscriptionPlanUpsertBulk) SetDescription(v string) *SubscriptionPlanUpsertBulk {
|
|
return u.Update(func(s *SubscriptionPlanUpsert) {
|
|
s.SetDescription(v)
|
|
})
|
|
}
|
|
|
|
// UpdateDescription sets the "description" field to the value that was provided on create.
|
|
func (u *SubscriptionPlanUpsertBulk) UpdateDescription() *SubscriptionPlanUpsertBulk {
|
|
return u.Update(func(s *SubscriptionPlanUpsert) {
|
|
s.UpdateDescription()
|
|
})
|
|
}
|
|
|
|
// SetPrice sets the "price" field.
|
|
func (u *SubscriptionPlanUpsertBulk) SetPrice(v float64) *SubscriptionPlanUpsertBulk {
|
|
return u.Update(func(s *SubscriptionPlanUpsert) {
|
|
s.SetPrice(v)
|
|
})
|
|
}
|
|
|
|
// AddPrice adds v to the "price" field.
|
|
func (u *SubscriptionPlanUpsertBulk) AddPrice(v float64) *SubscriptionPlanUpsertBulk {
|
|
return u.Update(func(s *SubscriptionPlanUpsert) {
|
|
s.AddPrice(v)
|
|
})
|
|
}
|
|
|
|
// UpdatePrice sets the "price" field to the value that was provided on create.
|
|
func (u *SubscriptionPlanUpsertBulk) UpdatePrice() *SubscriptionPlanUpsertBulk {
|
|
return u.Update(func(s *SubscriptionPlanUpsert) {
|
|
s.UpdatePrice()
|
|
})
|
|
}
|
|
|
|
// SetOriginalPrice sets the "original_price" field.
|
|
func (u *SubscriptionPlanUpsertBulk) SetOriginalPrice(v float64) *SubscriptionPlanUpsertBulk {
|
|
return u.Update(func(s *SubscriptionPlanUpsert) {
|
|
s.SetOriginalPrice(v)
|
|
})
|
|
}
|
|
|
|
// AddOriginalPrice adds v to the "original_price" field.
|
|
func (u *SubscriptionPlanUpsertBulk) AddOriginalPrice(v float64) *SubscriptionPlanUpsertBulk {
|
|
return u.Update(func(s *SubscriptionPlanUpsert) {
|
|
s.AddOriginalPrice(v)
|
|
})
|
|
}
|
|
|
|
// UpdateOriginalPrice sets the "original_price" field to the value that was provided on create.
|
|
func (u *SubscriptionPlanUpsertBulk) UpdateOriginalPrice() *SubscriptionPlanUpsertBulk {
|
|
return u.Update(func(s *SubscriptionPlanUpsert) {
|
|
s.UpdateOriginalPrice()
|
|
})
|
|
}
|
|
|
|
// ClearOriginalPrice clears the value of the "original_price" field.
|
|
func (u *SubscriptionPlanUpsertBulk) ClearOriginalPrice() *SubscriptionPlanUpsertBulk {
|
|
return u.Update(func(s *SubscriptionPlanUpsert) {
|
|
s.ClearOriginalPrice()
|
|
})
|
|
}
|
|
|
|
// SetValidityDays sets the "validity_days" field.
|
|
func (u *SubscriptionPlanUpsertBulk) SetValidityDays(v int) *SubscriptionPlanUpsertBulk {
|
|
return u.Update(func(s *SubscriptionPlanUpsert) {
|
|
s.SetValidityDays(v)
|
|
})
|
|
}
|
|
|
|
// AddValidityDays adds v to the "validity_days" field.
|
|
func (u *SubscriptionPlanUpsertBulk) AddValidityDays(v int) *SubscriptionPlanUpsertBulk {
|
|
return u.Update(func(s *SubscriptionPlanUpsert) {
|
|
s.AddValidityDays(v)
|
|
})
|
|
}
|
|
|
|
// UpdateValidityDays sets the "validity_days" field to the value that was provided on create.
|
|
func (u *SubscriptionPlanUpsertBulk) UpdateValidityDays() *SubscriptionPlanUpsertBulk {
|
|
return u.Update(func(s *SubscriptionPlanUpsert) {
|
|
s.UpdateValidityDays()
|
|
})
|
|
}
|
|
|
|
// SetValidityUnit sets the "validity_unit" field.
|
|
func (u *SubscriptionPlanUpsertBulk) SetValidityUnit(v string) *SubscriptionPlanUpsertBulk {
|
|
return u.Update(func(s *SubscriptionPlanUpsert) {
|
|
s.SetValidityUnit(v)
|
|
})
|
|
}
|
|
|
|
// UpdateValidityUnit sets the "validity_unit" field to the value that was provided on create.
|
|
func (u *SubscriptionPlanUpsertBulk) UpdateValidityUnit() *SubscriptionPlanUpsertBulk {
|
|
return u.Update(func(s *SubscriptionPlanUpsert) {
|
|
s.UpdateValidityUnit()
|
|
})
|
|
}
|
|
|
|
// SetFeatures sets the "features" field.
|
|
func (u *SubscriptionPlanUpsertBulk) SetFeatures(v string) *SubscriptionPlanUpsertBulk {
|
|
return u.Update(func(s *SubscriptionPlanUpsert) {
|
|
s.SetFeatures(v)
|
|
})
|
|
}
|
|
|
|
// UpdateFeatures sets the "features" field to the value that was provided on create.
|
|
func (u *SubscriptionPlanUpsertBulk) UpdateFeatures() *SubscriptionPlanUpsertBulk {
|
|
return u.Update(func(s *SubscriptionPlanUpsert) {
|
|
s.UpdateFeatures()
|
|
})
|
|
}
|
|
|
|
// SetProductName sets the "product_name" field.
|
|
func (u *SubscriptionPlanUpsertBulk) SetProductName(v string) *SubscriptionPlanUpsertBulk {
|
|
return u.Update(func(s *SubscriptionPlanUpsert) {
|
|
s.SetProductName(v)
|
|
})
|
|
}
|
|
|
|
// UpdateProductName sets the "product_name" field to the value that was provided on create.
|
|
func (u *SubscriptionPlanUpsertBulk) UpdateProductName() *SubscriptionPlanUpsertBulk {
|
|
return u.Update(func(s *SubscriptionPlanUpsert) {
|
|
s.UpdateProductName()
|
|
})
|
|
}
|
|
|
|
// SetForSale sets the "for_sale" field.
|
|
func (u *SubscriptionPlanUpsertBulk) SetForSale(v bool) *SubscriptionPlanUpsertBulk {
|
|
return u.Update(func(s *SubscriptionPlanUpsert) {
|
|
s.SetForSale(v)
|
|
})
|
|
}
|
|
|
|
// UpdateForSale sets the "for_sale" field to the value that was provided on create.
|
|
func (u *SubscriptionPlanUpsertBulk) UpdateForSale() *SubscriptionPlanUpsertBulk {
|
|
return u.Update(func(s *SubscriptionPlanUpsert) {
|
|
s.UpdateForSale()
|
|
})
|
|
}
|
|
|
|
// SetSortOrder sets the "sort_order" field.
|
|
func (u *SubscriptionPlanUpsertBulk) SetSortOrder(v int) *SubscriptionPlanUpsertBulk {
|
|
return u.Update(func(s *SubscriptionPlanUpsert) {
|
|
s.SetSortOrder(v)
|
|
})
|
|
}
|
|
|
|
// AddSortOrder adds v to the "sort_order" field.
|
|
func (u *SubscriptionPlanUpsertBulk) AddSortOrder(v int) *SubscriptionPlanUpsertBulk {
|
|
return u.Update(func(s *SubscriptionPlanUpsert) {
|
|
s.AddSortOrder(v)
|
|
})
|
|
}
|
|
|
|
// UpdateSortOrder sets the "sort_order" field to the value that was provided on create.
|
|
func (u *SubscriptionPlanUpsertBulk) UpdateSortOrder() *SubscriptionPlanUpsertBulk {
|
|
return u.Update(func(s *SubscriptionPlanUpsert) {
|
|
s.UpdateSortOrder()
|
|
})
|
|
}
|
|
|
|
// SetUpdatedAt sets the "updated_at" field.
|
|
func (u *SubscriptionPlanUpsertBulk) SetUpdatedAt(v time.Time) *SubscriptionPlanUpsertBulk {
|
|
return u.Update(func(s *SubscriptionPlanUpsert) {
|
|
s.SetUpdatedAt(v)
|
|
})
|
|
}
|
|
|
|
// UpdateUpdatedAt sets the "updated_at" field to the value that was provided on create.
|
|
func (u *SubscriptionPlanUpsertBulk) UpdateUpdatedAt() *SubscriptionPlanUpsertBulk {
|
|
return u.Update(func(s *SubscriptionPlanUpsert) {
|
|
s.UpdateUpdatedAt()
|
|
})
|
|
}
|
|
|
|
// Exec executes the query.
|
|
func (u *SubscriptionPlanUpsertBulk) 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 SubscriptionPlanCreateBulk instead", i)
|
|
}
|
|
}
|
|
if len(u.create.conflict) == 0 {
|
|
return errors.New("ent: missing options for SubscriptionPlanCreateBulk.OnConflict")
|
|
}
|
|
return u.create.Exec(ctx)
|
|
}
|
|
|
|
// ExecX is like Exec, but panics if an error occurs.
|
|
func (u *SubscriptionPlanUpsertBulk) ExecX(ctx context.Context) {
|
|
if err := u.create.Exec(ctx); err != nil {
|
|
panic(err)
|
|
}
|
|
}
|