475 lines
12 KiB
Go
475 lines
12 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 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.Code = field.NewString(tableName, "code")
|
|
_resourceLong.Live = field.NewInt32(tableName, "live")
|
|
_resourceLong.Type = field.NewInt(tableName, "type")
|
|
_resourceLong.Quota = field.NewInt32(tableName, "quota")
|
|
_resourceLong.ExpireAt = field.NewTime(tableName, "expire_at")
|
|
_resourceLong.Used = field.NewInt32(tableName, "used")
|
|
_resourceLong.Daily = field.NewInt32(tableName, "daily")
|
|
_resourceLong.LastAt = field.NewTime(tableName, "last_at")
|
|
_resourceLong.Sku = resourceLongHasOneSku{
|
|
db: db.Session(&gorm.Session{}),
|
|
|
|
RelationField: field.NewRelation("Sku", "models.ProductSku"),
|
|
Product: struct {
|
|
field.RelationField
|
|
Skus struct {
|
|
field.RelationField
|
|
}
|
|
}{
|
|
RelationField: field.NewRelation("Sku.Product", "models.Product"),
|
|
Skus: struct {
|
|
field.RelationField
|
|
}{
|
|
RelationField: field.NewRelation("Sku.Product.Skus", "models.ProductSku"),
|
|
},
|
|
},
|
|
Discount: struct {
|
|
field.RelationField
|
|
}{
|
|
RelationField: field.NewRelation("Sku.Discount", "models.ProductDiscount"),
|
|
},
|
|
}
|
|
|
|
_resourceLong.fillFieldMap()
|
|
|
|
return _resourceLong
|
|
}
|
|
|
|
type resourceLong struct {
|
|
resourceLongDo
|
|
|
|
ALL field.Asterisk
|
|
ID field.Int32
|
|
ResourceID field.Int32
|
|
Code field.String
|
|
Live field.Int32
|
|
Type field.Int
|
|
Quota field.Int32
|
|
ExpireAt field.Time
|
|
Used field.Int32
|
|
Daily field.Int32
|
|
LastAt field.Time
|
|
Sku resourceLongHasOneSku
|
|
|
|
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.Code = field.NewString(table, "code")
|
|
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 *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, 11)
|
|
r.fieldMap["id"] = r.ID
|
|
r.fieldMap["resource_id"] = r.ResourceID
|
|
r.fieldMap["code"] = r.Code
|
|
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 resourceLong) clone(db *gorm.DB) resourceLong {
|
|
r.resourceLongDo.ReplaceConnPool(db.Statement.ConnPool)
|
|
r.Sku.db = db.Session(&gorm.Session{Initialized: true})
|
|
r.Sku.db.Statement.ConnPool = db.Statement.ConnPool
|
|
return r
|
|
}
|
|
|
|
func (r resourceLong) replaceDB(db *gorm.DB) resourceLong {
|
|
r.resourceLongDo.ReplaceDB(db)
|
|
r.Sku.db = db.Session(&gorm.Session{})
|
|
return r
|
|
}
|
|
|
|
type resourceLongHasOneSku struct {
|
|
db *gorm.DB
|
|
|
|
field.RelationField
|
|
|
|
Product struct {
|
|
field.RelationField
|
|
Skus struct {
|
|
field.RelationField
|
|
}
|
|
}
|
|
Discount struct {
|
|
field.RelationField
|
|
}
|
|
}
|
|
|
|
func (a resourceLongHasOneSku) Where(conds ...field.Expr) *resourceLongHasOneSku {
|
|
if len(conds) == 0 {
|
|
return &a
|
|
}
|
|
|
|
exprs := make([]clause.Expression, 0, len(conds))
|
|
for _, cond := range conds {
|
|
exprs = append(exprs, cond.BeCond().(clause.Expression))
|
|
}
|
|
a.db = a.db.Clauses(clause.Where{Exprs: exprs})
|
|
return &a
|
|
}
|
|
|
|
func (a resourceLongHasOneSku) WithContext(ctx context.Context) *resourceLongHasOneSku {
|
|
a.db = a.db.WithContext(ctx)
|
|
return &a
|
|
}
|
|
|
|
func (a resourceLongHasOneSku) Session(session *gorm.Session) *resourceLongHasOneSku {
|
|
a.db = a.db.Session(session)
|
|
return &a
|
|
}
|
|
|
|
func (a resourceLongHasOneSku) Model(m *models.ResourceLong) *resourceLongHasOneSkuTx {
|
|
return &resourceLongHasOneSkuTx{a.db.Model(m).Association(a.Name())}
|
|
}
|
|
|
|
func (a resourceLongHasOneSku) Unscoped() *resourceLongHasOneSku {
|
|
a.db = a.db.Unscoped()
|
|
return &a
|
|
}
|
|
|
|
type resourceLongHasOneSkuTx struct{ tx *gorm.Association }
|
|
|
|
func (a resourceLongHasOneSkuTx) Find() (result *models.ProductSku, err error) {
|
|
return result, a.tx.Find(&result)
|
|
}
|
|
|
|
func (a resourceLongHasOneSkuTx) Append(values ...*models.ProductSku) (err error) {
|
|
targetValues := make([]interface{}, len(values))
|
|
for i, v := range values {
|
|
targetValues[i] = v
|
|
}
|
|
return a.tx.Append(targetValues...)
|
|
}
|
|
|
|
func (a resourceLongHasOneSkuTx) Replace(values ...*models.ProductSku) (err error) {
|
|
targetValues := make([]interface{}, len(values))
|
|
for i, v := range values {
|
|
targetValues[i] = v
|
|
}
|
|
return a.tx.Replace(targetValues...)
|
|
}
|
|
|
|
func (a resourceLongHasOneSkuTx) Delete(values ...*models.ProductSku) (err error) {
|
|
targetValues := make([]interface{}, len(values))
|
|
for i, v := range values {
|
|
targetValues[i] = v
|
|
}
|
|
return a.tx.Delete(targetValues...)
|
|
}
|
|
|
|
func (a resourceLongHasOneSkuTx) Clear() error {
|
|
return a.tx.Clear()
|
|
}
|
|
|
|
func (a resourceLongHasOneSkuTx) Count() int64 {
|
|
return a.tx.Count()
|
|
}
|
|
|
|
func (a resourceLongHasOneSkuTx) Unscoped() *resourceLongHasOneSkuTx {
|
|
a.tx = a.tx.Unscoped()
|
|
return &a
|
|
}
|
|
|
|
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
|
|
}
|