449 lines
13 KiB
Go
449 lines
13 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 query
|
|
|
|
import (
|
|
"context"
|
|
"strings"
|
|
|
|
"gorm.io/gorm"
|
|
"gorm.io/gorm/clause"
|
|
"gorm.io/gorm/schema"
|
|
|
|
"gorm.io/gen"
|
|
"gorm.io/gen/field"
|
|
|
|
"gorm.io/plugin/dbresolver"
|
|
|
|
"gitea.youtukeji.com.cn/xiabin/youtu_server/gorm-gen/dao/model"
|
|
"gitea.youtukeji.com.cn/xiabin/youtu_server/gorm-gen/querier"
|
|
)
|
|
|
|
func newGameScore(db *gorm.DB, opts ...gen.DOOption) gameScore {
|
|
_gameScore := gameScore{}
|
|
|
|
_gameScore.gameScoreDo.UseDB(db, opts...)
|
|
_gameScore.gameScoreDo.UseModel(&model.GameScore{})
|
|
|
|
tableName := _gameScore.gameScoreDo.TableName()
|
|
_gameScore.ALL = field.NewAsterisk(tableName)
|
|
_gameScore.ID = field.NewUint64(tableName, "id")
|
|
_gameScore.AppAccount = field.NewUint32(tableName, "app_account")
|
|
_gameScore.AppUserID = field.NewUint64(tableName, "app_user_id")
|
|
_gameScore.Score = field.NewUint32(tableName, "score")
|
|
_gameScore.T = field.NewUint32(tableName, "t")
|
|
|
|
_gameScore.fillFieldMap()
|
|
|
|
return _gameScore
|
|
}
|
|
|
|
type gameScore struct {
|
|
gameScoreDo
|
|
|
|
ALL field.Asterisk
|
|
ID field.Uint64
|
|
AppAccount field.Uint32
|
|
AppUserID field.Uint64
|
|
Score field.Uint32
|
|
T field.Uint32
|
|
|
|
fieldMap map[string]field.Expr
|
|
}
|
|
|
|
func (g gameScore) Table(newTableName string) *gameScore {
|
|
g.gameScoreDo.UseTable(newTableName)
|
|
return g.updateTableName(newTableName)
|
|
}
|
|
|
|
func (g gameScore) As(alias string) *gameScore {
|
|
g.gameScoreDo.DO = *(g.gameScoreDo.As(alias).(*gen.DO))
|
|
return g.updateTableName(alias)
|
|
}
|
|
|
|
func (g *gameScore) updateTableName(table string) *gameScore {
|
|
g.ALL = field.NewAsterisk(table)
|
|
g.ID = field.NewUint64(table, "id")
|
|
g.AppAccount = field.NewUint32(table, "app_account")
|
|
g.AppUserID = field.NewUint64(table, "app_user_id")
|
|
g.Score = field.NewUint32(table, "score")
|
|
g.T = field.NewUint32(table, "t")
|
|
|
|
g.fillFieldMap()
|
|
|
|
return g
|
|
}
|
|
|
|
func (g *gameScore) GetFieldByName(fieldName string) (field.OrderExpr, bool) {
|
|
_f, ok := g.fieldMap[fieldName]
|
|
if !ok || _f == nil {
|
|
return nil, false
|
|
}
|
|
_oe, ok := _f.(field.OrderExpr)
|
|
return _oe, ok
|
|
}
|
|
|
|
func (g *gameScore) fillFieldMap() {
|
|
g.fieldMap = make(map[string]field.Expr, 5)
|
|
g.fieldMap["id"] = g.ID
|
|
g.fieldMap["app_account"] = g.AppAccount
|
|
g.fieldMap["app_user_id"] = g.AppUserID
|
|
g.fieldMap["score"] = g.Score
|
|
g.fieldMap["t"] = g.T
|
|
}
|
|
|
|
func (g gameScore) clone(db *gorm.DB) gameScore {
|
|
g.gameScoreDo.ReplaceConnPool(db.Statement.ConnPool)
|
|
return g
|
|
}
|
|
|
|
func (g gameScore) replaceDB(db *gorm.DB) gameScore {
|
|
g.gameScoreDo.ReplaceDB(db)
|
|
return g
|
|
}
|
|
|
|
type gameScoreDo struct{ gen.DO }
|
|
|
|
type IGameScoreDo interface {
|
|
gen.SubQuery
|
|
Debug() IGameScoreDo
|
|
WithContext(ctx context.Context) IGameScoreDo
|
|
WithResult(fc func(tx gen.Dao)) gen.ResultInfo
|
|
ReplaceDB(db *gorm.DB)
|
|
ReadDB() IGameScoreDo
|
|
WriteDB() IGameScoreDo
|
|
As(alias string) gen.Dao
|
|
Session(config *gorm.Session) IGameScoreDo
|
|
Columns(cols ...field.Expr) gen.Columns
|
|
Clauses(conds ...clause.Expression) IGameScoreDo
|
|
Not(conds ...gen.Condition) IGameScoreDo
|
|
Or(conds ...gen.Condition) IGameScoreDo
|
|
Select(conds ...field.Expr) IGameScoreDo
|
|
Where(conds ...gen.Condition) IGameScoreDo
|
|
Order(conds ...field.Expr) IGameScoreDo
|
|
Distinct(cols ...field.Expr) IGameScoreDo
|
|
Omit(cols ...field.Expr) IGameScoreDo
|
|
Join(table schema.Tabler, on ...field.Expr) IGameScoreDo
|
|
LeftJoin(table schema.Tabler, on ...field.Expr) IGameScoreDo
|
|
RightJoin(table schema.Tabler, on ...field.Expr) IGameScoreDo
|
|
Group(cols ...field.Expr) IGameScoreDo
|
|
Having(conds ...gen.Condition) IGameScoreDo
|
|
Limit(limit int) IGameScoreDo
|
|
Offset(offset int) IGameScoreDo
|
|
Count() (count int64, err error)
|
|
Scopes(funcs ...func(gen.Dao) gen.Dao) IGameScoreDo
|
|
Unscoped() IGameScoreDo
|
|
Create(values ...*model.GameScore) error
|
|
CreateInBatches(values []*model.GameScore, batchSize int) error
|
|
Save(values ...*model.GameScore) error
|
|
First() (*model.GameScore, error)
|
|
Take() (*model.GameScore, error)
|
|
Last() (*model.GameScore, error)
|
|
Find() ([]*model.GameScore, error)
|
|
FindInBatch(batchSize int, fc func(tx gen.Dao, batch int) error) (results []*model.GameScore, err error)
|
|
FindInBatches(result *[]*model.GameScore, batchSize int, fc func(tx gen.Dao, batch int) error) error
|
|
Pluck(column field.Expr, dest interface{}) error
|
|
Delete(...*model.GameScore) (info gen.ResultInfo, err error)
|
|
Update(column field.Expr, value interface{}) (info gen.ResultInfo, err error)
|
|
UpdateSimple(columns ...field.AssignExpr) (info gen.ResultInfo, err error)
|
|
Updates(value interface{}) (info gen.ResultInfo, err error)
|
|
UpdateColumn(column field.Expr, value interface{}) (info gen.ResultInfo, err error)
|
|
UpdateColumnSimple(columns ...field.AssignExpr) (info gen.ResultInfo, err error)
|
|
UpdateColumns(value interface{}) (info gen.ResultInfo, err error)
|
|
UpdateFrom(q gen.SubQuery) gen.Dao
|
|
Attrs(attrs ...field.AssignExpr) IGameScoreDo
|
|
Assign(attrs ...field.AssignExpr) IGameScoreDo
|
|
Joins(fields ...field.RelationField) IGameScoreDo
|
|
Preload(fields ...field.RelationField) IGameScoreDo
|
|
FirstOrInit() (*model.GameScore, error)
|
|
FirstOrCreate() (*model.GameScore, error)
|
|
FindByPage(offset int, limit int) (result []*model.GameScore, count int64, err error)
|
|
ScanByPage(result interface{}, offset int, limit int) (count int64, err error)
|
|
Scan(result interface{}) (err error)
|
|
Returning(value interface{}, columns ...string) IGameScoreDo
|
|
UnderlyingDB() *gorm.DB
|
|
schema.Tabler
|
|
|
|
GetUserRank(appId uint32, userId uint64, t uint32) (result querier.RankingData, err error)
|
|
FindDistinctRanking() (result []*model.GameScore, err error)
|
|
}
|
|
|
|
// SELECT
|
|
//
|
|
// app_user.nickname,
|
|
// app_user.avatar,
|
|
// gs.score,
|
|
// gs.app_user_id,
|
|
// gs.t_rank
|
|
// FROM
|
|
// (
|
|
// SELECT
|
|
// game_score.score,
|
|
// game_score.app_user_id,
|
|
// game_score.app_account,
|
|
// rank() OVER (ORDER BY game_score.score DESC) t_rank
|
|
// FROM
|
|
// game_score
|
|
// WHERE
|
|
// game_score.t = ?
|
|
// AND game_score.app_account = ?
|
|
// ) AS gs
|
|
// LEFT JOIN app_user ON app_user.id = gs.app_user_id
|
|
// WHERE
|
|
// gs.app_user_id = ?
|
|
// LIMIT 1;
|
|
func (g gameScoreDo) GetUserRank(appId uint32, userId uint64, t uint32) (result querier.RankingData, err error) {
|
|
var generateSQL strings.Builder
|
|
generateSQL.WriteString("SELECT app_user.nickname, app_user.avatar, gs.score, gs.app_user_id, gs.t_rank FROM ( SELECT game_score.score, game_score.app_user_id, game_score.app_account, rank() OVER (ORDER BY game_score.score DESC) t_rank FROM game_score WHERE game_score.t = ? AND game_score.app_account = ? ) AS gs LEFT JOIN app_user ON app_user.id = gs.app_user_id WHERE gs.app_user_id = ? LIMIT 1; ")
|
|
|
|
var executeSQL *gorm.DB
|
|
executeSQL = g.UnderlyingDB().Raw(generateSQL.String()).Take(&result) // ignore_security_alert
|
|
err = executeSQL.Error
|
|
|
|
return
|
|
}
|
|
|
|
// select DISTINCT app_account,t from game_score
|
|
func (g gameScoreDo) FindDistinctRanking() (result []*model.GameScore, err error) {
|
|
var generateSQL strings.Builder
|
|
generateSQL.WriteString("select DISTINCT app_account,t from game_score ")
|
|
|
|
var executeSQL *gorm.DB
|
|
executeSQL = g.UnderlyingDB().Raw(generateSQL.String()).Find(&result) // ignore_security_alert
|
|
err = executeSQL.Error
|
|
|
|
return
|
|
}
|
|
|
|
func (g gameScoreDo) Debug() IGameScoreDo {
|
|
return g.withDO(g.DO.Debug())
|
|
}
|
|
|
|
func (g gameScoreDo) WithContext(ctx context.Context) IGameScoreDo {
|
|
return g.withDO(g.DO.WithContext(ctx))
|
|
}
|
|
|
|
func (g gameScoreDo) ReadDB() IGameScoreDo {
|
|
return g.Clauses(dbresolver.Read)
|
|
}
|
|
|
|
func (g gameScoreDo) WriteDB() IGameScoreDo {
|
|
return g.Clauses(dbresolver.Write)
|
|
}
|
|
|
|
func (g gameScoreDo) Session(config *gorm.Session) IGameScoreDo {
|
|
return g.withDO(g.DO.Session(config))
|
|
}
|
|
|
|
func (g gameScoreDo) Clauses(conds ...clause.Expression) IGameScoreDo {
|
|
return g.withDO(g.DO.Clauses(conds...))
|
|
}
|
|
|
|
func (g gameScoreDo) Returning(value interface{}, columns ...string) IGameScoreDo {
|
|
return g.withDO(g.DO.Returning(value, columns...))
|
|
}
|
|
|
|
func (g gameScoreDo) Not(conds ...gen.Condition) IGameScoreDo {
|
|
return g.withDO(g.DO.Not(conds...))
|
|
}
|
|
|
|
func (g gameScoreDo) Or(conds ...gen.Condition) IGameScoreDo {
|
|
return g.withDO(g.DO.Or(conds...))
|
|
}
|
|
|
|
func (g gameScoreDo) Select(conds ...field.Expr) IGameScoreDo {
|
|
return g.withDO(g.DO.Select(conds...))
|
|
}
|
|
|
|
func (g gameScoreDo) Where(conds ...gen.Condition) IGameScoreDo {
|
|
return g.withDO(g.DO.Where(conds...))
|
|
}
|
|
|
|
func (g gameScoreDo) Order(conds ...field.Expr) IGameScoreDo {
|
|
return g.withDO(g.DO.Order(conds...))
|
|
}
|
|
|
|
func (g gameScoreDo) Distinct(cols ...field.Expr) IGameScoreDo {
|
|
return g.withDO(g.DO.Distinct(cols...))
|
|
}
|
|
|
|
func (g gameScoreDo) Omit(cols ...field.Expr) IGameScoreDo {
|
|
return g.withDO(g.DO.Omit(cols...))
|
|
}
|
|
|
|
func (g gameScoreDo) Join(table schema.Tabler, on ...field.Expr) IGameScoreDo {
|
|
return g.withDO(g.DO.Join(table, on...))
|
|
}
|
|
|
|
func (g gameScoreDo) LeftJoin(table schema.Tabler, on ...field.Expr) IGameScoreDo {
|
|
return g.withDO(g.DO.LeftJoin(table, on...))
|
|
}
|
|
|
|
func (g gameScoreDo) RightJoin(table schema.Tabler, on ...field.Expr) IGameScoreDo {
|
|
return g.withDO(g.DO.RightJoin(table, on...))
|
|
}
|
|
|
|
func (g gameScoreDo) Group(cols ...field.Expr) IGameScoreDo {
|
|
return g.withDO(g.DO.Group(cols...))
|
|
}
|
|
|
|
func (g gameScoreDo) Having(conds ...gen.Condition) IGameScoreDo {
|
|
return g.withDO(g.DO.Having(conds...))
|
|
}
|
|
|
|
func (g gameScoreDo) Limit(limit int) IGameScoreDo {
|
|
return g.withDO(g.DO.Limit(limit))
|
|
}
|
|
|
|
func (g gameScoreDo) Offset(offset int) IGameScoreDo {
|
|
return g.withDO(g.DO.Offset(offset))
|
|
}
|
|
|
|
func (g gameScoreDo) Scopes(funcs ...func(gen.Dao) gen.Dao) IGameScoreDo {
|
|
return g.withDO(g.DO.Scopes(funcs...))
|
|
}
|
|
|
|
func (g gameScoreDo) Unscoped() IGameScoreDo {
|
|
return g.withDO(g.DO.Unscoped())
|
|
}
|
|
|
|
func (g gameScoreDo) Create(values ...*model.GameScore) error {
|
|
if len(values) == 0 {
|
|
return nil
|
|
}
|
|
return g.DO.Create(values)
|
|
}
|
|
|
|
func (g gameScoreDo) CreateInBatches(values []*model.GameScore, batchSize int) error {
|
|
return g.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 (g gameScoreDo) Save(values ...*model.GameScore) error {
|
|
if len(values) == 0 {
|
|
return nil
|
|
}
|
|
return g.DO.Save(values)
|
|
}
|
|
|
|
func (g gameScoreDo) First() (*model.GameScore, error) {
|
|
if result, err := g.DO.First(); err != nil {
|
|
return nil, err
|
|
} else {
|
|
return result.(*model.GameScore), nil
|
|
}
|
|
}
|
|
|
|
func (g gameScoreDo) Take() (*model.GameScore, error) {
|
|
if result, err := g.DO.Take(); err != nil {
|
|
return nil, err
|
|
} else {
|
|
return result.(*model.GameScore), nil
|
|
}
|
|
}
|
|
|
|
func (g gameScoreDo) Last() (*model.GameScore, error) {
|
|
if result, err := g.DO.Last(); err != nil {
|
|
return nil, err
|
|
} else {
|
|
return result.(*model.GameScore), nil
|
|
}
|
|
}
|
|
|
|
func (g gameScoreDo) Find() ([]*model.GameScore, error) {
|
|
result, err := g.DO.Find()
|
|
return result.([]*model.GameScore), err
|
|
}
|
|
|
|
func (g gameScoreDo) FindInBatch(batchSize int, fc func(tx gen.Dao, batch int) error) (results []*model.GameScore, err error) {
|
|
buf := make([]*model.GameScore, 0, batchSize)
|
|
err = g.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 (g gameScoreDo) FindInBatches(result *[]*model.GameScore, batchSize int, fc func(tx gen.Dao, batch int) error) error {
|
|
return g.DO.FindInBatches(result, batchSize, fc)
|
|
}
|
|
|
|
func (g gameScoreDo) Attrs(attrs ...field.AssignExpr) IGameScoreDo {
|
|
return g.withDO(g.DO.Attrs(attrs...))
|
|
}
|
|
|
|
func (g gameScoreDo) Assign(attrs ...field.AssignExpr) IGameScoreDo {
|
|
return g.withDO(g.DO.Assign(attrs...))
|
|
}
|
|
|
|
func (g gameScoreDo) Joins(fields ...field.RelationField) IGameScoreDo {
|
|
for _, _f := range fields {
|
|
g = *g.withDO(g.DO.Joins(_f))
|
|
}
|
|
return &g
|
|
}
|
|
|
|
func (g gameScoreDo) Preload(fields ...field.RelationField) IGameScoreDo {
|
|
for _, _f := range fields {
|
|
g = *g.withDO(g.DO.Preload(_f))
|
|
}
|
|
return &g
|
|
}
|
|
|
|
func (g gameScoreDo) FirstOrInit() (*model.GameScore, error) {
|
|
if result, err := g.DO.FirstOrInit(); err != nil {
|
|
return nil, err
|
|
} else {
|
|
return result.(*model.GameScore), nil
|
|
}
|
|
}
|
|
|
|
func (g gameScoreDo) FirstOrCreate() (*model.GameScore, error) {
|
|
if result, err := g.DO.FirstOrCreate(); err != nil {
|
|
return nil, err
|
|
} else {
|
|
return result.(*model.GameScore), nil
|
|
}
|
|
}
|
|
|
|
func (g gameScoreDo) FindByPage(offset int, limit int) (result []*model.GameScore, count int64, err error) {
|
|
result, err = g.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 = g.Offset(-1).Limit(-1).Count()
|
|
return
|
|
}
|
|
|
|
func (g gameScoreDo) ScanByPage(result interface{}, offset int, limit int) (count int64, err error) {
|
|
count, err = g.Count()
|
|
if err != nil {
|
|
return
|
|
}
|
|
|
|
err = g.Offset(offset).Limit(limit).Scan(result)
|
|
return
|
|
}
|
|
|
|
func (g gameScoreDo) Scan(result interface{}) (err error) {
|
|
return g.DO.Scan(result)
|
|
}
|
|
|
|
func (g gameScoreDo) Delete(models ...*model.GameScore) (result gen.ResultInfo, err error) {
|
|
return g.DO.Delete(models)
|
|
}
|
|
|
|
func (g *gameScoreDo) withDO(do gen.Dao) *gameScoreDo {
|
|
g.DO = *do.(*gen.DO)
|
|
return g
|
|
}
|