fix: some api bug

This commit is contained in:
wwweww
2026-03-31 22:12:06 +08:00
parent c5ff4f0216
commit e7970ac25f
219 changed files with 16195 additions and 2126 deletions
+4 -4
View File
@@ -268,7 +268,7 @@ func (c *WalletClient) UpdateOne(_m *Wallet) *WalletUpdateOne {
}
// UpdateOneID returns an update builder for the given id.
func (c *WalletClient) UpdateOneID(id int) *WalletUpdateOne {
func (c *WalletClient) UpdateOneID(id int64) *WalletUpdateOne {
mutation := newWalletMutation(c.config, OpUpdateOne, withWalletID(id))
return &WalletUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation}
}
@@ -285,7 +285,7 @@ func (c *WalletClient) DeleteOne(_m *Wallet) *WalletDeleteOne {
}
// DeleteOneID returns a builder for deleting the given entity by its id.
func (c *WalletClient) DeleteOneID(id int) *WalletDeleteOne {
func (c *WalletClient) DeleteOneID(id int64) *WalletDeleteOne {
builder := c.Delete().Where(wallet.ID(id))
builder.mutation.id = &id
builder.mutation.op = OpDeleteOne
@@ -302,12 +302,12 @@ func (c *WalletClient) Query() *WalletQuery {
}
// Get returns a Wallet entity by its id.
func (c *WalletClient) Get(ctx context.Context, id int) (*Wallet, error) {
func (c *WalletClient) Get(ctx context.Context, id int64) (*Wallet, error) {
return c.Query().Where(wallet.ID(id)).Only(ctx)
}
// GetX is like Get, but panics if an error occurs.
func (c *WalletClient) GetX(ctx context.Context, id int) *Wallet {
func (c *WalletClient) GetX(ctx context.Context, id int64) *Wallet {
obj, err := c.Get(ctx, id)
if err != nil {
panic(err)
@@ -10,8 +10,7 @@ import (
var (
// WalletsColumns holds the columns for the "wallets" table.
WalletsColumns = []*schema.Column{
{Name: "id", Type: field.TypeInt, Increment: true},
{Name: "user_id", Type: field.TypeInt64, Unique: true},
{Name: "user_id", Type: field.TypeInt64, Increment: true},
{Name: "balance", Type: field.TypeOther, SchemaType: map[string]string{"postgres": "decimal(12,2)"}},
{Name: "frozen_balance", Type: field.TypeOther, SchemaType: map[string]string{"postgres": "decimal(12,2)"}},
{Name: "version", Type: field.TypeInt, Default: 1},
@@ -33,7 +32,6 @@ var (
{Name: "description", Type: field.TypeJSON},
{Name: "order_id", Type: field.TypeInt64, Unique: true},
{Name: "created_at", Type: field.TypeTime},
{Name: "search_text", Type: field.TypeString},
}
// WalletTransactionsTable holds the schema information for the "wallet_transactions" table.
WalletTransactionsTable = &schema.Table{
+35 -94
View File
@@ -35,9 +35,7 @@ type WalletMutation struct {
config
op Op
typ string
id *int
user_id *int64
adduser_id *int64
id *int64
balance *decimal.Decimal
frozen_balance *decimal.Decimal
version *int
@@ -69,7 +67,7 @@ func newWalletMutation(c config, op Op, opts ...walletOption) *WalletMutation {
}
// withWalletID sets the ID field of the mutation.
func withWalletID(id int) walletOption {
func withWalletID(id int64) walletOption {
return func(m *WalletMutation) {
var (
err error
@@ -119,9 +117,15 @@ func (m WalletMutation) Tx() (*Tx, error) {
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 int, exists bool) {
func (m *WalletMutation) ID() (id int64, exists bool) {
if m.id == nil {
return
}
@@ -132,12 +136,12 @@ func (m *WalletMutation) ID() (id int, exists bool) {
// 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) ([]int, error) {
func (m *WalletMutation) IDs(ctx context.Context) ([]int64, error) {
switch {
case m.op.Is(OpUpdateOne | OpDeleteOne):
id, exists := m.ID()
if exists {
return []int{id}, nil
return []int64{id}, nil
}
fallthrough
case m.op.Is(OpUpdate | OpDelete):
@@ -147,62 +151,6 @@ func (m *WalletMutation) IDs(ctx context.Context) ([]int, error) {
}
}
// SetUserID sets the "user_id" field.
func (m *WalletMutation) 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 *WalletMutation) 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 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) 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 *WalletMutation) 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 *WalletMutation) 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 *WalletMutation) ResetUserID() {
m.user_id = nil
m.adduser_id = nil
}
// SetBalance sets the "balance" field.
func (m *WalletMutation) SetBalance(d decimal.Decimal) {
m.balance = &d
@@ -401,10 +349,7 @@ func (m *WalletMutation) Type() string {
// order to get all numeric fields that were incremented/decremented, call
// AddedFields().
func (m *WalletMutation) Fields() []string {
fields := make([]string, 0, 5)
if m.user_id != nil {
fields = append(fields, wallet.FieldUserID)
}
fields := make([]string, 0, 4)
if m.balance != nil {
fields = append(fields, wallet.FieldBalance)
}
@@ -425,8 +370,6 @@ func (m *WalletMutation) Fields() []string {
// schema.
func (m *WalletMutation) Field(name string) (ent.Value, bool) {
switch name {
case wallet.FieldUserID:
return m.UserID()
case wallet.FieldBalance:
return m.Balance()
case wallet.FieldFrozenBalance:
@@ -444,8 +387,6 @@ func (m *WalletMutation) Field(name string) (ent.Value, bool) {
// database failed.
func (m *WalletMutation) OldField(ctx context.Context, name string) (ent.Value, error) {
switch name {
case wallet.FieldUserID:
return m.OldUserID(ctx)
case wallet.FieldBalance:
return m.OldBalance(ctx)
case wallet.FieldFrozenBalance:
@@ -463,13 +404,6 @@ func (m *WalletMutation) OldField(ctx context.Context, name string) (ent.Value,
// type.
func (m *WalletMutation) SetField(name string, value ent.Value) error {
switch name {
case wallet.FieldUserID:
v, ok := value.(int64)
if !ok {
return fmt.Errorf("unexpected type %T for field %s", value, name)
}
m.SetUserID(v)
return nil
case wallet.FieldBalance:
v, ok := value.(decimal.Decimal)
if !ok {
@@ -506,9 +440,6 @@ func (m *WalletMutation) SetField(name string, value ent.Value) error {
// this mutation.
func (m *WalletMutation) AddedFields() []string {
var fields []string
if m.adduser_id != nil {
fields = append(fields, wallet.FieldUserID)
}
if m.addversion != nil {
fields = append(fields, wallet.FieldVersion)
}
@@ -520,8 +451,6 @@ func (m *WalletMutation) AddedFields() []string {
// was not set, or was not defined in the schema.
func (m *WalletMutation) AddedField(name string) (ent.Value, bool) {
switch name {
case wallet.FieldUserID:
return m.AddedUserID()
case wallet.FieldVersion:
return m.AddedVersion()
}
@@ -533,13 +462,6 @@ func (m *WalletMutation) AddedField(name string) (ent.Value, bool) {
// type.
func (m *WalletMutation) AddField(name string, value ent.Value) error {
switch name {
case wallet.FieldUserID:
v, ok := value.(int64)
if !ok {
return fmt.Errorf("unexpected type %T for field %s", value, name)
}
m.AddUserID(v)
return nil
case wallet.FieldVersion:
v, ok := value.(int)
if !ok {
@@ -574,9 +496,6 @@ func (m *WalletMutation) ClearField(name string) error {
// It returns an error if the field is not defined in the schema.
func (m *WalletMutation) ResetField(name string) error {
switch name {
case wallet.FieldUserID:
m.ResetUserID()
return nil
case wallet.FieldBalance:
m.ResetBalance()
return nil
@@ -1106,9 +1025,22 @@ func (m *WalletTransactionsMutation) OldSearchText(ctx context.Context) (v strin
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.
@@ -1340,7 +1272,11 @@ func (m *WalletTransactionsMutation) AddField(name string, value ent.Value) erro
// ClearedFields returns all nullable fields that were cleared during this
// mutation.
func (m *WalletTransactionsMutation) ClearedFields() []string {
return nil
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
@@ -1353,6 +1289,11 @@ func (m *WalletTransactionsMutation) FieldCleared(name string) bool {
// 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)
}
@@ -5,6 +5,7 @@ package models
import (
"juwan-backend/app/wallet/rpc/internal/models/schema"
"juwan-backend/app/wallet/rpc/internal/models/wallet"
"time"
"github.com/shopspring/decimal"
)
@@ -27,4 +28,8 @@ func init() {
walletDescVersion := walletFields[3].Descriptor()
// wallet.DefaultVersion holds the default value on creation for the version field.
wallet.DefaultVersion = walletDescVersion.Default.(int)
// walletDescUpdatedAt is the schema descriptor for updated_at field.
walletDescUpdatedAt := walletFields[4].Descriptor()
// wallet.DefaultUpdatedAt holds the default value on creation for the updated_at field.
wallet.DefaultUpdatedAt = walletDescUpdatedAt.Default.(func() time.Time)
}
@@ -1,6 +1,8 @@
package schema
import (
"time"
"entgo.io/ent"
"entgo.io/ent/dialect"
"entgo.io/ent/schema/field"
@@ -17,7 +19,7 @@ type Wallet struct {
// Fields of the Wallet.
func (Wallet) Fields() []ent.Field {
return []ent.Field{
field.Int64("user_id").Immutable().Unique(),
field.Int64("id").StorageKey("user_id").Immutable().Unique(),
field.Other("balance", decimal.Decimal{}).
Default(defalutBalance).
SchemaType(map[string]string{
@@ -29,7 +31,7 @@ func (Wallet) Fields() []ent.Field {
dialect.Postgres: "decimal(12,2)",
}),
field.Int("version").Default(1),
field.Time("updated_at"),
field.Time("updated_at").Default(time.Now),
}
}
@@ -1,8 +1,11 @@
package schema
import (
"juwan-backend/pkg/types"
"entgo.io/ent"
"entgo.io/ent/dialect"
"entgo.io/ent/dialect/entsql"
"entgo.io/ent/schema/field"
"github.com/shopspring/decimal"
)
@@ -26,10 +29,14 @@ func (WalletTransactions) Fields() []ent.Field {
SchemaType(map[string]string{
dialect.Postgres: "decimal(12,2)",
}).Unique().Immutable(),
field.Strings("description"),
field.Other("description", types.TextArray{}).SchemaType(map[string]string{
dialect.Postgres: "text[]",
}).Optional(),
field.Int64("order_id").Immutable().Unique(),
field.Time("created_at"),
field.String("search_text"),
field.String("search_text").Optional().Immutable().Annotations(entsql.Annotation{
Skip: true,
}),
}
}
+3 -14
View File
@@ -17,9 +17,7 @@ import (
type Wallet struct {
config `json:"-"`
// ID of the ent.
ID int `json:"id,omitempty"`
// UserID holds the value of the "user_id" field.
UserID int64 `json:"user_id,omitempty"`
ID int64 `json:"id,omitempty"`
// Balance holds the value of the "balance" field.
Balance decimal.Decimal `json:"balance,omitempty"`
// FrozenBalance holds the value of the "frozen_balance" field.
@@ -38,7 +36,7 @@ func (*Wallet) scanValues(columns []string) ([]any, error) {
switch columns[i] {
case wallet.FieldBalance, wallet.FieldFrozenBalance:
values[i] = new(decimal.Decimal)
case wallet.FieldID, wallet.FieldUserID, wallet.FieldVersion:
case wallet.FieldID, wallet.FieldVersion:
values[i] = new(sql.NullInt64)
case wallet.FieldUpdatedAt:
values[i] = new(sql.NullTime)
@@ -62,13 +60,7 @@ func (_m *Wallet) assignValues(columns []string, values []any) error {
if !ok {
return fmt.Errorf("unexpected type %T for field id", value)
}
_m.ID = int(value.Int64)
case wallet.FieldUserID:
if value, ok := values[i].(*sql.NullInt64); !ok {
return fmt.Errorf("unexpected type %T for field user_id", values[i])
} else if value.Valid {
_m.UserID = value.Int64
}
_m.ID = int64(value.Int64)
case wallet.FieldBalance:
if value, ok := values[i].(*decimal.Decimal); !ok {
return fmt.Errorf("unexpected type %T for field balance", values[i])
@@ -129,9 +121,6 @@ func (_m *Wallet) String() string {
var builder strings.Builder
builder.WriteString("Wallet(")
builder.WriteString(fmt.Sprintf("id=%v, ", _m.ID))
builder.WriteString("user_id=")
builder.WriteString(fmt.Sprintf("%v", _m.UserID))
builder.WriteString(", ")
builder.WriteString("balance=")
builder.WriteString(fmt.Sprintf("%v", _m.Balance))
builder.WriteString(", ")
@@ -3,6 +3,8 @@
package wallet
import (
"time"
"entgo.io/ent/dialect/sql"
"github.com/shopspring/decimal"
)
@@ -11,9 +13,7 @@ const (
// Label holds the string label denoting the wallet type in the database.
Label = "wallet"
// FieldID holds the string denoting the id field in the database.
FieldID = "id"
// FieldUserID holds the string denoting the user_id field in the database.
FieldUserID = "user_id"
FieldID = "user_id"
// FieldBalance holds the string denoting the balance field in the database.
FieldBalance = "balance"
// FieldFrozenBalance holds the string denoting the frozen_balance field in the database.
@@ -29,7 +29,6 @@ const (
// Columns holds all SQL columns for wallet fields.
var Columns = []string{
FieldID,
FieldUserID,
FieldBalance,
FieldFrozenBalance,
FieldVersion,
@@ -53,6 +52,8 @@ var (
DefaultFrozenBalance decimal.Decimal
// DefaultVersion holds the default value on creation for the "version" field.
DefaultVersion int
// DefaultUpdatedAt holds the default value on creation for the "updated_at" field.
DefaultUpdatedAt func() time.Time
)
// OrderOption defines the ordering options for the Wallet queries.
@@ -63,11 +64,6 @@ func ByID(opts ...sql.OrderTermOption) OrderOption {
return sql.OrderByField(FieldID, opts...).ToFunc()
}
// ByUserID orders the results by the user_id field.
func ByUserID(opts ...sql.OrderTermOption) OrderOption {
return sql.OrderByField(FieldUserID, opts...).ToFunc()
}
// ByBalance orders the results by the balance field.
func ByBalance(opts ...sql.OrderTermOption) OrderOption {
return sql.OrderByField(FieldBalance, opts...).ToFunc()
+9 -54
View File
@@ -11,55 +11,50 @@ import (
)
// ID filters vertices based on their ID field.
func ID(id int) predicate.Wallet {
func ID(id int64) predicate.Wallet {
return predicate.Wallet(sql.FieldEQ(FieldID, id))
}
// IDEQ applies the EQ predicate on the ID field.
func IDEQ(id int) predicate.Wallet {
func IDEQ(id int64) predicate.Wallet {
return predicate.Wallet(sql.FieldEQ(FieldID, id))
}
// IDNEQ applies the NEQ predicate on the ID field.
func IDNEQ(id int) predicate.Wallet {
func IDNEQ(id int64) predicate.Wallet {
return predicate.Wallet(sql.FieldNEQ(FieldID, id))
}
// IDIn applies the In predicate on the ID field.
func IDIn(ids ...int) predicate.Wallet {
func IDIn(ids ...int64) predicate.Wallet {
return predicate.Wallet(sql.FieldIn(FieldID, ids...))
}
// IDNotIn applies the NotIn predicate on the ID field.
func IDNotIn(ids ...int) predicate.Wallet {
func IDNotIn(ids ...int64) predicate.Wallet {
return predicate.Wallet(sql.FieldNotIn(FieldID, ids...))
}
// IDGT applies the GT predicate on the ID field.
func IDGT(id int) predicate.Wallet {
func IDGT(id int64) predicate.Wallet {
return predicate.Wallet(sql.FieldGT(FieldID, id))
}
// IDGTE applies the GTE predicate on the ID field.
func IDGTE(id int) predicate.Wallet {
func IDGTE(id int64) predicate.Wallet {
return predicate.Wallet(sql.FieldGTE(FieldID, id))
}
// IDLT applies the LT predicate on the ID field.
func IDLT(id int) predicate.Wallet {
func IDLT(id int64) predicate.Wallet {
return predicate.Wallet(sql.FieldLT(FieldID, id))
}
// IDLTE applies the LTE predicate on the ID field.
func IDLTE(id int) predicate.Wallet {
func IDLTE(id int64) predicate.Wallet {
return predicate.Wallet(sql.FieldLTE(FieldID, id))
}
// UserID applies equality check predicate on the "user_id" field. It's identical to UserIDEQ.
func UserID(v int64) predicate.Wallet {
return predicate.Wallet(sql.FieldEQ(FieldUserID, v))
}
// Balance applies equality check predicate on the "balance" field. It's identical to BalanceEQ.
func Balance(v decimal.Decimal) predicate.Wallet {
return predicate.Wallet(sql.FieldEQ(FieldBalance, v))
@@ -80,46 +75,6 @@ func UpdatedAt(v time.Time) predicate.Wallet {
return predicate.Wallet(sql.FieldEQ(FieldUpdatedAt, v))
}
// UserIDEQ applies the EQ predicate on the "user_id" field.
func UserIDEQ(v int64) predicate.Wallet {
return predicate.Wallet(sql.FieldEQ(FieldUserID, v))
}
// UserIDNEQ applies the NEQ predicate on the "user_id" field.
func UserIDNEQ(v int64) predicate.Wallet {
return predicate.Wallet(sql.FieldNEQ(FieldUserID, v))
}
// UserIDIn applies the In predicate on the "user_id" field.
func UserIDIn(vs ...int64) predicate.Wallet {
return predicate.Wallet(sql.FieldIn(FieldUserID, vs...))
}
// UserIDNotIn applies the NotIn predicate on the "user_id" field.
func UserIDNotIn(vs ...int64) predicate.Wallet {
return predicate.Wallet(sql.FieldNotIn(FieldUserID, vs...))
}
// UserIDGT applies the GT predicate on the "user_id" field.
func UserIDGT(v int64) predicate.Wallet {
return predicate.Wallet(sql.FieldGT(FieldUserID, v))
}
// UserIDGTE applies the GTE predicate on the "user_id" field.
func UserIDGTE(v int64) predicate.Wallet {
return predicate.Wallet(sql.FieldGTE(FieldUserID, v))
}
// UserIDLT applies the LT predicate on the "user_id" field.
func UserIDLT(v int64) predicate.Wallet {
return predicate.Wallet(sql.FieldLT(FieldUserID, v))
}
// UserIDLTE applies the LTE predicate on the "user_id" field.
func UserIDLTE(v int64) predicate.Wallet {
return predicate.Wallet(sql.FieldLTE(FieldUserID, v))
}
// BalanceEQ applies the EQ predicate on the "balance" field.
func BalanceEQ(v decimal.Decimal) predicate.Wallet {
return predicate.Wallet(sql.FieldEQ(FieldBalance, v))
+28 -17
View File
@@ -21,12 +21,6 @@ type WalletCreate struct {
hooks []Hook
}
// SetUserID sets the "user_id" field.
func (_c *WalletCreate) SetUserID(v int64) *WalletCreate {
_c.mutation.SetUserID(v)
return _c
}
// SetBalance sets the "balance" field.
func (_c *WalletCreate) SetBalance(v decimal.Decimal) *WalletCreate {
_c.mutation.SetBalance(v)
@@ -75,6 +69,20 @@ func (_c *WalletCreate) SetUpdatedAt(v time.Time) *WalletCreate {
return _c
}
// SetNillableUpdatedAt sets the "updated_at" field if the given value is not nil.
func (_c *WalletCreate) SetNillableUpdatedAt(v *time.Time) *WalletCreate {
if v != nil {
_c.SetUpdatedAt(*v)
}
return _c
}
// SetID sets the "id" field.
func (_c *WalletCreate) SetID(v int64) *WalletCreate {
_c.mutation.SetID(v)
return _c
}
// Mutation returns the WalletMutation object of the builder.
func (_c *WalletCreate) Mutation() *WalletMutation {
return _c.mutation
@@ -122,13 +130,14 @@ func (_c *WalletCreate) defaults() {
v := wallet.DefaultVersion
_c.mutation.SetVersion(v)
}
if _, ok := _c.mutation.UpdatedAt(); !ok {
v := wallet.DefaultUpdatedAt()
_c.mutation.SetUpdatedAt(v)
}
}
// check runs all checks and user-defined validators on the builder.
func (_c *WalletCreate) check() error {
if _, ok := _c.mutation.UserID(); !ok {
return &ValidationError{Name: "user_id", err: errors.New(`models: missing required field "Wallet.user_id"`)}
}
if _, ok := _c.mutation.Balance(); !ok {
return &ValidationError{Name: "balance", err: errors.New(`models: missing required field "Wallet.balance"`)}
}
@@ -155,8 +164,10 @@ func (_c *WalletCreate) sqlSave(ctx context.Context) (*Wallet, error) {
}
return nil, err
}
id := _spec.ID.Value.(int64)
_node.ID = int(id)
if _spec.ID.Value != _node.ID {
id := _spec.ID.Value.(int64)
_node.ID = int64(id)
}
_c.mutation.id = &_node.ID
_c.mutation.done = true
return _node, nil
@@ -165,11 +176,11 @@ func (_c *WalletCreate) sqlSave(ctx context.Context) (*Wallet, error) {
func (_c *WalletCreate) createSpec() (*Wallet, *sqlgraph.CreateSpec) {
var (
_node = &Wallet{config: _c.config}
_spec = sqlgraph.NewCreateSpec(wallet.Table, sqlgraph.NewFieldSpec(wallet.FieldID, field.TypeInt))
_spec = sqlgraph.NewCreateSpec(wallet.Table, sqlgraph.NewFieldSpec(wallet.FieldID, field.TypeInt64))
)
if value, ok := _c.mutation.UserID(); ok {
_spec.SetField(wallet.FieldUserID, field.TypeInt64, value)
_node.UserID = value
if id, ok := _c.mutation.ID(); ok {
_node.ID = id
_spec.ID.Value = id
}
if value, ok := _c.mutation.Balance(); ok {
_spec.SetField(wallet.FieldBalance, field.TypeOther, value)
@@ -235,9 +246,9 @@ func (_c *WalletCreateBulk) Save(ctx context.Context) ([]*Wallet, error) {
return nil, err
}
mutation.id = &nodes[i].ID
if specs[i].ID.Value != nil {
if specs[i].ID.Value != nil && nodes[i].ID == 0 {
id := specs[i].ID.Value.(int64)
nodes[i].ID = int(id)
nodes[i].ID = int64(id)
}
mutation.done = true
return nodes[i], nil
@@ -40,7 +40,7 @@ func (_d *WalletDelete) ExecX(ctx context.Context) int {
}
func (_d *WalletDelete) sqlExec(ctx context.Context) (int, error) {
_spec := sqlgraph.NewDeleteSpec(wallet.Table, sqlgraph.NewFieldSpec(wallet.FieldID, field.TypeInt))
_spec := sqlgraph.NewDeleteSpec(wallet.Table, sqlgraph.NewFieldSpec(wallet.FieldID, field.TypeInt64))
if ps := _d.mutation.predicates; len(ps) > 0 {
_spec.Predicate = func(selector *sql.Selector) {
for i := range ps {
+13 -13
View File
@@ -82,8 +82,8 @@ func (_q *WalletQuery) FirstX(ctx context.Context) *Wallet {
// FirstID returns the first Wallet ID from the query.
// Returns a *NotFoundError when no Wallet ID was found.
func (_q *WalletQuery) FirstID(ctx context.Context) (id int, err error) {
var ids []int
func (_q *WalletQuery) FirstID(ctx context.Context) (id int64, err error) {
var ids []int64
if ids, err = _q.Limit(1).IDs(setContextOp(ctx, _q.ctx, ent.OpQueryFirstID)); err != nil {
return
}
@@ -95,7 +95,7 @@ func (_q *WalletQuery) FirstID(ctx context.Context) (id int, err error) {
}
// FirstIDX is like FirstID, but panics if an error occurs.
func (_q *WalletQuery) FirstIDX(ctx context.Context) int {
func (_q *WalletQuery) FirstIDX(ctx context.Context) int64 {
id, err := _q.FirstID(ctx)
if err != nil && !IsNotFound(err) {
panic(err)
@@ -133,8 +133,8 @@ func (_q *WalletQuery) OnlyX(ctx context.Context) *Wallet {
// OnlyID is like Only, but returns the only Wallet ID in the query.
// Returns a *NotSingularError when more than one Wallet ID is found.
// Returns a *NotFoundError when no entities are found.
func (_q *WalletQuery) OnlyID(ctx context.Context) (id int, err error) {
var ids []int
func (_q *WalletQuery) OnlyID(ctx context.Context) (id int64, err error) {
var ids []int64
if ids, err = _q.Limit(2).IDs(setContextOp(ctx, _q.ctx, ent.OpQueryOnlyID)); err != nil {
return
}
@@ -150,7 +150,7 @@ func (_q *WalletQuery) OnlyID(ctx context.Context) (id int, err error) {
}
// OnlyIDX is like OnlyID, but panics if an error occurs.
func (_q *WalletQuery) OnlyIDX(ctx context.Context) int {
func (_q *WalletQuery) OnlyIDX(ctx context.Context) int64 {
id, err := _q.OnlyID(ctx)
if err != nil {
panic(err)
@@ -178,7 +178,7 @@ func (_q *WalletQuery) AllX(ctx context.Context) []*Wallet {
}
// IDs executes the query and returns a list of Wallet IDs.
func (_q *WalletQuery) IDs(ctx context.Context) (ids []int, err error) {
func (_q *WalletQuery) IDs(ctx context.Context) (ids []int64, err error) {
if _q.ctx.Unique == nil && _q.path != nil {
_q.Unique(true)
}
@@ -190,7 +190,7 @@ func (_q *WalletQuery) IDs(ctx context.Context) (ids []int, err error) {
}
// IDsX is like IDs, but panics if an error occurs.
func (_q *WalletQuery) IDsX(ctx context.Context) []int {
func (_q *WalletQuery) IDsX(ctx context.Context) []int64 {
ids, err := _q.IDs(ctx)
if err != nil {
panic(err)
@@ -262,12 +262,12 @@ func (_q *WalletQuery) Clone() *WalletQuery {
// Example:
//
// var v []struct {
// UserID int64 `json:"user_id,omitempty"`
// Balance decimal.Decimal `json:"balance,omitempty"`
// Count int `json:"count,omitempty"`
// }
//
// client.Wallet.Query().
// GroupBy(wallet.FieldUserID).
// GroupBy(wallet.FieldBalance).
// Aggregate(models.Count()).
// Scan(ctx, &v)
func (_q *WalletQuery) GroupBy(field string, fields ...string) *WalletGroupBy {
@@ -285,11 +285,11 @@ func (_q *WalletQuery) GroupBy(field string, fields ...string) *WalletGroupBy {
// Example:
//
// var v []struct {
// UserID int64 `json:"user_id,omitempty"`
// Balance decimal.Decimal `json:"balance,omitempty"`
// }
//
// client.Wallet.Query().
// Select(wallet.FieldUserID).
// Select(wallet.FieldBalance).
// Scan(ctx, &v)
func (_q *WalletQuery) Select(fields ...string) *WalletSelect {
_q.ctx.Fields = append(_q.ctx.Fields, fields...)
@@ -365,7 +365,7 @@ func (_q *WalletQuery) sqlCount(ctx context.Context) (int, error) {
}
func (_q *WalletQuery) querySpec() *sqlgraph.QuerySpec {
_spec := sqlgraph.NewQuerySpec(wallet.Table, wallet.Columns, sqlgraph.NewFieldSpec(wallet.FieldID, field.TypeInt))
_spec := sqlgraph.NewQuerySpec(wallet.Table, wallet.Columns, sqlgraph.NewFieldSpec(wallet.FieldID, field.TypeInt64))
_spec.From = _q.sql
if unique := _q.ctx.Unique; unique != nil {
_spec.Unique = *unique
@@ -125,7 +125,7 @@ func (_u *WalletUpdate) ExecX(ctx context.Context) {
}
func (_u *WalletUpdate) sqlSave(ctx context.Context) (_node int, err error) {
_spec := sqlgraph.NewUpdateSpec(wallet.Table, wallet.Columns, sqlgraph.NewFieldSpec(wallet.FieldID, field.TypeInt))
_spec := sqlgraph.NewUpdateSpec(wallet.Table, wallet.Columns, sqlgraph.NewFieldSpec(wallet.FieldID, field.TypeInt64))
if ps := _u.mutation.predicates; len(ps) > 0 {
_spec.Predicate = func(selector *sql.Selector) {
for i := range ps {
@@ -277,7 +277,7 @@ func (_u *WalletUpdateOne) ExecX(ctx context.Context) {
}
func (_u *WalletUpdateOne) sqlSave(ctx context.Context) (_node *Wallet, err error) {
_spec := sqlgraph.NewUpdateSpec(wallet.Table, wallet.Columns, sqlgraph.NewFieldSpec(wallet.FieldID, field.TypeInt))
_spec := sqlgraph.NewUpdateSpec(wallet.Table, wallet.Columns, sqlgraph.NewFieldSpec(wallet.FieldID, field.TypeInt64))
id, ok := _u.mutation.ID()
if !ok {
return nil, &ValidationError{Name: "id", err: errors.New(`models: missing "Wallet.id" for update`)}
@@ -420,6 +420,16 @@ func SearchTextHasSuffix(v string) predicate.WalletTransactions {
return predicate.WalletTransactions(sql.FieldHasSuffix(FieldSearchText, v))
}
// SearchTextIsNil applies the IsNil predicate on the "search_text" field.
func SearchTextIsNil() predicate.WalletTransactions {
return predicate.WalletTransactions(sql.FieldIsNull(FieldSearchText))
}
// SearchTextNotNil applies the NotNil predicate on the "search_text" field.
func SearchTextNotNil() predicate.WalletTransactions {
return predicate.WalletTransactions(sql.FieldNotNull(FieldSearchText))
}
// SearchTextEqualFold applies the EqualFold predicate on the "search_text" field.
func SearchTextEqualFold(v string) predicate.WalletTransactions {
return predicate.WalletTransactions(sql.FieldEqualFold(FieldSearchText, v))
@@ -69,6 +69,14 @@ func (_c *WalletTransactionsCreate) SetSearchText(v string) *WalletTransactionsC
return _c
}
// SetNillableSearchText sets the "search_text" field if the given value is not nil.
func (_c *WalletTransactionsCreate) SetNillableSearchText(v *string) *WalletTransactionsCreate {
if v != nil {
_c.SetSearchText(*v)
}
return _c
}
// SetID sets the "id" field.
func (_c *WalletTransactionsCreate) SetID(v string) *WalletTransactionsCreate {
_c.mutation.SetID(v)
@@ -130,9 +138,6 @@ func (_c *WalletTransactionsCreate) check() error {
if _, ok := _c.mutation.CreatedAt(); !ok {
return &ValidationError{Name: "created_at", err: errors.New(`models: missing required field "WalletTransactions.created_at"`)}
}
if _, ok := _c.mutation.SearchText(); !ok {
return &ValidationError{Name: "search_text", err: errors.New(`models: missing required field "WalletTransactions.search_text"`)}
}
return nil
}
@@ -69,20 +69,6 @@ func (_u *WalletTransactionsUpdate) SetNillableCreatedAt(v *time.Time) *WalletTr
return _u
}
// SetSearchText sets the "search_text" field.
func (_u *WalletTransactionsUpdate) SetSearchText(v string) *WalletTransactionsUpdate {
_u.mutation.SetSearchText(v)
return _u
}
// SetNillableSearchText sets the "search_text" field if the given value is not nil.
func (_u *WalletTransactionsUpdate) SetNillableSearchText(v *string) *WalletTransactionsUpdate {
if v != nil {
_u.SetSearchText(*v)
}
return _u
}
// Mutation returns the WalletTransactionsMutation object of the builder.
func (_u *WalletTransactionsUpdate) Mutation() *WalletTransactionsMutation {
return _u.mutation
@@ -138,8 +124,8 @@ func (_u *WalletTransactionsUpdate) sqlSave(ctx context.Context) (_node int, err
if value, ok := _u.mutation.CreatedAt(); ok {
_spec.SetField(wallettransactions.FieldCreatedAt, field.TypeTime, value)
}
if value, ok := _u.mutation.SearchText(); ok {
_spec.SetField(wallettransactions.FieldSearchText, field.TypeString, value)
if _u.mutation.SearchTextCleared() {
_spec.ClearField(wallettransactions.FieldSearchText, field.TypeString)
}
if _node, err = sqlgraph.UpdateNodes(ctx, _u.driver, _spec); err != nil {
if _, ok := err.(*sqlgraph.NotFoundError); ok {
@@ -201,20 +187,6 @@ func (_u *WalletTransactionsUpdateOne) SetNillableCreatedAt(v *time.Time) *Walle
return _u
}
// SetSearchText sets the "search_text" field.
func (_u *WalletTransactionsUpdateOne) SetSearchText(v string) *WalletTransactionsUpdateOne {
_u.mutation.SetSearchText(v)
return _u
}
// SetNillableSearchText sets the "search_text" field if the given value is not nil.
func (_u *WalletTransactionsUpdateOne) SetNillableSearchText(v *string) *WalletTransactionsUpdateOne {
if v != nil {
_u.SetSearchText(*v)
}
return _u
}
// Mutation returns the WalletTransactionsMutation object of the builder.
func (_u *WalletTransactionsUpdateOne) Mutation() *WalletTransactionsMutation {
return _u.mutation
@@ -300,8 +272,8 @@ func (_u *WalletTransactionsUpdateOne) sqlSave(ctx context.Context) (_node *Wall
if value, ok := _u.mutation.CreatedAt(); ok {
_spec.SetField(wallettransactions.FieldCreatedAt, field.TypeTime, value)
}
if value, ok := _u.mutation.SearchText(); ok {
_spec.SetField(wallettransactions.FieldSearchText, field.TypeString, value)
if _u.mutation.SearchTextCleared() {
_spec.ClearField(wallettransactions.FieldSearchText, field.TypeString)
}
_node = &WalletTransactions{config: _u.config}
_spec.Assign = _node.assignValues