重命名资源套餐相关结构体和数据库表,新增长效套餐类型
This commit is contained in:
@@ -55,10 +55,10 @@ func newBill(db *gorm.DB, opts ...gen.DOOption) bill {
|
||||
db: db.Session(&gorm.Session{}),
|
||||
|
||||
RelationField: field.NewRelation("Resource", "models.Resource"),
|
||||
Pss: struct {
|
||||
Short: struct {
|
||||
field.RelationField
|
||||
}{
|
||||
RelationField: field.NewRelation("Resource.Pss", "models.ResourcePss"),
|
||||
RelationField: field.NewRelation("Resource.Short", "models.ResourceShort"),
|
||||
},
|
||||
}
|
||||
|
||||
@@ -305,7 +305,7 @@ type billBelongsToResource struct {
|
||||
|
||||
field.RelationField
|
||||
|
||||
Pss struct {
|
||||
Short struct {
|
||||
field.RelationField
|
||||
}
|
||||
}
|
||||
|
||||
@@ -34,9 +34,8 @@ var (
|
||||
Proxy *proxy
|
||||
Refund *refund
|
||||
Resource *resource
|
||||
ResourcePps *resourcePps
|
||||
ResourcePsr *resourcePsr
|
||||
ResourcePss *resourcePss
|
||||
ResourceLong *resourceLong
|
||||
ResourceShort *resourceShort
|
||||
Session *session
|
||||
Trade *trade
|
||||
User *user
|
||||
@@ -65,9 +64,8 @@ func SetDefault(db *gorm.DB, opts ...gen.DOOption) {
|
||||
Proxy = &Q.Proxy
|
||||
Refund = &Q.Refund
|
||||
Resource = &Q.Resource
|
||||
ResourcePps = &Q.ResourcePps
|
||||
ResourcePsr = &Q.ResourcePsr
|
||||
ResourcePss = &Q.ResourcePss
|
||||
ResourceLong = &Q.ResourceLong
|
||||
ResourceShort = &Q.ResourceShort
|
||||
Session = &Q.Session
|
||||
Trade = &Q.Trade
|
||||
User = &Q.User
|
||||
@@ -97,9 +95,8 @@ func Use(db *gorm.DB, opts ...gen.DOOption) *Query {
|
||||
Proxy: newProxy(db, opts...),
|
||||
Refund: newRefund(db, opts...),
|
||||
Resource: newResource(db, opts...),
|
||||
ResourcePps: newResourcePps(db, opts...),
|
||||
ResourcePsr: newResourcePsr(db, opts...),
|
||||
ResourcePss: newResourcePss(db, opts...),
|
||||
ResourceLong: newResourceLong(db, opts...),
|
||||
ResourceShort: newResourceShort(db, opts...),
|
||||
Session: newSession(db, opts...),
|
||||
Trade: newTrade(db, opts...),
|
||||
User: newUser(db, opts...),
|
||||
@@ -130,9 +127,8 @@ type Query struct {
|
||||
Proxy proxy
|
||||
Refund refund
|
||||
Resource resource
|
||||
ResourcePps resourcePps
|
||||
ResourcePsr resourcePsr
|
||||
ResourcePss resourcePss
|
||||
ResourceLong resourceLong
|
||||
ResourceShort resourceShort
|
||||
Session session
|
||||
Trade trade
|
||||
User user
|
||||
@@ -164,9 +160,8 @@ func (q *Query) clone(db *gorm.DB) *Query {
|
||||
Proxy: q.Proxy.clone(db),
|
||||
Refund: q.Refund.clone(db),
|
||||
Resource: q.Resource.clone(db),
|
||||
ResourcePps: q.ResourcePps.clone(db),
|
||||
ResourcePsr: q.ResourcePsr.clone(db),
|
||||
ResourcePss: q.ResourcePss.clone(db),
|
||||
ResourceLong: q.ResourceLong.clone(db),
|
||||
ResourceShort: q.ResourceShort.clone(db),
|
||||
Session: q.Session.clone(db),
|
||||
Trade: q.Trade.clone(db),
|
||||
User: q.User.clone(db),
|
||||
@@ -205,9 +200,8 @@ func (q *Query) ReplaceDB(db *gorm.DB) *Query {
|
||||
Proxy: q.Proxy.replaceDB(db),
|
||||
Refund: q.Refund.replaceDB(db),
|
||||
Resource: q.Resource.replaceDB(db),
|
||||
ResourcePps: q.ResourcePps.replaceDB(db),
|
||||
ResourcePsr: q.ResourcePsr.replaceDB(db),
|
||||
ResourcePss: q.ResourcePss.replaceDB(db),
|
||||
ResourceLong: q.ResourceLong.replaceDB(db),
|
||||
ResourceShort: q.ResourceShort.replaceDB(db),
|
||||
Session: q.Session.replaceDB(db),
|
||||
Trade: q.Trade.replaceDB(db),
|
||||
User: q.User.replaceDB(db),
|
||||
@@ -236,9 +230,8 @@ type queryCtx struct {
|
||||
Proxy *proxyDo
|
||||
Refund *refundDo
|
||||
Resource *resourceDo
|
||||
ResourcePps *resourcePpsDo
|
||||
ResourcePsr *resourcePsrDo
|
||||
ResourcePss *resourcePssDo
|
||||
ResourceLong *resourceLongDo
|
||||
ResourceShort *resourceShortDo
|
||||
Session *sessionDo
|
||||
Trade *tradeDo
|
||||
User *userDo
|
||||
@@ -267,9 +260,8 @@ func (q *Query) WithContext(ctx context.Context) *queryCtx {
|
||||
Proxy: q.Proxy.WithContext(ctx),
|
||||
Refund: q.Refund.WithContext(ctx),
|
||||
Resource: q.Resource.WithContext(ctx),
|
||||
ResourcePps: q.ResourcePps.WithContext(ctx),
|
||||
ResourcePsr: q.ResourcePsr.WithContext(ctx),
|
||||
ResourcePss: q.ResourcePss.WithContext(ctx),
|
||||
ResourceLong: q.ResourceLong.WithContext(ctx),
|
||||
ResourceShort: q.ResourceShort.WithContext(ctx),
|
||||
Session: q.Session.WithContext(ctx),
|
||||
Trade: q.Trade.WithContext(ctx),
|
||||
User: q.User.WithContext(ctx),
|
||||
|
||||
@@ -35,10 +35,10 @@ func newResource(db *gorm.DB, opts ...gen.DOOption) resource {
|
||||
_resource.CreatedAt = field.NewField(tableName, "created_at")
|
||||
_resource.UpdatedAt = field.NewField(tableName, "updated_at")
|
||||
_resource.DeletedAt = field.NewField(tableName, "deleted_at")
|
||||
_resource.Pss = resourceHasOnePss{
|
||||
_resource.Short = resourceHasOneShort{
|
||||
db: db.Session(&gorm.Session{}),
|
||||
|
||||
RelationField: field.NewRelation("Pss", "models.ResourcePss"),
|
||||
RelationField: field.NewRelation("Short", "models.ResourceShort"),
|
||||
}
|
||||
|
||||
_resource.fillFieldMap()
|
||||
@@ -58,7 +58,7 @@ type resource struct {
|
||||
CreatedAt field.Field // 创建时间
|
||||
UpdatedAt field.Field // 更新时间
|
||||
DeletedAt field.Field // 删除时间
|
||||
Pss resourceHasOnePss
|
||||
Short resourceHasOneShort
|
||||
|
||||
fieldMap map[string]field.Expr
|
||||
}
|
||||
@@ -121,13 +121,13 @@ func (r resource) replaceDB(db *gorm.DB) resource {
|
||||
return r
|
||||
}
|
||||
|
||||
type resourceHasOnePss struct {
|
||||
type resourceHasOneShort struct {
|
||||
db *gorm.DB
|
||||
|
||||
field.RelationField
|
||||
}
|
||||
|
||||
func (a resourceHasOnePss) Where(conds ...field.Expr) *resourceHasOnePss {
|
||||
func (a resourceHasOneShort) Where(conds ...field.Expr) *resourceHasOneShort {
|
||||
if len(conds) == 0 {
|
||||
return &a
|
||||
}
|
||||
@@ -140,27 +140,27 @@ func (a resourceHasOnePss) Where(conds ...field.Expr) *resourceHasOnePss {
|
||||
return &a
|
||||
}
|
||||
|
||||
func (a resourceHasOnePss) WithContext(ctx context.Context) *resourceHasOnePss {
|
||||
func (a resourceHasOneShort) WithContext(ctx context.Context) *resourceHasOneShort {
|
||||
a.db = a.db.WithContext(ctx)
|
||||
return &a
|
||||
}
|
||||
|
||||
func (a resourceHasOnePss) Session(session *gorm.Session) *resourceHasOnePss {
|
||||
func (a resourceHasOneShort) Session(session *gorm.Session) *resourceHasOneShort {
|
||||
a.db = a.db.Session(session)
|
||||
return &a
|
||||
}
|
||||
|
||||
func (a resourceHasOnePss) Model(m *models.Resource) *resourceHasOnePssTx {
|
||||
return &resourceHasOnePssTx{a.db.Model(m).Association(a.Name())}
|
||||
func (a resourceHasOneShort) Model(m *models.Resource) *resourceHasOneShortTx {
|
||||
return &resourceHasOneShortTx{a.db.Model(m).Association(a.Name())}
|
||||
}
|
||||
|
||||
type resourceHasOnePssTx struct{ tx *gorm.Association }
|
||||
type resourceHasOneShortTx struct{ tx *gorm.Association }
|
||||
|
||||
func (a resourceHasOnePssTx) Find() (result *models.ResourcePss, err error) {
|
||||
func (a resourceHasOneShortTx) Find() (result *models.ResourceShort, err error) {
|
||||
return result, a.tx.Find(&result)
|
||||
}
|
||||
|
||||
func (a resourceHasOnePssTx) Append(values ...*models.ResourcePss) (err error) {
|
||||
func (a resourceHasOneShortTx) Append(values ...*models.ResourceShort) (err error) {
|
||||
targetValues := make([]interface{}, len(values))
|
||||
for i, v := range values {
|
||||
targetValues[i] = v
|
||||
@@ -168,7 +168,7 @@ func (a resourceHasOnePssTx) Append(values ...*models.ResourcePss) (err error) {
|
||||
return a.tx.Append(targetValues...)
|
||||
}
|
||||
|
||||
func (a resourceHasOnePssTx) Replace(values ...*models.ResourcePss) (err error) {
|
||||
func (a resourceHasOneShortTx) Replace(values ...*models.ResourceShort) (err error) {
|
||||
targetValues := make([]interface{}, len(values))
|
||||
for i, v := range values {
|
||||
targetValues[i] = v
|
||||
@@ -176,7 +176,7 @@ func (a resourceHasOnePssTx) Replace(values ...*models.ResourcePss) (err error)
|
||||
return a.tx.Replace(targetValues...)
|
||||
}
|
||||
|
||||
func (a resourceHasOnePssTx) Delete(values ...*models.ResourcePss) (err error) {
|
||||
func (a resourceHasOneShortTx) Delete(values ...*models.ResourceShort) (err error) {
|
||||
targetValues := make([]interface{}, len(values))
|
||||
for i, v := range values {
|
||||
targetValues[i] = v
|
||||
@@ -184,11 +184,11 @@ func (a resourceHasOnePssTx) Delete(values ...*models.ResourcePss) (err error) {
|
||||
return a.tx.Delete(targetValues...)
|
||||
}
|
||||
|
||||
func (a resourceHasOnePssTx) Clear() error {
|
||||
func (a resourceHasOneShortTx) Clear() error {
|
||||
return a.tx.Clear()
|
||||
}
|
||||
|
||||
func (a resourceHasOnePssTx) Count() int64 {
|
||||
func (a resourceHasOneShortTx) Count() int64 {
|
||||
return a.tx.Count()
|
||||
}
|
||||
|
||||
|
||||
355
web/queries/resource_long.gen.go
Normal file
355
web/queries/resource_long.gen.go
Normal file
@@ -0,0 +1,355 @@
|
||||
// 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 newResourceLong(db *gorm.DB, opts ...gen.DOOption) resourceLong {
|
||||
_resourceLong := resourceLong{}
|
||||
|
||||
_resourceLong.resourceLongDo.UseDB(db, opts...)
|
||||
_resourceLong.resourceLongDo.UseModel(&models.ResourceLong{})
|
||||
|
||||
tableName := _resourceLong.resourceLongDo.TableName()
|
||||
_resourceLong.ALL = field.NewAsterisk(tableName)
|
||||
_resourceLong.ID = field.NewInt32(tableName, "id")
|
||||
_resourceLong.ResourceID = field.NewInt32(tableName, "resource_id")
|
||||
_resourceLong.Type = field.NewInt32(tableName, "type")
|
||||
_resourceLong.Live = field.NewInt32(tableName, "live")
|
||||
_resourceLong.Expire = field.NewField(tableName, "expire")
|
||||
_resourceLong.Quota = field.NewInt32(tableName, "quota")
|
||||
_resourceLong.Used = field.NewInt32(tableName, "used")
|
||||
_resourceLong.DailyLimit = field.NewInt32(tableName, "daily_limit")
|
||||
_resourceLong.DailyUsed = field.NewInt32(tableName, "daily_used")
|
||||
_resourceLong.DailyLast = field.NewField(tableName, "daily_last")
|
||||
|
||||
_resourceLong.fillFieldMap()
|
||||
|
||||
return _resourceLong
|
||||
}
|
||||
|
||||
type resourceLong struct {
|
||||
resourceLongDo
|
||||
|
||||
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 resourceLong) Table(newTableName string) *resourceLong {
|
||||
r.resourceLongDo.UseTable(newTableName)
|
||||
return r.updateTableName(newTableName)
|
||||
}
|
||||
|
||||
func (r resourceLong) As(alias string) *resourceLong {
|
||||
r.resourceLongDo.DO = *(r.resourceLongDo.As(alias).(*gen.DO))
|
||||
return r.updateTableName(alias)
|
||||
}
|
||||
|
||||
func (r *resourceLong) updateTableName(table string) *resourceLong {
|
||||
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 *resourceLong) 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 *resourceLong) 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 resourceLong) clone(db *gorm.DB) resourceLong {
|
||||
r.resourceLongDo.ReplaceConnPool(db.Statement.ConnPool)
|
||||
return r
|
||||
}
|
||||
|
||||
func (r resourceLong) replaceDB(db *gorm.DB) resourceLong {
|
||||
r.resourceLongDo.ReplaceDB(db)
|
||||
return r
|
||||
}
|
||||
|
||||
type resourceLongDo struct{ gen.DO }
|
||||
|
||||
func (r resourceLongDo) Debug() *resourceLongDo {
|
||||
return r.withDO(r.DO.Debug())
|
||||
}
|
||||
|
||||
func (r resourceLongDo) WithContext(ctx context.Context) *resourceLongDo {
|
||||
return r.withDO(r.DO.WithContext(ctx))
|
||||
}
|
||||
|
||||
func (r resourceLongDo) ReadDB() *resourceLongDo {
|
||||
return r.Clauses(dbresolver.Read)
|
||||
}
|
||||
|
||||
func (r resourceLongDo) WriteDB() *resourceLongDo {
|
||||
return r.Clauses(dbresolver.Write)
|
||||
}
|
||||
|
||||
func (r resourceLongDo) Session(config *gorm.Session) *resourceLongDo {
|
||||
return r.withDO(r.DO.Session(config))
|
||||
}
|
||||
|
||||
func (r resourceLongDo) Clauses(conds ...clause.Expression) *resourceLongDo {
|
||||
return r.withDO(r.DO.Clauses(conds...))
|
||||
}
|
||||
|
||||
func (r resourceLongDo) Returning(value interface{}, columns ...string) *resourceLongDo {
|
||||
return r.withDO(r.DO.Returning(value, columns...))
|
||||
}
|
||||
|
||||
func (r resourceLongDo) Not(conds ...gen.Condition) *resourceLongDo {
|
||||
return r.withDO(r.DO.Not(conds...))
|
||||
}
|
||||
|
||||
func (r resourceLongDo) Or(conds ...gen.Condition) *resourceLongDo {
|
||||
return r.withDO(r.DO.Or(conds...))
|
||||
}
|
||||
|
||||
func (r resourceLongDo) Select(conds ...field.Expr) *resourceLongDo {
|
||||
return r.withDO(r.DO.Select(conds...))
|
||||
}
|
||||
|
||||
func (r resourceLongDo) Where(conds ...gen.Condition) *resourceLongDo {
|
||||
return r.withDO(r.DO.Where(conds...))
|
||||
}
|
||||
|
||||
func (r resourceLongDo) Order(conds ...field.Expr) *resourceLongDo {
|
||||
return r.withDO(r.DO.Order(conds...))
|
||||
}
|
||||
|
||||
func (r resourceLongDo) Distinct(cols ...field.Expr) *resourceLongDo {
|
||||
return r.withDO(r.DO.Distinct(cols...))
|
||||
}
|
||||
|
||||
func (r resourceLongDo) Omit(cols ...field.Expr) *resourceLongDo {
|
||||
return r.withDO(r.DO.Omit(cols...))
|
||||
}
|
||||
|
||||
func (r resourceLongDo) Join(table schema.Tabler, on ...field.Expr) *resourceLongDo {
|
||||
return r.withDO(r.DO.Join(table, on...))
|
||||
}
|
||||
|
||||
func (r resourceLongDo) LeftJoin(table schema.Tabler, on ...field.Expr) *resourceLongDo {
|
||||
return r.withDO(r.DO.LeftJoin(table, on...))
|
||||
}
|
||||
|
||||
func (r resourceLongDo) RightJoin(table schema.Tabler, on ...field.Expr) *resourceLongDo {
|
||||
return r.withDO(r.DO.RightJoin(table, on...))
|
||||
}
|
||||
|
||||
func (r resourceLongDo) Group(cols ...field.Expr) *resourceLongDo {
|
||||
return r.withDO(r.DO.Group(cols...))
|
||||
}
|
||||
|
||||
func (r resourceLongDo) Having(conds ...gen.Condition) *resourceLongDo {
|
||||
return r.withDO(r.DO.Having(conds...))
|
||||
}
|
||||
|
||||
func (r resourceLongDo) Limit(limit int) *resourceLongDo {
|
||||
return r.withDO(r.DO.Limit(limit))
|
||||
}
|
||||
|
||||
func (r resourceLongDo) Offset(offset int) *resourceLongDo {
|
||||
return r.withDO(r.DO.Offset(offset))
|
||||
}
|
||||
|
||||
func (r resourceLongDo) Scopes(funcs ...func(gen.Dao) gen.Dao) *resourceLongDo {
|
||||
return r.withDO(r.DO.Scopes(funcs...))
|
||||
}
|
||||
|
||||
func (r resourceLongDo) Unscoped() *resourceLongDo {
|
||||
return r.withDO(r.DO.Unscoped())
|
||||
}
|
||||
|
||||
func (r resourceLongDo) Create(values ...*models.ResourceLong) error {
|
||||
if len(values) == 0 {
|
||||
return nil
|
||||
}
|
||||
return r.DO.Create(values)
|
||||
}
|
||||
|
||||
func (r resourceLongDo) CreateInBatches(values []*models.ResourceLong, 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 resourceLongDo) Save(values ...*models.ResourceLong) error {
|
||||
if len(values) == 0 {
|
||||
return nil
|
||||
}
|
||||
return r.DO.Save(values)
|
||||
}
|
||||
|
||||
func (r resourceLongDo) First() (*models.ResourceLong, error) {
|
||||
if result, err := r.DO.First(); err != nil {
|
||||
return nil, err
|
||||
} else {
|
||||
return result.(*models.ResourceLong), nil
|
||||
}
|
||||
}
|
||||
|
||||
func (r resourceLongDo) Take() (*models.ResourceLong, error) {
|
||||
if result, err := r.DO.Take(); err != nil {
|
||||
return nil, err
|
||||
} else {
|
||||
return result.(*models.ResourceLong), nil
|
||||
}
|
||||
}
|
||||
|
||||
func (r resourceLongDo) Last() (*models.ResourceLong, error) {
|
||||
if result, err := r.DO.Last(); err != nil {
|
||||
return nil, err
|
||||
} else {
|
||||
return result.(*models.ResourceLong), nil
|
||||
}
|
||||
}
|
||||
|
||||
func (r resourceLongDo) Find() ([]*models.ResourceLong, error) {
|
||||
result, err := r.DO.Find()
|
||||
return result.([]*models.ResourceLong), err
|
||||
}
|
||||
|
||||
func (r resourceLongDo) FindInBatch(batchSize int, fc func(tx gen.Dao, batch int) error) (results []*models.ResourceLong, err error) {
|
||||
buf := make([]*models.ResourceLong, 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 resourceLongDo) FindInBatches(result *[]*models.ResourceLong, batchSize int, fc func(tx gen.Dao, batch int) error) error {
|
||||
return r.DO.FindInBatches(result, batchSize, fc)
|
||||
}
|
||||
|
||||
func (r resourceLongDo) Attrs(attrs ...field.AssignExpr) *resourceLongDo {
|
||||
return r.withDO(r.DO.Attrs(attrs...))
|
||||
}
|
||||
|
||||
func (r resourceLongDo) Assign(attrs ...field.AssignExpr) *resourceLongDo {
|
||||
return r.withDO(r.DO.Assign(attrs...))
|
||||
}
|
||||
|
||||
func (r resourceLongDo) Joins(fields ...field.RelationField) *resourceLongDo {
|
||||
for _, _f := range fields {
|
||||
r = *r.withDO(r.DO.Joins(_f))
|
||||
}
|
||||
return &r
|
||||
}
|
||||
|
||||
func (r resourceLongDo) Preload(fields ...field.RelationField) *resourceLongDo {
|
||||
for _, _f := range fields {
|
||||
r = *r.withDO(r.DO.Preload(_f))
|
||||
}
|
||||
return &r
|
||||
}
|
||||
|
||||
func (r resourceLongDo) FirstOrInit() (*models.ResourceLong, error) {
|
||||
if result, err := r.DO.FirstOrInit(); err != nil {
|
||||
return nil, err
|
||||
} else {
|
||||
return result.(*models.ResourceLong), nil
|
||||
}
|
||||
}
|
||||
|
||||
func (r resourceLongDo) FirstOrCreate() (*models.ResourceLong, error) {
|
||||
if result, err := r.DO.FirstOrCreate(); err != nil {
|
||||
return nil, err
|
||||
} else {
|
||||
return result.(*models.ResourceLong), nil
|
||||
}
|
||||
}
|
||||
|
||||
func (r resourceLongDo) FindByPage(offset int, limit int) (result []*models.ResourceLong, 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 resourceLongDo) 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 resourceLongDo) Scan(result interface{}) (err error) {
|
||||
return r.DO.Scan(result)
|
||||
}
|
||||
|
||||
func (r resourceLongDo) Delete(models ...*models.ResourceLong) (result gen.ResultInfo, err error) {
|
||||
return r.DO.Delete(models)
|
||||
}
|
||||
|
||||
func (r *resourceLongDo) withDO(do gen.Dao) *resourceLongDo {
|
||||
r.DO = *do.(*gen.DO)
|
||||
return r
|
||||
}
|
||||
@@ -1,323 +0,0 @@
|
||||
// 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 newResourcePps(db *gorm.DB, opts ...gen.DOOption) resourcePps {
|
||||
_resourcePps := resourcePps{}
|
||||
|
||||
_resourcePps.resourcePpsDo.UseDB(db, opts...)
|
||||
_resourcePps.resourcePpsDo.UseModel(&models.ResourcePps{})
|
||||
|
||||
tableName := _resourcePps.resourcePpsDo.TableName()
|
||||
_resourcePps.ALL = field.NewAsterisk(tableName)
|
||||
_resourcePps.ID = field.NewInt32(tableName, "id")
|
||||
_resourcePps.ResourceID = field.NewInt32(tableName, "resource_id")
|
||||
|
||||
_resourcePps.fillFieldMap()
|
||||
|
||||
return _resourcePps
|
||||
}
|
||||
|
||||
type resourcePps struct {
|
||||
resourcePpsDo
|
||||
|
||||
ALL field.Asterisk
|
||||
ID field.Int32 // ID
|
||||
ResourceID field.Int32 // 套餐ID
|
||||
|
||||
fieldMap map[string]field.Expr
|
||||
}
|
||||
|
||||
func (r resourcePps) Table(newTableName string) *resourcePps {
|
||||
r.resourcePpsDo.UseTable(newTableName)
|
||||
return r.updateTableName(newTableName)
|
||||
}
|
||||
|
||||
func (r resourcePps) As(alias string) *resourcePps {
|
||||
r.resourcePpsDo.DO = *(r.resourcePpsDo.As(alias).(*gen.DO))
|
||||
return r.updateTableName(alias)
|
||||
}
|
||||
|
||||
func (r *resourcePps) updateTableName(table string) *resourcePps {
|
||||
r.ALL = field.NewAsterisk(table)
|
||||
r.ID = field.NewInt32(table, "id")
|
||||
r.ResourceID = field.NewInt32(table, "resource_id")
|
||||
|
||||
r.fillFieldMap()
|
||||
|
||||
return r
|
||||
}
|
||||
|
||||
func (r *resourcePps) 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 *resourcePps) fillFieldMap() {
|
||||
r.fieldMap = make(map[string]field.Expr, 2)
|
||||
r.fieldMap["id"] = r.ID
|
||||
r.fieldMap["resource_id"] = r.ResourceID
|
||||
}
|
||||
|
||||
func (r resourcePps) clone(db *gorm.DB) resourcePps {
|
||||
r.resourcePpsDo.ReplaceConnPool(db.Statement.ConnPool)
|
||||
return r
|
||||
}
|
||||
|
||||
func (r resourcePps) replaceDB(db *gorm.DB) resourcePps {
|
||||
r.resourcePpsDo.ReplaceDB(db)
|
||||
return r
|
||||
}
|
||||
|
||||
type resourcePpsDo struct{ gen.DO }
|
||||
|
||||
func (r resourcePpsDo) Debug() *resourcePpsDo {
|
||||
return r.withDO(r.DO.Debug())
|
||||
}
|
||||
|
||||
func (r resourcePpsDo) WithContext(ctx context.Context) *resourcePpsDo {
|
||||
return r.withDO(r.DO.WithContext(ctx))
|
||||
}
|
||||
|
||||
func (r resourcePpsDo) ReadDB() *resourcePpsDo {
|
||||
return r.Clauses(dbresolver.Read)
|
||||
}
|
||||
|
||||
func (r resourcePpsDo) WriteDB() *resourcePpsDo {
|
||||
return r.Clauses(dbresolver.Write)
|
||||
}
|
||||
|
||||
func (r resourcePpsDo) Session(config *gorm.Session) *resourcePpsDo {
|
||||
return r.withDO(r.DO.Session(config))
|
||||
}
|
||||
|
||||
func (r resourcePpsDo) Clauses(conds ...clause.Expression) *resourcePpsDo {
|
||||
return r.withDO(r.DO.Clauses(conds...))
|
||||
}
|
||||
|
||||
func (r resourcePpsDo) Returning(value interface{}, columns ...string) *resourcePpsDo {
|
||||
return r.withDO(r.DO.Returning(value, columns...))
|
||||
}
|
||||
|
||||
func (r resourcePpsDo) Not(conds ...gen.Condition) *resourcePpsDo {
|
||||
return r.withDO(r.DO.Not(conds...))
|
||||
}
|
||||
|
||||
func (r resourcePpsDo) Or(conds ...gen.Condition) *resourcePpsDo {
|
||||
return r.withDO(r.DO.Or(conds...))
|
||||
}
|
||||
|
||||
func (r resourcePpsDo) Select(conds ...field.Expr) *resourcePpsDo {
|
||||
return r.withDO(r.DO.Select(conds...))
|
||||
}
|
||||
|
||||
func (r resourcePpsDo) Where(conds ...gen.Condition) *resourcePpsDo {
|
||||
return r.withDO(r.DO.Where(conds...))
|
||||
}
|
||||
|
||||
func (r resourcePpsDo) Order(conds ...field.Expr) *resourcePpsDo {
|
||||
return r.withDO(r.DO.Order(conds...))
|
||||
}
|
||||
|
||||
func (r resourcePpsDo) Distinct(cols ...field.Expr) *resourcePpsDo {
|
||||
return r.withDO(r.DO.Distinct(cols...))
|
||||
}
|
||||
|
||||
func (r resourcePpsDo) Omit(cols ...field.Expr) *resourcePpsDo {
|
||||
return r.withDO(r.DO.Omit(cols...))
|
||||
}
|
||||
|
||||
func (r resourcePpsDo) Join(table schema.Tabler, on ...field.Expr) *resourcePpsDo {
|
||||
return r.withDO(r.DO.Join(table, on...))
|
||||
}
|
||||
|
||||
func (r resourcePpsDo) LeftJoin(table schema.Tabler, on ...field.Expr) *resourcePpsDo {
|
||||
return r.withDO(r.DO.LeftJoin(table, on...))
|
||||
}
|
||||
|
||||
func (r resourcePpsDo) RightJoin(table schema.Tabler, on ...field.Expr) *resourcePpsDo {
|
||||
return r.withDO(r.DO.RightJoin(table, on...))
|
||||
}
|
||||
|
||||
func (r resourcePpsDo) Group(cols ...field.Expr) *resourcePpsDo {
|
||||
return r.withDO(r.DO.Group(cols...))
|
||||
}
|
||||
|
||||
func (r resourcePpsDo) Having(conds ...gen.Condition) *resourcePpsDo {
|
||||
return r.withDO(r.DO.Having(conds...))
|
||||
}
|
||||
|
||||
func (r resourcePpsDo) Limit(limit int) *resourcePpsDo {
|
||||
return r.withDO(r.DO.Limit(limit))
|
||||
}
|
||||
|
||||
func (r resourcePpsDo) Offset(offset int) *resourcePpsDo {
|
||||
return r.withDO(r.DO.Offset(offset))
|
||||
}
|
||||
|
||||
func (r resourcePpsDo) Scopes(funcs ...func(gen.Dao) gen.Dao) *resourcePpsDo {
|
||||
return r.withDO(r.DO.Scopes(funcs...))
|
||||
}
|
||||
|
||||
func (r resourcePpsDo) Unscoped() *resourcePpsDo {
|
||||
return r.withDO(r.DO.Unscoped())
|
||||
}
|
||||
|
||||
func (r resourcePpsDo) Create(values ...*models.ResourcePps) error {
|
||||
if len(values) == 0 {
|
||||
return nil
|
||||
}
|
||||
return r.DO.Create(values)
|
||||
}
|
||||
|
||||
func (r resourcePpsDo) CreateInBatches(values []*models.ResourcePps, 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 resourcePpsDo) Save(values ...*models.ResourcePps) error {
|
||||
if len(values) == 0 {
|
||||
return nil
|
||||
}
|
||||
return r.DO.Save(values)
|
||||
}
|
||||
|
||||
func (r resourcePpsDo) First() (*models.ResourcePps, error) {
|
||||
if result, err := r.DO.First(); err != nil {
|
||||
return nil, err
|
||||
} else {
|
||||
return result.(*models.ResourcePps), nil
|
||||
}
|
||||
}
|
||||
|
||||
func (r resourcePpsDo) Take() (*models.ResourcePps, error) {
|
||||
if result, err := r.DO.Take(); err != nil {
|
||||
return nil, err
|
||||
} else {
|
||||
return result.(*models.ResourcePps), nil
|
||||
}
|
||||
}
|
||||
|
||||
func (r resourcePpsDo) Last() (*models.ResourcePps, error) {
|
||||
if result, err := r.DO.Last(); err != nil {
|
||||
return nil, err
|
||||
} else {
|
||||
return result.(*models.ResourcePps), nil
|
||||
}
|
||||
}
|
||||
|
||||
func (r resourcePpsDo) Find() ([]*models.ResourcePps, error) {
|
||||
result, err := r.DO.Find()
|
||||
return result.([]*models.ResourcePps), err
|
||||
}
|
||||
|
||||
func (r resourcePpsDo) FindInBatch(batchSize int, fc func(tx gen.Dao, batch int) error) (results []*models.ResourcePps, err error) {
|
||||
buf := make([]*models.ResourcePps, 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 resourcePpsDo) FindInBatches(result *[]*models.ResourcePps, batchSize int, fc func(tx gen.Dao, batch int) error) error {
|
||||
return r.DO.FindInBatches(result, batchSize, fc)
|
||||
}
|
||||
|
||||
func (r resourcePpsDo) Attrs(attrs ...field.AssignExpr) *resourcePpsDo {
|
||||
return r.withDO(r.DO.Attrs(attrs...))
|
||||
}
|
||||
|
||||
func (r resourcePpsDo) Assign(attrs ...field.AssignExpr) *resourcePpsDo {
|
||||
return r.withDO(r.DO.Assign(attrs...))
|
||||
}
|
||||
|
||||
func (r resourcePpsDo) Joins(fields ...field.RelationField) *resourcePpsDo {
|
||||
for _, _f := range fields {
|
||||
r = *r.withDO(r.DO.Joins(_f))
|
||||
}
|
||||
return &r
|
||||
}
|
||||
|
||||
func (r resourcePpsDo) Preload(fields ...field.RelationField) *resourcePpsDo {
|
||||
for _, _f := range fields {
|
||||
r = *r.withDO(r.DO.Preload(_f))
|
||||
}
|
||||
return &r
|
||||
}
|
||||
|
||||
func (r resourcePpsDo) FirstOrInit() (*models.ResourcePps, error) {
|
||||
if result, err := r.DO.FirstOrInit(); err != nil {
|
||||
return nil, err
|
||||
} else {
|
||||
return result.(*models.ResourcePps), nil
|
||||
}
|
||||
}
|
||||
|
||||
func (r resourcePpsDo) FirstOrCreate() (*models.ResourcePps, error) {
|
||||
if result, err := r.DO.FirstOrCreate(); err != nil {
|
||||
return nil, err
|
||||
} else {
|
||||
return result.(*models.ResourcePps), nil
|
||||
}
|
||||
}
|
||||
|
||||
func (r resourcePpsDo) FindByPage(offset int, limit int) (result []*models.ResourcePps, 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 resourcePpsDo) 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 resourcePpsDo) Scan(result interface{}) (err error) {
|
||||
return r.DO.Scan(result)
|
||||
}
|
||||
|
||||
func (r resourcePpsDo) Delete(models ...*models.ResourcePps) (result gen.ResultInfo, err error) {
|
||||
return r.DO.Delete(models)
|
||||
}
|
||||
|
||||
func (r *resourcePpsDo) withDO(do gen.Dao) *resourcePpsDo {
|
||||
r.DO = *do.(*gen.DO)
|
||||
return r
|
||||
}
|
||||
@@ -1,339 +0,0 @@
|
||||
// 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 newResourcePsr(db *gorm.DB, opts ...gen.DOOption) resourcePsr {
|
||||
_resourcePsr := resourcePsr{}
|
||||
|
||||
_resourcePsr.resourcePsrDo.UseDB(db, opts...)
|
||||
_resourcePsr.resourcePsrDo.UseModel(&models.ResourcePsr{})
|
||||
|
||||
tableName := _resourcePsr.resourcePsrDo.TableName()
|
||||
_resourcePsr.ALL = field.NewAsterisk(tableName)
|
||||
_resourcePsr.ID = field.NewInt32(tableName, "id")
|
||||
_resourcePsr.ResourceID = field.NewInt32(tableName, "resource_id")
|
||||
_resourcePsr.Live = field.NewInt32(tableName, "live")
|
||||
_resourcePsr.Conn = field.NewInt32(tableName, "conn")
|
||||
_resourcePsr.Expire = field.NewField(tableName, "expire")
|
||||
_resourcePsr.Used = field.NewBool(tableName, "used")
|
||||
|
||||
_resourcePsr.fillFieldMap()
|
||||
|
||||
return _resourcePsr
|
||||
}
|
||||
|
||||
type resourcePsr struct {
|
||||
resourcePsrDo
|
||||
|
||||
ALL field.Asterisk
|
||||
ID field.Int32 // ID
|
||||
ResourceID field.Int32 // 套餐ID
|
||||
Live field.Int32 // 轮换周期(秒)
|
||||
Conn field.Int32 // 最大连接数
|
||||
Expire field.Field // 过期时间
|
||||
Used field.Bool // 是否已使用
|
||||
|
||||
fieldMap map[string]field.Expr
|
||||
}
|
||||
|
||||
func (r resourcePsr) Table(newTableName string) *resourcePsr {
|
||||
r.resourcePsrDo.UseTable(newTableName)
|
||||
return r.updateTableName(newTableName)
|
||||
}
|
||||
|
||||
func (r resourcePsr) As(alias string) *resourcePsr {
|
||||
r.resourcePsrDo.DO = *(r.resourcePsrDo.As(alias).(*gen.DO))
|
||||
return r.updateTableName(alias)
|
||||
}
|
||||
|
||||
func (r *resourcePsr) updateTableName(table string) *resourcePsr {
|
||||
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.Conn = field.NewInt32(table, "conn")
|
||||
r.Expire = field.NewField(table, "expire")
|
||||
r.Used = field.NewBool(table, "used")
|
||||
|
||||
r.fillFieldMap()
|
||||
|
||||
return r
|
||||
}
|
||||
|
||||
func (r *resourcePsr) 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 *resourcePsr) fillFieldMap() {
|
||||
r.fieldMap = make(map[string]field.Expr, 6)
|
||||
r.fieldMap["id"] = r.ID
|
||||
r.fieldMap["resource_id"] = r.ResourceID
|
||||
r.fieldMap["live"] = r.Live
|
||||
r.fieldMap["conn"] = r.Conn
|
||||
r.fieldMap["expire"] = r.Expire
|
||||
r.fieldMap["used"] = r.Used
|
||||
}
|
||||
|
||||
func (r resourcePsr) clone(db *gorm.DB) resourcePsr {
|
||||
r.resourcePsrDo.ReplaceConnPool(db.Statement.ConnPool)
|
||||
return r
|
||||
}
|
||||
|
||||
func (r resourcePsr) replaceDB(db *gorm.DB) resourcePsr {
|
||||
r.resourcePsrDo.ReplaceDB(db)
|
||||
return r
|
||||
}
|
||||
|
||||
type resourcePsrDo struct{ gen.DO }
|
||||
|
||||
func (r resourcePsrDo) Debug() *resourcePsrDo {
|
||||
return r.withDO(r.DO.Debug())
|
||||
}
|
||||
|
||||
func (r resourcePsrDo) WithContext(ctx context.Context) *resourcePsrDo {
|
||||
return r.withDO(r.DO.WithContext(ctx))
|
||||
}
|
||||
|
||||
func (r resourcePsrDo) ReadDB() *resourcePsrDo {
|
||||
return r.Clauses(dbresolver.Read)
|
||||
}
|
||||
|
||||
func (r resourcePsrDo) WriteDB() *resourcePsrDo {
|
||||
return r.Clauses(dbresolver.Write)
|
||||
}
|
||||
|
||||
func (r resourcePsrDo) Session(config *gorm.Session) *resourcePsrDo {
|
||||
return r.withDO(r.DO.Session(config))
|
||||
}
|
||||
|
||||
func (r resourcePsrDo) Clauses(conds ...clause.Expression) *resourcePsrDo {
|
||||
return r.withDO(r.DO.Clauses(conds...))
|
||||
}
|
||||
|
||||
func (r resourcePsrDo) Returning(value interface{}, columns ...string) *resourcePsrDo {
|
||||
return r.withDO(r.DO.Returning(value, columns...))
|
||||
}
|
||||
|
||||
func (r resourcePsrDo) Not(conds ...gen.Condition) *resourcePsrDo {
|
||||
return r.withDO(r.DO.Not(conds...))
|
||||
}
|
||||
|
||||
func (r resourcePsrDo) Or(conds ...gen.Condition) *resourcePsrDo {
|
||||
return r.withDO(r.DO.Or(conds...))
|
||||
}
|
||||
|
||||
func (r resourcePsrDo) Select(conds ...field.Expr) *resourcePsrDo {
|
||||
return r.withDO(r.DO.Select(conds...))
|
||||
}
|
||||
|
||||
func (r resourcePsrDo) Where(conds ...gen.Condition) *resourcePsrDo {
|
||||
return r.withDO(r.DO.Where(conds...))
|
||||
}
|
||||
|
||||
func (r resourcePsrDo) Order(conds ...field.Expr) *resourcePsrDo {
|
||||
return r.withDO(r.DO.Order(conds...))
|
||||
}
|
||||
|
||||
func (r resourcePsrDo) Distinct(cols ...field.Expr) *resourcePsrDo {
|
||||
return r.withDO(r.DO.Distinct(cols...))
|
||||
}
|
||||
|
||||
func (r resourcePsrDo) Omit(cols ...field.Expr) *resourcePsrDo {
|
||||
return r.withDO(r.DO.Omit(cols...))
|
||||
}
|
||||
|
||||
func (r resourcePsrDo) Join(table schema.Tabler, on ...field.Expr) *resourcePsrDo {
|
||||
return r.withDO(r.DO.Join(table, on...))
|
||||
}
|
||||
|
||||
func (r resourcePsrDo) LeftJoin(table schema.Tabler, on ...field.Expr) *resourcePsrDo {
|
||||
return r.withDO(r.DO.LeftJoin(table, on...))
|
||||
}
|
||||
|
||||
func (r resourcePsrDo) RightJoin(table schema.Tabler, on ...field.Expr) *resourcePsrDo {
|
||||
return r.withDO(r.DO.RightJoin(table, on...))
|
||||
}
|
||||
|
||||
func (r resourcePsrDo) Group(cols ...field.Expr) *resourcePsrDo {
|
||||
return r.withDO(r.DO.Group(cols...))
|
||||
}
|
||||
|
||||
func (r resourcePsrDo) Having(conds ...gen.Condition) *resourcePsrDo {
|
||||
return r.withDO(r.DO.Having(conds...))
|
||||
}
|
||||
|
||||
func (r resourcePsrDo) Limit(limit int) *resourcePsrDo {
|
||||
return r.withDO(r.DO.Limit(limit))
|
||||
}
|
||||
|
||||
func (r resourcePsrDo) Offset(offset int) *resourcePsrDo {
|
||||
return r.withDO(r.DO.Offset(offset))
|
||||
}
|
||||
|
||||
func (r resourcePsrDo) Scopes(funcs ...func(gen.Dao) gen.Dao) *resourcePsrDo {
|
||||
return r.withDO(r.DO.Scopes(funcs...))
|
||||
}
|
||||
|
||||
func (r resourcePsrDo) Unscoped() *resourcePsrDo {
|
||||
return r.withDO(r.DO.Unscoped())
|
||||
}
|
||||
|
||||
func (r resourcePsrDo) Create(values ...*models.ResourcePsr) error {
|
||||
if len(values) == 0 {
|
||||
return nil
|
||||
}
|
||||
return r.DO.Create(values)
|
||||
}
|
||||
|
||||
func (r resourcePsrDo) CreateInBatches(values []*models.ResourcePsr, 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 resourcePsrDo) Save(values ...*models.ResourcePsr) error {
|
||||
if len(values) == 0 {
|
||||
return nil
|
||||
}
|
||||
return r.DO.Save(values)
|
||||
}
|
||||
|
||||
func (r resourcePsrDo) First() (*models.ResourcePsr, error) {
|
||||
if result, err := r.DO.First(); err != nil {
|
||||
return nil, err
|
||||
} else {
|
||||
return result.(*models.ResourcePsr), nil
|
||||
}
|
||||
}
|
||||
|
||||
func (r resourcePsrDo) Take() (*models.ResourcePsr, error) {
|
||||
if result, err := r.DO.Take(); err != nil {
|
||||
return nil, err
|
||||
} else {
|
||||
return result.(*models.ResourcePsr), nil
|
||||
}
|
||||
}
|
||||
|
||||
func (r resourcePsrDo) Last() (*models.ResourcePsr, error) {
|
||||
if result, err := r.DO.Last(); err != nil {
|
||||
return nil, err
|
||||
} else {
|
||||
return result.(*models.ResourcePsr), nil
|
||||
}
|
||||
}
|
||||
|
||||
func (r resourcePsrDo) Find() ([]*models.ResourcePsr, error) {
|
||||
result, err := r.DO.Find()
|
||||
return result.([]*models.ResourcePsr), err
|
||||
}
|
||||
|
||||
func (r resourcePsrDo) FindInBatch(batchSize int, fc func(tx gen.Dao, batch int) error) (results []*models.ResourcePsr, err error) {
|
||||
buf := make([]*models.ResourcePsr, 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 resourcePsrDo) FindInBatches(result *[]*models.ResourcePsr, batchSize int, fc func(tx gen.Dao, batch int) error) error {
|
||||
return r.DO.FindInBatches(result, batchSize, fc)
|
||||
}
|
||||
|
||||
func (r resourcePsrDo) Attrs(attrs ...field.AssignExpr) *resourcePsrDo {
|
||||
return r.withDO(r.DO.Attrs(attrs...))
|
||||
}
|
||||
|
||||
func (r resourcePsrDo) Assign(attrs ...field.AssignExpr) *resourcePsrDo {
|
||||
return r.withDO(r.DO.Assign(attrs...))
|
||||
}
|
||||
|
||||
func (r resourcePsrDo) Joins(fields ...field.RelationField) *resourcePsrDo {
|
||||
for _, _f := range fields {
|
||||
r = *r.withDO(r.DO.Joins(_f))
|
||||
}
|
||||
return &r
|
||||
}
|
||||
|
||||
func (r resourcePsrDo) Preload(fields ...field.RelationField) *resourcePsrDo {
|
||||
for _, _f := range fields {
|
||||
r = *r.withDO(r.DO.Preload(_f))
|
||||
}
|
||||
return &r
|
||||
}
|
||||
|
||||
func (r resourcePsrDo) FirstOrInit() (*models.ResourcePsr, error) {
|
||||
if result, err := r.DO.FirstOrInit(); err != nil {
|
||||
return nil, err
|
||||
} else {
|
||||
return result.(*models.ResourcePsr), nil
|
||||
}
|
||||
}
|
||||
|
||||
func (r resourcePsrDo) FirstOrCreate() (*models.ResourcePsr, error) {
|
||||
if result, err := r.DO.FirstOrCreate(); err != nil {
|
||||
return nil, err
|
||||
} else {
|
||||
return result.(*models.ResourcePsr), nil
|
||||
}
|
||||
}
|
||||
|
||||
func (r resourcePsrDo) FindByPage(offset int, limit int) (result []*models.ResourcePsr, 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 resourcePsrDo) 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 resourcePsrDo) Scan(result interface{}) (err error) {
|
||||
return r.DO.Scan(result)
|
||||
}
|
||||
|
||||
func (r resourcePsrDo) Delete(models ...*models.ResourcePsr) (result gen.ResultInfo, err error) {
|
||||
return r.DO.Delete(models)
|
||||
}
|
||||
|
||||
func (r *resourcePsrDo) withDO(do gen.Dao) *resourcePsrDo {
|
||||
r.DO = *do.(*gen.DO)
|
||||
return r
|
||||
}
|
||||
@@ -1,355 +0,0 @@
|
||||
// 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 newResourcePss(db *gorm.DB, opts ...gen.DOOption) resourcePss {
|
||||
_resourcePss := resourcePss{}
|
||||
|
||||
_resourcePss.resourcePssDo.UseDB(db, opts...)
|
||||
_resourcePss.resourcePssDo.UseModel(&models.ResourcePss{})
|
||||
|
||||
tableName := _resourcePss.resourcePssDo.TableName()
|
||||
_resourcePss.ALL = field.NewAsterisk(tableName)
|
||||
_resourcePss.ID = field.NewInt32(tableName, "id")
|
||||
_resourcePss.ResourceID = field.NewInt32(tableName, "resource_id")
|
||||
_resourcePss.Type = field.NewInt32(tableName, "type")
|
||||
_resourcePss.Live = field.NewInt32(tableName, "live")
|
||||
_resourcePss.Expire = field.NewField(tableName, "expire")
|
||||
_resourcePss.Quota = field.NewInt32(tableName, "quota")
|
||||
_resourcePss.Used = field.NewInt32(tableName, "used")
|
||||
_resourcePss.DailyLimit = field.NewInt32(tableName, "daily_limit")
|
||||
_resourcePss.DailyUsed = field.NewInt32(tableName, "daily_used")
|
||||
_resourcePss.DailyLast = field.NewField(tableName, "daily_last")
|
||||
|
||||
_resourcePss.fillFieldMap()
|
||||
|
||||
return _resourcePss
|
||||
}
|
||||
|
||||
type resourcePss struct {
|
||||
resourcePssDo
|
||||
|
||||
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 resourcePss) Table(newTableName string) *resourcePss {
|
||||
r.resourcePssDo.UseTable(newTableName)
|
||||
return r.updateTableName(newTableName)
|
||||
}
|
||||
|
||||
func (r resourcePss) As(alias string) *resourcePss {
|
||||
r.resourcePssDo.DO = *(r.resourcePssDo.As(alias).(*gen.DO))
|
||||
return r.updateTableName(alias)
|
||||
}
|
||||
|
||||
func (r *resourcePss) updateTableName(table string) *resourcePss {
|
||||
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 *resourcePss) 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 *resourcePss) 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 resourcePss) clone(db *gorm.DB) resourcePss {
|
||||
r.resourcePssDo.ReplaceConnPool(db.Statement.ConnPool)
|
||||
return r
|
||||
}
|
||||
|
||||
func (r resourcePss) replaceDB(db *gorm.DB) resourcePss {
|
||||
r.resourcePssDo.ReplaceDB(db)
|
||||
return r
|
||||
}
|
||||
|
||||
type resourcePssDo struct{ gen.DO }
|
||||
|
||||
func (r resourcePssDo) Debug() *resourcePssDo {
|
||||
return r.withDO(r.DO.Debug())
|
||||
}
|
||||
|
||||
func (r resourcePssDo) WithContext(ctx context.Context) *resourcePssDo {
|
||||
return r.withDO(r.DO.WithContext(ctx))
|
||||
}
|
||||
|
||||
func (r resourcePssDo) ReadDB() *resourcePssDo {
|
||||
return r.Clauses(dbresolver.Read)
|
||||
}
|
||||
|
||||
func (r resourcePssDo) WriteDB() *resourcePssDo {
|
||||
return r.Clauses(dbresolver.Write)
|
||||
}
|
||||
|
||||
func (r resourcePssDo) Session(config *gorm.Session) *resourcePssDo {
|
||||
return r.withDO(r.DO.Session(config))
|
||||
}
|
||||
|
||||
func (r resourcePssDo) Clauses(conds ...clause.Expression) *resourcePssDo {
|
||||
return r.withDO(r.DO.Clauses(conds...))
|
||||
}
|
||||
|
||||
func (r resourcePssDo) Returning(value interface{}, columns ...string) *resourcePssDo {
|
||||
return r.withDO(r.DO.Returning(value, columns...))
|
||||
}
|
||||
|
||||
func (r resourcePssDo) Not(conds ...gen.Condition) *resourcePssDo {
|
||||
return r.withDO(r.DO.Not(conds...))
|
||||
}
|
||||
|
||||
func (r resourcePssDo) Or(conds ...gen.Condition) *resourcePssDo {
|
||||
return r.withDO(r.DO.Or(conds...))
|
||||
}
|
||||
|
||||
func (r resourcePssDo) Select(conds ...field.Expr) *resourcePssDo {
|
||||
return r.withDO(r.DO.Select(conds...))
|
||||
}
|
||||
|
||||
func (r resourcePssDo) Where(conds ...gen.Condition) *resourcePssDo {
|
||||
return r.withDO(r.DO.Where(conds...))
|
||||
}
|
||||
|
||||
func (r resourcePssDo) Order(conds ...field.Expr) *resourcePssDo {
|
||||
return r.withDO(r.DO.Order(conds...))
|
||||
}
|
||||
|
||||
func (r resourcePssDo) Distinct(cols ...field.Expr) *resourcePssDo {
|
||||
return r.withDO(r.DO.Distinct(cols...))
|
||||
}
|
||||
|
||||
func (r resourcePssDo) Omit(cols ...field.Expr) *resourcePssDo {
|
||||
return r.withDO(r.DO.Omit(cols...))
|
||||
}
|
||||
|
||||
func (r resourcePssDo) Join(table schema.Tabler, on ...field.Expr) *resourcePssDo {
|
||||
return r.withDO(r.DO.Join(table, on...))
|
||||
}
|
||||
|
||||
func (r resourcePssDo) LeftJoin(table schema.Tabler, on ...field.Expr) *resourcePssDo {
|
||||
return r.withDO(r.DO.LeftJoin(table, on...))
|
||||
}
|
||||
|
||||
func (r resourcePssDo) RightJoin(table schema.Tabler, on ...field.Expr) *resourcePssDo {
|
||||
return r.withDO(r.DO.RightJoin(table, on...))
|
||||
}
|
||||
|
||||
func (r resourcePssDo) Group(cols ...field.Expr) *resourcePssDo {
|
||||
return r.withDO(r.DO.Group(cols...))
|
||||
}
|
||||
|
||||
func (r resourcePssDo) Having(conds ...gen.Condition) *resourcePssDo {
|
||||
return r.withDO(r.DO.Having(conds...))
|
||||
}
|
||||
|
||||
func (r resourcePssDo) Limit(limit int) *resourcePssDo {
|
||||
return r.withDO(r.DO.Limit(limit))
|
||||
}
|
||||
|
||||
func (r resourcePssDo) Offset(offset int) *resourcePssDo {
|
||||
return r.withDO(r.DO.Offset(offset))
|
||||
}
|
||||
|
||||
func (r resourcePssDo) Scopes(funcs ...func(gen.Dao) gen.Dao) *resourcePssDo {
|
||||
return r.withDO(r.DO.Scopes(funcs...))
|
||||
}
|
||||
|
||||
func (r resourcePssDo) Unscoped() *resourcePssDo {
|
||||
return r.withDO(r.DO.Unscoped())
|
||||
}
|
||||
|
||||
func (r resourcePssDo) Create(values ...*models.ResourcePss) error {
|
||||
if len(values) == 0 {
|
||||
return nil
|
||||
}
|
||||
return r.DO.Create(values)
|
||||
}
|
||||
|
||||
func (r resourcePssDo) CreateInBatches(values []*models.ResourcePss, 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 resourcePssDo) Save(values ...*models.ResourcePss) error {
|
||||
if len(values) == 0 {
|
||||
return nil
|
||||
}
|
||||
return r.DO.Save(values)
|
||||
}
|
||||
|
||||
func (r resourcePssDo) First() (*models.ResourcePss, error) {
|
||||
if result, err := r.DO.First(); err != nil {
|
||||
return nil, err
|
||||
} else {
|
||||
return result.(*models.ResourcePss), nil
|
||||
}
|
||||
}
|
||||
|
||||
func (r resourcePssDo) Take() (*models.ResourcePss, error) {
|
||||
if result, err := r.DO.Take(); err != nil {
|
||||
return nil, err
|
||||
} else {
|
||||
return result.(*models.ResourcePss), nil
|
||||
}
|
||||
}
|
||||
|
||||
func (r resourcePssDo) Last() (*models.ResourcePss, error) {
|
||||
if result, err := r.DO.Last(); err != nil {
|
||||
return nil, err
|
||||
} else {
|
||||
return result.(*models.ResourcePss), nil
|
||||
}
|
||||
}
|
||||
|
||||
func (r resourcePssDo) Find() ([]*models.ResourcePss, error) {
|
||||
result, err := r.DO.Find()
|
||||
return result.([]*models.ResourcePss), err
|
||||
}
|
||||
|
||||
func (r resourcePssDo) FindInBatch(batchSize int, fc func(tx gen.Dao, batch int) error) (results []*models.ResourcePss, err error) {
|
||||
buf := make([]*models.ResourcePss, 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 resourcePssDo) FindInBatches(result *[]*models.ResourcePss, batchSize int, fc func(tx gen.Dao, batch int) error) error {
|
||||
return r.DO.FindInBatches(result, batchSize, fc)
|
||||
}
|
||||
|
||||
func (r resourcePssDo) Attrs(attrs ...field.AssignExpr) *resourcePssDo {
|
||||
return r.withDO(r.DO.Attrs(attrs...))
|
||||
}
|
||||
|
||||
func (r resourcePssDo) Assign(attrs ...field.AssignExpr) *resourcePssDo {
|
||||
return r.withDO(r.DO.Assign(attrs...))
|
||||
}
|
||||
|
||||
func (r resourcePssDo) Joins(fields ...field.RelationField) *resourcePssDo {
|
||||
for _, _f := range fields {
|
||||
r = *r.withDO(r.DO.Joins(_f))
|
||||
}
|
||||
return &r
|
||||
}
|
||||
|
||||
func (r resourcePssDo) Preload(fields ...field.RelationField) *resourcePssDo {
|
||||
for _, _f := range fields {
|
||||
r = *r.withDO(r.DO.Preload(_f))
|
||||
}
|
||||
return &r
|
||||
}
|
||||
|
||||
func (r resourcePssDo) FirstOrInit() (*models.ResourcePss, error) {
|
||||
if result, err := r.DO.FirstOrInit(); err != nil {
|
||||
return nil, err
|
||||
} else {
|
||||
return result.(*models.ResourcePss), nil
|
||||
}
|
||||
}
|
||||
|
||||
func (r resourcePssDo) FirstOrCreate() (*models.ResourcePss, error) {
|
||||
if result, err := r.DO.FirstOrCreate(); err != nil {
|
||||
return nil, err
|
||||
} else {
|
||||
return result.(*models.ResourcePss), nil
|
||||
}
|
||||
}
|
||||
|
||||
func (r resourcePssDo) FindByPage(offset int, limit int) (result []*models.ResourcePss, 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 resourcePssDo) 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 resourcePssDo) Scan(result interface{}) (err error) {
|
||||
return r.DO.Scan(result)
|
||||
}
|
||||
|
||||
func (r resourcePssDo) Delete(models ...*models.ResourcePss) (result gen.ResultInfo, err error) {
|
||||
return r.DO.Delete(models)
|
||||
}
|
||||
|
||||
func (r *resourcePssDo) withDO(do gen.Dao) *resourcePssDo {
|
||||
r.DO = *do.(*gen.DO)
|
||||
return r
|
||||
}
|
||||
355
web/queries/resource_short.gen.go
Normal file
355
web/queries/resource_short.gen.go
Normal file
@@ -0,0 +1,355 @@
|
||||
// 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
|
||||
}
|
||||
Reference in New Issue
Block a user