chore: stabilize lint and verify builds
This commit is contained in:
@@ -22,9 +22,10 @@ func Truncate(ctx context.Context, db *sql.DB, tableName ...string) error {
|
||||
for _, name := range tableName {
|
||||
sql := fmt.Sprintf("TRUNCATE TABLE %s RESTART IDENTITY", name)
|
||||
if _, err := db.ExecContext(ctx, sql); err != nil {
|
||||
return err
|
||||
return fmt.Errorf("truncate table %s: %w", name, err)
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -41,10 +42,15 @@ func WrapLikeRight(v string) string {
|
||||
}
|
||||
|
||||
func Provide(...opt.Option) error {
|
||||
return container.Container.Provide(func(db *gorm.DB) contracts.Initial {
|
||||
if err := container.Container.Provide(func(db *gorm.DB) contracts.Initial {
|
||||
models.SetDefault(db)
|
||||
|
||||
return models.Q
|
||||
}, atom.GroupInitial)
|
||||
}, atom.GroupInitial); err != nil {
|
||||
return fmt.Errorf("provide database initial: %w", err)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func DefaultProvider() container.ProviderContainer {
|
||||
|
||||
@@ -25,17 +25,19 @@ type ordersSnapshotWire struct {
|
||||
Data json.RawMessage `json:"data"`
|
||||
}
|
||||
|
||||
func (s *OrdersSnapshot) UnmarshalJSON(b []byte) error {
|
||||
var w ordersSnapshotWire
|
||||
if err := json.Unmarshal(b, &w); err == nil && (w.Kind != "" || w.Data != nil) {
|
||||
s.Kind = w.Kind
|
||||
s.Data = w.Data
|
||||
func (snapshot *OrdersSnapshot) UnmarshalJSON(raw []byte) error {
|
||||
var wire ordersSnapshotWire
|
||||
if err := json.Unmarshal(raw, &wire); err == nil && (wire.Kind != "" || wire.Data != nil) {
|
||||
snapshot.Kind = wire.Kind
|
||||
snapshot.Data = wire.Data
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// 兼容旧结构:旧 snapshot 通常是一个扁平对象(没有 kind/data)。
|
||||
s.Kind = "legacy"
|
||||
s.Data = append(s.Data[:0], b...)
|
||||
snapshot.Kind = "legacy"
|
||||
snapshot.Data = append(snapshot.Data[:0], raw...)
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,29 @@
|
||||
-- +goose Up
|
||||
-- +goose StatementBegin
|
||||
CREATE TABLE IF NOT EXISTS recharge_codes(
|
||||
id bigserial PRIMARY KEY,
|
||||
code varchar(64) NOT NULL,
|
||||
amount bigint NOT NULL,
|
||||
status varchar(32) DEFAULT 'inactive',
|
||||
activated_by bigint DEFAULT 0,
|
||||
activated_at timestamp with time zone,
|
||||
redeemed_by bigint DEFAULT 0,
|
||||
redeemed_at timestamp with time zone,
|
||||
redeemed_order_id bigint DEFAULT 0,
|
||||
remark varchar(255) DEFAULT '',
|
||||
created_at timestamp with time zone DEFAULT NOW(),
|
||||
updated_at timestamp with time zone DEFAULT NOW(),
|
||||
UNIQUE (code)
|
||||
);
|
||||
|
||||
CREATE INDEX IF NOT EXISTS idx_recharge_codes_status ON recharge_codes(status);
|
||||
CREATE INDEX IF NOT EXISTS idx_recharge_codes_activated_at ON recharge_codes(activated_at);
|
||||
CREATE INDEX IF NOT EXISTS idx_recharge_codes_redeemed_at ON recharge_codes(redeemed_at);
|
||||
CREATE INDEX IF NOT EXISTS idx_recharge_codes_redeemed_by ON recharge_codes(redeemed_by);
|
||||
CREATE INDEX IF NOT EXISTS idx_recharge_codes_redeemed_order ON recharge_codes(redeemed_order_id);
|
||||
-- +goose StatementEnd
|
||||
|
||||
-- +goose Down
|
||||
-- +goose StatementBegin
|
||||
DROP TABLE IF EXISTS recharge_codes;
|
||||
-- +goose StatementEnd
|
||||
@@ -31,6 +31,7 @@ var (
|
||||
OrderQuery *orderQuery
|
||||
OrderItemQuery *orderItemQuery
|
||||
PayoutAccountQuery *payoutAccountQuery
|
||||
RechargeCodeQuery *rechargeCodeQuery
|
||||
SystemConfigQuery *systemConfigQuery
|
||||
TenantQuery *tenantQuery
|
||||
TenantInviteQuery *tenantInviteQuery
|
||||
@@ -59,6 +60,7 @@ func SetDefault(db *gorm.DB, opts ...gen.DOOption) {
|
||||
OrderQuery = &Q.Order
|
||||
OrderItemQuery = &Q.OrderItem
|
||||
PayoutAccountQuery = &Q.PayoutAccount
|
||||
RechargeCodeQuery = &Q.RechargeCode
|
||||
SystemConfigQuery = &Q.SystemConfig
|
||||
TenantQuery = &Q.Tenant
|
||||
TenantInviteQuery = &Q.TenantInvite
|
||||
@@ -88,6 +90,7 @@ func Use(db *gorm.DB, opts ...gen.DOOption) *Query {
|
||||
Order: newOrder(db, opts...),
|
||||
OrderItem: newOrderItem(db, opts...),
|
||||
PayoutAccount: newPayoutAccount(db, opts...),
|
||||
RechargeCode: newRechargeCode(db, opts...),
|
||||
SystemConfig: newSystemConfig(db, opts...),
|
||||
Tenant: newTenant(db, opts...),
|
||||
TenantInvite: newTenantInvite(db, opts...),
|
||||
@@ -118,6 +121,7 @@ type Query struct {
|
||||
Order orderQuery
|
||||
OrderItem orderItemQuery
|
||||
PayoutAccount payoutAccountQuery
|
||||
RechargeCode rechargeCodeQuery
|
||||
SystemConfig systemConfigQuery
|
||||
Tenant tenantQuery
|
||||
TenantInvite tenantInviteQuery
|
||||
@@ -149,6 +153,7 @@ func (q *Query) clone(db *gorm.DB) *Query {
|
||||
Order: q.Order.clone(db),
|
||||
OrderItem: q.OrderItem.clone(db),
|
||||
PayoutAccount: q.PayoutAccount.clone(db),
|
||||
RechargeCode: q.RechargeCode.clone(db),
|
||||
SystemConfig: q.SystemConfig.clone(db),
|
||||
Tenant: q.Tenant.clone(db),
|
||||
TenantInvite: q.TenantInvite.clone(db),
|
||||
@@ -187,6 +192,7 @@ func (q *Query) ReplaceDB(db *gorm.DB) *Query {
|
||||
Order: q.Order.replaceDB(db),
|
||||
OrderItem: q.OrderItem.replaceDB(db),
|
||||
PayoutAccount: q.PayoutAccount.replaceDB(db),
|
||||
RechargeCode: q.RechargeCode.replaceDB(db),
|
||||
SystemConfig: q.SystemConfig.replaceDB(db),
|
||||
Tenant: q.Tenant.replaceDB(db),
|
||||
TenantInvite: q.TenantInvite.replaceDB(db),
|
||||
@@ -215,6 +221,7 @@ type queryCtx struct {
|
||||
Order *orderQueryDo
|
||||
OrderItem *orderItemQueryDo
|
||||
PayoutAccount *payoutAccountQueryDo
|
||||
RechargeCode *rechargeCodeQueryDo
|
||||
SystemConfig *systemConfigQueryDo
|
||||
Tenant *tenantQueryDo
|
||||
TenantInvite *tenantInviteQueryDo
|
||||
@@ -243,6 +250,7 @@ func (q *Query) WithContext(ctx context.Context) *queryCtx {
|
||||
Order: q.Order.WithContext(ctx),
|
||||
OrderItem: q.OrderItem.WithContext(ctx),
|
||||
PayoutAccount: q.PayoutAccount.WithContext(ctx),
|
||||
RechargeCode: q.RechargeCode.WithContext(ctx),
|
||||
SystemConfig: q.SystemConfig.WithContext(ctx),
|
||||
Tenant: q.Tenant.WithContext(ctx),
|
||||
TenantInvite: q.TenantInvite.WithContext(ctx),
|
||||
|
||||
66
backend/database/models/recharge_codes.gen.go
Normal file
66
backend/database/models/recharge_codes.gen.go
Normal file
@@ -0,0 +1,66 @@
|
||||
// Code generated by go.ipao.vip/gen. DO NOT EDIT.
|
||||
// Code generated by go.ipao.vip/gen. DO NOT EDIT.
|
||||
// Code generated by go.ipao.vip/gen. DO NOT EDIT.
|
||||
|
||||
package models
|
||||
|
||||
import (
|
||||
"context"
|
||||
"time"
|
||||
|
||||
"go.ipao.vip/gen"
|
||||
)
|
||||
|
||||
const TableNameRechargeCode = "recharge_codes"
|
||||
|
||||
// RechargeCode mapped from table <recharge_codes>
|
||||
type RechargeCode struct {
|
||||
ID int64 `gorm:"column:id;type:bigint;primaryKey;autoIncrement:true" json:"id"`
|
||||
Code string `gorm:"column:code;type:character varying(64);not null" json:"code"`
|
||||
Amount int64 `gorm:"column:amount;type:bigint;not null" json:"amount"`
|
||||
Status string `gorm:"column:status;type:character varying(32);default:inactive" json:"status"`
|
||||
ActivatedBy int64 `gorm:"column:activated_by;type:bigint" json:"activated_by"`
|
||||
ActivatedAt time.Time `gorm:"column:activated_at;type:timestamp with time zone" json:"activated_at"`
|
||||
RedeemedBy int64 `gorm:"column:redeemed_by;type:bigint" json:"redeemed_by"`
|
||||
RedeemedAt time.Time `gorm:"column:redeemed_at;type:timestamp with time zone" json:"redeemed_at"`
|
||||
RedeemedOrderID int64 `gorm:"column:redeemed_order_id;type:bigint" json:"redeemed_order_id"`
|
||||
Remark string `gorm:"column:remark;type:character varying(255)" json:"remark"`
|
||||
CreatedAt time.Time `gorm:"column:created_at;type:timestamp with time zone;default:now()" json:"created_at"`
|
||||
UpdatedAt time.Time `gorm:"column:updated_at;type:timestamp with time zone;default:now()" json:"updated_at"`
|
||||
}
|
||||
|
||||
// Quick operations without importing query package
|
||||
// Update applies changed fields to the database using the default DB.
|
||||
func (m *RechargeCode) Update(ctx context.Context) (gen.ResultInfo, error) {
|
||||
return Q.RechargeCode.WithContext(ctx).Updates(m)
|
||||
}
|
||||
|
||||
// Save upserts the model using the default DB.
|
||||
func (m *RechargeCode) Save(ctx context.Context) error {
|
||||
return Q.RechargeCode.WithContext(ctx).Save(m)
|
||||
}
|
||||
|
||||
// Create inserts the model using the default DB.
|
||||
func (m *RechargeCode) Create(ctx context.Context) error {
|
||||
return Q.RechargeCode.WithContext(ctx).Create(m)
|
||||
}
|
||||
|
||||
// Delete removes the row represented by the model using the default DB.
|
||||
func (m *RechargeCode) Delete(ctx context.Context) (gen.ResultInfo, error) {
|
||||
return Q.RechargeCode.WithContext(ctx).Delete(m)
|
||||
}
|
||||
|
||||
// ForceDelete permanently deletes the row (ignores soft delete) using the default DB.
|
||||
func (m *RechargeCode) ForceDelete(ctx context.Context) (gen.ResultInfo, error) {
|
||||
return Q.RechargeCode.WithContext(ctx).Unscoped().Delete(m)
|
||||
}
|
||||
|
||||
// Reload reloads the model from database by its primary key and overwrites current fields.
|
||||
func (m *RechargeCode) Reload(ctx context.Context) error {
|
||||
fresh, err := Q.RechargeCode.WithContext(ctx).GetByID(m.ID)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
*m = *fresh
|
||||
return nil
|
||||
}
|
||||
505
backend/database/models/recharge_codes.query.gen.go
Normal file
505
backend/database/models/recharge_codes.query.gen.go
Normal file
@@ -0,0 +1,505 @@
|
||||
// Code generated by go.ipao.vip/gen. DO NOT EDIT.
|
||||
// Code generated by go.ipao.vip/gen. DO NOT EDIT.
|
||||
// Code generated by go.ipao.vip/gen. DO NOT EDIT.
|
||||
|
||||
package models
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"gorm.io/gorm"
|
||||
"gorm.io/gorm/clause"
|
||||
"gorm.io/gorm/schema"
|
||||
|
||||
"go.ipao.vip/gen"
|
||||
"go.ipao.vip/gen/field"
|
||||
|
||||
"gorm.io/plugin/dbresolver"
|
||||
)
|
||||
|
||||
func newRechargeCode(db *gorm.DB, opts ...gen.DOOption) rechargeCodeQuery {
|
||||
_rechargeCodeQuery := rechargeCodeQuery{}
|
||||
|
||||
_rechargeCodeQuery.rechargeCodeQueryDo.UseDB(db, opts...)
|
||||
_rechargeCodeQuery.rechargeCodeQueryDo.UseModel(&RechargeCode{})
|
||||
|
||||
tableName := _rechargeCodeQuery.rechargeCodeQueryDo.TableName()
|
||||
_rechargeCodeQuery.ALL = field.NewAsterisk(tableName)
|
||||
_rechargeCodeQuery.ID = field.NewInt64(tableName, "id")
|
||||
_rechargeCodeQuery.Code = field.NewString(tableName, "code")
|
||||
_rechargeCodeQuery.Amount = field.NewInt64(tableName, "amount")
|
||||
_rechargeCodeQuery.Status = field.NewString(tableName, "status")
|
||||
_rechargeCodeQuery.ActivatedBy = field.NewInt64(tableName, "activated_by")
|
||||
_rechargeCodeQuery.ActivatedAt = field.NewTime(tableName, "activated_at")
|
||||
_rechargeCodeQuery.RedeemedBy = field.NewInt64(tableName, "redeemed_by")
|
||||
_rechargeCodeQuery.RedeemedAt = field.NewTime(tableName, "redeemed_at")
|
||||
_rechargeCodeQuery.RedeemedOrderID = field.NewInt64(tableName, "redeemed_order_id")
|
||||
_rechargeCodeQuery.Remark = field.NewString(tableName, "remark")
|
||||
_rechargeCodeQuery.CreatedAt = field.NewTime(tableName, "created_at")
|
||||
_rechargeCodeQuery.UpdatedAt = field.NewTime(tableName, "updated_at")
|
||||
|
||||
_rechargeCodeQuery.fillFieldMap()
|
||||
|
||||
return _rechargeCodeQuery
|
||||
}
|
||||
|
||||
type rechargeCodeQuery struct {
|
||||
rechargeCodeQueryDo rechargeCodeQueryDo
|
||||
|
||||
ALL field.Asterisk
|
||||
ID field.Int64
|
||||
Code field.String
|
||||
Amount field.Int64
|
||||
Status field.String
|
||||
ActivatedBy field.Int64
|
||||
ActivatedAt field.Time
|
||||
RedeemedBy field.Int64
|
||||
RedeemedAt field.Time
|
||||
RedeemedOrderID field.Int64
|
||||
Remark field.String
|
||||
CreatedAt field.Time
|
||||
UpdatedAt field.Time
|
||||
|
||||
fieldMap map[string]field.Expr
|
||||
}
|
||||
|
||||
func (r rechargeCodeQuery) Table(newTableName string) *rechargeCodeQuery {
|
||||
r.rechargeCodeQueryDo.UseTable(newTableName)
|
||||
return r.updateTableName(newTableName)
|
||||
}
|
||||
|
||||
func (r rechargeCodeQuery) As(alias string) *rechargeCodeQuery {
|
||||
r.rechargeCodeQueryDo.DO = *(r.rechargeCodeQueryDo.As(alias).(*gen.DO))
|
||||
return r.updateTableName(alias)
|
||||
}
|
||||
|
||||
func (r *rechargeCodeQuery) updateTableName(table string) *rechargeCodeQuery {
|
||||
r.ALL = field.NewAsterisk(table)
|
||||
r.ID = field.NewInt64(table, "id")
|
||||
r.Code = field.NewString(table, "code")
|
||||
r.Amount = field.NewInt64(table, "amount")
|
||||
r.Status = field.NewString(table, "status")
|
||||
r.ActivatedBy = field.NewInt64(table, "activated_by")
|
||||
r.ActivatedAt = field.NewTime(table, "activated_at")
|
||||
r.RedeemedBy = field.NewInt64(table, "redeemed_by")
|
||||
r.RedeemedAt = field.NewTime(table, "redeemed_at")
|
||||
r.RedeemedOrderID = field.NewInt64(table, "redeemed_order_id")
|
||||
r.Remark = field.NewString(table, "remark")
|
||||
r.CreatedAt = field.NewTime(table, "created_at")
|
||||
r.UpdatedAt = field.NewTime(table, "updated_at")
|
||||
|
||||
r.fillFieldMap()
|
||||
|
||||
return r
|
||||
}
|
||||
|
||||
func (r *rechargeCodeQuery) QueryContext(ctx context.Context) (*rechargeCodeQuery, *rechargeCodeQueryDo) {
|
||||
return r, r.rechargeCodeQueryDo.WithContext(ctx)
|
||||
}
|
||||
|
||||
func (r *rechargeCodeQuery) WithContext(ctx context.Context) *rechargeCodeQueryDo {
|
||||
return r.rechargeCodeQueryDo.WithContext(ctx)
|
||||
}
|
||||
|
||||
func (r rechargeCodeQuery) TableName() string { return r.rechargeCodeQueryDo.TableName() }
|
||||
|
||||
func (r rechargeCodeQuery) Alias() string { return r.rechargeCodeQueryDo.Alias() }
|
||||
|
||||
func (r rechargeCodeQuery) Columns(cols ...field.Expr) gen.Columns {
|
||||
return r.rechargeCodeQueryDo.Columns(cols...)
|
||||
}
|
||||
|
||||
func (r *rechargeCodeQuery) GetFieldByName(fieldName string) (field.OrderExpr, bool) {
|
||||
_f, ok := r.fieldMap[fieldName]
|
||||
if !ok || _f == nil {
|
||||
return nil, false
|
||||
}
|
||||
_oe, ok := _f.(field.OrderExpr)
|
||||
return _oe, ok
|
||||
}
|
||||
|
||||
func (r *rechargeCodeQuery) fillFieldMap() {
|
||||
r.fieldMap = make(map[string]field.Expr, 12)
|
||||
r.fieldMap["id"] = r.ID
|
||||
r.fieldMap["code"] = r.Code
|
||||
r.fieldMap["amount"] = r.Amount
|
||||
r.fieldMap["status"] = r.Status
|
||||
r.fieldMap["activated_by"] = r.ActivatedBy
|
||||
r.fieldMap["activated_at"] = r.ActivatedAt
|
||||
r.fieldMap["redeemed_by"] = r.RedeemedBy
|
||||
r.fieldMap["redeemed_at"] = r.RedeemedAt
|
||||
r.fieldMap["redeemed_order_id"] = r.RedeemedOrderID
|
||||
r.fieldMap["remark"] = r.Remark
|
||||
r.fieldMap["created_at"] = r.CreatedAt
|
||||
r.fieldMap["updated_at"] = r.UpdatedAt
|
||||
}
|
||||
|
||||
func (r rechargeCodeQuery) clone(db *gorm.DB) rechargeCodeQuery {
|
||||
r.rechargeCodeQueryDo.ReplaceConnPool(db.Statement.ConnPool)
|
||||
return r
|
||||
}
|
||||
|
||||
func (r rechargeCodeQuery) replaceDB(db *gorm.DB) rechargeCodeQuery {
|
||||
r.rechargeCodeQueryDo.ReplaceDB(db)
|
||||
return r
|
||||
}
|
||||
|
||||
type rechargeCodeQueryDo struct{ gen.DO }
|
||||
|
||||
func (r rechargeCodeQueryDo) Debug() *rechargeCodeQueryDo {
|
||||
return r.withDO(r.DO.Debug())
|
||||
}
|
||||
|
||||
func (r rechargeCodeQueryDo) WithContext(ctx context.Context) *rechargeCodeQueryDo {
|
||||
return r.withDO(r.DO.WithContext(ctx))
|
||||
}
|
||||
|
||||
func (r rechargeCodeQueryDo) ReadDB() *rechargeCodeQueryDo {
|
||||
return r.Clauses(dbresolver.Read)
|
||||
}
|
||||
|
||||
func (r rechargeCodeQueryDo) WriteDB() *rechargeCodeQueryDo {
|
||||
return r.Clauses(dbresolver.Write)
|
||||
}
|
||||
|
||||
func (r rechargeCodeQueryDo) Session(config *gorm.Session) *rechargeCodeQueryDo {
|
||||
return r.withDO(r.DO.Session(config))
|
||||
}
|
||||
|
||||
func (r rechargeCodeQueryDo) Clauses(conds ...clause.Expression) *rechargeCodeQueryDo {
|
||||
return r.withDO(r.DO.Clauses(conds...))
|
||||
}
|
||||
|
||||
func (r rechargeCodeQueryDo) Returning(value interface{}, columns ...string) *rechargeCodeQueryDo {
|
||||
return r.withDO(r.DO.Returning(value, columns...))
|
||||
}
|
||||
|
||||
func (r rechargeCodeQueryDo) Not(conds ...gen.Condition) *rechargeCodeQueryDo {
|
||||
return r.withDO(r.DO.Not(conds...))
|
||||
}
|
||||
|
||||
func (r rechargeCodeQueryDo) Or(conds ...gen.Condition) *rechargeCodeQueryDo {
|
||||
return r.withDO(r.DO.Or(conds...))
|
||||
}
|
||||
|
||||
func (r rechargeCodeQueryDo) Select(conds ...field.Expr) *rechargeCodeQueryDo {
|
||||
return r.withDO(r.DO.Select(conds...))
|
||||
}
|
||||
|
||||
func (r rechargeCodeQueryDo) Where(conds ...gen.Condition) *rechargeCodeQueryDo {
|
||||
return r.withDO(r.DO.Where(conds...))
|
||||
}
|
||||
|
||||
func (r rechargeCodeQueryDo) Order(conds ...field.Expr) *rechargeCodeQueryDo {
|
||||
return r.withDO(r.DO.Order(conds...))
|
||||
}
|
||||
|
||||
func (r rechargeCodeQueryDo) Distinct(cols ...field.Expr) *rechargeCodeQueryDo {
|
||||
return r.withDO(r.DO.Distinct(cols...))
|
||||
}
|
||||
|
||||
func (r rechargeCodeQueryDo) Omit(cols ...field.Expr) *rechargeCodeQueryDo {
|
||||
return r.withDO(r.DO.Omit(cols...))
|
||||
}
|
||||
|
||||
func (r rechargeCodeQueryDo) Join(table schema.Tabler, on ...field.Expr) *rechargeCodeQueryDo {
|
||||
return r.withDO(r.DO.Join(table, on...))
|
||||
}
|
||||
|
||||
func (r rechargeCodeQueryDo) LeftJoin(table schema.Tabler, on ...field.Expr) *rechargeCodeQueryDo {
|
||||
return r.withDO(r.DO.LeftJoin(table, on...))
|
||||
}
|
||||
|
||||
func (r rechargeCodeQueryDo) RightJoin(table schema.Tabler, on ...field.Expr) *rechargeCodeQueryDo {
|
||||
return r.withDO(r.DO.RightJoin(table, on...))
|
||||
}
|
||||
|
||||
func (r rechargeCodeQueryDo) Group(cols ...field.Expr) *rechargeCodeQueryDo {
|
||||
return r.withDO(r.DO.Group(cols...))
|
||||
}
|
||||
|
||||
func (r rechargeCodeQueryDo) Having(conds ...gen.Condition) *rechargeCodeQueryDo {
|
||||
return r.withDO(r.DO.Having(conds...))
|
||||
}
|
||||
|
||||
func (r rechargeCodeQueryDo) Limit(limit int) *rechargeCodeQueryDo {
|
||||
return r.withDO(r.DO.Limit(limit))
|
||||
}
|
||||
|
||||
func (r rechargeCodeQueryDo) Offset(offset int) *rechargeCodeQueryDo {
|
||||
return r.withDO(r.DO.Offset(offset))
|
||||
}
|
||||
|
||||
func (r rechargeCodeQueryDo) Scopes(funcs ...func(gen.Dao) gen.Dao) *rechargeCodeQueryDo {
|
||||
return r.withDO(r.DO.Scopes(funcs...))
|
||||
}
|
||||
|
||||
func (r rechargeCodeQueryDo) Unscoped() *rechargeCodeQueryDo {
|
||||
return r.withDO(r.DO.Unscoped())
|
||||
}
|
||||
|
||||
func (r rechargeCodeQueryDo) Create(values ...*RechargeCode) error {
|
||||
if len(values) == 0 {
|
||||
return nil
|
||||
}
|
||||
return r.DO.Create(values)
|
||||
}
|
||||
|
||||
func (r rechargeCodeQueryDo) CreateInBatches(values []*RechargeCode, batchSize int) error {
|
||||
return r.DO.CreateInBatches(values, batchSize)
|
||||
}
|
||||
|
||||
// Save : !!! underlying implementation is different with GORM
|
||||
// The method is equivalent to executing the statement: db.Clauses(clause.OnConflict{UpdateAll: true}).Create(values)
|
||||
func (r rechargeCodeQueryDo) Save(values ...*RechargeCode) error {
|
||||
if len(values) == 0 {
|
||||
return nil
|
||||
}
|
||||
return r.DO.Save(values)
|
||||
}
|
||||
|
||||
func (r rechargeCodeQueryDo) First() (*RechargeCode, error) {
|
||||
if result, err := r.DO.First(); err != nil {
|
||||
return nil, err
|
||||
} else {
|
||||
return result.(*RechargeCode), nil
|
||||
}
|
||||
}
|
||||
|
||||
func (r rechargeCodeQueryDo) Take() (*RechargeCode, error) {
|
||||
if result, err := r.DO.Take(); err != nil {
|
||||
return nil, err
|
||||
} else {
|
||||
return result.(*RechargeCode), nil
|
||||
}
|
||||
}
|
||||
|
||||
func (r rechargeCodeQueryDo) Last() (*RechargeCode, error) {
|
||||
if result, err := r.DO.Last(); err != nil {
|
||||
return nil, err
|
||||
} else {
|
||||
return result.(*RechargeCode), nil
|
||||
}
|
||||
}
|
||||
|
||||
func (r rechargeCodeQueryDo) Find() ([]*RechargeCode, error) {
|
||||
result, err := r.DO.Find()
|
||||
return result.([]*RechargeCode), err
|
||||
}
|
||||
|
||||
func (r rechargeCodeQueryDo) FindInBatch(batchSize int, fc func(tx gen.Dao, batch int) error) (results []*RechargeCode, err error) {
|
||||
buf := make([]*RechargeCode, 0, batchSize)
|
||||
err = r.DO.FindInBatches(&buf, batchSize, func(tx gen.Dao, batch int) error {
|
||||
defer func() { results = append(results, buf...) }()
|
||||
return fc(tx, batch)
|
||||
})
|
||||
return results, err
|
||||
}
|
||||
|
||||
func (r rechargeCodeQueryDo) FindInBatches(result *[]*RechargeCode, batchSize int, fc func(tx gen.Dao, batch int) error) error {
|
||||
return r.DO.FindInBatches(result, batchSize, fc)
|
||||
}
|
||||
|
||||
func (r rechargeCodeQueryDo) Attrs(attrs ...field.AssignExpr) *rechargeCodeQueryDo {
|
||||
return r.withDO(r.DO.Attrs(attrs...))
|
||||
}
|
||||
|
||||
func (r rechargeCodeQueryDo) Assign(attrs ...field.AssignExpr) *rechargeCodeQueryDo {
|
||||
return r.withDO(r.DO.Assign(attrs...))
|
||||
}
|
||||
|
||||
func (r rechargeCodeQueryDo) Joins(fields ...field.RelationField) *rechargeCodeQueryDo {
|
||||
for _, _f := range fields {
|
||||
r = *r.withDO(r.DO.Joins(_f))
|
||||
}
|
||||
return &r
|
||||
}
|
||||
|
||||
func (r rechargeCodeQueryDo) Preload(fields ...field.RelationField) *rechargeCodeQueryDo {
|
||||
for _, _f := range fields {
|
||||
r = *r.withDO(r.DO.Preload(_f))
|
||||
}
|
||||
return &r
|
||||
}
|
||||
|
||||
func (r rechargeCodeQueryDo) FirstOrInit() (*RechargeCode, error) {
|
||||
if result, err := r.DO.FirstOrInit(); err != nil {
|
||||
return nil, err
|
||||
} else {
|
||||
return result.(*RechargeCode), nil
|
||||
}
|
||||
}
|
||||
|
||||
func (r rechargeCodeQueryDo) FirstOrCreate() (*RechargeCode, error) {
|
||||
if result, err := r.DO.FirstOrCreate(); err != nil {
|
||||
return nil, err
|
||||
} else {
|
||||
return result.(*RechargeCode), nil
|
||||
}
|
||||
}
|
||||
|
||||
func (r rechargeCodeQueryDo) FindByPage(offset int, limit int) (result []*RechargeCode, count int64, err error) {
|
||||
result, err = r.Offset(offset).Limit(limit).Find()
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
if size := len(result); 0 < limit && 0 < size && size < limit {
|
||||
count = int64(size + offset)
|
||||
return
|
||||
}
|
||||
|
||||
count, err = r.Offset(-1).Limit(-1).Count()
|
||||
return
|
||||
}
|
||||
|
||||
func (r rechargeCodeQueryDo) ScanByPage(result interface{}, offset int, limit int) (count int64, err error) {
|
||||
count, err = r.Count()
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
err = r.Offset(offset).Limit(limit).Scan(result)
|
||||
return
|
||||
}
|
||||
|
||||
func (r rechargeCodeQueryDo) Scan(result interface{}) (err error) {
|
||||
return r.DO.Scan(result)
|
||||
}
|
||||
|
||||
func (r rechargeCodeQueryDo) Delete(models ...*RechargeCode) (result gen.ResultInfo, err error) {
|
||||
return r.DO.Delete(models)
|
||||
}
|
||||
|
||||
// ForceDelete performs a permanent delete (ignores soft-delete) for current scope.
|
||||
func (r rechargeCodeQueryDo) ForceDelete() (gen.ResultInfo, error) {
|
||||
return r.Unscoped().Delete()
|
||||
}
|
||||
|
||||
// Inc increases the given column by step for current scope.
|
||||
func (r rechargeCodeQueryDo) Inc(column field.Expr, step int64) (gen.ResultInfo, error) {
|
||||
// column = column + step
|
||||
e := field.NewUnsafeFieldRaw("?+?", column.RawExpr(), step)
|
||||
return r.DO.UpdateColumn(column, e)
|
||||
}
|
||||
|
||||
// Dec decreases the given column by step for current scope.
|
||||
func (r rechargeCodeQueryDo) Dec(column field.Expr, step int64) (gen.ResultInfo, error) {
|
||||
// column = column - step
|
||||
e := field.NewUnsafeFieldRaw("?-?", column.RawExpr(), step)
|
||||
return r.DO.UpdateColumn(column, e)
|
||||
}
|
||||
|
||||
// Sum returns SUM(column) for current scope.
|
||||
func (r rechargeCodeQueryDo) Sum(column field.Expr) (float64, error) {
|
||||
var _v float64
|
||||
agg := field.NewUnsafeFieldRaw("SUM(?)", column.RawExpr())
|
||||
if err := r.Select(agg).Scan(&_v); err != nil {
|
||||
return 0, err
|
||||
}
|
||||
return _v, nil
|
||||
}
|
||||
|
||||
// Avg returns AVG(column) for current scope.
|
||||
func (r rechargeCodeQueryDo) Avg(column field.Expr) (float64, error) {
|
||||
var _v float64
|
||||
agg := field.NewUnsafeFieldRaw("AVG(?)", column.RawExpr())
|
||||
if err := r.Select(agg).Scan(&_v); err != nil {
|
||||
return 0, err
|
||||
}
|
||||
return _v, nil
|
||||
}
|
||||
|
||||
// Min returns MIN(column) for current scope.
|
||||
func (r rechargeCodeQueryDo) Min(column field.Expr) (float64, error) {
|
||||
var _v float64
|
||||
agg := field.NewUnsafeFieldRaw("MIN(?)", column.RawExpr())
|
||||
if err := r.Select(agg).Scan(&_v); err != nil {
|
||||
return 0, err
|
||||
}
|
||||
return _v, nil
|
||||
}
|
||||
|
||||
// Max returns MAX(column) for current scope.
|
||||
func (r rechargeCodeQueryDo) Max(column field.Expr) (float64, error) {
|
||||
var _v float64
|
||||
agg := field.NewUnsafeFieldRaw("MAX(?)", column.RawExpr())
|
||||
if err := r.Select(agg).Scan(&_v); err != nil {
|
||||
return 0, err
|
||||
}
|
||||
return _v, nil
|
||||
}
|
||||
|
||||
// PluckMap returns a map[key]value for selected key/value expressions within current scope.
|
||||
func (r rechargeCodeQueryDo) PluckMap(key, val field.Expr) (map[interface{}]interface{}, error) {
|
||||
do := r.Select(key, val)
|
||||
rows, err := do.DO.Rows()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer rows.Close()
|
||||
mm := make(map[interface{}]interface{})
|
||||
for rows.Next() {
|
||||
var k interface{}
|
||||
var v interface{}
|
||||
if err := rows.Scan(&k, &v); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
mm[k] = v
|
||||
}
|
||||
return mm, rows.Err()
|
||||
}
|
||||
|
||||
// Exists returns true if any record matches the given conditions.
|
||||
func (r rechargeCodeQueryDo) Exists(conds ...gen.Condition) (bool, error) {
|
||||
cnt, err := r.Where(conds...).Count()
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
return cnt > 0, nil
|
||||
}
|
||||
|
||||
// PluckIDs returns all primary key values under current scope.
|
||||
func (r rechargeCodeQueryDo) PluckIDs() ([]int64, error) {
|
||||
ids := make([]int64, 0, 16)
|
||||
pk := field.NewInt64(r.TableName(), "id")
|
||||
if err := r.DO.Pluck(pk, &ids); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return ids, nil
|
||||
}
|
||||
|
||||
// GetByID finds a single record by primary key.
|
||||
func (r rechargeCodeQueryDo) GetByID(id int64) (*RechargeCode, error) {
|
||||
pk := field.NewInt64(r.TableName(), "id")
|
||||
return r.Where(pk.Eq(id)).First()
|
||||
}
|
||||
|
||||
// GetByIDs finds records by primary key list.
|
||||
func (r rechargeCodeQueryDo) GetByIDs(ids ...int64) ([]*RechargeCode, error) {
|
||||
if len(ids) == 0 {
|
||||
return []*RechargeCode{}, nil
|
||||
}
|
||||
pk := field.NewInt64(r.TableName(), "id")
|
||||
return r.Where(pk.In(ids...)).Find()
|
||||
}
|
||||
|
||||
// DeleteByID deletes records by primary key.
|
||||
func (r rechargeCodeQueryDo) DeleteByID(id int64) (gen.ResultInfo, error) {
|
||||
pk := field.NewInt64(r.TableName(), "id")
|
||||
return r.Where(pk.Eq(id)).Delete()
|
||||
}
|
||||
|
||||
// DeleteByIDs deletes records by a list of primary keys.
|
||||
func (r rechargeCodeQueryDo) DeleteByIDs(ids ...int64) (gen.ResultInfo, error) {
|
||||
if len(ids) == 0 {
|
||||
return gen.ResultInfo{RowsAffected: 0, Error: nil}, nil
|
||||
}
|
||||
pk := field.NewInt64(r.TableName(), "id")
|
||||
return r.Where(pk.In(ids...)).Delete()
|
||||
}
|
||||
|
||||
func (r *rechargeCodeQueryDo) withDO(do gen.Dao) *rechargeCodeQueryDo {
|
||||
r.DO = *do.(*gen.DO)
|
||||
return r
|
||||
}
|
||||
Reference in New Issue
Block a user