Files
2026-03-31 22:12:06 +08:00

1379 lines
42 KiB
Go

// Code generated by ent, DO NOT EDIT.
package models
import (
"context"
"errors"
"fmt"
"juwan-backend/app/wallet/rpc/internal/models/predicate"
"juwan-backend/app/wallet/rpc/internal/models/wallet"
"juwan-backend/app/wallet/rpc/internal/models/wallettransactions"
"sync"
"time"
"entgo.io/ent"
"entgo.io/ent/dialect/sql"
"github.com/shopspring/decimal"
)
const (
// Operation types.
OpCreate = ent.OpCreate
OpDelete = ent.OpDelete
OpDeleteOne = ent.OpDeleteOne
OpUpdate = ent.OpUpdate
OpUpdateOne = ent.OpUpdateOne
// Node types.
TypeWallet = "Wallet"
TypeWalletTransactions = "WalletTransactions"
)
// WalletMutation represents an operation that mutates the Wallet nodes in the graph.
type WalletMutation struct {
config
op Op
typ string
id *int64
balance *decimal.Decimal
frozen_balance *decimal.Decimal
version *int
addversion *int
updated_at *time.Time
clearedFields map[string]struct{}
done bool
oldValue func(context.Context) (*Wallet, error)
predicates []predicate.Wallet
}
var _ ent.Mutation = (*WalletMutation)(nil)
// walletOption allows management of the mutation configuration using functional options.
type walletOption func(*WalletMutation)
// newWalletMutation creates new mutation for the Wallet entity.
func newWalletMutation(c config, op Op, opts ...walletOption) *WalletMutation {
m := &WalletMutation{
config: c,
op: op,
typ: TypeWallet,
clearedFields: make(map[string]struct{}),
}
for _, opt := range opts {
opt(m)
}
return m
}
// withWalletID sets the ID field of the mutation.
func withWalletID(id int64) walletOption {
return func(m *WalletMutation) {
var (
err error
once sync.Once
value *Wallet
)
m.oldValue = func(ctx context.Context) (*Wallet, error) {
once.Do(func() {
if m.done {
err = errors.New("querying old values post mutation is not allowed")
} else {
value, err = m.Client().Wallet.Get(ctx, id)
}
})
return value, err
}
m.id = &id
}
}
// withWallet sets the old Wallet of the mutation.
func withWallet(node *Wallet) walletOption {
return func(m *WalletMutation) {
m.oldValue = func(context.Context) (*Wallet, error) {
return node, nil
}
m.id = &node.ID
}
}
// Client returns a new `ent.Client` from the mutation. If the mutation was
// executed in a transaction (ent.Tx), a transactional client is returned.
func (m WalletMutation) Client() *Client {
client := &Client{config: m.config}
client.init()
return client
}
// Tx returns an `ent.Tx` for mutations that were executed in transactions;
// it returns an error otherwise.
func (m WalletMutation) Tx() (*Tx, error) {
if _, ok := m.driver.(*txDriver); !ok {
return nil, errors.New("models: mutation is not running in a transaction")
}
tx := &Tx{config: m.config}
tx.init()
return tx, nil
}
// SetID sets the value of the id field. Note that this
// operation is only accepted on creation of Wallet entities.
func (m *WalletMutation) SetID(id int64) {
m.id = &id
}
// ID returns the ID value in the mutation. Note that the ID is only available
// if it was provided to the builder or after it was returned from the database.
func (m *WalletMutation) ID() (id int64, exists bool) {
if m.id == nil {
return
}
return *m.id, true
}
// IDs queries the database and returns the entity ids that match the mutation's predicate.
// That means, if the mutation is applied within a transaction with an isolation level such
// as sql.LevelSerializable, the returned ids match the ids of the rows that will be updated
// or updated by the mutation.
func (m *WalletMutation) IDs(ctx context.Context) ([]int64, error) {
switch {
case m.op.Is(OpUpdateOne | OpDeleteOne):
id, exists := m.ID()
if exists {
return []int64{id}, nil
}
fallthrough
case m.op.Is(OpUpdate | OpDelete):
return m.Client().Wallet.Query().Where(m.predicates...).IDs(ctx)
default:
return nil, fmt.Errorf("IDs is not allowed on %s operations", m.op)
}
}
// SetBalance sets the "balance" field.
func (m *WalletMutation) SetBalance(d decimal.Decimal) {
m.balance = &d
}
// Balance returns the value of the "balance" field in the mutation.
func (m *WalletMutation) Balance() (r decimal.Decimal, exists bool) {
v := m.balance
if v == nil {
return
}
return *v, true
}
// OldBalance returns the old "balance" field's value of the Wallet entity.
// If the Wallet object wasn't provided to the builder, the object is fetched from the database.
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
func (m *WalletMutation) OldBalance(ctx context.Context) (v decimal.Decimal, err error) {
if !m.op.Is(OpUpdateOne) {
return v, errors.New("OldBalance is only allowed on UpdateOne operations")
}
if m.id == nil || m.oldValue == nil {
return v, errors.New("OldBalance requires an ID field in the mutation")
}
oldValue, err := m.oldValue(ctx)
if err != nil {
return v, fmt.Errorf("querying old value for OldBalance: %w", err)
}
return oldValue.Balance, nil
}
// ResetBalance resets all changes to the "balance" field.
func (m *WalletMutation) ResetBalance() {
m.balance = nil
}
// SetFrozenBalance sets the "frozen_balance" field.
func (m *WalletMutation) SetFrozenBalance(d decimal.Decimal) {
m.frozen_balance = &d
}
// FrozenBalance returns the value of the "frozen_balance" field in the mutation.
func (m *WalletMutation) FrozenBalance() (r decimal.Decimal, exists bool) {
v := m.frozen_balance
if v == nil {
return
}
return *v, true
}
// OldFrozenBalance returns the old "frozen_balance" field's value of the Wallet entity.
// If the Wallet object wasn't provided to the builder, the object is fetched from the database.
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
func (m *WalletMutation) OldFrozenBalance(ctx context.Context) (v decimal.Decimal, err error) {
if !m.op.Is(OpUpdateOne) {
return v, errors.New("OldFrozenBalance is only allowed on UpdateOne operations")
}
if m.id == nil || m.oldValue == nil {
return v, errors.New("OldFrozenBalance requires an ID field in the mutation")
}
oldValue, err := m.oldValue(ctx)
if err != nil {
return v, fmt.Errorf("querying old value for OldFrozenBalance: %w", err)
}
return oldValue.FrozenBalance, nil
}
// ResetFrozenBalance resets all changes to the "frozen_balance" field.
func (m *WalletMutation) ResetFrozenBalance() {
m.frozen_balance = nil
}
// SetVersion sets the "version" field.
func (m *WalletMutation) SetVersion(i int) {
m.version = &i
m.addversion = nil
}
// Version returns the value of the "version" field in the mutation.
func (m *WalletMutation) Version() (r int, exists bool) {
v := m.version
if v == nil {
return
}
return *v, true
}
// OldVersion returns the old "version" field's value of the Wallet entity.
// If the Wallet object wasn't provided to the builder, the object is fetched from the database.
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
func (m *WalletMutation) OldVersion(ctx context.Context) (v int, err error) {
if !m.op.Is(OpUpdateOne) {
return v, errors.New("OldVersion is only allowed on UpdateOne operations")
}
if m.id == nil || m.oldValue == nil {
return v, errors.New("OldVersion requires an ID field in the mutation")
}
oldValue, err := m.oldValue(ctx)
if err != nil {
return v, fmt.Errorf("querying old value for OldVersion: %w", err)
}
return oldValue.Version, nil
}
// AddVersion adds i to the "version" field.
func (m *WalletMutation) AddVersion(i int) {
if m.addversion != nil {
*m.addversion += i
} else {
m.addversion = &i
}
}
// AddedVersion returns the value that was added to the "version" field in this mutation.
func (m *WalletMutation) AddedVersion() (r int, exists bool) {
v := m.addversion
if v == nil {
return
}
return *v, true
}
// ResetVersion resets all changes to the "version" field.
func (m *WalletMutation) ResetVersion() {
m.version = nil
m.addversion = nil
}
// SetUpdatedAt sets the "updated_at" field.
func (m *WalletMutation) SetUpdatedAt(t time.Time) {
m.updated_at = &t
}
// UpdatedAt returns the value of the "updated_at" field in the mutation.
func (m *WalletMutation) UpdatedAt() (r time.Time, exists bool) {
v := m.updated_at
if v == nil {
return
}
return *v, true
}
// OldUpdatedAt returns the old "updated_at" field's value of the Wallet entity.
// If the Wallet object wasn't provided to the builder, the object is fetched from the database.
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
func (m *WalletMutation) OldUpdatedAt(ctx context.Context) (v time.Time, err error) {
if !m.op.Is(OpUpdateOne) {
return v, errors.New("OldUpdatedAt is only allowed on UpdateOne operations")
}
if m.id == nil || m.oldValue == nil {
return v, errors.New("OldUpdatedAt requires an ID field in the mutation")
}
oldValue, err := m.oldValue(ctx)
if err != nil {
return v, fmt.Errorf("querying old value for OldUpdatedAt: %w", err)
}
return oldValue.UpdatedAt, nil
}
// ResetUpdatedAt resets all changes to the "updated_at" field.
func (m *WalletMutation) ResetUpdatedAt() {
m.updated_at = nil
}
// Where appends a list predicates to the WalletMutation builder.
func (m *WalletMutation) Where(ps ...predicate.Wallet) {
m.predicates = append(m.predicates, ps...)
}
// WhereP appends storage-level predicates to the WalletMutation builder. Using this method,
// users can use type-assertion to append predicates that do not depend on any generated package.
func (m *WalletMutation) WhereP(ps ...func(*sql.Selector)) {
p := make([]predicate.Wallet, len(ps))
for i := range ps {
p[i] = ps[i]
}
m.Where(p...)
}
// Op returns the operation name.
func (m *WalletMutation) Op() Op {
return m.op
}
// SetOp allows setting the mutation operation.
func (m *WalletMutation) SetOp(op Op) {
m.op = op
}
// Type returns the node type of this mutation (Wallet).
func (m *WalletMutation) Type() string {
return m.typ
}
// Fields returns all fields that were changed during this mutation. Note that in
// order to get all numeric fields that were incremented/decremented, call
// AddedFields().
func (m *WalletMutation) Fields() []string {
fields := make([]string, 0, 4)
if m.balance != nil {
fields = append(fields, wallet.FieldBalance)
}
if m.frozen_balance != nil {
fields = append(fields, wallet.FieldFrozenBalance)
}
if m.version != nil {
fields = append(fields, wallet.FieldVersion)
}
if m.updated_at != nil {
fields = append(fields, wallet.FieldUpdatedAt)
}
return fields
}
// Field returns the value of a field with the given name. The second boolean
// return value indicates that this field was not set, or was not defined in the
// schema.
func (m *WalletMutation) Field(name string) (ent.Value, bool) {
switch name {
case wallet.FieldBalance:
return m.Balance()
case wallet.FieldFrozenBalance:
return m.FrozenBalance()
case wallet.FieldVersion:
return m.Version()
case wallet.FieldUpdatedAt:
return m.UpdatedAt()
}
return nil, false
}
// OldField returns the old value of the field from the database. An error is
// returned if the mutation operation is not UpdateOne, or the query to the
// database failed.
func (m *WalletMutation) OldField(ctx context.Context, name string) (ent.Value, error) {
switch name {
case wallet.FieldBalance:
return m.OldBalance(ctx)
case wallet.FieldFrozenBalance:
return m.OldFrozenBalance(ctx)
case wallet.FieldVersion:
return m.OldVersion(ctx)
case wallet.FieldUpdatedAt:
return m.OldUpdatedAt(ctx)
}
return nil, fmt.Errorf("unknown Wallet field %s", name)
}
// SetField sets the value of a field with the given name. It returns an error if
// the field is not defined in the schema, or if the type mismatched the field
// type.
func (m *WalletMutation) SetField(name string, value ent.Value) error {
switch name {
case wallet.FieldBalance:
v, ok := value.(decimal.Decimal)
if !ok {
return fmt.Errorf("unexpected type %T for field %s", value, name)
}
m.SetBalance(v)
return nil
case wallet.FieldFrozenBalance:
v, ok := value.(decimal.Decimal)
if !ok {
return fmt.Errorf("unexpected type %T for field %s", value, name)
}
m.SetFrozenBalance(v)
return nil
case wallet.FieldVersion:
v, ok := value.(int)
if !ok {
return fmt.Errorf("unexpected type %T for field %s", value, name)
}
m.SetVersion(v)
return nil
case wallet.FieldUpdatedAt:
v, ok := value.(time.Time)
if !ok {
return fmt.Errorf("unexpected type %T for field %s", value, name)
}
m.SetUpdatedAt(v)
return nil
}
return fmt.Errorf("unknown Wallet field %s", name)
}
// AddedFields returns all numeric fields that were incremented/decremented during
// this mutation.
func (m *WalletMutation) AddedFields() []string {
var fields []string
if m.addversion != nil {
fields = append(fields, wallet.FieldVersion)
}
return fields
}
// AddedField returns the numeric value that was incremented/decremented on a field
// with the given name. The second boolean return value indicates that this field
// was not set, or was not defined in the schema.
func (m *WalletMutation) AddedField(name string) (ent.Value, bool) {
switch name {
case wallet.FieldVersion:
return m.AddedVersion()
}
return nil, false
}
// AddField adds the value to the field with the given name. It returns an error if
// the field is not defined in the schema, or if the type mismatched the field
// type.
func (m *WalletMutation) AddField(name string, value ent.Value) error {
switch name {
case wallet.FieldVersion:
v, ok := value.(int)
if !ok {
return fmt.Errorf("unexpected type %T for field %s", value, name)
}
m.AddVersion(v)
return nil
}
return fmt.Errorf("unknown Wallet numeric field %s", name)
}
// ClearedFields returns all nullable fields that were cleared during this
// mutation.
func (m *WalletMutation) ClearedFields() []string {
return nil
}
// FieldCleared returns a boolean indicating if a field with the given name was
// cleared in this mutation.
func (m *WalletMutation) FieldCleared(name string) bool {
_, ok := m.clearedFields[name]
return ok
}
// ClearField clears the value of the field with the given name. It returns an
// error if the field is not defined in the schema.
func (m *WalletMutation) ClearField(name string) error {
return fmt.Errorf("unknown Wallet nullable field %s", name)
}
// ResetField resets all changes in the mutation for the field with the given name.
// It returns an error if the field is not defined in the schema.
func (m *WalletMutation) ResetField(name string) error {
switch name {
case wallet.FieldBalance:
m.ResetBalance()
return nil
case wallet.FieldFrozenBalance:
m.ResetFrozenBalance()
return nil
case wallet.FieldVersion:
m.ResetVersion()
return nil
case wallet.FieldUpdatedAt:
m.ResetUpdatedAt()
return nil
}
return fmt.Errorf("unknown Wallet field %s", name)
}
// AddedEdges returns all edge names that were set/added in this mutation.
func (m *WalletMutation) AddedEdges() []string {
edges := make([]string, 0, 0)
return edges
}
// AddedIDs returns all IDs (to other nodes) that were added for the given edge
// name in this mutation.
func (m *WalletMutation) AddedIDs(name string) []ent.Value {
return nil
}
// RemovedEdges returns all edge names that were removed in this mutation.
func (m *WalletMutation) RemovedEdges() []string {
edges := make([]string, 0, 0)
return edges
}
// RemovedIDs returns all IDs (to other nodes) that were removed for the edge with
// the given name in this mutation.
func (m *WalletMutation) RemovedIDs(name string) []ent.Value {
return nil
}
// ClearedEdges returns all edge names that were cleared in this mutation.
func (m *WalletMutation) ClearedEdges() []string {
edges := make([]string, 0, 0)
return edges
}
// EdgeCleared returns a boolean which indicates if the edge with the given name
// was cleared in this mutation.
func (m *WalletMutation) EdgeCleared(name string) bool {
return false
}
// ClearEdge clears the value of the edge with the given name. It returns an error
// if that edge is not defined in the schema.
func (m *WalletMutation) ClearEdge(name string) error {
return fmt.Errorf("unknown Wallet unique edge %s", name)
}
// ResetEdge resets all changes to the edge with the given name in this mutation.
// It returns an error if the edge is not defined in the schema.
func (m *WalletMutation) ResetEdge(name string) error {
return fmt.Errorf("unknown Wallet edge %s", name)
}
// WalletTransactionsMutation represents an operation that mutates the WalletTransactions nodes in the graph.
type WalletTransactionsMutation struct {
config
op Op
typ string
id *string
user_id *int64
adduser_id *int64
_type *string
amount *decimal.Decimal
balance_after *decimal.Decimal
description *[]string
appenddescription []string
order_id *int64
addorder_id *int64
created_at *time.Time
search_text *string
clearedFields map[string]struct{}
done bool
oldValue func(context.Context) (*WalletTransactions, error)
predicates []predicate.WalletTransactions
}
var _ ent.Mutation = (*WalletTransactionsMutation)(nil)
// wallettransactionsOption allows management of the mutation configuration using functional options.
type wallettransactionsOption func(*WalletTransactionsMutation)
// newWalletTransactionsMutation creates new mutation for the WalletTransactions entity.
func newWalletTransactionsMutation(c config, op Op, opts ...wallettransactionsOption) *WalletTransactionsMutation {
m := &WalletTransactionsMutation{
config: c,
op: op,
typ: TypeWalletTransactions,
clearedFields: make(map[string]struct{}),
}
for _, opt := range opts {
opt(m)
}
return m
}
// withWalletTransactionsID sets the ID field of the mutation.
func withWalletTransactionsID(id string) wallettransactionsOption {
return func(m *WalletTransactionsMutation) {
var (
err error
once sync.Once
value *WalletTransactions
)
m.oldValue = func(ctx context.Context) (*WalletTransactions, error) {
once.Do(func() {
if m.done {
err = errors.New("querying old values post mutation is not allowed")
} else {
value, err = m.Client().WalletTransactions.Get(ctx, id)
}
})
return value, err
}
m.id = &id
}
}
// withWalletTransactions sets the old WalletTransactions of the mutation.
func withWalletTransactions(node *WalletTransactions) wallettransactionsOption {
return func(m *WalletTransactionsMutation) {
m.oldValue = func(context.Context) (*WalletTransactions, error) {
return node, nil
}
m.id = &node.ID
}
}
// Client returns a new `ent.Client` from the mutation. If the mutation was
// executed in a transaction (ent.Tx), a transactional client is returned.
func (m WalletTransactionsMutation) Client() *Client {
client := &Client{config: m.config}
client.init()
return client
}
// Tx returns an `ent.Tx` for mutations that were executed in transactions;
// it returns an error otherwise.
func (m WalletTransactionsMutation) Tx() (*Tx, error) {
if _, ok := m.driver.(*txDriver); !ok {
return nil, errors.New("models: mutation is not running in a transaction")
}
tx := &Tx{config: m.config}
tx.init()
return tx, nil
}
// SetID sets the value of the id field. Note that this
// operation is only accepted on creation of WalletTransactions entities.
func (m *WalletTransactionsMutation) SetID(id string) {
m.id = &id
}
// ID returns the ID value in the mutation. Note that the ID is only available
// if it was provided to the builder or after it was returned from the database.
func (m *WalletTransactionsMutation) ID() (id string, exists bool) {
if m.id == nil {
return
}
return *m.id, true
}
// IDs queries the database and returns the entity ids that match the mutation's predicate.
// That means, if the mutation is applied within a transaction with an isolation level such
// as sql.LevelSerializable, the returned ids match the ids of the rows that will be updated
// or updated by the mutation.
func (m *WalletTransactionsMutation) IDs(ctx context.Context) ([]string, error) {
switch {
case m.op.Is(OpUpdateOne | OpDeleteOne):
id, exists := m.ID()
if exists {
return []string{id}, nil
}
fallthrough
case m.op.Is(OpUpdate | OpDelete):
return m.Client().WalletTransactions.Query().Where(m.predicates...).IDs(ctx)
default:
return nil, fmt.Errorf("IDs is not allowed on %s operations", m.op)
}
}
// SetUserID sets the "user_id" field.
func (m *WalletTransactionsMutation) SetUserID(i int64) {
m.user_id = &i
m.adduser_id = nil
}
// UserID returns the value of the "user_id" field in the mutation.
func (m *WalletTransactionsMutation) UserID() (r int64, exists bool) {
v := m.user_id
if v == nil {
return
}
return *v, true
}
// OldUserID returns the old "user_id" field's value of the WalletTransactions entity.
// If the WalletTransactions object wasn't provided to the builder, the object is fetched from the database.
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
func (m *WalletTransactionsMutation) OldUserID(ctx context.Context) (v int64, err error) {
if !m.op.Is(OpUpdateOne) {
return v, errors.New("OldUserID is only allowed on UpdateOne operations")
}
if m.id == nil || m.oldValue == nil {
return v, errors.New("OldUserID requires an ID field in the mutation")
}
oldValue, err := m.oldValue(ctx)
if err != nil {
return v, fmt.Errorf("querying old value for OldUserID: %w", err)
}
return oldValue.UserID, nil
}
// AddUserID adds i to the "user_id" field.
func (m *WalletTransactionsMutation) AddUserID(i int64) {
if m.adduser_id != nil {
*m.adduser_id += i
} else {
m.adduser_id = &i
}
}
// AddedUserID returns the value that was added to the "user_id" field in this mutation.
func (m *WalletTransactionsMutation) AddedUserID() (r int64, exists bool) {
v := m.adduser_id
if v == nil {
return
}
return *v, true
}
// ResetUserID resets all changes to the "user_id" field.
func (m *WalletTransactionsMutation) ResetUserID() {
m.user_id = nil
m.adduser_id = nil
}
// SetType sets the "type" field.
func (m *WalletTransactionsMutation) SetType(s string) {
m._type = &s
}
// GetType returns the value of the "type" field in the mutation.
func (m *WalletTransactionsMutation) GetType() (r string, exists bool) {
v := m._type
if v == nil {
return
}
return *v, true
}
// OldType returns the old "type" field's value of the WalletTransactions entity.
// If the WalletTransactions object wasn't provided to the builder, the object is fetched from the database.
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
func (m *WalletTransactionsMutation) OldType(ctx context.Context) (v string, err error) {
if !m.op.Is(OpUpdateOne) {
return v, errors.New("OldType is only allowed on UpdateOne operations")
}
if m.id == nil || m.oldValue == nil {
return v, errors.New("OldType requires an ID field in the mutation")
}
oldValue, err := m.oldValue(ctx)
if err != nil {
return v, fmt.Errorf("querying old value for OldType: %w", err)
}
return oldValue.Type, nil
}
// ResetType resets all changes to the "type" field.
func (m *WalletTransactionsMutation) ResetType() {
m._type = nil
}
// SetAmount sets the "amount" field.
func (m *WalletTransactionsMutation) SetAmount(d decimal.Decimal) {
m.amount = &d
}
// Amount returns the value of the "amount" field in the mutation.
func (m *WalletTransactionsMutation) Amount() (r decimal.Decimal, exists bool) {
v := m.amount
if v == nil {
return
}
return *v, true
}
// OldAmount returns the old "amount" field's value of the WalletTransactions entity.
// If the WalletTransactions object wasn't provided to the builder, the object is fetched from the database.
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
func (m *WalletTransactionsMutation) OldAmount(ctx context.Context) (v decimal.Decimal, err error) {
if !m.op.Is(OpUpdateOne) {
return v, errors.New("OldAmount is only allowed on UpdateOne operations")
}
if m.id == nil || m.oldValue == nil {
return v, errors.New("OldAmount requires an ID field in the mutation")
}
oldValue, err := m.oldValue(ctx)
if err != nil {
return v, fmt.Errorf("querying old value for OldAmount: %w", err)
}
return oldValue.Amount, nil
}
// ResetAmount resets all changes to the "amount" field.
func (m *WalletTransactionsMutation) ResetAmount() {
m.amount = nil
}
// SetBalanceAfter sets the "balance_after" field.
func (m *WalletTransactionsMutation) SetBalanceAfter(d decimal.Decimal) {
m.balance_after = &d
}
// BalanceAfter returns the value of the "balance_after" field in the mutation.
func (m *WalletTransactionsMutation) BalanceAfter() (r decimal.Decimal, exists bool) {
v := m.balance_after
if v == nil {
return
}
return *v, true
}
// OldBalanceAfter returns the old "balance_after" field's value of the WalletTransactions entity.
// If the WalletTransactions object wasn't provided to the builder, the object is fetched from the database.
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
func (m *WalletTransactionsMutation) OldBalanceAfter(ctx context.Context) (v decimal.Decimal, err error) {
if !m.op.Is(OpUpdateOne) {
return v, errors.New("OldBalanceAfter is only allowed on UpdateOne operations")
}
if m.id == nil || m.oldValue == nil {
return v, errors.New("OldBalanceAfter requires an ID field in the mutation")
}
oldValue, err := m.oldValue(ctx)
if err != nil {
return v, fmt.Errorf("querying old value for OldBalanceAfter: %w", err)
}
return oldValue.BalanceAfter, nil
}
// ResetBalanceAfter resets all changes to the "balance_after" field.
func (m *WalletTransactionsMutation) ResetBalanceAfter() {
m.balance_after = nil
}
// SetDescription sets the "description" field.
func (m *WalletTransactionsMutation) SetDescription(s []string) {
m.description = &s
m.appenddescription = nil
}
// Description returns the value of the "description" field in the mutation.
func (m *WalletTransactionsMutation) Description() (r []string, exists bool) {
v := m.description
if v == nil {
return
}
return *v, true
}
// OldDescription returns the old "description" field's value of the WalletTransactions entity.
// If the WalletTransactions object wasn't provided to the builder, the object is fetched from the database.
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
func (m *WalletTransactionsMutation) OldDescription(ctx context.Context) (v []string, err error) {
if !m.op.Is(OpUpdateOne) {
return v, errors.New("OldDescription is only allowed on UpdateOne operations")
}
if m.id == nil || m.oldValue == nil {
return v, errors.New("OldDescription requires an ID field in the mutation")
}
oldValue, err := m.oldValue(ctx)
if err != nil {
return v, fmt.Errorf("querying old value for OldDescription: %w", err)
}
return oldValue.Description, nil
}
// AppendDescription adds s to the "description" field.
func (m *WalletTransactionsMutation) AppendDescription(s []string) {
m.appenddescription = append(m.appenddescription, s...)
}
// AppendedDescription returns the list of values that were appended to the "description" field in this mutation.
func (m *WalletTransactionsMutation) AppendedDescription() ([]string, bool) {
if len(m.appenddescription) == 0 {
return nil, false
}
return m.appenddescription, true
}
// ResetDescription resets all changes to the "description" field.
func (m *WalletTransactionsMutation) ResetDescription() {
m.description = nil
m.appenddescription = nil
}
// SetOrderID sets the "order_id" field.
func (m *WalletTransactionsMutation) SetOrderID(i int64) {
m.order_id = &i
m.addorder_id = nil
}
// OrderID returns the value of the "order_id" field in the mutation.
func (m *WalletTransactionsMutation) OrderID() (r int64, exists bool) {
v := m.order_id
if v == nil {
return
}
return *v, true
}
// OldOrderID returns the old "order_id" field's value of the WalletTransactions entity.
// If the WalletTransactions object wasn't provided to the builder, the object is fetched from the database.
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
func (m *WalletTransactionsMutation) OldOrderID(ctx context.Context) (v int64, err error) {
if !m.op.Is(OpUpdateOne) {
return v, errors.New("OldOrderID is only allowed on UpdateOne operations")
}
if m.id == nil || m.oldValue == nil {
return v, errors.New("OldOrderID requires an ID field in the mutation")
}
oldValue, err := m.oldValue(ctx)
if err != nil {
return v, fmt.Errorf("querying old value for OldOrderID: %w", err)
}
return oldValue.OrderID, nil
}
// AddOrderID adds i to the "order_id" field.
func (m *WalletTransactionsMutation) AddOrderID(i int64) {
if m.addorder_id != nil {
*m.addorder_id += i
} else {
m.addorder_id = &i
}
}
// AddedOrderID returns the value that was added to the "order_id" field in this mutation.
func (m *WalletTransactionsMutation) AddedOrderID() (r int64, exists bool) {
v := m.addorder_id
if v == nil {
return
}
return *v, true
}
// ResetOrderID resets all changes to the "order_id" field.
func (m *WalletTransactionsMutation) ResetOrderID() {
m.order_id = nil
m.addorder_id = nil
}
// SetCreatedAt sets the "created_at" field.
func (m *WalletTransactionsMutation) SetCreatedAt(t time.Time) {
m.created_at = &t
}
// CreatedAt returns the value of the "created_at" field in the mutation.
func (m *WalletTransactionsMutation) CreatedAt() (r time.Time, exists bool) {
v := m.created_at
if v == nil {
return
}
return *v, true
}
// OldCreatedAt returns the old "created_at" field's value of the WalletTransactions entity.
// If the WalletTransactions object wasn't provided to the builder, the object is fetched from the database.
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
func (m *WalletTransactionsMutation) OldCreatedAt(ctx context.Context) (v time.Time, err error) {
if !m.op.Is(OpUpdateOne) {
return v, errors.New("OldCreatedAt is only allowed on UpdateOne operations")
}
if m.id == nil || m.oldValue == nil {
return v, errors.New("OldCreatedAt requires an ID field in the mutation")
}
oldValue, err := m.oldValue(ctx)
if err != nil {
return v, fmt.Errorf("querying old value for OldCreatedAt: %w", err)
}
return oldValue.CreatedAt, nil
}
// ResetCreatedAt resets all changes to the "created_at" field.
func (m *WalletTransactionsMutation) ResetCreatedAt() {
m.created_at = nil
}
// SetSearchText sets the "search_text" field.
func (m *WalletTransactionsMutation) SetSearchText(s string) {
m.search_text = &s
}
// SearchText returns the value of the "search_text" field in the mutation.
func (m *WalletTransactionsMutation) SearchText() (r string, exists bool) {
v := m.search_text
if v == nil {
return
}
return *v, true
}
// OldSearchText returns the old "search_text" field's value of the WalletTransactions entity.
// If the WalletTransactions object wasn't provided to the builder, the object is fetched from the database.
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
func (m *WalletTransactionsMutation) OldSearchText(ctx context.Context) (v string, err error) {
if !m.op.Is(OpUpdateOne) {
return v, errors.New("OldSearchText is only allowed on UpdateOne operations")
}
if m.id == nil || m.oldValue == nil {
return v, errors.New("OldSearchText requires an ID field in the mutation")
}
oldValue, err := m.oldValue(ctx)
if err != nil {
return v, fmt.Errorf("querying old value for OldSearchText: %w", err)
}
return oldValue.SearchText, nil
}
// ClearSearchText clears the value of the "search_text" field.
func (m *WalletTransactionsMutation) ClearSearchText() {
m.search_text = nil
m.clearedFields[wallettransactions.FieldSearchText] = struct{}{}
}
// SearchTextCleared returns if the "search_text" field was cleared in this mutation.
func (m *WalletTransactionsMutation) SearchTextCleared() bool {
_, ok := m.clearedFields[wallettransactions.FieldSearchText]
return ok
}
// ResetSearchText resets all changes to the "search_text" field.
func (m *WalletTransactionsMutation) ResetSearchText() {
m.search_text = nil
delete(m.clearedFields, wallettransactions.FieldSearchText)
}
// Where appends a list predicates to the WalletTransactionsMutation builder.
func (m *WalletTransactionsMutation) Where(ps ...predicate.WalletTransactions) {
m.predicates = append(m.predicates, ps...)
}
// WhereP appends storage-level predicates to the WalletTransactionsMutation builder. Using this method,
// users can use type-assertion to append predicates that do not depend on any generated package.
func (m *WalletTransactionsMutation) WhereP(ps ...func(*sql.Selector)) {
p := make([]predicate.WalletTransactions, len(ps))
for i := range ps {
p[i] = ps[i]
}
m.Where(p...)
}
// Op returns the operation name.
func (m *WalletTransactionsMutation) Op() Op {
return m.op
}
// SetOp allows setting the mutation operation.
func (m *WalletTransactionsMutation) SetOp(op Op) {
m.op = op
}
// Type returns the node type of this mutation (WalletTransactions).
func (m *WalletTransactionsMutation) Type() string {
return m.typ
}
// Fields returns all fields that were changed during this mutation. Note that in
// order to get all numeric fields that were incremented/decremented, call
// AddedFields().
func (m *WalletTransactionsMutation) Fields() []string {
fields := make([]string, 0, 8)
if m.user_id != nil {
fields = append(fields, wallettransactions.FieldUserID)
}
if m._type != nil {
fields = append(fields, wallettransactions.FieldType)
}
if m.amount != nil {
fields = append(fields, wallettransactions.FieldAmount)
}
if m.balance_after != nil {
fields = append(fields, wallettransactions.FieldBalanceAfter)
}
if m.description != nil {
fields = append(fields, wallettransactions.FieldDescription)
}
if m.order_id != nil {
fields = append(fields, wallettransactions.FieldOrderID)
}
if m.created_at != nil {
fields = append(fields, wallettransactions.FieldCreatedAt)
}
if m.search_text != nil {
fields = append(fields, wallettransactions.FieldSearchText)
}
return fields
}
// Field returns the value of a field with the given name. The second boolean
// return value indicates that this field was not set, or was not defined in the
// schema.
func (m *WalletTransactionsMutation) Field(name string) (ent.Value, bool) {
switch name {
case wallettransactions.FieldUserID:
return m.UserID()
case wallettransactions.FieldType:
return m.GetType()
case wallettransactions.FieldAmount:
return m.Amount()
case wallettransactions.FieldBalanceAfter:
return m.BalanceAfter()
case wallettransactions.FieldDescription:
return m.Description()
case wallettransactions.FieldOrderID:
return m.OrderID()
case wallettransactions.FieldCreatedAt:
return m.CreatedAt()
case wallettransactions.FieldSearchText:
return m.SearchText()
}
return nil, false
}
// OldField returns the old value of the field from the database. An error is
// returned if the mutation operation is not UpdateOne, or the query to the
// database failed.
func (m *WalletTransactionsMutation) OldField(ctx context.Context, name string) (ent.Value, error) {
switch name {
case wallettransactions.FieldUserID:
return m.OldUserID(ctx)
case wallettransactions.FieldType:
return m.OldType(ctx)
case wallettransactions.FieldAmount:
return m.OldAmount(ctx)
case wallettransactions.FieldBalanceAfter:
return m.OldBalanceAfter(ctx)
case wallettransactions.FieldDescription:
return m.OldDescription(ctx)
case wallettransactions.FieldOrderID:
return m.OldOrderID(ctx)
case wallettransactions.FieldCreatedAt:
return m.OldCreatedAt(ctx)
case wallettransactions.FieldSearchText:
return m.OldSearchText(ctx)
}
return nil, fmt.Errorf("unknown WalletTransactions field %s", name)
}
// SetField sets the value of a field with the given name. It returns an error if
// the field is not defined in the schema, or if the type mismatched the field
// type.
func (m *WalletTransactionsMutation) SetField(name string, value ent.Value) error {
switch name {
case wallettransactions.FieldUserID:
v, ok := value.(int64)
if !ok {
return fmt.Errorf("unexpected type %T for field %s", value, name)
}
m.SetUserID(v)
return nil
case wallettransactions.FieldType:
v, ok := value.(string)
if !ok {
return fmt.Errorf("unexpected type %T for field %s", value, name)
}
m.SetType(v)
return nil
case wallettransactions.FieldAmount:
v, ok := value.(decimal.Decimal)
if !ok {
return fmt.Errorf("unexpected type %T for field %s", value, name)
}
m.SetAmount(v)
return nil
case wallettransactions.FieldBalanceAfter:
v, ok := value.(decimal.Decimal)
if !ok {
return fmt.Errorf("unexpected type %T for field %s", value, name)
}
m.SetBalanceAfter(v)
return nil
case wallettransactions.FieldDescription:
v, ok := value.([]string)
if !ok {
return fmt.Errorf("unexpected type %T for field %s", value, name)
}
m.SetDescription(v)
return nil
case wallettransactions.FieldOrderID:
v, ok := value.(int64)
if !ok {
return fmt.Errorf("unexpected type %T for field %s", value, name)
}
m.SetOrderID(v)
return nil
case wallettransactions.FieldCreatedAt:
v, ok := value.(time.Time)
if !ok {
return fmt.Errorf("unexpected type %T for field %s", value, name)
}
m.SetCreatedAt(v)
return nil
case wallettransactions.FieldSearchText:
v, ok := value.(string)
if !ok {
return fmt.Errorf("unexpected type %T for field %s", value, name)
}
m.SetSearchText(v)
return nil
}
return fmt.Errorf("unknown WalletTransactions field %s", name)
}
// AddedFields returns all numeric fields that were incremented/decremented during
// this mutation.
func (m *WalletTransactionsMutation) AddedFields() []string {
var fields []string
if m.adduser_id != nil {
fields = append(fields, wallettransactions.FieldUserID)
}
if m.addorder_id != nil {
fields = append(fields, wallettransactions.FieldOrderID)
}
return fields
}
// AddedField returns the numeric value that was incremented/decremented on a field
// with the given name. The second boolean return value indicates that this field
// was not set, or was not defined in the schema.
func (m *WalletTransactionsMutation) AddedField(name string) (ent.Value, bool) {
switch name {
case wallettransactions.FieldUserID:
return m.AddedUserID()
case wallettransactions.FieldOrderID:
return m.AddedOrderID()
}
return nil, false
}
// AddField adds the value to the field with the given name. It returns an error if
// the field is not defined in the schema, or if the type mismatched the field
// type.
func (m *WalletTransactionsMutation) AddField(name string, value ent.Value) error {
switch name {
case wallettransactions.FieldUserID:
v, ok := value.(int64)
if !ok {
return fmt.Errorf("unexpected type %T for field %s", value, name)
}
m.AddUserID(v)
return nil
case wallettransactions.FieldOrderID:
v, ok := value.(int64)
if !ok {
return fmt.Errorf("unexpected type %T for field %s", value, name)
}
m.AddOrderID(v)
return nil
}
return fmt.Errorf("unknown WalletTransactions numeric field %s", name)
}
// ClearedFields returns all nullable fields that were cleared during this
// mutation.
func (m *WalletTransactionsMutation) ClearedFields() []string {
var fields []string
if m.FieldCleared(wallettransactions.FieldSearchText) {
fields = append(fields, wallettransactions.FieldSearchText)
}
return fields
}
// FieldCleared returns a boolean indicating if a field with the given name was
// cleared in this mutation.
func (m *WalletTransactionsMutation) FieldCleared(name string) bool {
_, ok := m.clearedFields[name]
return ok
}
// ClearField clears the value of the field with the given name. It returns an
// error if the field is not defined in the schema.
func (m *WalletTransactionsMutation) ClearField(name string) error {
switch name {
case wallettransactions.FieldSearchText:
m.ClearSearchText()
return nil
}
return fmt.Errorf("unknown WalletTransactions nullable field %s", name)
}
// ResetField resets all changes in the mutation for the field with the given name.
// It returns an error if the field is not defined in the schema.
func (m *WalletTransactionsMutation) ResetField(name string) error {
switch name {
case wallettransactions.FieldUserID:
m.ResetUserID()
return nil
case wallettransactions.FieldType:
m.ResetType()
return nil
case wallettransactions.FieldAmount:
m.ResetAmount()
return nil
case wallettransactions.FieldBalanceAfter:
m.ResetBalanceAfter()
return nil
case wallettransactions.FieldDescription:
m.ResetDescription()
return nil
case wallettransactions.FieldOrderID:
m.ResetOrderID()
return nil
case wallettransactions.FieldCreatedAt:
m.ResetCreatedAt()
return nil
case wallettransactions.FieldSearchText:
m.ResetSearchText()
return nil
}
return fmt.Errorf("unknown WalletTransactions field %s", name)
}
// AddedEdges returns all edge names that were set/added in this mutation.
func (m *WalletTransactionsMutation) AddedEdges() []string {
edges := make([]string, 0, 0)
return edges
}
// AddedIDs returns all IDs (to other nodes) that were added for the given edge
// name in this mutation.
func (m *WalletTransactionsMutation) AddedIDs(name string) []ent.Value {
return nil
}
// RemovedEdges returns all edge names that were removed in this mutation.
func (m *WalletTransactionsMutation) RemovedEdges() []string {
edges := make([]string, 0, 0)
return edges
}
// RemovedIDs returns all IDs (to other nodes) that were removed for the edge with
// the given name in this mutation.
func (m *WalletTransactionsMutation) RemovedIDs(name string) []ent.Value {
return nil
}
// ClearedEdges returns all edge names that were cleared in this mutation.
func (m *WalletTransactionsMutation) ClearedEdges() []string {
edges := make([]string, 0, 0)
return edges
}
// EdgeCleared returns a boolean which indicates if the edge with the given name
// was cleared in this mutation.
func (m *WalletTransactionsMutation) EdgeCleared(name string) bool {
return false
}
// ClearEdge clears the value of the edge with the given name. It returns an error
// if that edge is not defined in the schema.
func (m *WalletTransactionsMutation) ClearEdge(name string) error {
return fmt.Errorf("unknown WalletTransactions unique edge %s", name)
}
// ResetEdge resets all changes to the edge with the given name in this mutation.
// It returns an error if the edge is not defined in the schema.
func (m *WalletTransactionsMutation) ResetEdge(name string) error {
return fmt.Errorf("unknown WalletTransactions edge %s", name)
}