// Code generated by ent, DO NOT EDIT. package ent import ( "context" "errors" "fmt" "mingyang-admin-pay/rpc/ent/app" "mingyang-admin-pay/rpc/ent/paychannel" "mingyang-admin-pay/rpc/ent/payorder" "mingyang-admin-pay/rpc/ent/payorderextension" "mingyang-admin-pay/rpc/ent/payrefund" "mingyang-admin-pay/rpc/ent/predicate" "time" "entgo.io/ent/dialect/sql" "entgo.io/ent/dialect/sql/sqlgraph" "entgo.io/ent/schema/field" ) // PayChannelUpdate is the builder for updating PayChannel entities. type PayChannelUpdate struct { config hooks []Hook mutation *PayChannelMutation } // Where appends a list predicates to the PayChannelUpdate builder. func (_u *PayChannelUpdate) Where(ps ...predicate.PayChannel) *PayChannelUpdate { _u.mutation.Where(ps...) return _u } // SetUpdatedAt sets the "updated_at" field. func (_u *PayChannelUpdate) SetUpdatedAt(v time.Time) *PayChannelUpdate { _u.mutation.SetUpdatedAt(v) return _u } // SetStatus sets the "status" field. func (_u *PayChannelUpdate) SetStatus(v uint8) *PayChannelUpdate { _u.mutation.ResetStatus() _u.mutation.SetStatus(v) return _u } // SetNillableStatus sets the "status" field if the given value is not nil. func (_u *PayChannelUpdate) SetNillableStatus(v *uint8) *PayChannelUpdate { if v != nil { _u.SetStatus(*v) } return _u } // AddStatus adds value to the "status" field. func (_u *PayChannelUpdate) AddStatus(v int8) *PayChannelUpdate { _u.mutation.AddStatus(v) return _u } // ClearStatus clears the value of the "status" field. func (_u *PayChannelUpdate) ClearStatus() *PayChannelUpdate { _u.mutation.ClearStatus() return _u } // SetDeletedAt sets the "deleted_at" field. func (_u *PayChannelUpdate) SetDeletedAt(v time.Time) *PayChannelUpdate { _u.mutation.SetDeletedAt(v) return _u } // SetNillableDeletedAt sets the "deleted_at" field if the given value is not nil. func (_u *PayChannelUpdate) SetNillableDeletedAt(v *time.Time) *PayChannelUpdate { if v != nil { _u.SetDeletedAt(*v) } return _u } // ClearDeletedAt clears the value of the "deleted_at" field. func (_u *PayChannelUpdate) ClearDeletedAt() *PayChannelUpdate { _u.mutation.ClearDeletedAt() return _u } // SetCode sets the "code" field. func (_u *PayChannelUpdate) SetCode(v string) *PayChannelUpdate { _u.mutation.SetCode(v) return _u } // SetNillableCode sets the "code" field if the given value is not nil. func (_u *PayChannelUpdate) SetNillableCode(v *string) *PayChannelUpdate { if v != nil { _u.SetCode(*v) } return _u } // SetNameEn sets the "name_en" field. func (_u *PayChannelUpdate) SetNameEn(v string) *PayChannelUpdate { _u.mutation.SetNameEn(v) return _u } // SetNillableNameEn sets the "name_en" field if the given value is not nil. func (_u *PayChannelUpdate) SetNillableNameEn(v *string) *PayChannelUpdate { if v != nil { _u.SetNameEn(*v) } return _u } // SetNameZh sets the "name_zh" field. func (_u *PayChannelUpdate) SetNameZh(v string) *PayChannelUpdate { _u.mutation.SetNameZh(v) return _u } // SetNillableNameZh sets the "name_zh" field if the given value is not nil. func (_u *PayChannelUpdate) SetNillableNameZh(v *string) *PayChannelUpdate { if v != nil { _u.SetNameZh(*v) } return _u } // SetFreeRate sets the "free_rate" field. func (_u *PayChannelUpdate) SetFreeRate(v string) *PayChannelUpdate { _u.mutation.SetFreeRate(v) return _u } // SetNillableFreeRate sets the "free_rate" field if the given value is not nil. func (_u *PayChannelUpdate) SetNillableFreeRate(v *string) *PayChannelUpdate { if v != nil { _u.SetFreeRate(*v) } return _u } // SetAppID sets the "app_id" field. func (_u *PayChannelUpdate) SetAppID(v uint64) *PayChannelUpdate { _u.mutation.SetAppID(v) return _u } // SetNillableAppID sets the "app_id" field if the given value is not nil. func (_u *PayChannelUpdate) SetNillableAppID(v *uint64) *PayChannelUpdate { if v != nil { _u.SetAppID(*v) } return _u } // SetConfig sets the "config" field. func (_u *PayChannelUpdate) SetConfig(v map[string]interface{}) *PayChannelUpdate { _u.mutation.SetConfig(v) return _u } // SetRemake sets the "remake" field. func (_u *PayChannelUpdate) SetRemake(v string) *PayChannelUpdate { _u.mutation.SetRemake(v) return _u } // SetNillableRemake sets the "remake" field if the given value is not nil. func (_u *PayChannelUpdate) SetNillableRemake(v *string) *PayChannelUpdate { if v != nil { _u.SetRemake(*v) } return _u } // ClearRemake clears the value of the "remake" field. func (_u *PayChannelUpdate) ClearRemake() *PayChannelUpdate { _u.mutation.ClearRemake() return _u } // SetIcon sets the "icon" field. func (_u *PayChannelUpdate) SetIcon(v uint64) *PayChannelUpdate { _u.mutation.ResetIcon() _u.mutation.SetIcon(v) return _u } // SetNillableIcon sets the "icon" field if the given value is not nil. func (_u *PayChannelUpdate) SetNillableIcon(v *uint64) *PayChannelUpdate { if v != nil { _u.SetIcon(*v) } return _u } // AddIcon adds value to the "icon" field. func (_u *PayChannelUpdate) AddIcon(v int64) *PayChannelUpdate { _u.mutation.AddIcon(v) return _u } // ClearIcon clears the value of the "icon" field. func (_u *PayChannelUpdate) ClearIcon() *PayChannelUpdate { _u.mutation.ClearIcon() return _u } // SetOrderTimeOut sets the "order_time_out" field. func (_u *PayChannelUpdate) SetOrderTimeOut(v string) *PayChannelUpdate { _u.mutation.SetOrderTimeOut(v) return _u } // SetNillableOrderTimeOut sets the "order_time_out" field if the given value is not nil. func (_u *PayChannelUpdate) SetNillableOrderTimeOut(v *string) *PayChannelUpdate { if v != nil { _u.SetOrderTimeOut(*v) } return _u } // SetSupportCurrency sets the "support_currency" field. func (_u *PayChannelUpdate) SetSupportCurrency(v string) *PayChannelUpdate { _u.mutation.SetSupportCurrency(v) return _u } // SetNillableSupportCurrency sets the "support_currency" field if the given value is not nil. func (_u *PayChannelUpdate) SetNillableSupportCurrency(v *string) *PayChannelUpdate { if v != nil { _u.SetSupportCurrency(*v) } return _u } // AddOrderIDs adds the "orders" edge to the PayOrder entity by IDs. func (_u *PayChannelUpdate) AddOrderIDs(ids ...uint64) *PayChannelUpdate { _u.mutation.AddOrderIDs(ids...) return _u } // AddOrders adds the "orders" edges to the PayOrder entity. func (_u *PayChannelUpdate) AddOrders(v ...*PayOrder) *PayChannelUpdate { ids := make([]uint64, len(v)) for i := range v { ids[i] = v[i].ID } return _u.AddOrderIDs(ids...) } // AddOrdersExtensionIDs adds the "orders_extension" edge to the PayOrderExtension entity by IDs. func (_u *PayChannelUpdate) AddOrdersExtensionIDs(ids ...uint64) *PayChannelUpdate { _u.mutation.AddOrdersExtensionIDs(ids...) return _u } // AddOrdersExtension adds the "orders_extension" edges to the PayOrderExtension entity. func (_u *PayChannelUpdate) AddOrdersExtension(v ...*PayOrderExtension) *PayChannelUpdate { ids := make([]uint64, len(v)) for i := range v { ids[i] = v[i].ID } return _u.AddOrdersExtensionIDs(ids...) } // AddRefundIDs adds the "refund" edge to the PayRefund entity by IDs. func (_u *PayChannelUpdate) AddRefundIDs(ids ...uint64) *PayChannelUpdate { _u.mutation.AddRefundIDs(ids...) return _u } // AddRefund adds the "refund" edges to the PayRefund entity. func (_u *PayChannelUpdate) AddRefund(v ...*PayRefund) *PayChannelUpdate { ids := make([]uint64, len(v)) for i := range v { ids[i] = v[i].ID } return _u.AddRefundIDs(ids...) } // SetApp sets the "app" edge to the App entity. func (_u *PayChannelUpdate) SetApp(v *App) *PayChannelUpdate { return _u.SetAppID(v.ID) } // Mutation returns the PayChannelMutation object of the builder. func (_u *PayChannelUpdate) Mutation() *PayChannelMutation { return _u.mutation } // ClearOrders clears all "orders" edges to the PayOrder entity. func (_u *PayChannelUpdate) ClearOrders() *PayChannelUpdate { _u.mutation.ClearOrders() return _u } // RemoveOrderIDs removes the "orders" edge to PayOrder entities by IDs. func (_u *PayChannelUpdate) RemoveOrderIDs(ids ...uint64) *PayChannelUpdate { _u.mutation.RemoveOrderIDs(ids...) return _u } // RemoveOrders removes "orders" edges to PayOrder entities. func (_u *PayChannelUpdate) RemoveOrders(v ...*PayOrder) *PayChannelUpdate { ids := make([]uint64, len(v)) for i := range v { ids[i] = v[i].ID } return _u.RemoveOrderIDs(ids...) } // ClearOrdersExtension clears all "orders_extension" edges to the PayOrderExtension entity. func (_u *PayChannelUpdate) ClearOrdersExtension() *PayChannelUpdate { _u.mutation.ClearOrdersExtension() return _u } // RemoveOrdersExtensionIDs removes the "orders_extension" edge to PayOrderExtension entities by IDs. func (_u *PayChannelUpdate) RemoveOrdersExtensionIDs(ids ...uint64) *PayChannelUpdate { _u.mutation.RemoveOrdersExtensionIDs(ids...) return _u } // RemoveOrdersExtension removes "orders_extension" edges to PayOrderExtension entities. func (_u *PayChannelUpdate) RemoveOrdersExtension(v ...*PayOrderExtension) *PayChannelUpdate { ids := make([]uint64, len(v)) for i := range v { ids[i] = v[i].ID } return _u.RemoveOrdersExtensionIDs(ids...) } // ClearRefund clears all "refund" edges to the PayRefund entity. func (_u *PayChannelUpdate) ClearRefund() *PayChannelUpdate { _u.mutation.ClearRefund() return _u } // RemoveRefundIDs removes the "refund" edge to PayRefund entities by IDs. func (_u *PayChannelUpdate) RemoveRefundIDs(ids ...uint64) *PayChannelUpdate { _u.mutation.RemoveRefundIDs(ids...) return _u } // RemoveRefund removes "refund" edges to PayRefund entities. func (_u *PayChannelUpdate) RemoveRefund(v ...*PayRefund) *PayChannelUpdate { ids := make([]uint64, len(v)) for i := range v { ids[i] = v[i].ID } return _u.RemoveRefundIDs(ids...) } // ClearApp clears the "app" edge to the App entity. func (_u *PayChannelUpdate) ClearApp() *PayChannelUpdate { _u.mutation.ClearApp() return _u } // Save executes the query and returns the number of nodes affected by the update operation. func (_u *PayChannelUpdate) 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 *PayChannelUpdate) SaveX(ctx context.Context) int { affected, err := _u.Save(ctx) if err != nil { panic(err) } return affected } // Exec executes the query. func (_u *PayChannelUpdate) Exec(ctx context.Context) error { _, err := _u.Save(ctx) return err } // ExecX is like Exec, but panics if an error occurs. func (_u *PayChannelUpdate) 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 *PayChannelUpdate) defaults() { if _, ok := _u.mutation.UpdatedAt(); !ok { v := paychannel.UpdateDefaultUpdatedAt() _u.mutation.SetUpdatedAt(v) } } // check runs all checks and user-defined validators on the builder. func (_u *PayChannelUpdate) check() error { if _u.mutation.AppCleared() && len(_u.mutation.AppIDs()) > 0 { return errors.New(`ent: clearing a required unique edge "PayChannel.app"`) } return nil } func (_u *PayChannelUpdate) sqlSave(ctx context.Context) (_node int, err error) { if err := _u.check(); err != nil { return _node, err } _spec := sqlgraph.NewUpdateSpec(paychannel.Table, paychannel.Columns, sqlgraph.NewFieldSpec(paychannel.FieldID, field.TypeUint64)) 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.UpdatedAt(); ok { _spec.SetField(paychannel.FieldUpdatedAt, field.TypeTime, value) } if value, ok := _u.mutation.Status(); ok { _spec.SetField(paychannel.FieldStatus, field.TypeUint8, value) } if value, ok := _u.mutation.AddedStatus(); ok { _spec.AddField(paychannel.FieldStatus, field.TypeUint8, value) } if _u.mutation.StatusCleared() { _spec.ClearField(paychannel.FieldStatus, field.TypeUint8) } if value, ok := _u.mutation.DeletedAt(); ok { _spec.SetField(paychannel.FieldDeletedAt, field.TypeTime, value) } if _u.mutation.DeletedAtCleared() { _spec.ClearField(paychannel.FieldDeletedAt, field.TypeTime) } if value, ok := _u.mutation.Code(); ok { _spec.SetField(paychannel.FieldCode, field.TypeString, value) } if value, ok := _u.mutation.NameEn(); ok { _spec.SetField(paychannel.FieldNameEn, field.TypeString, value) } if value, ok := _u.mutation.NameZh(); ok { _spec.SetField(paychannel.FieldNameZh, field.TypeString, value) } if value, ok := _u.mutation.FreeRate(); ok { _spec.SetField(paychannel.FieldFreeRate, field.TypeString, value) } if value, ok := _u.mutation.Config(); ok { _spec.SetField(paychannel.FieldConfig, field.TypeJSON, value) } if value, ok := _u.mutation.Remake(); ok { _spec.SetField(paychannel.FieldRemake, field.TypeString, value) } if _u.mutation.RemakeCleared() { _spec.ClearField(paychannel.FieldRemake, field.TypeString) } if value, ok := _u.mutation.Icon(); ok { _spec.SetField(paychannel.FieldIcon, field.TypeUint64, value) } if value, ok := _u.mutation.AddedIcon(); ok { _spec.AddField(paychannel.FieldIcon, field.TypeUint64, value) } if _u.mutation.IconCleared() { _spec.ClearField(paychannel.FieldIcon, field.TypeUint64) } if value, ok := _u.mutation.OrderTimeOut(); ok { _spec.SetField(paychannel.FieldOrderTimeOut, field.TypeString, value) } if value, ok := _u.mutation.SupportCurrency(); ok { _spec.SetField(paychannel.FieldSupportCurrency, field.TypeString, value) } if _u.mutation.OrdersCleared() { edge := &sqlgraph.EdgeSpec{ Rel: sqlgraph.O2M, Inverse: true, Table: paychannel.OrdersTable, Columns: []string{paychannel.OrdersColumn}, Bidi: false, Target: &sqlgraph.EdgeTarget{ IDSpec: sqlgraph.NewFieldSpec(payorder.FieldID, field.TypeUint64), }, } _spec.Edges.Clear = append(_spec.Edges.Clear, edge) } if nodes := _u.mutation.RemovedOrdersIDs(); len(nodes) > 0 && !_u.mutation.OrdersCleared() { edge := &sqlgraph.EdgeSpec{ Rel: sqlgraph.O2M, Inverse: true, Table: paychannel.OrdersTable, Columns: []string{paychannel.OrdersColumn}, Bidi: false, Target: &sqlgraph.EdgeTarget{ IDSpec: sqlgraph.NewFieldSpec(payorder.FieldID, field.TypeUint64), }, } for _, k := range nodes { edge.Target.Nodes = append(edge.Target.Nodes, k) } _spec.Edges.Clear = append(_spec.Edges.Clear, edge) } if nodes := _u.mutation.OrdersIDs(); len(nodes) > 0 { edge := &sqlgraph.EdgeSpec{ Rel: sqlgraph.O2M, Inverse: true, Table: paychannel.OrdersTable, Columns: []string{paychannel.OrdersColumn}, Bidi: false, Target: &sqlgraph.EdgeTarget{ IDSpec: sqlgraph.NewFieldSpec(payorder.FieldID, field.TypeUint64), }, } for _, k := range nodes { edge.Target.Nodes = append(edge.Target.Nodes, k) } _spec.Edges.Add = append(_spec.Edges.Add, edge) } if _u.mutation.OrdersExtensionCleared() { edge := &sqlgraph.EdgeSpec{ Rel: sqlgraph.O2M, Inverse: true, Table: paychannel.OrdersExtensionTable, Columns: []string{paychannel.OrdersExtensionColumn}, Bidi: false, Target: &sqlgraph.EdgeTarget{ IDSpec: sqlgraph.NewFieldSpec(payorderextension.FieldID, field.TypeUint64), }, } _spec.Edges.Clear = append(_spec.Edges.Clear, edge) } if nodes := _u.mutation.RemovedOrdersExtensionIDs(); len(nodes) > 0 && !_u.mutation.OrdersExtensionCleared() { edge := &sqlgraph.EdgeSpec{ Rel: sqlgraph.O2M, Inverse: true, Table: paychannel.OrdersExtensionTable, Columns: []string{paychannel.OrdersExtensionColumn}, Bidi: false, Target: &sqlgraph.EdgeTarget{ IDSpec: sqlgraph.NewFieldSpec(payorderextension.FieldID, field.TypeUint64), }, } for _, k := range nodes { edge.Target.Nodes = append(edge.Target.Nodes, k) } _spec.Edges.Clear = append(_spec.Edges.Clear, edge) } if nodes := _u.mutation.OrdersExtensionIDs(); len(nodes) > 0 { edge := &sqlgraph.EdgeSpec{ Rel: sqlgraph.O2M, Inverse: true, Table: paychannel.OrdersExtensionTable, Columns: []string{paychannel.OrdersExtensionColumn}, Bidi: false, Target: &sqlgraph.EdgeTarget{ IDSpec: sqlgraph.NewFieldSpec(payorderextension.FieldID, field.TypeUint64), }, } for _, k := range nodes { edge.Target.Nodes = append(edge.Target.Nodes, k) } _spec.Edges.Add = append(_spec.Edges.Add, edge) } if _u.mutation.RefundCleared() { edge := &sqlgraph.EdgeSpec{ Rel: sqlgraph.O2M, Inverse: true, Table: paychannel.RefundTable, Columns: []string{paychannel.RefundColumn}, Bidi: false, Target: &sqlgraph.EdgeTarget{ IDSpec: sqlgraph.NewFieldSpec(payrefund.FieldID, field.TypeUint64), }, } _spec.Edges.Clear = append(_spec.Edges.Clear, edge) } if nodes := _u.mutation.RemovedRefundIDs(); len(nodes) > 0 && !_u.mutation.RefundCleared() { edge := &sqlgraph.EdgeSpec{ Rel: sqlgraph.O2M, Inverse: true, Table: paychannel.RefundTable, Columns: []string{paychannel.RefundColumn}, Bidi: false, Target: &sqlgraph.EdgeTarget{ IDSpec: sqlgraph.NewFieldSpec(payrefund.FieldID, field.TypeUint64), }, } for _, k := range nodes { edge.Target.Nodes = append(edge.Target.Nodes, k) } _spec.Edges.Clear = append(_spec.Edges.Clear, edge) } if nodes := _u.mutation.RefundIDs(); len(nodes) > 0 { edge := &sqlgraph.EdgeSpec{ Rel: sqlgraph.O2M, Inverse: true, Table: paychannel.RefundTable, Columns: []string{paychannel.RefundColumn}, Bidi: false, Target: &sqlgraph.EdgeTarget{ IDSpec: sqlgraph.NewFieldSpec(payrefund.FieldID, field.TypeUint64), }, } for _, k := range nodes { edge.Target.Nodes = append(edge.Target.Nodes, k) } _spec.Edges.Add = append(_spec.Edges.Add, edge) } if _u.mutation.AppCleared() { edge := &sqlgraph.EdgeSpec{ Rel: sqlgraph.M2O, Inverse: false, Table: paychannel.AppTable, Columns: []string{paychannel.AppColumn}, Bidi: false, Target: &sqlgraph.EdgeTarget{ IDSpec: sqlgraph.NewFieldSpec(app.FieldID, field.TypeUint64), }, } _spec.Edges.Clear = append(_spec.Edges.Clear, edge) } if nodes := _u.mutation.AppIDs(); len(nodes) > 0 { edge := &sqlgraph.EdgeSpec{ Rel: sqlgraph.M2O, Inverse: false, Table: paychannel.AppTable, Columns: []string{paychannel.AppColumn}, Bidi: false, Target: &sqlgraph.EdgeTarget{ IDSpec: sqlgraph.NewFieldSpec(app.FieldID, field.TypeUint64), }, } for _, k := range nodes { edge.Target.Nodes = append(edge.Target.Nodes, k) } _spec.Edges.Add = append(_spec.Edges.Add, edge) } if _node, err = sqlgraph.UpdateNodes(ctx, _u.driver, _spec); err != nil { if _, ok := err.(*sqlgraph.NotFoundError); ok { err = &NotFoundError{paychannel.Label} } else if sqlgraph.IsConstraintError(err) { err = &ConstraintError{msg: err.Error(), wrap: err} } return 0, err } _u.mutation.done = true return _node, nil } // PayChannelUpdateOne is the builder for updating a single PayChannel entity. type PayChannelUpdateOne struct { config fields []string hooks []Hook mutation *PayChannelMutation } // SetUpdatedAt sets the "updated_at" field. func (_u *PayChannelUpdateOne) SetUpdatedAt(v time.Time) *PayChannelUpdateOne { _u.mutation.SetUpdatedAt(v) return _u } // SetStatus sets the "status" field. func (_u *PayChannelUpdateOne) SetStatus(v uint8) *PayChannelUpdateOne { _u.mutation.ResetStatus() _u.mutation.SetStatus(v) return _u } // SetNillableStatus sets the "status" field if the given value is not nil. func (_u *PayChannelUpdateOne) SetNillableStatus(v *uint8) *PayChannelUpdateOne { if v != nil { _u.SetStatus(*v) } return _u } // AddStatus adds value to the "status" field. func (_u *PayChannelUpdateOne) AddStatus(v int8) *PayChannelUpdateOne { _u.mutation.AddStatus(v) return _u } // ClearStatus clears the value of the "status" field. func (_u *PayChannelUpdateOne) ClearStatus() *PayChannelUpdateOne { _u.mutation.ClearStatus() return _u } // SetDeletedAt sets the "deleted_at" field. func (_u *PayChannelUpdateOne) SetDeletedAt(v time.Time) *PayChannelUpdateOne { _u.mutation.SetDeletedAt(v) return _u } // SetNillableDeletedAt sets the "deleted_at" field if the given value is not nil. func (_u *PayChannelUpdateOne) SetNillableDeletedAt(v *time.Time) *PayChannelUpdateOne { if v != nil { _u.SetDeletedAt(*v) } return _u } // ClearDeletedAt clears the value of the "deleted_at" field. func (_u *PayChannelUpdateOne) ClearDeletedAt() *PayChannelUpdateOne { _u.mutation.ClearDeletedAt() return _u } // SetCode sets the "code" field. func (_u *PayChannelUpdateOne) SetCode(v string) *PayChannelUpdateOne { _u.mutation.SetCode(v) return _u } // SetNillableCode sets the "code" field if the given value is not nil. func (_u *PayChannelUpdateOne) SetNillableCode(v *string) *PayChannelUpdateOne { if v != nil { _u.SetCode(*v) } return _u } // SetNameEn sets the "name_en" field. func (_u *PayChannelUpdateOne) SetNameEn(v string) *PayChannelUpdateOne { _u.mutation.SetNameEn(v) return _u } // SetNillableNameEn sets the "name_en" field if the given value is not nil. func (_u *PayChannelUpdateOne) SetNillableNameEn(v *string) *PayChannelUpdateOne { if v != nil { _u.SetNameEn(*v) } return _u } // SetNameZh sets the "name_zh" field. func (_u *PayChannelUpdateOne) SetNameZh(v string) *PayChannelUpdateOne { _u.mutation.SetNameZh(v) return _u } // SetNillableNameZh sets the "name_zh" field if the given value is not nil. func (_u *PayChannelUpdateOne) SetNillableNameZh(v *string) *PayChannelUpdateOne { if v != nil { _u.SetNameZh(*v) } return _u } // SetFreeRate sets the "free_rate" field. func (_u *PayChannelUpdateOne) SetFreeRate(v string) *PayChannelUpdateOne { _u.mutation.SetFreeRate(v) return _u } // SetNillableFreeRate sets the "free_rate" field if the given value is not nil. func (_u *PayChannelUpdateOne) SetNillableFreeRate(v *string) *PayChannelUpdateOne { if v != nil { _u.SetFreeRate(*v) } return _u } // SetAppID sets the "app_id" field. func (_u *PayChannelUpdateOne) SetAppID(v uint64) *PayChannelUpdateOne { _u.mutation.SetAppID(v) return _u } // SetNillableAppID sets the "app_id" field if the given value is not nil. func (_u *PayChannelUpdateOne) SetNillableAppID(v *uint64) *PayChannelUpdateOne { if v != nil { _u.SetAppID(*v) } return _u } // SetConfig sets the "config" field. func (_u *PayChannelUpdateOne) SetConfig(v map[string]interface{}) *PayChannelUpdateOne { _u.mutation.SetConfig(v) return _u } // SetRemake sets the "remake" field. func (_u *PayChannelUpdateOne) SetRemake(v string) *PayChannelUpdateOne { _u.mutation.SetRemake(v) return _u } // SetNillableRemake sets the "remake" field if the given value is not nil. func (_u *PayChannelUpdateOne) SetNillableRemake(v *string) *PayChannelUpdateOne { if v != nil { _u.SetRemake(*v) } return _u } // ClearRemake clears the value of the "remake" field. func (_u *PayChannelUpdateOne) ClearRemake() *PayChannelUpdateOne { _u.mutation.ClearRemake() return _u } // SetIcon sets the "icon" field. func (_u *PayChannelUpdateOne) SetIcon(v uint64) *PayChannelUpdateOne { _u.mutation.ResetIcon() _u.mutation.SetIcon(v) return _u } // SetNillableIcon sets the "icon" field if the given value is not nil. func (_u *PayChannelUpdateOne) SetNillableIcon(v *uint64) *PayChannelUpdateOne { if v != nil { _u.SetIcon(*v) } return _u } // AddIcon adds value to the "icon" field. func (_u *PayChannelUpdateOne) AddIcon(v int64) *PayChannelUpdateOne { _u.mutation.AddIcon(v) return _u } // ClearIcon clears the value of the "icon" field. func (_u *PayChannelUpdateOne) ClearIcon() *PayChannelUpdateOne { _u.mutation.ClearIcon() return _u } // SetOrderTimeOut sets the "order_time_out" field. func (_u *PayChannelUpdateOne) SetOrderTimeOut(v string) *PayChannelUpdateOne { _u.mutation.SetOrderTimeOut(v) return _u } // SetNillableOrderTimeOut sets the "order_time_out" field if the given value is not nil. func (_u *PayChannelUpdateOne) SetNillableOrderTimeOut(v *string) *PayChannelUpdateOne { if v != nil { _u.SetOrderTimeOut(*v) } return _u } // SetSupportCurrency sets the "support_currency" field. func (_u *PayChannelUpdateOne) SetSupportCurrency(v string) *PayChannelUpdateOne { _u.mutation.SetSupportCurrency(v) return _u } // SetNillableSupportCurrency sets the "support_currency" field if the given value is not nil. func (_u *PayChannelUpdateOne) SetNillableSupportCurrency(v *string) *PayChannelUpdateOne { if v != nil { _u.SetSupportCurrency(*v) } return _u } // AddOrderIDs adds the "orders" edge to the PayOrder entity by IDs. func (_u *PayChannelUpdateOne) AddOrderIDs(ids ...uint64) *PayChannelUpdateOne { _u.mutation.AddOrderIDs(ids...) return _u } // AddOrders adds the "orders" edges to the PayOrder entity. func (_u *PayChannelUpdateOne) AddOrders(v ...*PayOrder) *PayChannelUpdateOne { ids := make([]uint64, len(v)) for i := range v { ids[i] = v[i].ID } return _u.AddOrderIDs(ids...) } // AddOrdersExtensionIDs adds the "orders_extension" edge to the PayOrderExtension entity by IDs. func (_u *PayChannelUpdateOne) AddOrdersExtensionIDs(ids ...uint64) *PayChannelUpdateOne { _u.mutation.AddOrdersExtensionIDs(ids...) return _u } // AddOrdersExtension adds the "orders_extension" edges to the PayOrderExtension entity. func (_u *PayChannelUpdateOne) AddOrdersExtension(v ...*PayOrderExtension) *PayChannelUpdateOne { ids := make([]uint64, len(v)) for i := range v { ids[i] = v[i].ID } return _u.AddOrdersExtensionIDs(ids...) } // AddRefundIDs adds the "refund" edge to the PayRefund entity by IDs. func (_u *PayChannelUpdateOne) AddRefundIDs(ids ...uint64) *PayChannelUpdateOne { _u.mutation.AddRefundIDs(ids...) return _u } // AddRefund adds the "refund" edges to the PayRefund entity. func (_u *PayChannelUpdateOne) AddRefund(v ...*PayRefund) *PayChannelUpdateOne { ids := make([]uint64, len(v)) for i := range v { ids[i] = v[i].ID } return _u.AddRefundIDs(ids...) } // SetApp sets the "app" edge to the App entity. func (_u *PayChannelUpdateOne) SetApp(v *App) *PayChannelUpdateOne { return _u.SetAppID(v.ID) } // Mutation returns the PayChannelMutation object of the builder. func (_u *PayChannelUpdateOne) Mutation() *PayChannelMutation { return _u.mutation } // ClearOrders clears all "orders" edges to the PayOrder entity. func (_u *PayChannelUpdateOne) ClearOrders() *PayChannelUpdateOne { _u.mutation.ClearOrders() return _u } // RemoveOrderIDs removes the "orders" edge to PayOrder entities by IDs. func (_u *PayChannelUpdateOne) RemoveOrderIDs(ids ...uint64) *PayChannelUpdateOne { _u.mutation.RemoveOrderIDs(ids...) return _u } // RemoveOrders removes "orders" edges to PayOrder entities. func (_u *PayChannelUpdateOne) RemoveOrders(v ...*PayOrder) *PayChannelUpdateOne { ids := make([]uint64, len(v)) for i := range v { ids[i] = v[i].ID } return _u.RemoveOrderIDs(ids...) } // ClearOrdersExtension clears all "orders_extension" edges to the PayOrderExtension entity. func (_u *PayChannelUpdateOne) ClearOrdersExtension() *PayChannelUpdateOne { _u.mutation.ClearOrdersExtension() return _u } // RemoveOrdersExtensionIDs removes the "orders_extension" edge to PayOrderExtension entities by IDs. func (_u *PayChannelUpdateOne) RemoveOrdersExtensionIDs(ids ...uint64) *PayChannelUpdateOne { _u.mutation.RemoveOrdersExtensionIDs(ids...) return _u } // RemoveOrdersExtension removes "orders_extension" edges to PayOrderExtension entities. func (_u *PayChannelUpdateOne) RemoveOrdersExtension(v ...*PayOrderExtension) *PayChannelUpdateOne { ids := make([]uint64, len(v)) for i := range v { ids[i] = v[i].ID } return _u.RemoveOrdersExtensionIDs(ids...) } // ClearRefund clears all "refund" edges to the PayRefund entity. func (_u *PayChannelUpdateOne) ClearRefund() *PayChannelUpdateOne { _u.mutation.ClearRefund() return _u } // RemoveRefundIDs removes the "refund" edge to PayRefund entities by IDs. func (_u *PayChannelUpdateOne) RemoveRefundIDs(ids ...uint64) *PayChannelUpdateOne { _u.mutation.RemoveRefundIDs(ids...) return _u } // RemoveRefund removes "refund" edges to PayRefund entities. func (_u *PayChannelUpdateOne) RemoveRefund(v ...*PayRefund) *PayChannelUpdateOne { ids := make([]uint64, len(v)) for i := range v { ids[i] = v[i].ID } return _u.RemoveRefundIDs(ids...) } // ClearApp clears the "app" edge to the App entity. func (_u *PayChannelUpdateOne) ClearApp() *PayChannelUpdateOne { _u.mutation.ClearApp() return _u } // Where appends a list predicates to the PayChannelUpdate builder. func (_u *PayChannelUpdateOne) Where(ps ...predicate.PayChannel) *PayChannelUpdateOne { _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 *PayChannelUpdateOne) Select(field string, fields ...string) *PayChannelUpdateOne { _u.fields = append([]string{field}, fields...) return _u } // Save executes the query and returns the updated PayChannel entity. func (_u *PayChannelUpdateOne) Save(ctx context.Context) (*PayChannel, error) { _u.defaults() return withHooks(ctx, _u.sqlSave, _u.mutation, _u.hooks) } // SaveX is like Save, but panics if an error occurs. func (_u *PayChannelUpdateOne) SaveX(ctx context.Context) *PayChannel { node, err := _u.Save(ctx) if err != nil { panic(err) } return node } // Exec executes the query on the entity. func (_u *PayChannelUpdateOne) Exec(ctx context.Context) error { _, err := _u.Save(ctx) return err } // ExecX is like Exec, but panics if an error occurs. func (_u *PayChannelUpdateOne) 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 *PayChannelUpdateOne) defaults() { if _, ok := _u.mutation.UpdatedAt(); !ok { v := paychannel.UpdateDefaultUpdatedAt() _u.mutation.SetUpdatedAt(v) } } // check runs all checks and user-defined validators on the builder. func (_u *PayChannelUpdateOne) check() error { if _u.mutation.AppCleared() && len(_u.mutation.AppIDs()) > 0 { return errors.New(`ent: clearing a required unique edge "PayChannel.app"`) } return nil } func (_u *PayChannelUpdateOne) sqlSave(ctx context.Context) (_node *PayChannel, err error) { if err := _u.check(); err != nil { return _node, err } _spec := sqlgraph.NewUpdateSpec(paychannel.Table, paychannel.Columns, sqlgraph.NewFieldSpec(paychannel.FieldID, field.TypeUint64)) id, ok := _u.mutation.ID() if !ok { return nil, &ValidationError{Name: "id", err: errors.New(`ent: missing "PayChannel.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, paychannel.FieldID) for _, f := range fields { if !paychannel.ValidColumn(f) { return nil, &ValidationError{Name: f, err: fmt.Errorf("ent: invalid field %q for query", f)} } if f != paychannel.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.UpdatedAt(); ok { _spec.SetField(paychannel.FieldUpdatedAt, field.TypeTime, value) } if value, ok := _u.mutation.Status(); ok { _spec.SetField(paychannel.FieldStatus, field.TypeUint8, value) } if value, ok := _u.mutation.AddedStatus(); ok { _spec.AddField(paychannel.FieldStatus, field.TypeUint8, value) } if _u.mutation.StatusCleared() { _spec.ClearField(paychannel.FieldStatus, field.TypeUint8) } if value, ok := _u.mutation.DeletedAt(); ok { _spec.SetField(paychannel.FieldDeletedAt, field.TypeTime, value) } if _u.mutation.DeletedAtCleared() { _spec.ClearField(paychannel.FieldDeletedAt, field.TypeTime) } if value, ok := _u.mutation.Code(); ok { _spec.SetField(paychannel.FieldCode, field.TypeString, value) } if value, ok := _u.mutation.NameEn(); ok { _spec.SetField(paychannel.FieldNameEn, field.TypeString, value) } if value, ok := _u.mutation.NameZh(); ok { _spec.SetField(paychannel.FieldNameZh, field.TypeString, value) } if value, ok := _u.mutation.FreeRate(); ok { _spec.SetField(paychannel.FieldFreeRate, field.TypeString, value) } if value, ok := _u.mutation.Config(); ok { _spec.SetField(paychannel.FieldConfig, field.TypeJSON, value) } if value, ok := _u.mutation.Remake(); ok { _spec.SetField(paychannel.FieldRemake, field.TypeString, value) } if _u.mutation.RemakeCleared() { _spec.ClearField(paychannel.FieldRemake, field.TypeString) } if value, ok := _u.mutation.Icon(); ok { _spec.SetField(paychannel.FieldIcon, field.TypeUint64, value) } if value, ok := _u.mutation.AddedIcon(); ok { _spec.AddField(paychannel.FieldIcon, field.TypeUint64, value) } if _u.mutation.IconCleared() { _spec.ClearField(paychannel.FieldIcon, field.TypeUint64) } if value, ok := _u.mutation.OrderTimeOut(); ok { _spec.SetField(paychannel.FieldOrderTimeOut, field.TypeString, value) } if value, ok := _u.mutation.SupportCurrency(); ok { _spec.SetField(paychannel.FieldSupportCurrency, field.TypeString, value) } if _u.mutation.OrdersCleared() { edge := &sqlgraph.EdgeSpec{ Rel: sqlgraph.O2M, Inverse: true, Table: paychannel.OrdersTable, Columns: []string{paychannel.OrdersColumn}, Bidi: false, Target: &sqlgraph.EdgeTarget{ IDSpec: sqlgraph.NewFieldSpec(payorder.FieldID, field.TypeUint64), }, } _spec.Edges.Clear = append(_spec.Edges.Clear, edge) } if nodes := _u.mutation.RemovedOrdersIDs(); len(nodes) > 0 && !_u.mutation.OrdersCleared() { edge := &sqlgraph.EdgeSpec{ Rel: sqlgraph.O2M, Inverse: true, Table: paychannel.OrdersTable, Columns: []string{paychannel.OrdersColumn}, Bidi: false, Target: &sqlgraph.EdgeTarget{ IDSpec: sqlgraph.NewFieldSpec(payorder.FieldID, field.TypeUint64), }, } for _, k := range nodes { edge.Target.Nodes = append(edge.Target.Nodes, k) } _spec.Edges.Clear = append(_spec.Edges.Clear, edge) } if nodes := _u.mutation.OrdersIDs(); len(nodes) > 0 { edge := &sqlgraph.EdgeSpec{ Rel: sqlgraph.O2M, Inverse: true, Table: paychannel.OrdersTable, Columns: []string{paychannel.OrdersColumn}, Bidi: false, Target: &sqlgraph.EdgeTarget{ IDSpec: sqlgraph.NewFieldSpec(payorder.FieldID, field.TypeUint64), }, } for _, k := range nodes { edge.Target.Nodes = append(edge.Target.Nodes, k) } _spec.Edges.Add = append(_spec.Edges.Add, edge) } if _u.mutation.OrdersExtensionCleared() { edge := &sqlgraph.EdgeSpec{ Rel: sqlgraph.O2M, Inverse: true, Table: paychannel.OrdersExtensionTable, Columns: []string{paychannel.OrdersExtensionColumn}, Bidi: false, Target: &sqlgraph.EdgeTarget{ IDSpec: sqlgraph.NewFieldSpec(payorderextension.FieldID, field.TypeUint64), }, } _spec.Edges.Clear = append(_spec.Edges.Clear, edge) } if nodes := _u.mutation.RemovedOrdersExtensionIDs(); len(nodes) > 0 && !_u.mutation.OrdersExtensionCleared() { edge := &sqlgraph.EdgeSpec{ Rel: sqlgraph.O2M, Inverse: true, Table: paychannel.OrdersExtensionTable, Columns: []string{paychannel.OrdersExtensionColumn}, Bidi: false, Target: &sqlgraph.EdgeTarget{ IDSpec: sqlgraph.NewFieldSpec(payorderextension.FieldID, field.TypeUint64), }, } for _, k := range nodes { edge.Target.Nodes = append(edge.Target.Nodes, k) } _spec.Edges.Clear = append(_spec.Edges.Clear, edge) } if nodes := _u.mutation.OrdersExtensionIDs(); len(nodes) > 0 { edge := &sqlgraph.EdgeSpec{ Rel: sqlgraph.O2M, Inverse: true, Table: paychannel.OrdersExtensionTable, Columns: []string{paychannel.OrdersExtensionColumn}, Bidi: false, Target: &sqlgraph.EdgeTarget{ IDSpec: sqlgraph.NewFieldSpec(payorderextension.FieldID, field.TypeUint64), }, } for _, k := range nodes { edge.Target.Nodes = append(edge.Target.Nodes, k) } _spec.Edges.Add = append(_spec.Edges.Add, edge) } if _u.mutation.RefundCleared() { edge := &sqlgraph.EdgeSpec{ Rel: sqlgraph.O2M, Inverse: true, Table: paychannel.RefundTable, Columns: []string{paychannel.RefundColumn}, Bidi: false, Target: &sqlgraph.EdgeTarget{ IDSpec: sqlgraph.NewFieldSpec(payrefund.FieldID, field.TypeUint64), }, } _spec.Edges.Clear = append(_spec.Edges.Clear, edge) } if nodes := _u.mutation.RemovedRefundIDs(); len(nodes) > 0 && !_u.mutation.RefundCleared() { edge := &sqlgraph.EdgeSpec{ Rel: sqlgraph.O2M, Inverse: true, Table: paychannel.RefundTable, Columns: []string{paychannel.RefundColumn}, Bidi: false, Target: &sqlgraph.EdgeTarget{ IDSpec: sqlgraph.NewFieldSpec(payrefund.FieldID, field.TypeUint64), }, } for _, k := range nodes { edge.Target.Nodes = append(edge.Target.Nodes, k) } _spec.Edges.Clear = append(_spec.Edges.Clear, edge) } if nodes := _u.mutation.RefundIDs(); len(nodes) > 0 { edge := &sqlgraph.EdgeSpec{ Rel: sqlgraph.O2M, Inverse: true, Table: paychannel.RefundTable, Columns: []string{paychannel.RefundColumn}, Bidi: false, Target: &sqlgraph.EdgeTarget{ IDSpec: sqlgraph.NewFieldSpec(payrefund.FieldID, field.TypeUint64), }, } for _, k := range nodes { edge.Target.Nodes = append(edge.Target.Nodes, k) } _spec.Edges.Add = append(_spec.Edges.Add, edge) } if _u.mutation.AppCleared() { edge := &sqlgraph.EdgeSpec{ Rel: sqlgraph.M2O, Inverse: false, Table: paychannel.AppTable, Columns: []string{paychannel.AppColumn}, Bidi: false, Target: &sqlgraph.EdgeTarget{ IDSpec: sqlgraph.NewFieldSpec(app.FieldID, field.TypeUint64), }, } _spec.Edges.Clear = append(_spec.Edges.Clear, edge) } if nodes := _u.mutation.AppIDs(); len(nodes) > 0 { edge := &sqlgraph.EdgeSpec{ Rel: sqlgraph.M2O, Inverse: false, Table: paychannel.AppTable, Columns: []string{paychannel.AppColumn}, Bidi: false, Target: &sqlgraph.EdgeTarget{ IDSpec: sqlgraph.NewFieldSpec(app.FieldID, field.TypeUint64), }, } for _, k := range nodes { edge.Target.Nodes = append(edge.Target.Nodes, k) } _spec.Edges.Add = append(_spec.Edges.Add, edge) } _node = &PayChannel{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{paychannel.Label} } else if sqlgraph.IsConstraintError(err) { err = &ConstraintError{msg: err.Error(), wrap: err} } return nil, err } _u.mutation.done = true return _node, nil }