356 lines
9.9 KiB
Go
356 lines
9.9 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 newResourceShort(db *gorm.DB, opts ...gen.DOOption) resourceShort {
|
||
_resourceShort := resourceShort{}
|
||
|
||
_resourceShort.resourceShortDo.UseDB(db, opts...)
|
||
_resourceShort.resourceShortDo.UseModel(&models.ResourceShort{})
|
||
|
||
tableName := _resourceShort.resourceShortDo.TableName()
|
||
_resourceShort.ALL = field.NewAsterisk(tableName)
|
||
_resourceShort.ID = field.NewInt32(tableName, "id")
|
||
_resourceShort.ResourceID = field.NewInt32(tableName, "resource_id")
|
||
_resourceShort.Type = field.NewInt32(tableName, "type")
|
||
_resourceShort.Live = field.NewInt32(tableName, "live")
|
||
_resourceShort.Expire = field.NewField(tableName, "expire")
|
||
_resourceShort.Quota = field.NewInt32(tableName, "quota")
|
||
_resourceShort.Used = field.NewInt32(tableName, "used")
|
||
_resourceShort.DailyLimit = field.NewInt32(tableName, "daily_limit")
|
||
_resourceShort.DailyUsed = field.NewInt32(tableName, "daily_used")
|
||
_resourceShort.DailyLast = field.NewField(tableName, "daily_last")
|
||
|
||
_resourceShort.fillFieldMap()
|
||
|
||
return _resourceShort
|
||
}
|
||
|
||
type resourceShort struct {
|
||
resourceShortDo
|
||
|
||
ALL field.Asterisk
|
||
ID field.Int32 // ID
|
||
ResourceID field.Int32 // 套餐ID
|
||
Type field.Int32 // 套餐类型:1-包时,2-包量
|
||
Live field.Int32 // 可用时长(秒)
|
||
Expire field.Field // 过期时间
|
||
Quota field.Int32 // 配额数量
|
||
Used field.Int32 // 已用数量
|
||
DailyLimit field.Int32 // 每日限制
|
||
DailyUsed field.Int32 // 今日已用数量
|
||
DailyLast field.Field // 今日最后使用时间
|
||
|
||
fieldMap map[string]field.Expr
|
||
}
|
||
|
||
func (r resourceShort) Table(newTableName string) *resourceShort {
|
||
r.resourceShortDo.UseTable(newTableName)
|
||
return r.updateTableName(newTableName)
|
||
}
|
||
|
||
func (r resourceShort) As(alias string) *resourceShort {
|
||
r.resourceShortDo.DO = *(r.resourceShortDo.As(alias).(*gen.DO))
|
||
return r.updateTableName(alias)
|
||
}
|
||
|
||
func (r *resourceShort) updateTableName(table string) *resourceShort {
|
||
r.ALL = field.NewAsterisk(table)
|
||
r.ID = field.NewInt32(table, "id")
|
||
r.ResourceID = field.NewInt32(table, "resource_id")
|
||
r.Type = field.NewInt32(table, "type")
|
||
r.Live = field.NewInt32(table, "live")
|
||
r.Expire = field.NewField(table, "expire")
|
||
r.Quota = field.NewInt32(table, "quota")
|
||
r.Used = field.NewInt32(table, "used")
|
||
r.DailyLimit = field.NewInt32(table, "daily_limit")
|
||
r.DailyUsed = field.NewInt32(table, "daily_used")
|
||
r.DailyLast = field.NewField(table, "daily_last")
|
||
|
||
r.fillFieldMap()
|
||
|
||
return r
|
||
}
|
||
|
||
func (r *resourceShort) 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 *resourceShort) fillFieldMap() {
|
||
r.fieldMap = make(map[string]field.Expr, 10)
|
||
r.fieldMap["id"] = r.ID
|
||
r.fieldMap["resource_id"] = r.ResourceID
|
||
r.fieldMap["type"] = r.Type
|
||
r.fieldMap["live"] = r.Live
|
||
r.fieldMap["expire"] = r.Expire
|
||
r.fieldMap["quota"] = r.Quota
|
||
r.fieldMap["used"] = r.Used
|
||
r.fieldMap["daily_limit"] = r.DailyLimit
|
||
r.fieldMap["daily_used"] = r.DailyUsed
|
||
r.fieldMap["daily_last"] = r.DailyLast
|
||
}
|
||
|
||
func (r resourceShort) clone(db *gorm.DB) resourceShort {
|
||
r.resourceShortDo.ReplaceConnPool(db.Statement.ConnPool)
|
||
return r
|
||
}
|
||
|
||
func (r resourceShort) replaceDB(db *gorm.DB) resourceShort {
|
||
r.resourceShortDo.ReplaceDB(db)
|
||
return r
|
||
}
|
||
|
||
type resourceShortDo struct{ gen.DO }
|
||
|
||
func (r resourceShortDo) Debug() *resourceShortDo {
|
||
return r.withDO(r.DO.Debug())
|
||
}
|
||
|
||
func (r resourceShortDo) WithContext(ctx context.Context) *resourceShortDo {
|
||
return r.withDO(r.DO.WithContext(ctx))
|
||
}
|
||
|
||
func (r resourceShortDo) ReadDB() *resourceShortDo {
|
||
return r.Clauses(dbresolver.Read)
|
||
}
|
||
|
||
func (r resourceShortDo) WriteDB() *resourceShortDo {
|
||
return r.Clauses(dbresolver.Write)
|
||
}
|
||
|
||
func (r resourceShortDo) Session(config *gorm.Session) *resourceShortDo {
|
||
return r.withDO(r.DO.Session(config))
|
||
}
|
||
|
||
func (r resourceShortDo) Clauses(conds ...clause.Expression) *resourceShortDo {
|
||
return r.withDO(r.DO.Clauses(conds...))
|
||
}
|
||
|
||
func (r resourceShortDo) Returning(value interface{}, columns ...string) *resourceShortDo {
|
||
return r.withDO(r.DO.Returning(value, columns...))
|
||
}
|
||
|
||
func (r resourceShortDo) Not(conds ...gen.Condition) *resourceShortDo {
|
||
return r.withDO(r.DO.Not(conds...))
|
||
}
|
||
|
||
func (r resourceShortDo) Or(conds ...gen.Condition) *resourceShortDo {
|
||
return r.withDO(r.DO.Or(conds...))
|
||
}
|
||
|
||
func (r resourceShortDo) Select(conds ...field.Expr) *resourceShortDo {
|
||
return r.withDO(r.DO.Select(conds...))
|
||
}
|
||
|
||
func (r resourceShortDo) Where(conds ...gen.Condition) *resourceShortDo {
|
||
return r.withDO(r.DO.Where(conds...))
|
||
}
|
||
|
||
func (r resourceShortDo) Order(conds ...field.Expr) *resourceShortDo {
|
||
return r.withDO(r.DO.Order(conds...))
|
||
}
|
||
|
||
func (r resourceShortDo) Distinct(cols ...field.Expr) *resourceShortDo {
|
||
return r.withDO(r.DO.Distinct(cols...))
|
||
}
|
||
|
||
func (r resourceShortDo) Omit(cols ...field.Expr) *resourceShortDo {
|
||
return r.withDO(r.DO.Omit(cols...))
|
||
}
|
||
|
||
func (r resourceShortDo) Join(table schema.Tabler, on ...field.Expr) *resourceShortDo {
|
||
return r.withDO(r.DO.Join(table, on...))
|
||
}
|
||
|
||
func (r resourceShortDo) LeftJoin(table schema.Tabler, on ...field.Expr) *resourceShortDo {
|
||
return r.withDO(r.DO.LeftJoin(table, on...))
|
||
}
|
||
|
||
func (r resourceShortDo) RightJoin(table schema.Tabler, on ...field.Expr) *resourceShortDo {
|
||
return r.withDO(r.DO.RightJoin(table, on...))
|
||
}
|
||
|
||
func (r resourceShortDo) Group(cols ...field.Expr) *resourceShortDo {
|
||
return r.withDO(r.DO.Group(cols...))
|
||
}
|
||
|
||
func (r resourceShortDo) Having(conds ...gen.Condition) *resourceShortDo {
|
||
return r.withDO(r.DO.Having(conds...))
|
||
}
|
||
|
||
func (r resourceShortDo) Limit(limit int) *resourceShortDo {
|
||
return r.withDO(r.DO.Limit(limit))
|
||
}
|
||
|
||
func (r resourceShortDo) Offset(offset int) *resourceShortDo {
|
||
return r.withDO(r.DO.Offset(offset))
|
||
}
|
||
|
||
func (r resourceShortDo) Scopes(funcs ...func(gen.Dao) gen.Dao) *resourceShortDo {
|
||
return r.withDO(r.DO.Scopes(funcs...))
|
||
}
|
||
|
||
func (r resourceShortDo) Unscoped() *resourceShortDo {
|
||
return r.withDO(r.DO.Unscoped())
|
||
}
|
||
|
||
func (r resourceShortDo) Create(values ...*models.ResourceShort) error {
|
||
if len(values) == 0 {
|
||
return nil
|
||
}
|
||
return r.DO.Create(values)
|
||
}
|
||
|
||
func (r resourceShortDo) CreateInBatches(values []*models.ResourceShort, 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 resourceShortDo) Save(values ...*models.ResourceShort) error {
|
||
if len(values) == 0 {
|
||
return nil
|
||
}
|
||
return r.DO.Save(values)
|
||
}
|
||
|
||
func (r resourceShortDo) First() (*models.ResourceShort, error) {
|
||
if result, err := r.DO.First(); err != nil {
|
||
return nil, err
|
||
} else {
|
||
return result.(*models.ResourceShort), nil
|
||
}
|
||
}
|
||
|
||
func (r resourceShortDo) Take() (*models.ResourceShort, error) {
|
||
if result, err := r.DO.Take(); err != nil {
|
||
return nil, err
|
||
} else {
|
||
return result.(*models.ResourceShort), nil
|
||
}
|
||
}
|
||
|
||
func (r resourceShortDo) Last() (*models.ResourceShort, error) {
|
||
if result, err := r.DO.Last(); err != nil {
|
||
return nil, err
|
||
} else {
|
||
return result.(*models.ResourceShort), nil
|
||
}
|
||
}
|
||
|
||
func (r resourceShortDo) Find() ([]*models.ResourceShort, error) {
|
||
result, err := r.DO.Find()
|
||
return result.([]*models.ResourceShort), err
|
||
}
|
||
|
||
func (r resourceShortDo) FindInBatch(batchSize int, fc func(tx gen.Dao, batch int) error) (results []*models.ResourceShort, err error) {
|
||
buf := make([]*models.ResourceShort, 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 resourceShortDo) FindInBatches(result *[]*models.ResourceShort, batchSize int, fc func(tx gen.Dao, batch int) error) error {
|
||
return r.DO.FindInBatches(result, batchSize, fc)
|
||
}
|
||
|
||
func (r resourceShortDo) Attrs(attrs ...field.AssignExpr) *resourceShortDo {
|
||
return r.withDO(r.DO.Attrs(attrs...))
|
||
}
|
||
|
||
func (r resourceShortDo) Assign(attrs ...field.AssignExpr) *resourceShortDo {
|
||
return r.withDO(r.DO.Assign(attrs...))
|
||
}
|
||
|
||
func (r resourceShortDo) Joins(fields ...field.RelationField) *resourceShortDo {
|
||
for _, _f := range fields {
|
||
r = *r.withDO(r.DO.Joins(_f))
|
||
}
|
||
return &r
|
||
}
|
||
|
||
func (r resourceShortDo) Preload(fields ...field.RelationField) *resourceShortDo {
|
||
for _, _f := range fields {
|
||
r = *r.withDO(r.DO.Preload(_f))
|
||
}
|
||
return &r
|
||
}
|
||
|
||
func (r resourceShortDo) FirstOrInit() (*models.ResourceShort, error) {
|
||
if result, err := r.DO.FirstOrInit(); err != nil {
|
||
return nil, err
|
||
} else {
|
||
return result.(*models.ResourceShort), nil
|
||
}
|
||
}
|
||
|
||
func (r resourceShortDo) FirstOrCreate() (*models.ResourceShort, error) {
|
||
if result, err := r.DO.FirstOrCreate(); err != nil {
|
||
return nil, err
|
||
} else {
|
||
return result.(*models.ResourceShort), nil
|
||
}
|
||
}
|
||
|
||
func (r resourceShortDo) FindByPage(offset int, limit int) (result []*models.ResourceShort, 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 resourceShortDo) 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 resourceShortDo) Scan(result interface{}) (err error) {
|
||
return r.DO.Scan(result)
|
||
}
|
||
|
||
func (r resourceShortDo) Delete(models ...*models.ResourceShort) (result gen.ResultInfo, err error) {
|
||
return r.DO.Delete(models)
|
||
}
|
||
|
||
func (r *resourceShortDo) withDO(do gen.Dao) *resourceShortDo {
|
||
r.DO = *do.(*gen.DO)
|
||
return r
|
||
}
|