// Code generated by gorm.io/gen. DO NOT EDIT. // Code generated by gorm.io/gen. DO NOT EDIT. // Code generated by gorm.io/gen. DO NOT EDIT. package queries import ( "context" "gorm.io/gorm" "gorm.io/gorm/clause" "gorm.io/gorm/schema" "gorm.io/gen" "gorm.io/gen/field" "gorm.io/plugin/dbresolver" "platform/web/models" ) func newBill(db *gorm.DB, opts ...gen.DOOption) bill { _bill := bill{} _bill.billDo.UseDB(db, opts...) _bill.billDo.UseModel(&models.Bill{}) tableName := _bill.billDo.TableName() _bill.ALL = field.NewAsterisk(tableName) _bill.ID = field.NewInt32(tableName, "id") _bill.UserID = field.NewInt32(tableName, "user_id") _bill.TradeID = field.NewInt32(tableName, "trade_id") _bill.ResourceID = field.NewInt32(tableName, "resource_id") _bill.RefundID = field.NewInt32(tableName, "refund_id") _bill.BillNo = field.NewString(tableName, "bill_no") _bill.Info = field.NewString(tableName, "info") _bill.Type = field.NewInt32(tableName, "type") _bill.Amount = field.NewField(tableName, "amount") _bill.CreatedAt = field.NewField(tableName, "created_at") _bill.UpdatedAt = field.NewField(tableName, "updated_at") _bill.DeletedAt = field.NewField(tableName, "deleted_at") _bill.Trade = billBelongsToTrade{ db: db.Session(&gorm.Session{}), RelationField: field.NewRelation("Trade", "models.Trade"), } _bill.Refund = billBelongsToRefund{ db: db.Session(&gorm.Session{}), RelationField: field.NewRelation("Refund", "models.Refund"), } _bill.Resource = billBelongsToResource{ db: db.Session(&gorm.Session{}), RelationField: field.NewRelation("Resource", "models.Resource"), Short: struct { field.RelationField }{ RelationField: field.NewRelation("Resource.Short", "models.ResourceShort"), }, Long: struct { field.RelationField }{ RelationField: field.NewRelation("Resource.Long", "models.ResourceLong"), }, } _bill.fillFieldMap() return _bill } type bill struct { billDo ALL field.Asterisk ID field.Int32 // 账单ID UserID field.Int32 // 用户ID TradeID field.Int32 // 订单ID ResourceID field.Int32 // 套餐ID RefundID field.Int32 // 退款ID BillNo field.String // 易读账单号 Info field.String // 产品可读信息 Type field.Int32 // 账单类型:1-消费,2-退款,3-充值 Amount field.Field // 账单金额 CreatedAt field.Field // 创建时间 UpdatedAt field.Field // 更新时间 DeletedAt field.Field // 删除时间 Trade billBelongsToTrade Refund billBelongsToRefund Resource billBelongsToResource fieldMap map[string]field.Expr } func (b bill) Table(newTableName string) *bill { b.billDo.UseTable(newTableName) return b.updateTableName(newTableName) } func (b bill) As(alias string) *bill { b.billDo.DO = *(b.billDo.As(alias).(*gen.DO)) return b.updateTableName(alias) } func (b *bill) updateTableName(table string) *bill { b.ALL = field.NewAsterisk(table) b.ID = field.NewInt32(table, "id") b.UserID = field.NewInt32(table, "user_id") b.TradeID = field.NewInt32(table, "trade_id") b.ResourceID = field.NewInt32(table, "resource_id") b.RefundID = field.NewInt32(table, "refund_id") b.BillNo = field.NewString(table, "bill_no") b.Info = field.NewString(table, "info") b.Type = field.NewInt32(table, "type") b.Amount = field.NewField(table, "amount") b.CreatedAt = field.NewField(table, "created_at") b.UpdatedAt = field.NewField(table, "updated_at") b.DeletedAt = field.NewField(table, "deleted_at") b.fillFieldMap() return b } func (b *bill) GetFieldByName(fieldName string) (field.OrderExpr, bool) { _f, ok := b.fieldMap[fieldName] if !ok || _f == nil { return nil, false } _oe, ok := _f.(field.OrderExpr) return _oe, ok } func (b *bill) fillFieldMap() { b.fieldMap = make(map[string]field.Expr, 15) b.fieldMap["id"] = b.ID b.fieldMap["user_id"] = b.UserID b.fieldMap["trade_id"] = b.TradeID b.fieldMap["resource_id"] = b.ResourceID b.fieldMap["refund_id"] = b.RefundID b.fieldMap["bill_no"] = b.BillNo b.fieldMap["info"] = b.Info b.fieldMap["type"] = b.Type b.fieldMap["amount"] = b.Amount b.fieldMap["created_at"] = b.CreatedAt b.fieldMap["updated_at"] = b.UpdatedAt b.fieldMap["deleted_at"] = b.DeletedAt } func (b bill) clone(db *gorm.DB) bill { b.billDo.ReplaceConnPool(db.Statement.ConnPool) b.Trade.db = db.Session(&gorm.Session{Initialized: true}) b.Trade.db.Statement.ConnPool = db.Statement.ConnPool b.Refund.db = db.Session(&gorm.Session{Initialized: true}) b.Refund.db.Statement.ConnPool = db.Statement.ConnPool b.Resource.db = db.Session(&gorm.Session{Initialized: true}) b.Resource.db.Statement.ConnPool = db.Statement.ConnPool return b } func (b bill) replaceDB(db *gorm.DB) bill { b.billDo.ReplaceDB(db) b.Trade.db = db.Session(&gorm.Session{}) b.Refund.db = db.Session(&gorm.Session{}) b.Resource.db = db.Session(&gorm.Session{}) return b } type billBelongsToTrade struct { db *gorm.DB field.RelationField } func (a billBelongsToTrade) Where(conds ...field.Expr) *billBelongsToTrade { if len(conds) == 0 { return &a } exprs := make([]clause.Expression, 0, len(conds)) for _, cond := range conds { exprs = append(exprs, cond.BeCond().(clause.Expression)) } a.db = a.db.Clauses(clause.Where{Exprs: exprs}) return &a } func (a billBelongsToTrade) WithContext(ctx context.Context) *billBelongsToTrade { a.db = a.db.WithContext(ctx) return &a } func (a billBelongsToTrade) Session(session *gorm.Session) *billBelongsToTrade { a.db = a.db.Session(session) return &a } func (a billBelongsToTrade) Model(m *models.Bill) *billBelongsToTradeTx { return &billBelongsToTradeTx{a.db.Model(m).Association(a.Name())} } func (a billBelongsToTrade) Unscoped() *billBelongsToTrade { a.db = a.db.Unscoped() return &a } type billBelongsToTradeTx struct{ tx *gorm.Association } func (a billBelongsToTradeTx) Find() (result *models.Trade, err error) { return result, a.tx.Find(&result) } func (a billBelongsToTradeTx) Append(values ...*models.Trade) (err error) { targetValues := make([]interface{}, len(values)) for i, v := range values { targetValues[i] = v } return a.tx.Append(targetValues...) } func (a billBelongsToTradeTx) Replace(values ...*models.Trade) (err error) { targetValues := make([]interface{}, len(values)) for i, v := range values { targetValues[i] = v } return a.tx.Replace(targetValues...) } func (a billBelongsToTradeTx) Delete(values ...*models.Trade) (err error) { targetValues := make([]interface{}, len(values)) for i, v := range values { targetValues[i] = v } return a.tx.Delete(targetValues...) } func (a billBelongsToTradeTx) Clear() error { return a.tx.Clear() } func (a billBelongsToTradeTx) Count() int64 { return a.tx.Count() } func (a billBelongsToTradeTx) Unscoped() *billBelongsToTradeTx { a.tx = a.tx.Unscoped() return &a } type billBelongsToRefund struct { db *gorm.DB field.RelationField } func (a billBelongsToRefund) Where(conds ...field.Expr) *billBelongsToRefund { if len(conds) == 0 { return &a } exprs := make([]clause.Expression, 0, len(conds)) for _, cond := range conds { exprs = append(exprs, cond.BeCond().(clause.Expression)) } a.db = a.db.Clauses(clause.Where{Exprs: exprs}) return &a } func (a billBelongsToRefund) WithContext(ctx context.Context) *billBelongsToRefund { a.db = a.db.WithContext(ctx) return &a } func (a billBelongsToRefund) Session(session *gorm.Session) *billBelongsToRefund { a.db = a.db.Session(session) return &a } func (a billBelongsToRefund) Model(m *models.Bill) *billBelongsToRefundTx { return &billBelongsToRefundTx{a.db.Model(m).Association(a.Name())} } func (a billBelongsToRefund) Unscoped() *billBelongsToRefund { a.db = a.db.Unscoped() return &a } type billBelongsToRefundTx struct{ tx *gorm.Association } func (a billBelongsToRefundTx) Find() (result *models.Refund, err error) { return result, a.tx.Find(&result) } func (a billBelongsToRefundTx) Append(values ...*models.Refund) (err error) { targetValues := make([]interface{}, len(values)) for i, v := range values { targetValues[i] = v } return a.tx.Append(targetValues...) } func (a billBelongsToRefundTx) Replace(values ...*models.Refund) (err error) { targetValues := make([]interface{}, len(values)) for i, v := range values { targetValues[i] = v } return a.tx.Replace(targetValues...) } func (a billBelongsToRefundTx) Delete(values ...*models.Refund) (err error) { targetValues := make([]interface{}, len(values)) for i, v := range values { targetValues[i] = v } return a.tx.Delete(targetValues...) } func (a billBelongsToRefundTx) Clear() error { return a.tx.Clear() } func (a billBelongsToRefundTx) Count() int64 { return a.tx.Count() } func (a billBelongsToRefundTx) Unscoped() *billBelongsToRefundTx { a.tx = a.tx.Unscoped() return &a } type billBelongsToResource struct { db *gorm.DB field.RelationField Short struct { field.RelationField } Long struct { field.RelationField } } func (a billBelongsToResource) Where(conds ...field.Expr) *billBelongsToResource { if len(conds) == 0 { return &a } exprs := make([]clause.Expression, 0, len(conds)) for _, cond := range conds { exprs = append(exprs, cond.BeCond().(clause.Expression)) } a.db = a.db.Clauses(clause.Where{Exprs: exprs}) return &a } func (a billBelongsToResource) WithContext(ctx context.Context) *billBelongsToResource { a.db = a.db.WithContext(ctx) return &a } func (a billBelongsToResource) Session(session *gorm.Session) *billBelongsToResource { a.db = a.db.Session(session) return &a } func (a billBelongsToResource) Model(m *models.Bill) *billBelongsToResourceTx { return &billBelongsToResourceTx{a.db.Model(m).Association(a.Name())} } func (a billBelongsToResource) Unscoped() *billBelongsToResource { a.db = a.db.Unscoped() return &a } type billBelongsToResourceTx struct{ tx *gorm.Association } func (a billBelongsToResourceTx) Find() (result *models.Resource, err error) { return result, a.tx.Find(&result) } func (a billBelongsToResourceTx) Append(values ...*models.Resource) (err error) { targetValues := make([]interface{}, len(values)) for i, v := range values { targetValues[i] = v } return a.tx.Append(targetValues...) } func (a billBelongsToResourceTx) Replace(values ...*models.Resource) (err error) { targetValues := make([]interface{}, len(values)) for i, v := range values { targetValues[i] = v } return a.tx.Replace(targetValues...) } func (a billBelongsToResourceTx) Delete(values ...*models.Resource) (err error) { targetValues := make([]interface{}, len(values)) for i, v := range values { targetValues[i] = v } return a.tx.Delete(targetValues...) } func (a billBelongsToResourceTx) Clear() error { return a.tx.Clear() } func (a billBelongsToResourceTx) Count() int64 { return a.tx.Count() } func (a billBelongsToResourceTx) Unscoped() *billBelongsToResourceTx { a.tx = a.tx.Unscoped() return &a } type billDo struct{ gen.DO } func (b billDo) Debug() *billDo { return b.withDO(b.DO.Debug()) } func (b billDo) WithContext(ctx context.Context) *billDo { return b.withDO(b.DO.WithContext(ctx)) } func (b billDo) ReadDB() *billDo { return b.Clauses(dbresolver.Read) } func (b billDo) WriteDB() *billDo { return b.Clauses(dbresolver.Write) } func (b billDo) Session(config *gorm.Session) *billDo { return b.withDO(b.DO.Session(config)) } func (b billDo) Clauses(conds ...clause.Expression) *billDo { return b.withDO(b.DO.Clauses(conds...)) } func (b billDo) Returning(value interface{}, columns ...string) *billDo { return b.withDO(b.DO.Returning(value, columns...)) } func (b billDo) Not(conds ...gen.Condition) *billDo { return b.withDO(b.DO.Not(conds...)) } func (b billDo) Or(conds ...gen.Condition) *billDo { return b.withDO(b.DO.Or(conds...)) } func (b billDo) Select(conds ...field.Expr) *billDo { return b.withDO(b.DO.Select(conds...)) } func (b billDo) Where(conds ...gen.Condition) *billDo { return b.withDO(b.DO.Where(conds...)) } func (b billDo) Order(conds ...field.Expr) *billDo { return b.withDO(b.DO.Order(conds...)) } func (b billDo) Distinct(cols ...field.Expr) *billDo { return b.withDO(b.DO.Distinct(cols...)) } func (b billDo) Omit(cols ...field.Expr) *billDo { return b.withDO(b.DO.Omit(cols...)) } func (b billDo) Join(table schema.Tabler, on ...field.Expr) *billDo { return b.withDO(b.DO.Join(table, on...)) } func (b billDo) LeftJoin(table schema.Tabler, on ...field.Expr) *billDo { return b.withDO(b.DO.LeftJoin(table, on...)) } func (b billDo) RightJoin(table schema.Tabler, on ...field.Expr) *billDo { return b.withDO(b.DO.RightJoin(table, on...)) } func (b billDo) Group(cols ...field.Expr) *billDo { return b.withDO(b.DO.Group(cols...)) } func (b billDo) Having(conds ...gen.Condition) *billDo { return b.withDO(b.DO.Having(conds...)) } func (b billDo) Limit(limit int) *billDo { return b.withDO(b.DO.Limit(limit)) } func (b billDo) Offset(offset int) *billDo { return b.withDO(b.DO.Offset(offset)) } func (b billDo) Scopes(funcs ...func(gen.Dao) gen.Dao) *billDo { return b.withDO(b.DO.Scopes(funcs...)) } func (b billDo) Unscoped() *billDo { return b.withDO(b.DO.Unscoped()) } func (b billDo) Create(values ...*models.Bill) error { if len(values) == 0 { return nil } return b.DO.Create(values) } func (b billDo) CreateInBatches(values []*models.Bill, batchSize int) error { return b.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 (b billDo) Save(values ...*models.Bill) error { if len(values) == 0 { return nil } return b.DO.Save(values) } func (b billDo) First() (*models.Bill, error) { if result, err := b.DO.First(); err != nil { return nil, err } else { return result.(*models.Bill), nil } } func (b billDo) Take() (*models.Bill, error) { if result, err := b.DO.Take(); err != nil { return nil, err } else { return result.(*models.Bill), nil } } func (b billDo) Last() (*models.Bill, error) { if result, err := b.DO.Last(); err != nil { return nil, err } else { return result.(*models.Bill), nil } } func (b billDo) Find() ([]*models.Bill, error) { result, err := b.DO.Find() return result.([]*models.Bill), err } func (b billDo) FindInBatch(batchSize int, fc func(tx gen.Dao, batch int) error) (results []*models.Bill, err error) { buf := make([]*models.Bill, 0, batchSize) err = b.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 (b billDo) FindInBatches(result *[]*models.Bill, batchSize int, fc func(tx gen.Dao, batch int) error) error { return b.DO.FindInBatches(result, batchSize, fc) } func (b billDo) Attrs(attrs ...field.AssignExpr) *billDo { return b.withDO(b.DO.Attrs(attrs...)) } func (b billDo) Assign(attrs ...field.AssignExpr) *billDo { return b.withDO(b.DO.Assign(attrs...)) } func (b billDo) Joins(fields ...field.RelationField) *billDo { for _, _f := range fields { b = *b.withDO(b.DO.Joins(_f)) } return &b } func (b billDo) Preload(fields ...field.RelationField) *billDo { for _, _f := range fields { b = *b.withDO(b.DO.Preload(_f)) } return &b } func (b billDo) FirstOrInit() (*models.Bill, error) { if result, err := b.DO.FirstOrInit(); err != nil { return nil, err } else { return result.(*models.Bill), nil } } func (b billDo) FirstOrCreate() (*models.Bill, error) { if result, err := b.DO.FirstOrCreate(); err != nil { return nil, err } else { return result.(*models.Bill), nil } } func (b billDo) FindByPage(offset int, limit int) (result []*models.Bill, count int64, err error) { result, err = b.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 = b.Offset(-1).Limit(-1).Count() return } func (b billDo) ScanByPage(result interface{}, offset int, limit int) (count int64, err error) { count, err = b.Count() if err != nil { return } err = b.Offset(offset).Limit(limit).Scan(result) return } func (b billDo) Scan(result interface{}) (err error) { return b.DO.Scan(result) } func (b billDo) Delete(models ...*models.Bill) (result gen.ResultInfo, err error) { return b.DO.Delete(models) } func (b *billDo) withDO(do gen.Dao) *billDo { b.DO = *do.(*gen.DO) return b }