| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357 |
- // Code generated by ent, DO NOT EDIT.
- package ent
- import (
- "context"
- "errors"
- "fmt"
- "entgo.io/ent/dialect/sql"
- "entgo.io/ent/dialect/sql/sqlgraph"
- "entgo.io/ent/schema/field"
- "github.com/Wei-Shaw/sub2api/ent/paymentauditlog"
- "github.com/Wei-Shaw/sub2api/ent/predicate"
- )
- // PaymentAuditLogUpdate is the builder for updating PaymentAuditLog entities.
- type PaymentAuditLogUpdate struct {
- config
- hooks []Hook
- mutation *PaymentAuditLogMutation
- }
- // Where appends a list predicates to the PaymentAuditLogUpdate builder.
- func (_u *PaymentAuditLogUpdate) Where(ps ...predicate.PaymentAuditLog) *PaymentAuditLogUpdate {
- _u.mutation.Where(ps...)
- return _u
- }
- // SetOrderID sets the "order_id" field.
- func (_u *PaymentAuditLogUpdate) SetOrderID(v string) *PaymentAuditLogUpdate {
- _u.mutation.SetOrderID(v)
- return _u
- }
- // SetNillableOrderID sets the "order_id" field if the given value is not nil.
- func (_u *PaymentAuditLogUpdate) SetNillableOrderID(v *string) *PaymentAuditLogUpdate {
- if v != nil {
- _u.SetOrderID(*v)
- }
- return _u
- }
- // SetAction sets the "action" field.
- func (_u *PaymentAuditLogUpdate) SetAction(v string) *PaymentAuditLogUpdate {
- _u.mutation.SetAction(v)
- return _u
- }
- // SetNillableAction sets the "action" field if the given value is not nil.
- func (_u *PaymentAuditLogUpdate) SetNillableAction(v *string) *PaymentAuditLogUpdate {
- if v != nil {
- _u.SetAction(*v)
- }
- return _u
- }
- // SetDetail sets the "detail" field.
- func (_u *PaymentAuditLogUpdate) SetDetail(v string) *PaymentAuditLogUpdate {
- _u.mutation.SetDetail(v)
- return _u
- }
- // SetNillableDetail sets the "detail" field if the given value is not nil.
- func (_u *PaymentAuditLogUpdate) SetNillableDetail(v *string) *PaymentAuditLogUpdate {
- if v != nil {
- _u.SetDetail(*v)
- }
- return _u
- }
- // SetOperator sets the "operator" field.
- func (_u *PaymentAuditLogUpdate) SetOperator(v string) *PaymentAuditLogUpdate {
- _u.mutation.SetOperator(v)
- return _u
- }
- // SetNillableOperator sets the "operator" field if the given value is not nil.
- func (_u *PaymentAuditLogUpdate) SetNillableOperator(v *string) *PaymentAuditLogUpdate {
- if v != nil {
- _u.SetOperator(*v)
- }
- return _u
- }
- // Mutation returns the PaymentAuditLogMutation object of the builder.
- func (_u *PaymentAuditLogUpdate) Mutation() *PaymentAuditLogMutation {
- return _u.mutation
- }
- // Save executes the query and returns the number of nodes affected by the update operation.
- func (_u *PaymentAuditLogUpdate) Save(ctx context.Context) (int, error) {
- return withHooks(ctx, _u.sqlSave, _u.mutation, _u.hooks)
- }
- // SaveX is like Save, but panics if an error occurs.
- func (_u *PaymentAuditLogUpdate) SaveX(ctx context.Context) int {
- affected, err := _u.Save(ctx)
- if err != nil {
- panic(err)
- }
- return affected
- }
- // Exec executes the query.
- func (_u *PaymentAuditLogUpdate) Exec(ctx context.Context) error {
- _, err := _u.Save(ctx)
- return err
- }
- // ExecX is like Exec, but panics if an error occurs.
- func (_u *PaymentAuditLogUpdate) ExecX(ctx context.Context) {
- if err := _u.Exec(ctx); err != nil {
- panic(err)
- }
- }
- // check runs all checks and user-defined validators on the builder.
- func (_u *PaymentAuditLogUpdate) check() error {
- if v, ok := _u.mutation.OrderID(); ok {
- if err := paymentauditlog.OrderIDValidator(v); err != nil {
- return &ValidationError{Name: "order_id", err: fmt.Errorf(`ent: validator failed for field "PaymentAuditLog.order_id": %w`, err)}
- }
- }
- if v, ok := _u.mutation.Action(); ok {
- if err := paymentauditlog.ActionValidator(v); err != nil {
- return &ValidationError{Name: "action", err: fmt.Errorf(`ent: validator failed for field "PaymentAuditLog.action": %w`, err)}
- }
- }
- if v, ok := _u.mutation.Operator(); ok {
- if err := paymentauditlog.OperatorValidator(v); err != nil {
- return &ValidationError{Name: "operator", err: fmt.Errorf(`ent: validator failed for field "PaymentAuditLog.operator": %w`, err)}
- }
- }
- return nil
- }
- func (_u *PaymentAuditLogUpdate) sqlSave(ctx context.Context) (_node int, err error) {
- if err := _u.check(); err != nil {
- return _node, err
- }
- _spec := sqlgraph.NewUpdateSpec(paymentauditlog.Table, paymentauditlog.Columns, sqlgraph.NewFieldSpec(paymentauditlog.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.OrderID(); ok {
- _spec.SetField(paymentauditlog.FieldOrderID, field.TypeString, value)
- }
- if value, ok := _u.mutation.Action(); ok {
- _spec.SetField(paymentauditlog.FieldAction, field.TypeString, value)
- }
- if value, ok := _u.mutation.Detail(); ok {
- _spec.SetField(paymentauditlog.FieldDetail, field.TypeString, value)
- }
- if value, ok := _u.mutation.Operator(); ok {
- _spec.SetField(paymentauditlog.FieldOperator, field.TypeString, value)
- }
- if _node, err = sqlgraph.UpdateNodes(ctx, _u.driver, _spec); err != nil {
- if _, ok := err.(*sqlgraph.NotFoundError); ok {
- err = &NotFoundError{paymentauditlog.Label}
- } else if sqlgraph.IsConstraintError(err) {
- err = &ConstraintError{msg: err.Error(), wrap: err}
- }
- return 0, err
- }
- _u.mutation.done = true
- return _node, nil
- }
- // PaymentAuditLogUpdateOne is the builder for updating a single PaymentAuditLog entity.
- type PaymentAuditLogUpdateOne struct {
- config
- fields []string
- hooks []Hook
- mutation *PaymentAuditLogMutation
- }
- // SetOrderID sets the "order_id" field.
- func (_u *PaymentAuditLogUpdateOne) SetOrderID(v string) *PaymentAuditLogUpdateOne {
- _u.mutation.SetOrderID(v)
- return _u
- }
- // SetNillableOrderID sets the "order_id" field if the given value is not nil.
- func (_u *PaymentAuditLogUpdateOne) SetNillableOrderID(v *string) *PaymentAuditLogUpdateOne {
- if v != nil {
- _u.SetOrderID(*v)
- }
- return _u
- }
- // SetAction sets the "action" field.
- func (_u *PaymentAuditLogUpdateOne) SetAction(v string) *PaymentAuditLogUpdateOne {
- _u.mutation.SetAction(v)
- return _u
- }
- // SetNillableAction sets the "action" field if the given value is not nil.
- func (_u *PaymentAuditLogUpdateOne) SetNillableAction(v *string) *PaymentAuditLogUpdateOne {
- if v != nil {
- _u.SetAction(*v)
- }
- return _u
- }
- // SetDetail sets the "detail" field.
- func (_u *PaymentAuditLogUpdateOne) SetDetail(v string) *PaymentAuditLogUpdateOne {
- _u.mutation.SetDetail(v)
- return _u
- }
- // SetNillableDetail sets the "detail" field if the given value is not nil.
- func (_u *PaymentAuditLogUpdateOne) SetNillableDetail(v *string) *PaymentAuditLogUpdateOne {
- if v != nil {
- _u.SetDetail(*v)
- }
- return _u
- }
- // SetOperator sets the "operator" field.
- func (_u *PaymentAuditLogUpdateOne) SetOperator(v string) *PaymentAuditLogUpdateOne {
- _u.mutation.SetOperator(v)
- return _u
- }
- // SetNillableOperator sets the "operator" field if the given value is not nil.
- func (_u *PaymentAuditLogUpdateOne) SetNillableOperator(v *string) *PaymentAuditLogUpdateOne {
- if v != nil {
- _u.SetOperator(*v)
- }
- return _u
- }
- // Mutation returns the PaymentAuditLogMutation object of the builder.
- func (_u *PaymentAuditLogUpdateOne) Mutation() *PaymentAuditLogMutation {
- return _u.mutation
- }
- // Where appends a list predicates to the PaymentAuditLogUpdate builder.
- func (_u *PaymentAuditLogUpdateOne) Where(ps ...predicate.PaymentAuditLog) *PaymentAuditLogUpdateOne {
- _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 *PaymentAuditLogUpdateOne) Select(field string, fields ...string) *PaymentAuditLogUpdateOne {
- _u.fields = append([]string{field}, fields...)
- return _u
- }
- // Save executes the query and returns the updated PaymentAuditLog entity.
- func (_u *PaymentAuditLogUpdateOne) Save(ctx context.Context) (*PaymentAuditLog, error) {
- return withHooks(ctx, _u.sqlSave, _u.mutation, _u.hooks)
- }
- // SaveX is like Save, but panics if an error occurs.
- func (_u *PaymentAuditLogUpdateOne) SaveX(ctx context.Context) *PaymentAuditLog {
- node, err := _u.Save(ctx)
- if err != nil {
- panic(err)
- }
- return node
- }
- // Exec executes the query on the entity.
- func (_u *PaymentAuditLogUpdateOne) Exec(ctx context.Context) error {
- _, err := _u.Save(ctx)
- return err
- }
- // ExecX is like Exec, but panics if an error occurs.
- func (_u *PaymentAuditLogUpdateOne) ExecX(ctx context.Context) {
- if err := _u.Exec(ctx); err != nil {
- panic(err)
- }
- }
- // check runs all checks and user-defined validators on the builder.
- func (_u *PaymentAuditLogUpdateOne) check() error {
- if v, ok := _u.mutation.OrderID(); ok {
- if err := paymentauditlog.OrderIDValidator(v); err != nil {
- return &ValidationError{Name: "order_id", err: fmt.Errorf(`ent: validator failed for field "PaymentAuditLog.order_id": %w`, err)}
- }
- }
- if v, ok := _u.mutation.Action(); ok {
- if err := paymentauditlog.ActionValidator(v); err != nil {
- return &ValidationError{Name: "action", err: fmt.Errorf(`ent: validator failed for field "PaymentAuditLog.action": %w`, err)}
- }
- }
- if v, ok := _u.mutation.Operator(); ok {
- if err := paymentauditlog.OperatorValidator(v); err != nil {
- return &ValidationError{Name: "operator", err: fmt.Errorf(`ent: validator failed for field "PaymentAuditLog.operator": %w`, err)}
- }
- }
- return nil
- }
- func (_u *PaymentAuditLogUpdateOne) sqlSave(ctx context.Context) (_node *PaymentAuditLog, err error) {
- if err := _u.check(); err != nil {
- return _node, err
- }
- _spec := sqlgraph.NewUpdateSpec(paymentauditlog.Table, paymentauditlog.Columns, sqlgraph.NewFieldSpec(paymentauditlog.FieldID, field.TypeInt64))
- id, ok := _u.mutation.ID()
- if !ok {
- return nil, &ValidationError{Name: "id", err: errors.New(`ent: missing "PaymentAuditLog.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, paymentauditlog.FieldID)
- for _, f := range fields {
- if !paymentauditlog.ValidColumn(f) {
- return nil, &ValidationError{Name: f, err: fmt.Errorf("ent: invalid field %q for query", f)}
- }
- if f != paymentauditlog.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.OrderID(); ok {
- _spec.SetField(paymentauditlog.FieldOrderID, field.TypeString, value)
- }
- if value, ok := _u.mutation.Action(); ok {
- _spec.SetField(paymentauditlog.FieldAction, field.TypeString, value)
- }
- if value, ok := _u.mutation.Detail(); ok {
- _spec.SetField(paymentauditlog.FieldDetail, field.TypeString, value)
- }
- if value, ok := _u.mutation.Operator(); ok {
- _spec.SetField(paymentauditlog.FieldOperator, field.TypeString, value)
- }
- _node = &PaymentAuditLog{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{paymentauditlog.Label}
- } else if sqlgraph.IsConstraintError(err) {
- err = &ConstraintError{msg: err.Error(), wrap: err}
- }
- return nil, err
- }
- _u.mutation.done = true
- return _node, nil
- }
|