| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794 |
- // 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/predicate"
- "github.com/Wei-Shaw/sub2api/ent/subscriptionplan"
- )
- // SubscriptionPlanUpdate is the builder for updating SubscriptionPlan entities.
- type SubscriptionPlanUpdate struct {
- config
- hooks []Hook
- mutation *SubscriptionPlanMutation
- }
- // Where appends a list predicates to the SubscriptionPlanUpdate builder.
- func (_u *SubscriptionPlanUpdate) Where(ps ...predicate.SubscriptionPlan) *SubscriptionPlanUpdate {
- _u.mutation.Where(ps...)
- return _u
- }
- // SetGroupID sets the "group_id" field.
- func (_u *SubscriptionPlanUpdate) SetGroupID(v int64) *SubscriptionPlanUpdate {
- _u.mutation.ResetGroupID()
- _u.mutation.SetGroupID(v)
- return _u
- }
- // SetNillableGroupID sets the "group_id" field if the given value is not nil.
- func (_u *SubscriptionPlanUpdate) SetNillableGroupID(v *int64) *SubscriptionPlanUpdate {
- if v != nil {
- _u.SetGroupID(*v)
- }
- return _u
- }
- // AddGroupID adds value to the "group_id" field.
- func (_u *SubscriptionPlanUpdate) AddGroupID(v int64) *SubscriptionPlanUpdate {
- _u.mutation.AddGroupID(v)
- return _u
- }
- // SetName sets the "name" field.
- func (_u *SubscriptionPlanUpdate) SetName(v string) *SubscriptionPlanUpdate {
- _u.mutation.SetName(v)
- return _u
- }
- // SetNillableName sets the "name" field if the given value is not nil.
- func (_u *SubscriptionPlanUpdate) SetNillableName(v *string) *SubscriptionPlanUpdate {
- if v != nil {
- _u.SetName(*v)
- }
- return _u
- }
- // SetDescription sets the "description" field.
- func (_u *SubscriptionPlanUpdate) SetDescription(v string) *SubscriptionPlanUpdate {
- _u.mutation.SetDescription(v)
- return _u
- }
- // SetNillableDescription sets the "description" field if the given value is not nil.
- func (_u *SubscriptionPlanUpdate) SetNillableDescription(v *string) *SubscriptionPlanUpdate {
- if v != nil {
- _u.SetDescription(*v)
- }
- return _u
- }
- // SetPrice sets the "price" field.
- func (_u *SubscriptionPlanUpdate) SetPrice(v float64) *SubscriptionPlanUpdate {
- _u.mutation.ResetPrice()
- _u.mutation.SetPrice(v)
- return _u
- }
- // SetNillablePrice sets the "price" field if the given value is not nil.
- func (_u *SubscriptionPlanUpdate) SetNillablePrice(v *float64) *SubscriptionPlanUpdate {
- if v != nil {
- _u.SetPrice(*v)
- }
- return _u
- }
- // AddPrice adds value to the "price" field.
- func (_u *SubscriptionPlanUpdate) AddPrice(v float64) *SubscriptionPlanUpdate {
- _u.mutation.AddPrice(v)
- return _u
- }
- // SetOriginalPrice sets the "original_price" field.
- func (_u *SubscriptionPlanUpdate) SetOriginalPrice(v float64) *SubscriptionPlanUpdate {
- _u.mutation.ResetOriginalPrice()
- _u.mutation.SetOriginalPrice(v)
- return _u
- }
- // SetNillableOriginalPrice sets the "original_price" field if the given value is not nil.
- func (_u *SubscriptionPlanUpdate) SetNillableOriginalPrice(v *float64) *SubscriptionPlanUpdate {
- if v != nil {
- _u.SetOriginalPrice(*v)
- }
- return _u
- }
- // AddOriginalPrice adds value to the "original_price" field.
- func (_u *SubscriptionPlanUpdate) AddOriginalPrice(v float64) *SubscriptionPlanUpdate {
- _u.mutation.AddOriginalPrice(v)
- return _u
- }
- // ClearOriginalPrice clears the value of the "original_price" field.
- func (_u *SubscriptionPlanUpdate) ClearOriginalPrice() *SubscriptionPlanUpdate {
- _u.mutation.ClearOriginalPrice()
- return _u
- }
- // SetCurrency sets the "currency" field.
- func (_u *SubscriptionPlanUpdate) SetCurrency(v string) *SubscriptionPlanUpdate {
- _u.mutation.SetCurrency(v)
- return _u
- }
- // SetNillableCurrency sets the "currency" field if the given value is not nil.
- func (_u *SubscriptionPlanUpdate) SetNillableCurrency(v *string) *SubscriptionPlanUpdate {
- if v != nil {
- _u.SetCurrency(*v)
- }
- return _u
- }
- // SetValidityDays sets the "validity_days" field.
- func (_u *SubscriptionPlanUpdate) SetValidityDays(v int) *SubscriptionPlanUpdate {
- _u.mutation.ResetValidityDays()
- _u.mutation.SetValidityDays(v)
- return _u
- }
- // SetNillableValidityDays sets the "validity_days" field if the given value is not nil.
- func (_u *SubscriptionPlanUpdate) SetNillableValidityDays(v *int) *SubscriptionPlanUpdate {
- if v != nil {
- _u.SetValidityDays(*v)
- }
- return _u
- }
- // AddValidityDays adds value to the "validity_days" field.
- func (_u *SubscriptionPlanUpdate) AddValidityDays(v int) *SubscriptionPlanUpdate {
- _u.mutation.AddValidityDays(v)
- return _u
- }
- // SetValidityUnit sets the "validity_unit" field.
- func (_u *SubscriptionPlanUpdate) SetValidityUnit(v string) *SubscriptionPlanUpdate {
- _u.mutation.SetValidityUnit(v)
- return _u
- }
- // SetNillableValidityUnit sets the "validity_unit" field if the given value is not nil.
- func (_u *SubscriptionPlanUpdate) SetNillableValidityUnit(v *string) *SubscriptionPlanUpdate {
- if v != nil {
- _u.SetValidityUnit(*v)
- }
- return _u
- }
- // SetFeatures sets the "features" field.
- func (_u *SubscriptionPlanUpdate) SetFeatures(v string) *SubscriptionPlanUpdate {
- _u.mutation.SetFeatures(v)
- return _u
- }
- // SetNillableFeatures sets the "features" field if the given value is not nil.
- func (_u *SubscriptionPlanUpdate) SetNillableFeatures(v *string) *SubscriptionPlanUpdate {
- if v != nil {
- _u.SetFeatures(*v)
- }
- return _u
- }
- // SetProductName sets the "product_name" field.
- func (_u *SubscriptionPlanUpdate) SetProductName(v string) *SubscriptionPlanUpdate {
- _u.mutation.SetProductName(v)
- return _u
- }
- // SetNillableProductName sets the "product_name" field if the given value is not nil.
- func (_u *SubscriptionPlanUpdate) SetNillableProductName(v *string) *SubscriptionPlanUpdate {
- if v != nil {
- _u.SetProductName(*v)
- }
- return _u
- }
- // SetForSale sets the "for_sale" field.
- func (_u *SubscriptionPlanUpdate) SetForSale(v bool) *SubscriptionPlanUpdate {
- _u.mutation.SetForSale(v)
- return _u
- }
- // SetNillableForSale sets the "for_sale" field if the given value is not nil.
- func (_u *SubscriptionPlanUpdate) SetNillableForSale(v *bool) *SubscriptionPlanUpdate {
- if v != nil {
- _u.SetForSale(*v)
- }
- return _u
- }
- // SetSortOrder sets the "sort_order" field.
- func (_u *SubscriptionPlanUpdate) SetSortOrder(v int) *SubscriptionPlanUpdate {
- _u.mutation.ResetSortOrder()
- _u.mutation.SetSortOrder(v)
- return _u
- }
- // SetNillableSortOrder sets the "sort_order" field if the given value is not nil.
- func (_u *SubscriptionPlanUpdate) SetNillableSortOrder(v *int) *SubscriptionPlanUpdate {
- if v != nil {
- _u.SetSortOrder(*v)
- }
- return _u
- }
- // AddSortOrder adds value to the "sort_order" field.
- func (_u *SubscriptionPlanUpdate) AddSortOrder(v int) *SubscriptionPlanUpdate {
- _u.mutation.AddSortOrder(v)
- return _u
- }
- // SetUpdatedAt sets the "updated_at" field.
- func (_u *SubscriptionPlanUpdate) SetUpdatedAt(v time.Time) *SubscriptionPlanUpdate {
- _u.mutation.SetUpdatedAt(v)
- return _u
- }
- // Mutation returns the SubscriptionPlanMutation object of the builder.
- func (_u *SubscriptionPlanUpdate) Mutation() *SubscriptionPlanMutation {
- return _u.mutation
- }
- // Save executes the query and returns the number of nodes affected by the update operation.
- func (_u *SubscriptionPlanUpdate) Save(ctx context.Context) (int, error) {
- _u.defaults()
- return withHooks(ctx, _u.sqlSave, _u.mutation, _u.hooks)
- }
- // SaveX is like Save, but panics if an error occurs.
- func (_u *SubscriptionPlanUpdate) SaveX(ctx context.Context) int {
- affected, err := _u.Save(ctx)
- if err != nil {
- panic(err)
- }
- return affected
- }
- // Exec executes the query.
- func (_u *SubscriptionPlanUpdate) Exec(ctx context.Context) error {
- _, err := _u.Save(ctx)
- return err
- }
- // ExecX is like Exec, but panics if an error occurs.
- func (_u *SubscriptionPlanUpdate) ExecX(ctx context.Context) {
- if err := _u.Exec(ctx); err != nil {
- panic(err)
- }
- }
- // defaults sets the default values of the builder before save.
- func (_u *SubscriptionPlanUpdate) defaults() {
- if _, ok := _u.mutation.UpdatedAt(); !ok {
- v := subscriptionplan.UpdateDefaultUpdatedAt()
- _u.mutation.SetUpdatedAt(v)
- }
- }
- // check runs all checks and user-defined validators on the builder.
- func (_u *SubscriptionPlanUpdate) check() error {
- if v, ok := _u.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 v, ok := _u.mutation.Currency(); ok {
- if err := subscriptionplan.CurrencyValidator(v); err != nil {
- return &ValidationError{Name: "currency", err: fmt.Errorf(`ent: validator failed for field "SubscriptionPlan.currency": %w`, err)}
- }
- }
- if v, ok := _u.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 v, ok := _u.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)}
- }
- }
- return nil
- }
- func (_u *SubscriptionPlanUpdate) sqlSave(ctx context.Context) (_node int, err error) {
- if err := _u.check(); err != nil {
- return _node, err
- }
- _spec := sqlgraph.NewUpdateSpec(subscriptionplan.Table, subscriptionplan.Columns, sqlgraph.NewFieldSpec(subscriptionplan.FieldID, field.TypeInt64))
- if ps := _u.mutation.predicates; len(ps) > 0 {
- _spec.Predicate = func(selector *sql.Selector) {
- for i := range ps {
- ps[i](selector)
- }
- }
- }
- if value, ok := _u.mutation.GroupID(); ok {
- _spec.SetField(subscriptionplan.FieldGroupID, field.TypeInt64, value)
- }
- if value, ok := _u.mutation.AddedGroupID(); ok {
- _spec.AddField(subscriptionplan.FieldGroupID, field.TypeInt64, value)
- }
- if value, ok := _u.mutation.Name(); ok {
- _spec.SetField(subscriptionplan.FieldName, field.TypeString, value)
- }
- if value, ok := _u.mutation.Description(); ok {
- _spec.SetField(subscriptionplan.FieldDescription, field.TypeString, value)
- }
- if value, ok := _u.mutation.Price(); ok {
- _spec.SetField(subscriptionplan.FieldPrice, field.TypeFloat64, value)
- }
- if value, ok := _u.mutation.AddedPrice(); ok {
- _spec.AddField(subscriptionplan.FieldPrice, field.TypeFloat64, value)
- }
- if value, ok := _u.mutation.OriginalPrice(); ok {
- _spec.SetField(subscriptionplan.FieldOriginalPrice, field.TypeFloat64, value)
- }
- if value, ok := _u.mutation.AddedOriginalPrice(); ok {
- _spec.AddField(subscriptionplan.FieldOriginalPrice, field.TypeFloat64, value)
- }
- if _u.mutation.OriginalPriceCleared() {
- _spec.ClearField(subscriptionplan.FieldOriginalPrice, field.TypeFloat64)
- }
- if value, ok := _u.mutation.Currency(); ok {
- _spec.SetField(subscriptionplan.FieldCurrency, field.TypeString, value)
- }
- if value, ok := _u.mutation.ValidityDays(); ok {
- _spec.SetField(subscriptionplan.FieldValidityDays, field.TypeInt, value)
- }
- if value, ok := _u.mutation.AddedValidityDays(); ok {
- _spec.AddField(subscriptionplan.FieldValidityDays, field.TypeInt, value)
- }
- if value, ok := _u.mutation.ValidityUnit(); ok {
- _spec.SetField(subscriptionplan.FieldValidityUnit, field.TypeString, value)
- }
- if value, ok := _u.mutation.Features(); ok {
- _spec.SetField(subscriptionplan.FieldFeatures, field.TypeString, value)
- }
- if value, ok := _u.mutation.ProductName(); ok {
- _spec.SetField(subscriptionplan.FieldProductName, field.TypeString, value)
- }
- if value, ok := _u.mutation.ForSale(); ok {
- _spec.SetField(subscriptionplan.FieldForSale, field.TypeBool, value)
- }
- if value, ok := _u.mutation.SortOrder(); ok {
- _spec.SetField(subscriptionplan.FieldSortOrder, field.TypeInt, value)
- }
- if value, ok := _u.mutation.AddedSortOrder(); ok {
- _spec.AddField(subscriptionplan.FieldSortOrder, field.TypeInt, value)
- }
- if value, ok := _u.mutation.UpdatedAt(); ok {
- _spec.SetField(subscriptionplan.FieldUpdatedAt, field.TypeTime, value)
- }
- if _node, err = sqlgraph.UpdateNodes(ctx, _u.driver, _spec); err != nil {
- if _, ok := err.(*sqlgraph.NotFoundError); ok {
- err = &NotFoundError{subscriptionplan.Label}
- } else if sqlgraph.IsConstraintError(err) {
- err = &ConstraintError{msg: err.Error(), wrap: err}
- }
- return 0, err
- }
- _u.mutation.done = true
- return _node, nil
- }
- // SubscriptionPlanUpdateOne is the builder for updating a single SubscriptionPlan entity.
- type SubscriptionPlanUpdateOne struct {
- config
- fields []string
- hooks []Hook
- mutation *SubscriptionPlanMutation
- }
- // SetGroupID sets the "group_id" field.
- func (_u *SubscriptionPlanUpdateOne) SetGroupID(v int64) *SubscriptionPlanUpdateOne {
- _u.mutation.ResetGroupID()
- _u.mutation.SetGroupID(v)
- return _u
- }
- // SetNillableGroupID sets the "group_id" field if the given value is not nil.
- func (_u *SubscriptionPlanUpdateOne) SetNillableGroupID(v *int64) *SubscriptionPlanUpdateOne {
- if v != nil {
- _u.SetGroupID(*v)
- }
- return _u
- }
- // AddGroupID adds value to the "group_id" field.
- func (_u *SubscriptionPlanUpdateOne) AddGroupID(v int64) *SubscriptionPlanUpdateOne {
- _u.mutation.AddGroupID(v)
- return _u
- }
- // SetName sets the "name" field.
- func (_u *SubscriptionPlanUpdateOne) SetName(v string) *SubscriptionPlanUpdateOne {
- _u.mutation.SetName(v)
- return _u
- }
- // SetNillableName sets the "name" field if the given value is not nil.
- func (_u *SubscriptionPlanUpdateOne) SetNillableName(v *string) *SubscriptionPlanUpdateOne {
- if v != nil {
- _u.SetName(*v)
- }
- return _u
- }
- // SetDescription sets the "description" field.
- func (_u *SubscriptionPlanUpdateOne) SetDescription(v string) *SubscriptionPlanUpdateOne {
- _u.mutation.SetDescription(v)
- return _u
- }
- // SetNillableDescription sets the "description" field if the given value is not nil.
- func (_u *SubscriptionPlanUpdateOne) SetNillableDescription(v *string) *SubscriptionPlanUpdateOne {
- if v != nil {
- _u.SetDescription(*v)
- }
- return _u
- }
- // SetPrice sets the "price" field.
- func (_u *SubscriptionPlanUpdateOne) SetPrice(v float64) *SubscriptionPlanUpdateOne {
- _u.mutation.ResetPrice()
- _u.mutation.SetPrice(v)
- return _u
- }
- // SetNillablePrice sets the "price" field if the given value is not nil.
- func (_u *SubscriptionPlanUpdateOne) SetNillablePrice(v *float64) *SubscriptionPlanUpdateOne {
- if v != nil {
- _u.SetPrice(*v)
- }
- return _u
- }
- // AddPrice adds value to the "price" field.
- func (_u *SubscriptionPlanUpdateOne) AddPrice(v float64) *SubscriptionPlanUpdateOne {
- _u.mutation.AddPrice(v)
- return _u
- }
- // SetOriginalPrice sets the "original_price" field.
- func (_u *SubscriptionPlanUpdateOne) SetOriginalPrice(v float64) *SubscriptionPlanUpdateOne {
- _u.mutation.ResetOriginalPrice()
- _u.mutation.SetOriginalPrice(v)
- return _u
- }
- // SetNillableOriginalPrice sets the "original_price" field if the given value is not nil.
- func (_u *SubscriptionPlanUpdateOne) SetNillableOriginalPrice(v *float64) *SubscriptionPlanUpdateOne {
- if v != nil {
- _u.SetOriginalPrice(*v)
- }
- return _u
- }
- // AddOriginalPrice adds value to the "original_price" field.
- func (_u *SubscriptionPlanUpdateOne) AddOriginalPrice(v float64) *SubscriptionPlanUpdateOne {
- _u.mutation.AddOriginalPrice(v)
- return _u
- }
- // ClearOriginalPrice clears the value of the "original_price" field.
- func (_u *SubscriptionPlanUpdateOne) ClearOriginalPrice() *SubscriptionPlanUpdateOne {
- _u.mutation.ClearOriginalPrice()
- return _u
- }
- // SetCurrency sets the "currency" field.
- func (_u *SubscriptionPlanUpdateOne) SetCurrency(v string) *SubscriptionPlanUpdateOne {
- _u.mutation.SetCurrency(v)
- return _u
- }
- // SetNillableCurrency sets the "currency" field if the given value is not nil.
- func (_u *SubscriptionPlanUpdateOne) SetNillableCurrency(v *string) *SubscriptionPlanUpdateOne {
- if v != nil {
- _u.SetCurrency(*v)
- }
- return _u
- }
- // SetValidityDays sets the "validity_days" field.
- func (_u *SubscriptionPlanUpdateOne) SetValidityDays(v int) *SubscriptionPlanUpdateOne {
- _u.mutation.ResetValidityDays()
- _u.mutation.SetValidityDays(v)
- return _u
- }
- // SetNillableValidityDays sets the "validity_days" field if the given value is not nil.
- func (_u *SubscriptionPlanUpdateOne) SetNillableValidityDays(v *int) *SubscriptionPlanUpdateOne {
- if v != nil {
- _u.SetValidityDays(*v)
- }
- return _u
- }
- // AddValidityDays adds value to the "validity_days" field.
- func (_u *SubscriptionPlanUpdateOne) AddValidityDays(v int) *SubscriptionPlanUpdateOne {
- _u.mutation.AddValidityDays(v)
- return _u
- }
- // SetValidityUnit sets the "validity_unit" field.
- func (_u *SubscriptionPlanUpdateOne) SetValidityUnit(v string) *SubscriptionPlanUpdateOne {
- _u.mutation.SetValidityUnit(v)
- return _u
- }
- // SetNillableValidityUnit sets the "validity_unit" field if the given value is not nil.
- func (_u *SubscriptionPlanUpdateOne) SetNillableValidityUnit(v *string) *SubscriptionPlanUpdateOne {
- if v != nil {
- _u.SetValidityUnit(*v)
- }
- return _u
- }
- // SetFeatures sets the "features" field.
- func (_u *SubscriptionPlanUpdateOne) SetFeatures(v string) *SubscriptionPlanUpdateOne {
- _u.mutation.SetFeatures(v)
- return _u
- }
- // SetNillableFeatures sets the "features" field if the given value is not nil.
- func (_u *SubscriptionPlanUpdateOne) SetNillableFeatures(v *string) *SubscriptionPlanUpdateOne {
- if v != nil {
- _u.SetFeatures(*v)
- }
- return _u
- }
- // SetProductName sets the "product_name" field.
- func (_u *SubscriptionPlanUpdateOne) SetProductName(v string) *SubscriptionPlanUpdateOne {
- _u.mutation.SetProductName(v)
- return _u
- }
- // SetNillableProductName sets the "product_name" field if the given value is not nil.
- func (_u *SubscriptionPlanUpdateOne) SetNillableProductName(v *string) *SubscriptionPlanUpdateOne {
- if v != nil {
- _u.SetProductName(*v)
- }
- return _u
- }
- // SetForSale sets the "for_sale" field.
- func (_u *SubscriptionPlanUpdateOne) SetForSale(v bool) *SubscriptionPlanUpdateOne {
- _u.mutation.SetForSale(v)
- return _u
- }
- // SetNillableForSale sets the "for_sale" field if the given value is not nil.
- func (_u *SubscriptionPlanUpdateOne) SetNillableForSale(v *bool) *SubscriptionPlanUpdateOne {
- if v != nil {
- _u.SetForSale(*v)
- }
- return _u
- }
- // SetSortOrder sets the "sort_order" field.
- func (_u *SubscriptionPlanUpdateOne) SetSortOrder(v int) *SubscriptionPlanUpdateOne {
- _u.mutation.ResetSortOrder()
- _u.mutation.SetSortOrder(v)
- return _u
- }
- // SetNillableSortOrder sets the "sort_order" field if the given value is not nil.
- func (_u *SubscriptionPlanUpdateOne) SetNillableSortOrder(v *int) *SubscriptionPlanUpdateOne {
- if v != nil {
- _u.SetSortOrder(*v)
- }
- return _u
- }
- // AddSortOrder adds value to the "sort_order" field.
- func (_u *SubscriptionPlanUpdateOne) AddSortOrder(v int) *SubscriptionPlanUpdateOne {
- _u.mutation.AddSortOrder(v)
- return _u
- }
- // SetUpdatedAt sets the "updated_at" field.
- func (_u *SubscriptionPlanUpdateOne) SetUpdatedAt(v time.Time) *SubscriptionPlanUpdateOne {
- _u.mutation.SetUpdatedAt(v)
- return _u
- }
- // Mutation returns the SubscriptionPlanMutation object of the builder.
- func (_u *SubscriptionPlanUpdateOne) Mutation() *SubscriptionPlanMutation {
- return _u.mutation
- }
- // Where appends a list predicates to the SubscriptionPlanUpdate builder.
- func (_u *SubscriptionPlanUpdateOne) Where(ps ...predicate.SubscriptionPlan) *SubscriptionPlanUpdateOne {
- _u.mutation.Where(ps...)
- return _u
- }
- // Select allows selecting one or more fields (columns) of the returned entity.
- // The default is selecting all fields defined in the entity schema.
- func (_u *SubscriptionPlanUpdateOne) Select(field string, fields ...string) *SubscriptionPlanUpdateOne {
- _u.fields = append([]string{field}, fields...)
- return _u
- }
- // Save executes the query and returns the updated SubscriptionPlan entity.
- func (_u *SubscriptionPlanUpdateOne) Save(ctx context.Context) (*SubscriptionPlan, error) {
- _u.defaults()
- return withHooks(ctx, _u.sqlSave, _u.mutation, _u.hooks)
- }
- // SaveX is like Save, but panics if an error occurs.
- func (_u *SubscriptionPlanUpdateOne) SaveX(ctx context.Context) *SubscriptionPlan {
- node, err := _u.Save(ctx)
- if err != nil {
- panic(err)
- }
- return node
- }
- // Exec executes the query on the entity.
- func (_u *SubscriptionPlanUpdateOne) Exec(ctx context.Context) error {
- _, err := _u.Save(ctx)
- return err
- }
- // ExecX is like Exec, but panics if an error occurs.
- func (_u *SubscriptionPlanUpdateOne) ExecX(ctx context.Context) {
- if err := _u.Exec(ctx); err != nil {
- panic(err)
- }
- }
- // defaults sets the default values of the builder before save.
- func (_u *SubscriptionPlanUpdateOne) defaults() {
- if _, ok := _u.mutation.UpdatedAt(); !ok {
- v := subscriptionplan.UpdateDefaultUpdatedAt()
- _u.mutation.SetUpdatedAt(v)
- }
- }
- // check runs all checks and user-defined validators on the builder.
- func (_u *SubscriptionPlanUpdateOne) check() error {
- if v, ok := _u.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 v, ok := _u.mutation.Currency(); ok {
- if err := subscriptionplan.CurrencyValidator(v); err != nil {
- return &ValidationError{Name: "currency", err: fmt.Errorf(`ent: validator failed for field "SubscriptionPlan.currency": %w`, err)}
- }
- }
- if v, ok := _u.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 v, ok := _u.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)}
- }
- }
- return nil
- }
- func (_u *SubscriptionPlanUpdateOne) sqlSave(ctx context.Context) (_node *SubscriptionPlan, err error) {
- if err := _u.check(); err != nil {
- return _node, err
- }
- _spec := sqlgraph.NewUpdateSpec(subscriptionplan.Table, subscriptionplan.Columns, sqlgraph.NewFieldSpec(subscriptionplan.FieldID, field.TypeInt64))
- id, ok := _u.mutation.ID()
- if !ok {
- return nil, &ValidationError{Name: "id", err: errors.New(`ent: missing "SubscriptionPlan.id" for update`)}
- }
- _spec.Node.ID.Value = id
- if fields := _u.fields; len(fields) > 0 {
- _spec.Node.Columns = make([]string, 0, len(fields))
- _spec.Node.Columns = append(_spec.Node.Columns, subscriptionplan.FieldID)
- for _, f := range fields {
- if !subscriptionplan.ValidColumn(f) {
- return nil, &ValidationError{Name: f, err: fmt.Errorf("ent: invalid field %q for query", f)}
- }
- if f != subscriptionplan.FieldID {
- _spec.Node.Columns = append(_spec.Node.Columns, f)
- }
- }
- }
- if ps := _u.mutation.predicates; len(ps) > 0 {
- _spec.Predicate = func(selector *sql.Selector) {
- for i := range ps {
- ps[i](selector)
- }
- }
- }
- if value, ok := _u.mutation.GroupID(); ok {
- _spec.SetField(subscriptionplan.FieldGroupID, field.TypeInt64, value)
- }
- if value, ok := _u.mutation.AddedGroupID(); ok {
- _spec.AddField(subscriptionplan.FieldGroupID, field.TypeInt64, value)
- }
- if value, ok := _u.mutation.Name(); ok {
- _spec.SetField(subscriptionplan.FieldName, field.TypeString, value)
- }
- if value, ok := _u.mutation.Description(); ok {
- _spec.SetField(subscriptionplan.FieldDescription, field.TypeString, value)
- }
- if value, ok := _u.mutation.Price(); ok {
- _spec.SetField(subscriptionplan.FieldPrice, field.TypeFloat64, value)
- }
- if value, ok := _u.mutation.AddedPrice(); ok {
- _spec.AddField(subscriptionplan.FieldPrice, field.TypeFloat64, value)
- }
- if value, ok := _u.mutation.OriginalPrice(); ok {
- _spec.SetField(subscriptionplan.FieldOriginalPrice, field.TypeFloat64, value)
- }
- if value, ok := _u.mutation.AddedOriginalPrice(); ok {
- _spec.AddField(subscriptionplan.FieldOriginalPrice, field.TypeFloat64, value)
- }
- if _u.mutation.OriginalPriceCleared() {
- _spec.ClearField(subscriptionplan.FieldOriginalPrice, field.TypeFloat64)
- }
- if value, ok := _u.mutation.Currency(); ok {
- _spec.SetField(subscriptionplan.FieldCurrency, field.TypeString, value)
- }
- if value, ok := _u.mutation.ValidityDays(); ok {
- _spec.SetField(subscriptionplan.FieldValidityDays, field.TypeInt, value)
- }
- if value, ok := _u.mutation.AddedValidityDays(); ok {
- _spec.AddField(subscriptionplan.FieldValidityDays, field.TypeInt, value)
- }
- if value, ok := _u.mutation.ValidityUnit(); ok {
- _spec.SetField(subscriptionplan.FieldValidityUnit, field.TypeString, value)
- }
- if value, ok := _u.mutation.Features(); ok {
- _spec.SetField(subscriptionplan.FieldFeatures, field.TypeString, value)
- }
- if value, ok := _u.mutation.ProductName(); ok {
- _spec.SetField(subscriptionplan.FieldProductName, field.TypeString, value)
- }
- if value, ok := _u.mutation.ForSale(); ok {
- _spec.SetField(subscriptionplan.FieldForSale, field.TypeBool, value)
- }
- if value, ok := _u.mutation.SortOrder(); ok {
- _spec.SetField(subscriptionplan.FieldSortOrder, field.TypeInt, value)
- }
- if value, ok := _u.mutation.AddedSortOrder(); ok {
- _spec.AddField(subscriptionplan.FieldSortOrder, field.TypeInt, value)
- }
- if value, ok := _u.mutation.UpdatedAt(); ok {
- _spec.SetField(subscriptionplan.FieldUpdatedAt, field.TypeTime, value)
- }
- _node = &SubscriptionPlan{config: _u.config}
- _spec.Assign = _node.assignValues
- _spec.ScanValues = _node.scanValues
- if err = sqlgraph.UpdateNode(ctx, _u.driver, _spec); err != nil {
- if _, ok := err.(*sqlgraph.NotFoundError); ok {
- err = &NotFoundError{subscriptionplan.Label}
- } else if sqlgraph.IsConstraintError(err) {
- err = &ConstraintError{msg: err.Error(), wrap: err}
- }
- return nil, err
- }
- _u.mutation.done = true
- return _node, nil
- }
|