360 lines
9.2 KiB
Go
360 lines
9.2 KiB
Go
// 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 newCoupon(db *gorm.DB, opts ...gen.DOOption) coupon {
|
||
_coupon := coupon{}
|
||
|
||
_coupon.couponDo.UseDB(db, opts...)
|
||
_coupon.couponDo.UseModel(&models.Coupon{})
|
||
|
||
tableName := _coupon.couponDo.TableName()
|
||
_coupon.ALL = field.NewAsterisk(tableName)
|
||
_coupon.ID = field.NewInt32(tableName, "id")
|
||
_coupon.UserID = field.NewInt32(tableName, "user_id")
|
||
_coupon.Code = field.NewString(tableName, "code")
|
||
_coupon.Remark = field.NewString(tableName, "remark")
|
||
_coupon.Amount = field.NewFloat64(tableName, "amount")
|
||
_coupon.MinAmount = field.NewFloat64(tableName, "min_amount")
|
||
_coupon.Status = field.NewInt32(tableName, "status")
|
||
_coupon.ExpireAt = field.NewField(tableName, "expire_at")
|
||
_coupon.CreatedAt = field.NewField(tableName, "created_at")
|
||
_coupon.UpdatedAt = field.NewField(tableName, "updated_at")
|
||
_coupon.DeletedAt = field.NewField(tableName, "deleted_at")
|
||
|
||
_coupon.fillFieldMap()
|
||
|
||
return _coupon
|
||
}
|
||
|
||
type coupon struct {
|
||
couponDo
|
||
|
||
ALL field.Asterisk
|
||
ID field.Int32 // 优惠券ID
|
||
UserID field.Int32 // 用户ID
|
||
Code field.String // 优惠券代码
|
||
Remark field.String // 优惠券备注
|
||
Amount field.Float64 // 优惠券金额
|
||
MinAmount field.Float64 // 最低消费金额
|
||
Status field.Int32 // 优惠券状态:0-未使用,1-已使用,2-已过期
|
||
ExpireAt field.Field // 过期时间
|
||
CreatedAt field.Field // 创建时间
|
||
UpdatedAt field.Field // 更新时间
|
||
DeletedAt field.Field // 删除时间
|
||
|
||
fieldMap map[string]field.Expr
|
||
}
|
||
|
||
func (c coupon) Table(newTableName string) *coupon {
|
||
c.couponDo.UseTable(newTableName)
|
||
return c.updateTableName(newTableName)
|
||
}
|
||
|
||
func (c coupon) As(alias string) *coupon {
|
||
c.couponDo.DO = *(c.couponDo.As(alias).(*gen.DO))
|
||
return c.updateTableName(alias)
|
||
}
|
||
|
||
func (c *coupon) updateTableName(table string) *coupon {
|
||
c.ALL = field.NewAsterisk(table)
|
||
c.ID = field.NewInt32(table, "id")
|
||
c.UserID = field.NewInt32(table, "user_id")
|
||
c.Code = field.NewString(table, "code")
|
||
c.Remark = field.NewString(table, "remark")
|
||
c.Amount = field.NewFloat64(table, "amount")
|
||
c.MinAmount = field.NewFloat64(table, "min_amount")
|
||
c.Status = field.NewInt32(table, "status")
|
||
c.ExpireAt = field.NewField(table, "expire_at")
|
||
c.CreatedAt = field.NewField(table, "created_at")
|
||
c.UpdatedAt = field.NewField(table, "updated_at")
|
||
c.DeletedAt = field.NewField(table, "deleted_at")
|
||
|
||
c.fillFieldMap()
|
||
|
||
return c
|
||
}
|
||
|
||
func (c *coupon) GetFieldByName(fieldName string) (field.OrderExpr, bool) {
|
||
_f, ok := c.fieldMap[fieldName]
|
||
if !ok || _f == nil {
|
||
return nil, false
|
||
}
|
||
_oe, ok := _f.(field.OrderExpr)
|
||
return _oe, ok
|
||
}
|
||
|
||
func (c *coupon) fillFieldMap() {
|
||
c.fieldMap = make(map[string]field.Expr, 11)
|
||
c.fieldMap["id"] = c.ID
|
||
c.fieldMap["user_id"] = c.UserID
|
||
c.fieldMap["code"] = c.Code
|
||
c.fieldMap["remark"] = c.Remark
|
||
c.fieldMap["amount"] = c.Amount
|
||
c.fieldMap["min_amount"] = c.MinAmount
|
||
c.fieldMap["status"] = c.Status
|
||
c.fieldMap["expire_at"] = c.ExpireAt
|
||
c.fieldMap["created_at"] = c.CreatedAt
|
||
c.fieldMap["updated_at"] = c.UpdatedAt
|
||
c.fieldMap["deleted_at"] = c.DeletedAt
|
||
}
|
||
|
||
func (c coupon) clone(db *gorm.DB) coupon {
|
||
c.couponDo.ReplaceConnPool(db.Statement.ConnPool)
|
||
return c
|
||
}
|
||
|
||
func (c coupon) replaceDB(db *gorm.DB) coupon {
|
||
c.couponDo.ReplaceDB(db)
|
||
return c
|
||
}
|
||
|
||
type couponDo struct{ gen.DO }
|
||
|
||
func (c couponDo) Debug() *couponDo {
|
||
return c.withDO(c.DO.Debug())
|
||
}
|
||
|
||
func (c couponDo) WithContext(ctx context.Context) *couponDo {
|
||
return c.withDO(c.DO.WithContext(ctx))
|
||
}
|
||
|
||
func (c couponDo) ReadDB() *couponDo {
|
||
return c.Clauses(dbresolver.Read)
|
||
}
|
||
|
||
func (c couponDo) WriteDB() *couponDo {
|
||
return c.Clauses(dbresolver.Write)
|
||
}
|
||
|
||
func (c couponDo) Session(config *gorm.Session) *couponDo {
|
||
return c.withDO(c.DO.Session(config))
|
||
}
|
||
|
||
func (c couponDo) Clauses(conds ...clause.Expression) *couponDo {
|
||
return c.withDO(c.DO.Clauses(conds...))
|
||
}
|
||
|
||
func (c couponDo) Returning(value interface{}, columns ...string) *couponDo {
|
||
return c.withDO(c.DO.Returning(value, columns...))
|
||
}
|
||
|
||
func (c couponDo) Not(conds ...gen.Condition) *couponDo {
|
||
return c.withDO(c.DO.Not(conds...))
|
||
}
|
||
|
||
func (c couponDo) Or(conds ...gen.Condition) *couponDo {
|
||
return c.withDO(c.DO.Or(conds...))
|
||
}
|
||
|
||
func (c couponDo) Select(conds ...field.Expr) *couponDo {
|
||
return c.withDO(c.DO.Select(conds...))
|
||
}
|
||
|
||
func (c couponDo) Where(conds ...gen.Condition) *couponDo {
|
||
return c.withDO(c.DO.Where(conds...))
|
||
}
|
||
|
||
func (c couponDo) Order(conds ...field.Expr) *couponDo {
|
||
return c.withDO(c.DO.Order(conds...))
|
||
}
|
||
|
||
func (c couponDo) Distinct(cols ...field.Expr) *couponDo {
|
||
return c.withDO(c.DO.Distinct(cols...))
|
||
}
|
||
|
||
func (c couponDo) Omit(cols ...field.Expr) *couponDo {
|
||
return c.withDO(c.DO.Omit(cols...))
|
||
}
|
||
|
||
func (c couponDo) Join(table schema.Tabler, on ...field.Expr) *couponDo {
|
||
return c.withDO(c.DO.Join(table, on...))
|
||
}
|
||
|
||
func (c couponDo) LeftJoin(table schema.Tabler, on ...field.Expr) *couponDo {
|
||
return c.withDO(c.DO.LeftJoin(table, on...))
|
||
}
|
||
|
||
func (c couponDo) RightJoin(table schema.Tabler, on ...field.Expr) *couponDo {
|
||
return c.withDO(c.DO.RightJoin(table, on...))
|
||
}
|
||
|
||
func (c couponDo) Group(cols ...field.Expr) *couponDo {
|
||
return c.withDO(c.DO.Group(cols...))
|
||
}
|
||
|
||
func (c couponDo) Having(conds ...gen.Condition) *couponDo {
|
||
return c.withDO(c.DO.Having(conds...))
|
||
}
|
||
|
||
func (c couponDo) Limit(limit int) *couponDo {
|
||
return c.withDO(c.DO.Limit(limit))
|
||
}
|
||
|
||
func (c couponDo) Offset(offset int) *couponDo {
|
||
return c.withDO(c.DO.Offset(offset))
|
||
}
|
||
|
||
func (c couponDo) Scopes(funcs ...func(gen.Dao) gen.Dao) *couponDo {
|
||
return c.withDO(c.DO.Scopes(funcs...))
|
||
}
|
||
|
||
func (c couponDo) Unscoped() *couponDo {
|
||
return c.withDO(c.DO.Unscoped())
|
||
}
|
||
|
||
func (c couponDo) Create(values ...*models.Coupon) error {
|
||
if len(values) == 0 {
|
||
return nil
|
||
}
|
||
return c.DO.Create(values)
|
||
}
|
||
|
||
func (c couponDo) CreateInBatches(values []*models.Coupon, batchSize int) error {
|
||
return c.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 (c couponDo) Save(values ...*models.Coupon) error {
|
||
if len(values) == 0 {
|
||
return nil
|
||
}
|
||
return c.DO.Save(values)
|
||
}
|
||
|
||
func (c couponDo) First() (*models.Coupon, error) {
|
||
if result, err := c.DO.First(); err != nil {
|
||
return nil, err
|
||
} else {
|
||
return result.(*models.Coupon), nil
|
||
}
|
||
}
|
||
|
||
func (c couponDo) Take() (*models.Coupon, error) {
|
||
if result, err := c.DO.Take(); err != nil {
|
||
return nil, err
|
||
} else {
|
||
return result.(*models.Coupon), nil
|
||
}
|
||
}
|
||
|
||
func (c couponDo) Last() (*models.Coupon, error) {
|
||
if result, err := c.DO.Last(); err != nil {
|
||
return nil, err
|
||
} else {
|
||
return result.(*models.Coupon), nil
|
||
}
|
||
}
|
||
|
||
func (c couponDo) Find() ([]*models.Coupon, error) {
|
||
result, err := c.DO.Find()
|
||
return result.([]*models.Coupon), err
|
||
}
|
||
|
||
func (c couponDo) FindInBatch(batchSize int, fc func(tx gen.Dao, batch int) error) (results []*models.Coupon, err error) {
|
||
buf := make([]*models.Coupon, 0, batchSize)
|
||
err = c.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 (c couponDo) FindInBatches(result *[]*models.Coupon, batchSize int, fc func(tx gen.Dao, batch int) error) error {
|
||
return c.DO.FindInBatches(result, batchSize, fc)
|
||
}
|
||
|
||
func (c couponDo) Attrs(attrs ...field.AssignExpr) *couponDo {
|
||
return c.withDO(c.DO.Attrs(attrs...))
|
||
}
|
||
|
||
func (c couponDo) Assign(attrs ...field.AssignExpr) *couponDo {
|
||
return c.withDO(c.DO.Assign(attrs...))
|
||
}
|
||
|
||
func (c couponDo) Joins(fields ...field.RelationField) *couponDo {
|
||
for _, _f := range fields {
|
||
c = *c.withDO(c.DO.Joins(_f))
|
||
}
|
||
return &c
|
||
}
|
||
|
||
func (c couponDo) Preload(fields ...field.RelationField) *couponDo {
|
||
for _, _f := range fields {
|
||
c = *c.withDO(c.DO.Preload(_f))
|
||
}
|
||
return &c
|
||
}
|
||
|
||
func (c couponDo) FirstOrInit() (*models.Coupon, error) {
|
||
if result, err := c.DO.FirstOrInit(); err != nil {
|
||
return nil, err
|
||
} else {
|
||
return result.(*models.Coupon), nil
|
||
}
|
||
}
|
||
|
||
func (c couponDo) FirstOrCreate() (*models.Coupon, error) {
|
||
if result, err := c.DO.FirstOrCreate(); err != nil {
|
||
return nil, err
|
||
} else {
|
||
return result.(*models.Coupon), nil
|
||
}
|
||
}
|
||
|
||
func (c couponDo) FindByPage(offset int, limit int) (result []*models.Coupon, count int64, err error) {
|
||
result, err = c.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 = c.Offset(-1).Limit(-1).Count()
|
||
return
|
||
}
|
||
|
||
func (c couponDo) ScanByPage(result interface{}, offset int, limit int) (count int64, err error) {
|
||
count, err = c.Count()
|
||
if err != nil {
|
||
return
|
||
}
|
||
|
||
err = c.Offset(offset).Limit(limit).Scan(result)
|
||
return
|
||
}
|
||
|
||
func (c couponDo) Scan(result interface{}) (err error) {
|
||
return c.DO.Scan(result)
|
||
}
|
||
|
||
func (c couponDo) Delete(models ...*models.Coupon) (result gen.ResultInfo, err error) {
|
||
return c.DO.Delete(models)
|
||
}
|
||
|
||
func (c *couponDo) withDO(do gen.Dao) *couponDo {
|
||
c.DO = *do.(*gen.DO)
|
||
return c
|
||
}
|