// 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.CreatedAt = field.NewTime(tableName, "created_at") _coupon.UpdatedAt = field.NewTime(tableName, "updated_at") _coupon.DeletedAt = field.NewField(tableName, "deleted_at") _coupon.Name = field.NewString(tableName, "name") _coupon.Amount = field.NewField(tableName, "amount") _coupon.MinAmount = field.NewField(tableName, "min_amount") _coupon.Count_ = field.NewInt32(tableName, "count") _coupon.Status = field.NewInt(tableName, "status") _coupon.ExpireType = field.NewInt(tableName, "expire_type") _coupon.ExpireAt = field.NewTime(tableName, "expire_at") _coupon.ExpireIn = field.NewInt(tableName, "expire_in") _coupon.fillFieldMap() return _coupon } type coupon struct { couponDo ALL field.Asterisk ID field.Int32 CreatedAt field.Time UpdatedAt field.Time DeletedAt field.Field Name field.String Amount field.Field MinAmount field.Field Count_ field.Int32 Status field.Int ExpireType field.Int ExpireAt field.Time ExpireIn field.Int 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.CreatedAt = field.NewTime(table, "created_at") c.UpdatedAt = field.NewTime(table, "updated_at") c.DeletedAt = field.NewField(table, "deleted_at") c.Name = field.NewString(table, "name") c.Amount = field.NewField(table, "amount") c.MinAmount = field.NewField(table, "min_amount") c.Count_ = field.NewInt32(table, "count") c.Status = field.NewInt(table, "status") c.ExpireType = field.NewInt(table, "expire_type") c.ExpireAt = field.NewTime(table, "expire_at") c.ExpireIn = field.NewInt(table, "expire_in") 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, 12) c.fieldMap["id"] = c.ID c.fieldMap["created_at"] = c.CreatedAt c.fieldMap["updated_at"] = c.UpdatedAt c.fieldMap["deleted_at"] = c.DeletedAt c.fieldMap["name"] = c.Name c.fieldMap["amount"] = c.Amount c.fieldMap["min_amount"] = c.MinAmount c.fieldMap["count"] = c.Count_ c.fieldMap["status"] = c.Status c.fieldMap["expire_type"] = c.ExpireType c.fieldMap["expire_at"] = c.ExpireAt c.fieldMap["expire_in"] = c.ExpireIn } 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 }