352 lines
9.5 KiB
Go
352 lines
9.5 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.Live = field.NewInt32(tableName, "live")
|
|
_resourceShort.Type = field.NewInt(tableName, "type")
|
|
_resourceShort.Quota = field.NewInt32(tableName, "quota")
|
|
_resourceShort.ExpireAt = field.NewTime(tableName, "expire_at")
|
|
_resourceShort.Used = field.NewInt32(tableName, "used")
|
|
_resourceShort.Daily = field.NewInt32(tableName, "daily")
|
|
_resourceShort.LastAt = field.NewTime(tableName, "last_at")
|
|
|
|
_resourceShort.fillFieldMap()
|
|
|
|
return _resourceShort
|
|
}
|
|
|
|
type resourceShort struct {
|
|
resourceShortDo
|
|
|
|
ALL field.Asterisk
|
|
ID field.Int32
|
|
ResourceID field.Int32
|
|
Live field.Int32
|
|
Type field.Int
|
|
Quota field.Int32
|
|
ExpireAt field.Time
|
|
Used field.Int32
|
|
Daily field.Int32
|
|
LastAt field.Time
|
|
|
|
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.Live = field.NewInt32(table, "live")
|
|
r.Type = field.NewInt(table, "type")
|
|
r.Quota = field.NewInt32(table, "quota")
|
|
r.ExpireAt = field.NewTime(table, "expire_at")
|
|
r.Used = field.NewInt32(table, "used")
|
|
r.Daily = field.NewInt32(table, "daily")
|
|
r.LastAt = field.NewTime(table, "last_at")
|
|
|
|
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, 9)
|
|
r.fieldMap["id"] = r.ID
|
|
r.fieldMap["resource_id"] = r.ResourceID
|
|
r.fieldMap["live"] = r.Live
|
|
r.fieldMap["type"] = r.Type
|
|
r.fieldMap["quota"] = r.Quota
|
|
r.fieldMap["expire_at"] = r.ExpireAt
|
|
r.fieldMap["used"] = r.Used
|
|
r.fieldMap["daily"] = r.Daily
|
|
r.fieldMap["last_at"] = r.LastAt
|
|
}
|
|
|
|
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
|
|
}
|