diff --git a/game_open_api/internal/svc/service_context.go b/game_open_api/internal/svc/service_context.go index 481684c..30e0059 100644 --- a/game_open_api/internal/svc/service_context.go +++ b/game_open_api/internal/svc/service_context.go @@ -6,7 +6,7 @@ import ( "errors" "gitea.youtukeji.com.cn/xiabin/youtu_server/game_open_api/internal/config" "gitea.youtukeji.com.cn/xiabin/youtu_server/game_open_api/internal/logic/rankings" - "gitea.youtukeji.com.cn/xiabin/youtu_server/gorm-gen/query" + "gitea.youtukeji.com.cn/xiabin/youtu_server/gorm-gen/dao/query" redisCacher "gitea.youtukeji.com.cn/xiabin/youtu_server/gorm-gen/redis" helper "gitea.youtukeji.com.cn/youtu/openapi-helper" "github.com/go-gorm/caches/v4" diff --git a/gorm-gen/dao/model/game_score.gen.go b/gorm-gen/dao/model/game_score.gen.go index efa5626..9d37b99 100644 --- a/gorm-gen/dao/model/game_score.gen.go +++ b/gorm-gen/dao/model/game_score.gen.go @@ -4,15 +4,20 @@ package model +import ( + "time" +) + const TableNameGameScore = "game_score" // GameScore mapped from table type GameScore struct { - ID uint64 `gorm:"column:id;type:bigint unsigned;primaryKey;autoIncrement:true" json:"id"` - AppAccount uint32 `gorm:"column:app_account;type:int unsigned;not null;uniqueIndex:rank_list,priority:1;comment:小游戏id" json:"app_account"` // 小游戏id - AppUserID uint64 `gorm:"column:app_user_id;type:bigint unsigned;not null;uniqueIndex:rank_list,priority:3;index:user_id,priority:1;comment:用户id" json:"app_user_id"` // 用户id - Score uint32 `gorm:"column:score;type:int unsigned;not null;comment:得分" json:"score"` // 得分 - T uint32 `gorm:"column:t;type:tinyint unsigned;not null;uniqueIndex:rank_list,priority:2;comment:得分类型(区分相同小游戏中的不同模式得分)" json:"t"` // 得分类型(区分相同小游戏中的不同模式得分) + ID uint64 `gorm:"column:id;type:bigint unsigned;primaryKey;autoIncrement:true" json:"id"` + AppAccount uint32 `gorm:"column:app_account;type:int unsigned;not null;uniqueIndex:rank_list,priority:1;comment:小游戏id" json:"app_account"` // 小游戏id + AppUserID uint64 `gorm:"column:app_user_id;type:bigint unsigned;not null;uniqueIndex:rank_list,priority:3;index:user_id,priority:1;comment:用户id" json:"app_user_id"` // 用户id + Score uint32 `gorm:"column:score;type:int unsigned;not null;comment:得分" json:"score"` // 得分 + T uint32 `gorm:"column:t;type:tinyint unsigned;not null;uniqueIndex:rank_list,priority:2;comment:得分类型(区分相同小游戏中的不同模式得分)" json:"t"` // 得分类型(区分相同小游戏中的不同模式得分) + UpdatedAt time.Time `gorm:"column:updated_at;type:timestamp;not null;default:CURRENT_TIMESTAMP;comment:更新时间" json:"updated_at"` // 更新时间 } // TableName GameScore's table name diff --git a/gorm-gen/dao/query/app_account.gen.go b/gorm-gen/dao/query/app_account.gen.go index 87841f5..c523ce3 100644 --- a/gorm-gen/dao/query/app_account.gen.go +++ b/gorm-gen/dao/query/app_account.gen.go @@ -6,6 +6,7 @@ package query import ( "context" + "strings" "gorm.io/gorm" "gorm.io/gorm/clause" @@ -40,14 +41,14 @@ func newAppAccount(db *gorm.DB, opts ...gen.DOOption) appAccount { } type appAccount struct { - appAccountDo appAccountDo + appAccountDo ALL field.Asterisk ID field.Uint32 - Type field.Uint32 // 类型(0:抖音,1:微信) + Type field.Uint32 AppID field.String Secret field.String - Remark field.String // 备注 + Remark field.String DeletedAt field.Field fieldMap map[string]field.Expr @@ -77,16 +78,6 @@ func (a *appAccount) updateTableName(table string) *appAccount { return a } -func (a *appAccount) WithContext(ctx context.Context) *appAccountDo { - return a.appAccountDo.WithContext(ctx) -} - -func (a appAccount) TableName() string { return a.appAccountDo.TableName() } - -func (a appAccount) Alias() string { return a.appAccountDo.Alias() } - -func (a appAccount) Columns(cols ...field.Expr) gen.Columns { return a.appAccountDo.Columns(cols...) } - func (a *appAccount) GetFieldByName(fieldName string) (field.OrderExpr, bool) { _f, ok := a.fieldMap[fieldName] if !ok || _f == nil { @@ -118,95 +109,172 @@ func (a appAccount) replaceDB(db *gorm.DB) appAccount { type appAccountDo struct{ gen.DO } -func (a appAccountDo) Debug() *appAccountDo { +type IAppAccountDo interface { + gen.SubQuery + Debug() IAppAccountDo + WithContext(ctx context.Context) IAppAccountDo + WithResult(fc func(tx gen.Dao)) gen.ResultInfo + ReplaceDB(db *gorm.DB) + ReadDB() IAppAccountDo + WriteDB() IAppAccountDo + As(alias string) gen.Dao + Session(config *gorm.Session) IAppAccountDo + Columns(cols ...field.Expr) gen.Columns + Clauses(conds ...clause.Expression) IAppAccountDo + Not(conds ...gen.Condition) IAppAccountDo + Or(conds ...gen.Condition) IAppAccountDo + Select(conds ...field.Expr) IAppAccountDo + Where(conds ...gen.Condition) IAppAccountDo + Order(conds ...field.Expr) IAppAccountDo + Distinct(cols ...field.Expr) IAppAccountDo + Omit(cols ...field.Expr) IAppAccountDo + Join(table schema.Tabler, on ...field.Expr) IAppAccountDo + LeftJoin(table schema.Tabler, on ...field.Expr) IAppAccountDo + RightJoin(table schema.Tabler, on ...field.Expr) IAppAccountDo + Group(cols ...field.Expr) IAppAccountDo + Having(conds ...gen.Condition) IAppAccountDo + Limit(limit int) IAppAccountDo + Offset(offset int) IAppAccountDo + Count() (count int64, err error) + Scopes(funcs ...func(gen.Dao) gen.Dao) IAppAccountDo + Unscoped() IAppAccountDo + Create(values ...*model.AppAccount) error + CreateInBatches(values []*model.AppAccount, batchSize int) error + Save(values ...*model.AppAccount) error + First() (*model.AppAccount, error) + Take() (*model.AppAccount, error) + Last() (*model.AppAccount, error) + Find() ([]*model.AppAccount, error) + FindInBatch(batchSize int, fc func(tx gen.Dao, batch int) error) (results []*model.AppAccount, err error) + FindInBatches(result *[]*model.AppAccount, batchSize int, fc func(tx gen.Dao, batch int) error) error + Pluck(column field.Expr, dest interface{}) error + Delete(...*model.AppAccount) (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) IAppAccountDo + Assign(attrs ...field.AssignExpr) IAppAccountDo + Joins(fields ...field.RelationField) IAppAccountDo + Preload(fields ...field.RelationField) IAppAccountDo + FirstOrInit() (*model.AppAccount, error) + FirstOrCreate() (*model.AppAccount, error) + FindByPage(offset int, limit int) (result []*model.AppAccount, 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) IAppAccountDo + UnderlyingDB() *gorm.DB + schema.Tabler + + GetAppConfig() (result []*model.AppAccount, err error) +} + +// GetAppConfig 获取所有小游戏配置 +// +// select `app_id`,`secret`,`ecpm_value`,`ecpm_view`,`type` from `app_account` left join douyin_ecpm_config on app_account.id = douyin_ecpm_config.app_account_id +func (a appAccountDo) GetAppConfig() (result []*model.AppAccount, err error) { + var generateSQL strings.Builder + generateSQL.WriteString("select `app_id`,`secret`,`ecpm_value`,`ecpm_view`,`type` from `app_account` left join douyin_ecpm_config on app_account.id = douyin_ecpm_config.app_account_id ") + + var executeSQL *gorm.DB + executeSQL = a.UnderlyingDB().Raw(generateSQL.String()).Find(&result) // ignore_security_alert + err = executeSQL.Error + + return +} + +func (a appAccountDo) Debug() IAppAccountDo { return a.withDO(a.DO.Debug()) } -func (a appAccountDo) WithContext(ctx context.Context) *appAccountDo { +func (a appAccountDo) WithContext(ctx context.Context) IAppAccountDo { return a.withDO(a.DO.WithContext(ctx)) } -func (a appAccountDo) ReadDB() *appAccountDo { +func (a appAccountDo) ReadDB() IAppAccountDo { return a.Clauses(dbresolver.Read) } -func (a appAccountDo) WriteDB() *appAccountDo { +func (a appAccountDo) WriteDB() IAppAccountDo { return a.Clauses(dbresolver.Write) } -func (a appAccountDo) Session(config *gorm.Session) *appAccountDo { +func (a appAccountDo) Session(config *gorm.Session) IAppAccountDo { return a.withDO(a.DO.Session(config)) } -func (a appAccountDo) Clauses(conds ...clause.Expression) *appAccountDo { +func (a appAccountDo) Clauses(conds ...clause.Expression) IAppAccountDo { return a.withDO(a.DO.Clauses(conds...)) } -func (a appAccountDo) Returning(value interface{}, columns ...string) *appAccountDo { +func (a appAccountDo) Returning(value interface{}, columns ...string) IAppAccountDo { return a.withDO(a.DO.Returning(value, columns...)) } -func (a appAccountDo) Not(conds ...gen.Condition) *appAccountDo { +func (a appAccountDo) Not(conds ...gen.Condition) IAppAccountDo { return a.withDO(a.DO.Not(conds...)) } -func (a appAccountDo) Or(conds ...gen.Condition) *appAccountDo { +func (a appAccountDo) Or(conds ...gen.Condition) IAppAccountDo { return a.withDO(a.DO.Or(conds...)) } -func (a appAccountDo) Select(conds ...field.Expr) *appAccountDo { +func (a appAccountDo) Select(conds ...field.Expr) IAppAccountDo { return a.withDO(a.DO.Select(conds...)) } -func (a appAccountDo) Where(conds ...gen.Condition) *appAccountDo { +func (a appAccountDo) Where(conds ...gen.Condition) IAppAccountDo { return a.withDO(a.DO.Where(conds...)) } -func (a appAccountDo) Order(conds ...field.Expr) *appAccountDo { +func (a appAccountDo) Order(conds ...field.Expr) IAppAccountDo { return a.withDO(a.DO.Order(conds...)) } -func (a appAccountDo) Distinct(cols ...field.Expr) *appAccountDo { +func (a appAccountDo) Distinct(cols ...field.Expr) IAppAccountDo { return a.withDO(a.DO.Distinct(cols...)) } -func (a appAccountDo) Omit(cols ...field.Expr) *appAccountDo { +func (a appAccountDo) Omit(cols ...field.Expr) IAppAccountDo { return a.withDO(a.DO.Omit(cols...)) } -func (a appAccountDo) Join(table schema.Tabler, on ...field.Expr) *appAccountDo { +func (a appAccountDo) Join(table schema.Tabler, on ...field.Expr) IAppAccountDo { return a.withDO(a.DO.Join(table, on...)) } -func (a appAccountDo) LeftJoin(table schema.Tabler, on ...field.Expr) *appAccountDo { +func (a appAccountDo) LeftJoin(table schema.Tabler, on ...field.Expr) IAppAccountDo { return a.withDO(a.DO.LeftJoin(table, on...)) } -func (a appAccountDo) RightJoin(table schema.Tabler, on ...field.Expr) *appAccountDo { +func (a appAccountDo) RightJoin(table schema.Tabler, on ...field.Expr) IAppAccountDo { return a.withDO(a.DO.RightJoin(table, on...)) } -func (a appAccountDo) Group(cols ...field.Expr) *appAccountDo { +func (a appAccountDo) Group(cols ...field.Expr) IAppAccountDo { return a.withDO(a.DO.Group(cols...)) } -func (a appAccountDo) Having(conds ...gen.Condition) *appAccountDo { +func (a appAccountDo) Having(conds ...gen.Condition) IAppAccountDo { return a.withDO(a.DO.Having(conds...)) } -func (a appAccountDo) Limit(limit int) *appAccountDo { +func (a appAccountDo) Limit(limit int) IAppAccountDo { return a.withDO(a.DO.Limit(limit)) } -func (a appAccountDo) Offset(offset int) *appAccountDo { +func (a appAccountDo) Offset(offset int) IAppAccountDo { return a.withDO(a.DO.Offset(offset)) } -func (a appAccountDo) Scopes(funcs ...func(gen.Dao) gen.Dao) *appAccountDo { +func (a appAccountDo) Scopes(funcs ...func(gen.Dao) gen.Dao) IAppAccountDo { return a.withDO(a.DO.Scopes(funcs...)) } -func (a appAccountDo) Unscoped() *appAccountDo { +func (a appAccountDo) Unscoped() IAppAccountDo { return a.withDO(a.DO.Unscoped()) } @@ -272,22 +340,22 @@ func (a appAccountDo) FindInBatches(result *[]*model.AppAccount, batchSize int, return a.DO.FindInBatches(result, batchSize, fc) } -func (a appAccountDo) Attrs(attrs ...field.AssignExpr) *appAccountDo { +func (a appAccountDo) Attrs(attrs ...field.AssignExpr) IAppAccountDo { return a.withDO(a.DO.Attrs(attrs...)) } -func (a appAccountDo) Assign(attrs ...field.AssignExpr) *appAccountDo { +func (a appAccountDo) Assign(attrs ...field.AssignExpr) IAppAccountDo { return a.withDO(a.DO.Assign(attrs...)) } -func (a appAccountDo) Joins(fields ...field.RelationField) *appAccountDo { +func (a appAccountDo) Joins(fields ...field.RelationField) IAppAccountDo { for _, _f := range fields { a = *a.withDO(a.DO.Joins(_f)) } return &a } -func (a appAccountDo) Preload(fields ...field.RelationField) *appAccountDo { +func (a appAccountDo) Preload(fields ...field.RelationField) IAppAccountDo { for _, _f := range fields { a = *a.withDO(a.DO.Preload(_f)) } diff --git a/gorm-gen/dao/query/app_user.gen.go b/gorm-gen/dao/query/app_user.gen.go index 477a314..a71caeb 100644 --- a/gorm-gen/dao/query/app_user.gen.go +++ b/gorm-gen/dao/query/app_user.gen.go @@ -43,18 +43,18 @@ func newAppUser(db *gorm.DB, opts ...gen.DOOption) appUser { } type appUser struct { - appUserDo appUserDo + appUserDo ALL field.Asterisk ID field.Uint64 - AppAccountID field.Uint32 // app_account表外键 + AppAccountID field.Uint32 Openid field.String Unionid field.String - Nickname field.String // 昵称 - Avatar field.String // 头像 - AnonymousOpenid field.String // 匿名openid - CreatedAt field.Time // 创建时间 - UpdatedAt field.Time // 更新时间 + Nickname field.String + Avatar field.String + AnonymousOpenid field.String + CreatedAt field.Time + UpdatedAt field.Time fieldMap map[string]field.Expr } @@ -86,14 +86,6 @@ func (a *appUser) updateTableName(table string) *appUser { return a } -func (a *appUser) WithContext(ctx context.Context) *appUserDo { return a.appUserDo.WithContext(ctx) } - -func (a appUser) TableName() string { return a.appUserDo.TableName() } - -func (a appUser) Alias() string { return a.appUserDo.Alias() } - -func (a appUser) Columns(cols ...field.Expr) gen.Columns { return a.appUserDo.Columns(cols...) } - func (a *appUser) GetFieldByName(fieldName string) (field.OrderExpr, bool) { _f, ok := a.fieldMap[fieldName] if !ok || _f == nil { @@ -128,95 +120,156 @@ func (a appUser) replaceDB(db *gorm.DB) appUser { type appUserDo struct{ gen.DO } -func (a appUserDo) Debug() *appUserDo { +type IAppUserDo interface { + gen.SubQuery + Debug() IAppUserDo + WithContext(ctx context.Context) IAppUserDo + WithResult(fc func(tx gen.Dao)) gen.ResultInfo + ReplaceDB(db *gorm.DB) + ReadDB() IAppUserDo + WriteDB() IAppUserDo + As(alias string) gen.Dao + Session(config *gorm.Session) IAppUserDo + Columns(cols ...field.Expr) gen.Columns + Clauses(conds ...clause.Expression) IAppUserDo + Not(conds ...gen.Condition) IAppUserDo + Or(conds ...gen.Condition) IAppUserDo + Select(conds ...field.Expr) IAppUserDo + Where(conds ...gen.Condition) IAppUserDo + Order(conds ...field.Expr) IAppUserDo + Distinct(cols ...field.Expr) IAppUserDo + Omit(cols ...field.Expr) IAppUserDo + Join(table schema.Tabler, on ...field.Expr) IAppUserDo + LeftJoin(table schema.Tabler, on ...field.Expr) IAppUserDo + RightJoin(table schema.Tabler, on ...field.Expr) IAppUserDo + Group(cols ...field.Expr) IAppUserDo + Having(conds ...gen.Condition) IAppUserDo + Limit(limit int) IAppUserDo + Offset(offset int) IAppUserDo + Count() (count int64, err error) + Scopes(funcs ...func(gen.Dao) gen.Dao) IAppUserDo + Unscoped() IAppUserDo + Create(values ...*model.AppUser) error + CreateInBatches(values []*model.AppUser, batchSize int) error + Save(values ...*model.AppUser) error + First() (*model.AppUser, error) + Take() (*model.AppUser, error) + Last() (*model.AppUser, error) + Find() ([]*model.AppUser, error) + FindInBatch(batchSize int, fc func(tx gen.Dao, batch int) error) (results []*model.AppUser, err error) + FindInBatches(result *[]*model.AppUser, batchSize int, fc func(tx gen.Dao, batch int) error) error + Pluck(column field.Expr, dest interface{}) error + Delete(...*model.AppUser) (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) IAppUserDo + Assign(attrs ...field.AssignExpr) IAppUserDo + Joins(fields ...field.RelationField) IAppUserDo + Preload(fields ...field.RelationField) IAppUserDo + FirstOrInit() (*model.AppUser, error) + FirstOrCreate() (*model.AppUser, error) + FindByPage(offset int, limit int) (result []*model.AppUser, 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) IAppUserDo + UnderlyingDB() *gorm.DB + schema.Tabler +} + +func (a appUserDo) Debug() IAppUserDo { return a.withDO(a.DO.Debug()) } -func (a appUserDo) WithContext(ctx context.Context) *appUserDo { +func (a appUserDo) WithContext(ctx context.Context) IAppUserDo { return a.withDO(a.DO.WithContext(ctx)) } -func (a appUserDo) ReadDB() *appUserDo { +func (a appUserDo) ReadDB() IAppUserDo { return a.Clauses(dbresolver.Read) } -func (a appUserDo) WriteDB() *appUserDo { +func (a appUserDo) WriteDB() IAppUserDo { return a.Clauses(dbresolver.Write) } -func (a appUserDo) Session(config *gorm.Session) *appUserDo { +func (a appUserDo) Session(config *gorm.Session) IAppUserDo { return a.withDO(a.DO.Session(config)) } -func (a appUserDo) Clauses(conds ...clause.Expression) *appUserDo { +func (a appUserDo) Clauses(conds ...clause.Expression) IAppUserDo { return a.withDO(a.DO.Clauses(conds...)) } -func (a appUserDo) Returning(value interface{}, columns ...string) *appUserDo { +func (a appUserDo) Returning(value interface{}, columns ...string) IAppUserDo { return a.withDO(a.DO.Returning(value, columns...)) } -func (a appUserDo) Not(conds ...gen.Condition) *appUserDo { +func (a appUserDo) Not(conds ...gen.Condition) IAppUserDo { return a.withDO(a.DO.Not(conds...)) } -func (a appUserDo) Or(conds ...gen.Condition) *appUserDo { +func (a appUserDo) Or(conds ...gen.Condition) IAppUserDo { return a.withDO(a.DO.Or(conds...)) } -func (a appUserDo) Select(conds ...field.Expr) *appUserDo { +func (a appUserDo) Select(conds ...field.Expr) IAppUserDo { return a.withDO(a.DO.Select(conds...)) } -func (a appUserDo) Where(conds ...gen.Condition) *appUserDo { +func (a appUserDo) Where(conds ...gen.Condition) IAppUserDo { return a.withDO(a.DO.Where(conds...)) } -func (a appUserDo) Order(conds ...field.Expr) *appUserDo { +func (a appUserDo) Order(conds ...field.Expr) IAppUserDo { return a.withDO(a.DO.Order(conds...)) } -func (a appUserDo) Distinct(cols ...field.Expr) *appUserDo { +func (a appUserDo) Distinct(cols ...field.Expr) IAppUserDo { return a.withDO(a.DO.Distinct(cols...)) } -func (a appUserDo) Omit(cols ...field.Expr) *appUserDo { +func (a appUserDo) Omit(cols ...field.Expr) IAppUserDo { return a.withDO(a.DO.Omit(cols...)) } -func (a appUserDo) Join(table schema.Tabler, on ...field.Expr) *appUserDo { +func (a appUserDo) Join(table schema.Tabler, on ...field.Expr) IAppUserDo { return a.withDO(a.DO.Join(table, on...)) } -func (a appUserDo) LeftJoin(table schema.Tabler, on ...field.Expr) *appUserDo { +func (a appUserDo) LeftJoin(table schema.Tabler, on ...field.Expr) IAppUserDo { return a.withDO(a.DO.LeftJoin(table, on...)) } -func (a appUserDo) RightJoin(table schema.Tabler, on ...field.Expr) *appUserDo { +func (a appUserDo) RightJoin(table schema.Tabler, on ...field.Expr) IAppUserDo { return a.withDO(a.DO.RightJoin(table, on...)) } -func (a appUserDo) Group(cols ...field.Expr) *appUserDo { +func (a appUserDo) Group(cols ...field.Expr) IAppUserDo { return a.withDO(a.DO.Group(cols...)) } -func (a appUserDo) Having(conds ...gen.Condition) *appUserDo { +func (a appUserDo) Having(conds ...gen.Condition) IAppUserDo { return a.withDO(a.DO.Having(conds...)) } -func (a appUserDo) Limit(limit int) *appUserDo { +func (a appUserDo) Limit(limit int) IAppUserDo { return a.withDO(a.DO.Limit(limit)) } -func (a appUserDo) Offset(offset int) *appUserDo { +func (a appUserDo) Offset(offset int) IAppUserDo { return a.withDO(a.DO.Offset(offset)) } -func (a appUserDo) Scopes(funcs ...func(gen.Dao) gen.Dao) *appUserDo { +func (a appUserDo) Scopes(funcs ...func(gen.Dao) gen.Dao) IAppUserDo { return a.withDO(a.DO.Scopes(funcs...)) } -func (a appUserDo) Unscoped() *appUserDo { +func (a appUserDo) Unscoped() IAppUserDo { return a.withDO(a.DO.Unscoped()) } @@ -282,22 +335,22 @@ func (a appUserDo) FindInBatches(result *[]*model.AppUser, batchSize int, fc fun return a.DO.FindInBatches(result, batchSize, fc) } -func (a appUserDo) Attrs(attrs ...field.AssignExpr) *appUserDo { +func (a appUserDo) Attrs(attrs ...field.AssignExpr) IAppUserDo { return a.withDO(a.DO.Attrs(attrs...)) } -func (a appUserDo) Assign(attrs ...field.AssignExpr) *appUserDo { +func (a appUserDo) Assign(attrs ...field.AssignExpr) IAppUserDo { return a.withDO(a.DO.Assign(attrs...)) } -func (a appUserDo) Joins(fields ...field.RelationField) *appUserDo { +func (a appUserDo) Joins(fields ...field.RelationField) IAppUserDo { for _, _f := range fields { a = *a.withDO(a.DO.Joins(_f)) } return &a } -func (a appUserDo) Preload(fields ...field.RelationField) *appUserDo { +func (a appUserDo) Preload(fields ...field.RelationField) IAppUserDo { for _, _f := range fields { a = *a.withDO(a.DO.Preload(_f)) } diff --git a/gorm-gen/dao/query/douyin_ecpm_config.gen.go b/gorm-gen/dao/query/douyin_ecpm_config.gen.go index b23e00e..c0e8af4 100644 --- a/gorm-gen/dao/query/douyin_ecpm_config.gen.go +++ b/gorm-gen/dao/query/douyin_ecpm_config.gen.go @@ -38,13 +38,13 @@ func newDouyinEcpmConfig(db *gorm.DB, opts ...gen.DOOption) douyinEcpmConfig { } type douyinEcpmConfig struct { - douyinEcpmConfigDo douyinEcpmConfigDo + douyinEcpmConfigDo ALL field.Asterisk ID field.Uint32 AppAccountID field.Uint32 - EcpmValue field.Uint32 // 值 - EcpmView field.Uint32 // 浏览次数 + EcpmValue field.Uint32 + EcpmView field.Uint32 fieldMap map[string]field.Expr } @@ -71,18 +71,6 @@ func (d *douyinEcpmConfig) updateTableName(table string) *douyinEcpmConfig { return d } -func (d *douyinEcpmConfig) WithContext(ctx context.Context) *douyinEcpmConfigDo { - return d.douyinEcpmConfigDo.WithContext(ctx) -} - -func (d douyinEcpmConfig) TableName() string { return d.douyinEcpmConfigDo.TableName() } - -func (d douyinEcpmConfig) Alias() string { return d.douyinEcpmConfigDo.Alias() } - -func (d douyinEcpmConfig) Columns(cols ...field.Expr) gen.Columns { - return d.douyinEcpmConfigDo.Columns(cols...) -} - func (d *douyinEcpmConfig) GetFieldByName(fieldName string) (field.OrderExpr, bool) { _f, ok := d.fieldMap[fieldName] if !ok || _f == nil { @@ -112,95 +100,156 @@ func (d douyinEcpmConfig) replaceDB(db *gorm.DB) douyinEcpmConfig { type douyinEcpmConfigDo struct{ gen.DO } -func (d douyinEcpmConfigDo) Debug() *douyinEcpmConfigDo { +type IDouyinEcpmConfigDo interface { + gen.SubQuery + Debug() IDouyinEcpmConfigDo + WithContext(ctx context.Context) IDouyinEcpmConfigDo + WithResult(fc func(tx gen.Dao)) gen.ResultInfo + ReplaceDB(db *gorm.DB) + ReadDB() IDouyinEcpmConfigDo + WriteDB() IDouyinEcpmConfigDo + As(alias string) gen.Dao + Session(config *gorm.Session) IDouyinEcpmConfigDo + Columns(cols ...field.Expr) gen.Columns + Clauses(conds ...clause.Expression) IDouyinEcpmConfigDo + Not(conds ...gen.Condition) IDouyinEcpmConfigDo + Or(conds ...gen.Condition) IDouyinEcpmConfigDo + Select(conds ...field.Expr) IDouyinEcpmConfigDo + Where(conds ...gen.Condition) IDouyinEcpmConfigDo + Order(conds ...field.Expr) IDouyinEcpmConfigDo + Distinct(cols ...field.Expr) IDouyinEcpmConfigDo + Omit(cols ...field.Expr) IDouyinEcpmConfigDo + Join(table schema.Tabler, on ...field.Expr) IDouyinEcpmConfigDo + LeftJoin(table schema.Tabler, on ...field.Expr) IDouyinEcpmConfigDo + RightJoin(table schema.Tabler, on ...field.Expr) IDouyinEcpmConfigDo + Group(cols ...field.Expr) IDouyinEcpmConfigDo + Having(conds ...gen.Condition) IDouyinEcpmConfigDo + Limit(limit int) IDouyinEcpmConfigDo + Offset(offset int) IDouyinEcpmConfigDo + Count() (count int64, err error) + Scopes(funcs ...func(gen.Dao) gen.Dao) IDouyinEcpmConfigDo + Unscoped() IDouyinEcpmConfigDo + Create(values ...*model.DouyinEcpmConfig) error + CreateInBatches(values []*model.DouyinEcpmConfig, batchSize int) error + Save(values ...*model.DouyinEcpmConfig) error + First() (*model.DouyinEcpmConfig, error) + Take() (*model.DouyinEcpmConfig, error) + Last() (*model.DouyinEcpmConfig, error) + Find() ([]*model.DouyinEcpmConfig, error) + FindInBatch(batchSize int, fc func(tx gen.Dao, batch int) error) (results []*model.DouyinEcpmConfig, err error) + FindInBatches(result *[]*model.DouyinEcpmConfig, batchSize int, fc func(tx gen.Dao, batch int) error) error + Pluck(column field.Expr, dest interface{}) error + Delete(...*model.DouyinEcpmConfig) (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) IDouyinEcpmConfigDo + Assign(attrs ...field.AssignExpr) IDouyinEcpmConfigDo + Joins(fields ...field.RelationField) IDouyinEcpmConfigDo + Preload(fields ...field.RelationField) IDouyinEcpmConfigDo + FirstOrInit() (*model.DouyinEcpmConfig, error) + FirstOrCreate() (*model.DouyinEcpmConfig, error) + FindByPage(offset int, limit int) (result []*model.DouyinEcpmConfig, 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) IDouyinEcpmConfigDo + UnderlyingDB() *gorm.DB + schema.Tabler +} + +func (d douyinEcpmConfigDo) Debug() IDouyinEcpmConfigDo { return d.withDO(d.DO.Debug()) } -func (d douyinEcpmConfigDo) WithContext(ctx context.Context) *douyinEcpmConfigDo { +func (d douyinEcpmConfigDo) WithContext(ctx context.Context) IDouyinEcpmConfigDo { return d.withDO(d.DO.WithContext(ctx)) } -func (d douyinEcpmConfigDo) ReadDB() *douyinEcpmConfigDo { +func (d douyinEcpmConfigDo) ReadDB() IDouyinEcpmConfigDo { return d.Clauses(dbresolver.Read) } -func (d douyinEcpmConfigDo) WriteDB() *douyinEcpmConfigDo { +func (d douyinEcpmConfigDo) WriteDB() IDouyinEcpmConfigDo { return d.Clauses(dbresolver.Write) } -func (d douyinEcpmConfigDo) Session(config *gorm.Session) *douyinEcpmConfigDo { +func (d douyinEcpmConfigDo) Session(config *gorm.Session) IDouyinEcpmConfigDo { return d.withDO(d.DO.Session(config)) } -func (d douyinEcpmConfigDo) Clauses(conds ...clause.Expression) *douyinEcpmConfigDo { +func (d douyinEcpmConfigDo) Clauses(conds ...clause.Expression) IDouyinEcpmConfigDo { return d.withDO(d.DO.Clauses(conds...)) } -func (d douyinEcpmConfigDo) Returning(value interface{}, columns ...string) *douyinEcpmConfigDo { +func (d douyinEcpmConfigDo) Returning(value interface{}, columns ...string) IDouyinEcpmConfigDo { return d.withDO(d.DO.Returning(value, columns...)) } -func (d douyinEcpmConfigDo) Not(conds ...gen.Condition) *douyinEcpmConfigDo { +func (d douyinEcpmConfigDo) Not(conds ...gen.Condition) IDouyinEcpmConfigDo { return d.withDO(d.DO.Not(conds...)) } -func (d douyinEcpmConfigDo) Or(conds ...gen.Condition) *douyinEcpmConfigDo { +func (d douyinEcpmConfigDo) Or(conds ...gen.Condition) IDouyinEcpmConfigDo { return d.withDO(d.DO.Or(conds...)) } -func (d douyinEcpmConfigDo) Select(conds ...field.Expr) *douyinEcpmConfigDo { +func (d douyinEcpmConfigDo) Select(conds ...field.Expr) IDouyinEcpmConfigDo { return d.withDO(d.DO.Select(conds...)) } -func (d douyinEcpmConfigDo) Where(conds ...gen.Condition) *douyinEcpmConfigDo { +func (d douyinEcpmConfigDo) Where(conds ...gen.Condition) IDouyinEcpmConfigDo { return d.withDO(d.DO.Where(conds...)) } -func (d douyinEcpmConfigDo) Order(conds ...field.Expr) *douyinEcpmConfigDo { +func (d douyinEcpmConfigDo) Order(conds ...field.Expr) IDouyinEcpmConfigDo { return d.withDO(d.DO.Order(conds...)) } -func (d douyinEcpmConfigDo) Distinct(cols ...field.Expr) *douyinEcpmConfigDo { +func (d douyinEcpmConfigDo) Distinct(cols ...field.Expr) IDouyinEcpmConfigDo { return d.withDO(d.DO.Distinct(cols...)) } -func (d douyinEcpmConfigDo) Omit(cols ...field.Expr) *douyinEcpmConfigDo { +func (d douyinEcpmConfigDo) Omit(cols ...field.Expr) IDouyinEcpmConfigDo { return d.withDO(d.DO.Omit(cols...)) } -func (d douyinEcpmConfigDo) Join(table schema.Tabler, on ...field.Expr) *douyinEcpmConfigDo { +func (d douyinEcpmConfigDo) Join(table schema.Tabler, on ...field.Expr) IDouyinEcpmConfigDo { return d.withDO(d.DO.Join(table, on...)) } -func (d douyinEcpmConfigDo) LeftJoin(table schema.Tabler, on ...field.Expr) *douyinEcpmConfigDo { +func (d douyinEcpmConfigDo) LeftJoin(table schema.Tabler, on ...field.Expr) IDouyinEcpmConfigDo { return d.withDO(d.DO.LeftJoin(table, on...)) } -func (d douyinEcpmConfigDo) RightJoin(table schema.Tabler, on ...field.Expr) *douyinEcpmConfigDo { +func (d douyinEcpmConfigDo) RightJoin(table schema.Tabler, on ...field.Expr) IDouyinEcpmConfigDo { return d.withDO(d.DO.RightJoin(table, on...)) } -func (d douyinEcpmConfigDo) Group(cols ...field.Expr) *douyinEcpmConfigDo { +func (d douyinEcpmConfigDo) Group(cols ...field.Expr) IDouyinEcpmConfigDo { return d.withDO(d.DO.Group(cols...)) } -func (d douyinEcpmConfigDo) Having(conds ...gen.Condition) *douyinEcpmConfigDo { +func (d douyinEcpmConfigDo) Having(conds ...gen.Condition) IDouyinEcpmConfigDo { return d.withDO(d.DO.Having(conds...)) } -func (d douyinEcpmConfigDo) Limit(limit int) *douyinEcpmConfigDo { +func (d douyinEcpmConfigDo) Limit(limit int) IDouyinEcpmConfigDo { return d.withDO(d.DO.Limit(limit)) } -func (d douyinEcpmConfigDo) Offset(offset int) *douyinEcpmConfigDo { +func (d douyinEcpmConfigDo) Offset(offset int) IDouyinEcpmConfigDo { return d.withDO(d.DO.Offset(offset)) } -func (d douyinEcpmConfigDo) Scopes(funcs ...func(gen.Dao) gen.Dao) *douyinEcpmConfigDo { +func (d douyinEcpmConfigDo) Scopes(funcs ...func(gen.Dao) gen.Dao) IDouyinEcpmConfigDo { return d.withDO(d.DO.Scopes(funcs...)) } -func (d douyinEcpmConfigDo) Unscoped() *douyinEcpmConfigDo { +func (d douyinEcpmConfigDo) Unscoped() IDouyinEcpmConfigDo { return d.withDO(d.DO.Unscoped()) } @@ -266,22 +315,22 @@ func (d douyinEcpmConfigDo) FindInBatches(result *[]*model.DouyinEcpmConfig, bat return d.DO.FindInBatches(result, batchSize, fc) } -func (d douyinEcpmConfigDo) Attrs(attrs ...field.AssignExpr) *douyinEcpmConfigDo { +func (d douyinEcpmConfigDo) Attrs(attrs ...field.AssignExpr) IDouyinEcpmConfigDo { return d.withDO(d.DO.Attrs(attrs...)) } -func (d douyinEcpmConfigDo) Assign(attrs ...field.AssignExpr) *douyinEcpmConfigDo { +func (d douyinEcpmConfigDo) Assign(attrs ...field.AssignExpr) IDouyinEcpmConfigDo { return d.withDO(d.DO.Assign(attrs...)) } -func (d douyinEcpmConfigDo) Joins(fields ...field.RelationField) *douyinEcpmConfigDo { +func (d douyinEcpmConfigDo) Joins(fields ...field.RelationField) IDouyinEcpmConfigDo { for _, _f := range fields { d = *d.withDO(d.DO.Joins(_f)) } return &d } -func (d douyinEcpmConfigDo) Preload(fields ...field.RelationField) *douyinEcpmConfigDo { +func (d douyinEcpmConfigDo) Preload(fields ...field.RelationField) IDouyinEcpmConfigDo { for _, _f := range fields { d = *d.withDO(d.DO.Preload(_f)) } diff --git a/gorm-gen/dao/query/game_score.gen.go b/gorm-gen/dao/query/game_score.gen.go index 9a2c7a5..7b37933 100644 --- a/gorm-gen/dao/query/game_score.gen.go +++ b/gorm-gen/dao/query/game_score.gen.go @@ -6,6 +6,7 @@ package query import ( "context" + "strings" "gorm.io/gorm" "gorm.io/gorm/clause" @@ -17,6 +18,7 @@ import ( "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 { @@ -32,6 +34,7 @@ func newGameScore(db *gorm.DB, opts ...gen.DOOption) gameScore { _gameScore.AppUserID = field.NewUint64(tableName, "app_user_id") _gameScore.Score = field.NewUint32(tableName, "score") _gameScore.T = field.NewUint32(tableName, "t") + _gameScore.UpdatedAt = field.NewTime(tableName, "updated_at") _gameScore.fillFieldMap() @@ -39,14 +42,15 @@ func newGameScore(db *gorm.DB, opts ...gen.DOOption) gameScore { } type gameScore struct { - gameScoreDo gameScoreDo + gameScoreDo ALL field.Asterisk ID field.Uint64 - AppAccount field.Uint32 // 小游戏id - AppUserID field.Uint64 // 用户id - Score field.Uint32 // 得分 - T field.Uint32 // 得分类型(区分相同小游戏中的不同模式得分) + AppAccount field.Uint32 + AppUserID field.Uint64 + Score field.Uint32 + T field.Uint32 + UpdatedAt field.Time fieldMap map[string]field.Expr } @@ -68,22 +72,13 @@ func (g *gameScore) updateTableName(table string) *gameScore { g.AppUserID = field.NewUint64(table, "app_user_id") g.Score = field.NewUint32(table, "score") g.T = field.NewUint32(table, "t") + g.UpdatedAt = field.NewTime(table, "updated_at") g.fillFieldMap() return g } -func (g *gameScore) WithContext(ctx context.Context) *gameScoreDo { - return g.gameScoreDo.WithContext(ctx) -} - -func (g gameScore) TableName() string { return g.gameScoreDo.TableName() } - -func (g gameScore) Alias() string { return g.gameScoreDo.Alias() } - -func (g gameScore) Columns(cols ...field.Expr) gen.Columns { return g.gameScoreDo.Columns(cols...) } - func (g *gameScore) GetFieldByName(fieldName string) (field.OrderExpr, bool) { _f, ok := g.fieldMap[fieldName] if !ok || _f == nil { @@ -94,12 +89,13 @@ func (g *gameScore) GetFieldByName(fieldName string) (field.OrderExpr, bool) { } func (g *gameScore) fillFieldMap() { - g.fieldMap = make(map[string]field.Expr, 5) + g.fieldMap = make(map[string]field.Expr, 6) 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 + g.fieldMap["updated_at"] = g.UpdatedAt } func (g gameScore) clone(db *gorm.DB) gameScore { @@ -114,95 +110,206 @@ func (g gameScore) replaceDB(db *gorm.DB) gameScore { type gameScoreDo struct{ gen.DO } -func (g gameScoreDo) Debug() *gameScoreDo { +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) *gameScoreDo { +func (g gameScoreDo) WithContext(ctx context.Context) IGameScoreDo { return g.withDO(g.DO.WithContext(ctx)) } -func (g gameScoreDo) ReadDB() *gameScoreDo { +func (g gameScoreDo) ReadDB() IGameScoreDo { return g.Clauses(dbresolver.Read) } -func (g gameScoreDo) WriteDB() *gameScoreDo { +func (g gameScoreDo) WriteDB() IGameScoreDo { return g.Clauses(dbresolver.Write) } -func (g gameScoreDo) Session(config *gorm.Session) *gameScoreDo { +func (g gameScoreDo) Session(config *gorm.Session) IGameScoreDo { return g.withDO(g.DO.Session(config)) } -func (g gameScoreDo) Clauses(conds ...clause.Expression) *gameScoreDo { +func (g gameScoreDo) Clauses(conds ...clause.Expression) IGameScoreDo { return g.withDO(g.DO.Clauses(conds...)) } -func (g gameScoreDo) Returning(value interface{}, columns ...string) *gameScoreDo { +func (g gameScoreDo) Returning(value interface{}, columns ...string) IGameScoreDo { return g.withDO(g.DO.Returning(value, columns...)) } -func (g gameScoreDo) Not(conds ...gen.Condition) *gameScoreDo { +func (g gameScoreDo) Not(conds ...gen.Condition) IGameScoreDo { return g.withDO(g.DO.Not(conds...)) } -func (g gameScoreDo) Or(conds ...gen.Condition) *gameScoreDo { +func (g gameScoreDo) Or(conds ...gen.Condition) IGameScoreDo { return g.withDO(g.DO.Or(conds...)) } -func (g gameScoreDo) Select(conds ...field.Expr) *gameScoreDo { +func (g gameScoreDo) Select(conds ...field.Expr) IGameScoreDo { return g.withDO(g.DO.Select(conds...)) } -func (g gameScoreDo) Where(conds ...gen.Condition) *gameScoreDo { +func (g gameScoreDo) Where(conds ...gen.Condition) IGameScoreDo { return g.withDO(g.DO.Where(conds...)) } -func (g gameScoreDo) Order(conds ...field.Expr) *gameScoreDo { +func (g gameScoreDo) Order(conds ...field.Expr) IGameScoreDo { return g.withDO(g.DO.Order(conds...)) } -func (g gameScoreDo) Distinct(cols ...field.Expr) *gameScoreDo { +func (g gameScoreDo) Distinct(cols ...field.Expr) IGameScoreDo { return g.withDO(g.DO.Distinct(cols...)) } -func (g gameScoreDo) Omit(cols ...field.Expr) *gameScoreDo { +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) *gameScoreDo { +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) *gameScoreDo { +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) *gameScoreDo { +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) *gameScoreDo { +func (g gameScoreDo) Group(cols ...field.Expr) IGameScoreDo { return g.withDO(g.DO.Group(cols...)) } -func (g gameScoreDo) Having(conds ...gen.Condition) *gameScoreDo { +func (g gameScoreDo) Having(conds ...gen.Condition) IGameScoreDo { return g.withDO(g.DO.Having(conds...)) } -func (g gameScoreDo) Limit(limit int) *gameScoreDo { +func (g gameScoreDo) Limit(limit int) IGameScoreDo { return g.withDO(g.DO.Limit(limit)) } -func (g gameScoreDo) Offset(offset int) *gameScoreDo { +func (g gameScoreDo) Offset(offset int) IGameScoreDo { return g.withDO(g.DO.Offset(offset)) } -func (g gameScoreDo) Scopes(funcs ...func(gen.Dao) gen.Dao) *gameScoreDo { +func (g gameScoreDo) Scopes(funcs ...func(gen.Dao) gen.Dao) IGameScoreDo { return g.withDO(g.DO.Scopes(funcs...)) } -func (g gameScoreDo) Unscoped() *gameScoreDo { +func (g gameScoreDo) Unscoped() IGameScoreDo { return g.withDO(g.DO.Unscoped()) } @@ -268,22 +375,22 @@ func (g gameScoreDo) FindInBatches(result *[]*model.GameScore, batchSize int, fc return g.DO.FindInBatches(result, batchSize, fc) } -func (g gameScoreDo) Attrs(attrs ...field.AssignExpr) *gameScoreDo { +func (g gameScoreDo) Attrs(attrs ...field.AssignExpr) IGameScoreDo { return g.withDO(g.DO.Attrs(attrs...)) } -func (g gameScoreDo) Assign(attrs ...field.AssignExpr) *gameScoreDo { +func (g gameScoreDo) Assign(attrs ...field.AssignExpr) IGameScoreDo { return g.withDO(g.DO.Assign(attrs...)) } -func (g gameScoreDo) Joins(fields ...field.RelationField) *gameScoreDo { +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) *gameScoreDo { +func (g gameScoreDo) Preload(fields ...field.RelationField) IGameScoreDo { for _, _f := range fields { g = *g.withDO(g.DO.Preload(_f)) } diff --git a/gorm-gen/dao/query/gen.go b/gorm-gen/dao/query/gen.go index 92c75c7..975700f 100644 --- a/gorm-gen/dao/query/gen.go +++ b/gorm-gen/dao/query/gen.go @@ -15,6 +15,22 @@ import ( "gorm.io/plugin/dbresolver" ) +var ( + Q = new(Query) + AppAccount *appAccount + AppUser *appUser + DouyinEcpmConfig *douyinEcpmConfig + GameScore *gameScore +) + +func SetDefault(db *gorm.DB, opts ...gen.DOOption) { + *Q = *Use(db, opts...) + AppAccount = &Q.AppAccount + AppUser = &Q.AppUser + DouyinEcpmConfig = &Q.DouyinEcpmConfig + GameScore = &Q.GameScore +} + func Use(db *gorm.DB, opts ...gen.DOOption) *Query { return &Query{ db: db, @@ -65,10 +81,10 @@ func (q *Query) ReplaceDB(db *gorm.DB) *Query { } type queryCtx struct { - AppAccount *appAccountDo - AppUser *appUserDo - DouyinEcpmConfig *douyinEcpmConfigDo - GameScore *gameScoreDo + AppAccount IAppAccountDo + AppUser IAppUserDo + DouyinEcpmConfig IDouyinEcpmConfigDo + GameScore IGameScoreDo } func (q *Query) WithContext(ctx context.Context) *queryCtx { diff --git a/gorm-gen/gen_model.go b/gorm-gen/gen_model.go index aa28a28..aeae612 100644 --- a/gorm-gen/gen_model.go +++ b/gorm-gen/gen_model.go @@ -39,7 +39,7 @@ func GetRandomUsername() string { func main() { g := gen.NewGenerator(gen.Config{ - OutPath: "./query", + OutPath: "./dao/query", Mode: gen.WithoutContext | gen.WithDefaultQuery | gen.WithQueryInterface, // generate mode }) dsn := "root:youtu!0113@tcp(localhost:3306)/ecpm?charset=utf8&parseTime=True&loc=Local" diff --git a/gorm-gen/query/app_account.gen.go b/gorm-gen/query/app_account.gen.go deleted file mode 100644 index c523ce3..0000000 --- a/gorm-gen/query/app_account.gen.go +++ /dev/null @@ -1,417 +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 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" -) - -func newAppAccount(db *gorm.DB, opts ...gen.DOOption) appAccount { - _appAccount := appAccount{} - - _appAccount.appAccountDo.UseDB(db, opts...) - _appAccount.appAccountDo.UseModel(&model.AppAccount{}) - - tableName := _appAccount.appAccountDo.TableName() - _appAccount.ALL = field.NewAsterisk(tableName) - _appAccount.ID = field.NewUint32(tableName, "id") - _appAccount.Type = field.NewUint32(tableName, "type") - _appAccount.AppID = field.NewString(tableName, "app_id") - _appAccount.Secret = field.NewString(tableName, "secret") - _appAccount.Remark = field.NewString(tableName, "remark") - _appAccount.DeletedAt = field.NewField(tableName, "deleted_at") - - _appAccount.fillFieldMap() - - return _appAccount -} - -type appAccount struct { - appAccountDo - - ALL field.Asterisk - ID field.Uint32 - Type field.Uint32 - AppID field.String - Secret field.String - Remark field.String - DeletedAt field.Field - - fieldMap map[string]field.Expr -} - -func (a appAccount) Table(newTableName string) *appAccount { - a.appAccountDo.UseTable(newTableName) - return a.updateTableName(newTableName) -} - -func (a appAccount) As(alias string) *appAccount { - a.appAccountDo.DO = *(a.appAccountDo.As(alias).(*gen.DO)) - return a.updateTableName(alias) -} - -func (a *appAccount) updateTableName(table string) *appAccount { - a.ALL = field.NewAsterisk(table) - a.ID = field.NewUint32(table, "id") - a.Type = field.NewUint32(table, "type") - a.AppID = field.NewString(table, "app_id") - a.Secret = field.NewString(table, "secret") - a.Remark = field.NewString(table, "remark") - a.DeletedAt = field.NewField(table, "deleted_at") - - a.fillFieldMap() - - return a -} - -func (a *appAccount) GetFieldByName(fieldName string) (field.OrderExpr, bool) { - _f, ok := a.fieldMap[fieldName] - if !ok || _f == nil { - return nil, false - } - _oe, ok := _f.(field.OrderExpr) - return _oe, ok -} - -func (a *appAccount) fillFieldMap() { - a.fieldMap = make(map[string]field.Expr, 6) - a.fieldMap["id"] = a.ID - a.fieldMap["type"] = a.Type - a.fieldMap["app_id"] = a.AppID - a.fieldMap["secret"] = a.Secret - a.fieldMap["remark"] = a.Remark - a.fieldMap["deleted_at"] = a.DeletedAt -} - -func (a appAccount) clone(db *gorm.DB) appAccount { - a.appAccountDo.ReplaceConnPool(db.Statement.ConnPool) - return a -} - -func (a appAccount) replaceDB(db *gorm.DB) appAccount { - a.appAccountDo.ReplaceDB(db) - return a -} - -type appAccountDo struct{ gen.DO } - -type IAppAccountDo interface { - gen.SubQuery - Debug() IAppAccountDo - WithContext(ctx context.Context) IAppAccountDo - WithResult(fc func(tx gen.Dao)) gen.ResultInfo - ReplaceDB(db *gorm.DB) - ReadDB() IAppAccountDo - WriteDB() IAppAccountDo - As(alias string) gen.Dao - Session(config *gorm.Session) IAppAccountDo - Columns(cols ...field.Expr) gen.Columns - Clauses(conds ...clause.Expression) IAppAccountDo - Not(conds ...gen.Condition) IAppAccountDo - Or(conds ...gen.Condition) IAppAccountDo - Select(conds ...field.Expr) IAppAccountDo - Where(conds ...gen.Condition) IAppAccountDo - Order(conds ...field.Expr) IAppAccountDo - Distinct(cols ...field.Expr) IAppAccountDo - Omit(cols ...field.Expr) IAppAccountDo - Join(table schema.Tabler, on ...field.Expr) IAppAccountDo - LeftJoin(table schema.Tabler, on ...field.Expr) IAppAccountDo - RightJoin(table schema.Tabler, on ...field.Expr) IAppAccountDo - Group(cols ...field.Expr) IAppAccountDo - Having(conds ...gen.Condition) IAppAccountDo - Limit(limit int) IAppAccountDo - Offset(offset int) IAppAccountDo - Count() (count int64, err error) - Scopes(funcs ...func(gen.Dao) gen.Dao) IAppAccountDo - Unscoped() IAppAccountDo - Create(values ...*model.AppAccount) error - CreateInBatches(values []*model.AppAccount, batchSize int) error - Save(values ...*model.AppAccount) error - First() (*model.AppAccount, error) - Take() (*model.AppAccount, error) - Last() (*model.AppAccount, error) - Find() ([]*model.AppAccount, error) - FindInBatch(batchSize int, fc func(tx gen.Dao, batch int) error) (results []*model.AppAccount, err error) - FindInBatches(result *[]*model.AppAccount, batchSize int, fc func(tx gen.Dao, batch int) error) error - Pluck(column field.Expr, dest interface{}) error - Delete(...*model.AppAccount) (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) IAppAccountDo - Assign(attrs ...field.AssignExpr) IAppAccountDo - Joins(fields ...field.RelationField) IAppAccountDo - Preload(fields ...field.RelationField) IAppAccountDo - FirstOrInit() (*model.AppAccount, error) - FirstOrCreate() (*model.AppAccount, error) - FindByPage(offset int, limit int) (result []*model.AppAccount, 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) IAppAccountDo - UnderlyingDB() *gorm.DB - schema.Tabler - - GetAppConfig() (result []*model.AppAccount, err error) -} - -// GetAppConfig 获取所有小游戏配置 -// -// select `app_id`,`secret`,`ecpm_value`,`ecpm_view`,`type` from `app_account` left join douyin_ecpm_config on app_account.id = douyin_ecpm_config.app_account_id -func (a appAccountDo) GetAppConfig() (result []*model.AppAccount, err error) { - var generateSQL strings.Builder - generateSQL.WriteString("select `app_id`,`secret`,`ecpm_value`,`ecpm_view`,`type` from `app_account` left join douyin_ecpm_config on app_account.id = douyin_ecpm_config.app_account_id ") - - var executeSQL *gorm.DB - executeSQL = a.UnderlyingDB().Raw(generateSQL.String()).Find(&result) // ignore_security_alert - err = executeSQL.Error - - return -} - -func (a appAccountDo) Debug() IAppAccountDo { - return a.withDO(a.DO.Debug()) -} - -func (a appAccountDo) WithContext(ctx context.Context) IAppAccountDo { - return a.withDO(a.DO.WithContext(ctx)) -} - -func (a appAccountDo) ReadDB() IAppAccountDo { - return a.Clauses(dbresolver.Read) -} - -func (a appAccountDo) WriteDB() IAppAccountDo { - return a.Clauses(dbresolver.Write) -} - -func (a appAccountDo) Session(config *gorm.Session) IAppAccountDo { - return a.withDO(a.DO.Session(config)) -} - -func (a appAccountDo) Clauses(conds ...clause.Expression) IAppAccountDo { - return a.withDO(a.DO.Clauses(conds...)) -} - -func (a appAccountDo) Returning(value interface{}, columns ...string) IAppAccountDo { - return a.withDO(a.DO.Returning(value, columns...)) -} - -func (a appAccountDo) Not(conds ...gen.Condition) IAppAccountDo { - return a.withDO(a.DO.Not(conds...)) -} - -func (a appAccountDo) Or(conds ...gen.Condition) IAppAccountDo { - return a.withDO(a.DO.Or(conds...)) -} - -func (a appAccountDo) Select(conds ...field.Expr) IAppAccountDo { - return a.withDO(a.DO.Select(conds...)) -} - -func (a appAccountDo) Where(conds ...gen.Condition) IAppAccountDo { - return a.withDO(a.DO.Where(conds...)) -} - -func (a appAccountDo) Order(conds ...field.Expr) IAppAccountDo { - return a.withDO(a.DO.Order(conds...)) -} - -func (a appAccountDo) Distinct(cols ...field.Expr) IAppAccountDo { - return a.withDO(a.DO.Distinct(cols...)) -} - -func (a appAccountDo) Omit(cols ...field.Expr) IAppAccountDo { - return a.withDO(a.DO.Omit(cols...)) -} - -func (a appAccountDo) Join(table schema.Tabler, on ...field.Expr) IAppAccountDo { - return a.withDO(a.DO.Join(table, on...)) -} - -func (a appAccountDo) LeftJoin(table schema.Tabler, on ...field.Expr) IAppAccountDo { - return a.withDO(a.DO.LeftJoin(table, on...)) -} - -func (a appAccountDo) RightJoin(table schema.Tabler, on ...field.Expr) IAppAccountDo { - return a.withDO(a.DO.RightJoin(table, on...)) -} - -func (a appAccountDo) Group(cols ...field.Expr) IAppAccountDo { - return a.withDO(a.DO.Group(cols...)) -} - -func (a appAccountDo) Having(conds ...gen.Condition) IAppAccountDo { - return a.withDO(a.DO.Having(conds...)) -} - -func (a appAccountDo) Limit(limit int) IAppAccountDo { - return a.withDO(a.DO.Limit(limit)) -} - -func (a appAccountDo) Offset(offset int) IAppAccountDo { - return a.withDO(a.DO.Offset(offset)) -} - -func (a appAccountDo) Scopes(funcs ...func(gen.Dao) gen.Dao) IAppAccountDo { - return a.withDO(a.DO.Scopes(funcs...)) -} - -func (a appAccountDo) Unscoped() IAppAccountDo { - return a.withDO(a.DO.Unscoped()) -} - -func (a appAccountDo) Create(values ...*model.AppAccount) error { - if len(values) == 0 { - return nil - } - return a.DO.Create(values) -} - -func (a appAccountDo) CreateInBatches(values []*model.AppAccount, batchSize int) error { - return a.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 (a appAccountDo) Save(values ...*model.AppAccount) error { - if len(values) == 0 { - return nil - } - return a.DO.Save(values) -} - -func (a appAccountDo) First() (*model.AppAccount, error) { - if result, err := a.DO.First(); err != nil { - return nil, err - } else { - return result.(*model.AppAccount), nil - } -} - -func (a appAccountDo) Take() (*model.AppAccount, error) { - if result, err := a.DO.Take(); err != nil { - return nil, err - } else { - return result.(*model.AppAccount), nil - } -} - -func (a appAccountDo) Last() (*model.AppAccount, error) { - if result, err := a.DO.Last(); err != nil { - return nil, err - } else { - return result.(*model.AppAccount), nil - } -} - -func (a appAccountDo) Find() ([]*model.AppAccount, error) { - result, err := a.DO.Find() - return result.([]*model.AppAccount), err -} - -func (a appAccountDo) FindInBatch(batchSize int, fc func(tx gen.Dao, batch int) error) (results []*model.AppAccount, err error) { - buf := make([]*model.AppAccount, 0, batchSize) - err = a.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 (a appAccountDo) FindInBatches(result *[]*model.AppAccount, batchSize int, fc func(tx gen.Dao, batch int) error) error { - return a.DO.FindInBatches(result, batchSize, fc) -} - -func (a appAccountDo) Attrs(attrs ...field.AssignExpr) IAppAccountDo { - return a.withDO(a.DO.Attrs(attrs...)) -} - -func (a appAccountDo) Assign(attrs ...field.AssignExpr) IAppAccountDo { - return a.withDO(a.DO.Assign(attrs...)) -} - -func (a appAccountDo) Joins(fields ...field.RelationField) IAppAccountDo { - for _, _f := range fields { - a = *a.withDO(a.DO.Joins(_f)) - } - return &a -} - -func (a appAccountDo) Preload(fields ...field.RelationField) IAppAccountDo { - for _, _f := range fields { - a = *a.withDO(a.DO.Preload(_f)) - } - return &a -} - -func (a appAccountDo) FirstOrInit() (*model.AppAccount, error) { - if result, err := a.DO.FirstOrInit(); err != nil { - return nil, err - } else { - return result.(*model.AppAccount), nil - } -} - -func (a appAccountDo) FirstOrCreate() (*model.AppAccount, error) { - if result, err := a.DO.FirstOrCreate(); err != nil { - return nil, err - } else { - return result.(*model.AppAccount), nil - } -} - -func (a appAccountDo) FindByPage(offset int, limit int) (result []*model.AppAccount, count int64, err error) { - result, err = a.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 = a.Offset(-1).Limit(-1).Count() - return -} - -func (a appAccountDo) ScanByPage(result interface{}, offset int, limit int) (count int64, err error) { - count, err = a.Count() - if err != nil { - return - } - - err = a.Offset(offset).Limit(limit).Scan(result) - return -} - -func (a appAccountDo) Scan(result interface{}) (err error) { - return a.DO.Scan(result) -} - -func (a appAccountDo) Delete(models ...*model.AppAccount) (result gen.ResultInfo, err error) { - return a.DO.Delete(models) -} - -func (a *appAccountDo) withDO(do gen.Dao) *appAccountDo { - a.DO = *do.(*gen.DO) - return a -} diff --git a/gorm-gen/query/app_user.gen.go b/gorm-gen/query/app_user.gen.go deleted file mode 100644 index a71caeb..0000000 --- a/gorm-gen/query/app_user.gen.go +++ /dev/null @@ -1,412 +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 query - -import ( - "context" - - "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" -) - -func newAppUser(db *gorm.DB, opts ...gen.DOOption) appUser { - _appUser := appUser{} - - _appUser.appUserDo.UseDB(db, opts...) - _appUser.appUserDo.UseModel(&model.AppUser{}) - - tableName := _appUser.appUserDo.TableName() - _appUser.ALL = field.NewAsterisk(tableName) - _appUser.ID = field.NewUint64(tableName, "id") - _appUser.AppAccountID = field.NewUint32(tableName, "app_account_id") - _appUser.Openid = field.NewString(tableName, "openid") - _appUser.Unionid = field.NewString(tableName, "unionid") - _appUser.Nickname = field.NewString(tableName, "nickname") - _appUser.Avatar = field.NewString(tableName, "avatar") - _appUser.AnonymousOpenid = field.NewString(tableName, "anonymous_openid") - _appUser.CreatedAt = field.NewTime(tableName, "created_at") - _appUser.UpdatedAt = field.NewTime(tableName, "updated_at") - - _appUser.fillFieldMap() - - return _appUser -} - -type appUser struct { - appUserDo - - ALL field.Asterisk - ID field.Uint64 - AppAccountID field.Uint32 - Openid field.String - Unionid field.String - Nickname field.String - Avatar field.String - AnonymousOpenid field.String - CreatedAt field.Time - UpdatedAt field.Time - - fieldMap map[string]field.Expr -} - -func (a appUser) Table(newTableName string) *appUser { - a.appUserDo.UseTable(newTableName) - return a.updateTableName(newTableName) -} - -func (a appUser) As(alias string) *appUser { - a.appUserDo.DO = *(a.appUserDo.As(alias).(*gen.DO)) - return a.updateTableName(alias) -} - -func (a *appUser) updateTableName(table string) *appUser { - a.ALL = field.NewAsterisk(table) - a.ID = field.NewUint64(table, "id") - a.AppAccountID = field.NewUint32(table, "app_account_id") - a.Openid = field.NewString(table, "openid") - a.Unionid = field.NewString(table, "unionid") - a.Nickname = field.NewString(table, "nickname") - a.Avatar = field.NewString(table, "avatar") - a.AnonymousOpenid = field.NewString(table, "anonymous_openid") - a.CreatedAt = field.NewTime(table, "created_at") - a.UpdatedAt = field.NewTime(table, "updated_at") - - a.fillFieldMap() - - return a -} - -func (a *appUser) GetFieldByName(fieldName string) (field.OrderExpr, bool) { - _f, ok := a.fieldMap[fieldName] - if !ok || _f == nil { - return nil, false - } - _oe, ok := _f.(field.OrderExpr) - return _oe, ok -} - -func (a *appUser) fillFieldMap() { - a.fieldMap = make(map[string]field.Expr, 9) - a.fieldMap["id"] = a.ID - a.fieldMap["app_account_id"] = a.AppAccountID - a.fieldMap["openid"] = a.Openid - a.fieldMap["unionid"] = a.Unionid - a.fieldMap["nickname"] = a.Nickname - a.fieldMap["avatar"] = a.Avatar - a.fieldMap["anonymous_openid"] = a.AnonymousOpenid - a.fieldMap["created_at"] = a.CreatedAt - a.fieldMap["updated_at"] = a.UpdatedAt -} - -func (a appUser) clone(db *gorm.DB) appUser { - a.appUserDo.ReplaceConnPool(db.Statement.ConnPool) - return a -} - -func (a appUser) replaceDB(db *gorm.DB) appUser { - a.appUserDo.ReplaceDB(db) - return a -} - -type appUserDo struct{ gen.DO } - -type IAppUserDo interface { - gen.SubQuery - Debug() IAppUserDo - WithContext(ctx context.Context) IAppUserDo - WithResult(fc func(tx gen.Dao)) gen.ResultInfo - ReplaceDB(db *gorm.DB) - ReadDB() IAppUserDo - WriteDB() IAppUserDo - As(alias string) gen.Dao - Session(config *gorm.Session) IAppUserDo - Columns(cols ...field.Expr) gen.Columns - Clauses(conds ...clause.Expression) IAppUserDo - Not(conds ...gen.Condition) IAppUserDo - Or(conds ...gen.Condition) IAppUserDo - Select(conds ...field.Expr) IAppUserDo - Where(conds ...gen.Condition) IAppUserDo - Order(conds ...field.Expr) IAppUserDo - Distinct(cols ...field.Expr) IAppUserDo - Omit(cols ...field.Expr) IAppUserDo - Join(table schema.Tabler, on ...field.Expr) IAppUserDo - LeftJoin(table schema.Tabler, on ...field.Expr) IAppUserDo - RightJoin(table schema.Tabler, on ...field.Expr) IAppUserDo - Group(cols ...field.Expr) IAppUserDo - Having(conds ...gen.Condition) IAppUserDo - Limit(limit int) IAppUserDo - Offset(offset int) IAppUserDo - Count() (count int64, err error) - Scopes(funcs ...func(gen.Dao) gen.Dao) IAppUserDo - Unscoped() IAppUserDo - Create(values ...*model.AppUser) error - CreateInBatches(values []*model.AppUser, batchSize int) error - Save(values ...*model.AppUser) error - First() (*model.AppUser, error) - Take() (*model.AppUser, error) - Last() (*model.AppUser, error) - Find() ([]*model.AppUser, error) - FindInBatch(batchSize int, fc func(tx gen.Dao, batch int) error) (results []*model.AppUser, err error) - FindInBatches(result *[]*model.AppUser, batchSize int, fc func(tx gen.Dao, batch int) error) error - Pluck(column field.Expr, dest interface{}) error - Delete(...*model.AppUser) (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) IAppUserDo - Assign(attrs ...field.AssignExpr) IAppUserDo - Joins(fields ...field.RelationField) IAppUserDo - Preload(fields ...field.RelationField) IAppUserDo - FirstOrInit() (*model.AppUser, error) - FirstOrCreate() (*model.AppUser, error) - FindByPage(offset int, limit int) (result []*model.AppUser, 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) IAppUserDo - UnderlyingDB() *gorm.DB - schema.Tabler -} - -func (a appUserDo) Debug() IAppUserDo { - return a.withDO(a.DO.Debug()) -} - -func (a appUserDo) WithContext(ctx context.Context) IAppUserDo { - return a.withDO(a.DO.WithContext(ctx)) -} - -func (a appUserDo) ReadDB() IAppUserDo { - return a.Clauses(dbresolver.Read) -} - -func (a appUserDo) WriteDB() IAppUserDo { - return a.Clauses(dbresolver.Write) -} - -func (a appUserDo) Session(config *gorm.Session) IAppUserDo { - return a.withDO(a.DO.Session(config)) -} - -func (a appUserDo) Clauses(conds ...clause.Expression) IAppUserDo { - return a.withDO(a.DO.Clauses(conds...)) -} - -func (a appUserDo) Returning(value interface{}, columns ...string) IAppUserDo { - return a.withDO(a.DO.Returning(value, columns...)) -} - -func (a appUserDo) Not(conds ...gen.Condition) IAppUserDo { - return a.withDO(a.DO.Not(conds...)) -} - -func (a appUserDo) Or(conds ...gen.Condition) IAppUserDo { - return a.withDO(a.DO.Or(conds...)) -} - -func (a appUserDo) Select(conds ...field.Expr) IAppUserDo { - return a.withDO(a.DO.Select(conds...)) -} - -func (a appUserDo) Where(conds ...gen.Condition) IAppUserDo { - return a.withDO(a.DO.Where(conds...)) -} - -func (a appUserDo) Order(conds ...field.Expr) IAppUserDo { - return a.withDO(a.DO.Order(conds...)) -} - -func (a appUserDo) Distinct(cols ...field.Expr) IAppUserDo { - return a.withDO(a.DO.Distinct(cols...)) -} - -func (a appUserDo) Omit(cols ...field.Expr) IAppUserDo { - return a.withDO(a.DO.Omit(cols...)) -} - -func (a appUserDo) Join(table schema.Tabler, on ...field.Expr) IAppUserDo { - return a.withDO(a.DO.Join(table, on...)) -} - -func (a appUserDo) LeftJoin(table schema.Tabler, on ...field.Expr) IAppUserDo { - return a.withDO(a.DO.LeftJoin(table, on...)) -} - -func (a appUserDo) RightJoin(table schema.Tabler, on ...field.Expr) IAppUserDo { - return a.withDO(a.DO.RightJoin(table, on...)) -} - -func (a appUserDo) Group(cols ...field.Expr) IAppUserDo { - return a.withDO(a.DO.Group(cols...)) -} - -func (a appUserDo) Having(conds ...gen.Condition) IAppUserDo { - return a.withDO(a.DO.Having(conds...)) -} - -func (a appUserDo) Limit(limit int) IAppUserDo { - return a.withDO(a.DO.Limit(limit)) -} - -func (a appUserDo) Offset(offset int) IAppUserDo { - return a.withDO(a.DO.Offset(offset)) -} - -func (a appUserDo) Scopes(funcs ...func(gen.Dao) gen.Dao) IAppUserDo { - return a.withDO(a.DO.Scopes(funcs...)) -} - -func (a appUserDo) Unscoped() IAppUserDo { - return a.withDO(a.DO.Unscoped()) -} - -func (a appUserDo) Create(values ...*model.AppUser) error { - if len(values) == 0 { - return nil - } - return a.DO.Create(values) -} - -func (a appUserDo) CreateInBatches(values []*model.AppUser, batchSize int) error { - return a.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 (a appUserDo) Save(values ...*model.AppUser) error { - if len(values) == 0 { - return nil - } - return a.DO.Save(values) -} - -func (a appUserDo) First() (*model.AppUser, error) { - if result, err := a.DO.First(); err != nil { - return nil, err - } else { - return result.(*model.AppUser), nil - } -} - -func (a appUserDo) Take() (*model.AppUser, error) { - if result, err := a.DO.Take(); err != nil { - return nil, err - } else { - return result.(*model.AppUser), nil - } -} - -func (a appUserDo) Last() (*model.AppUser, error) { - if result, err := a.DO.Last(); err != nil { - return nil, err - } else { - return result.(*model.AppUser), nil - } -} - -func (a appUserDo) Find() ([]*model.AppUser, error) { - result, err := a.DO.Find() - return result.([]*model.AppUser), err -} - -func (a appUserDo) FindInBatch(batchSize int, fc func(tx gen.Dao, batch int) error) (results []*model.AppUser, err error) { - buf := make([]*model.AppUser, 0, batchSize) - err = a.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 (a appUserDo) FindInBatches(result *[]*model.AppUser, batchSize int, fc func(tx gen.Dao, batch int) error) error { - return a.DO.FindInBatches(result, batchSize, fc) -} - -func (a appUserDo) Attrs(attrs ...field.AssignExpr) IAppUserDo { - return a.withDO(a.DO.Attrs(attrs...)) -} - -func (a appUserDo) Assign(attrs ...field.AssignExpr) IAppUserDo { - return a.withDO(a.DO.Assign(attrs...)) -} - -func (a appUserDo) Joins(fields ...field.RelationField) IAppUserDo { - for _, _f := range fields { - a = *a.withDO(a.DO.Joins(_f)) - } - return &a -} - -func (a appUserDo) Preload(fields ...field.RelationField) IAppUserDo { - for _, _f := range fields { - a = *a.withDO(a.DO.Preload(_f)) - } - return &a -} - -func (a appUserDo) FirstOrInit() (*model.AppUser, error) { - if result, err := a.DO.FirstOrInit(); err != nil { - return nil, err - } else { - return result.(*model.AppUser), nil - } -} - -func (a appUserDo) FirstOrCreate() (*model.AppUser, error) { - if result, err := a.DO.FirstOrCreate(); err != nil { - return nil, err - } else { - return result.(*model.AppUser), nil - } -} - -func (a appUserDo) FindByPage(offset int, limit int) (result []*model.AppUser, count int64, err error) { - result, err = a.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 = a.Offset(-1).Limit(-1).Count() - return -} - -func (a appUserDo) ScanByPage(result interface{}, offset int, limit int) (count int64, err error) { - count, err = a.Count() - if err != nil { - return - } - - err = a.Offset(offset).Limit(limit).Scan(result) - return -} - -func (a appUserDo) Scan(result interface{}) (err error) { - return a.DO.Scan(result) -} - -func (a appUserDo) Delete(models ...*model.AppUser) (result gen.ResultInfo, err error) { - return a.DO.Delete(models) -} - -func (a *appUserDo) withDO(do gen.Dao) *appUserDo { - a.DO = *do.(*gen.DO) - return a -} diff --git a/gorm-gen/query/douyin_ecpm_config.gen.go b/gorm-gen/query/douyin_ecpm_config.gen.go deleted file mode 100644 index c0e8af4..0000000 --- a/gorm-gen/query/douyin_ecpm_config.gen.go +++ /dev/null @@ -1,392 +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 query - -import ( - "context" - - "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" -) - -func newDouyinEcpmConfig(db *gorm.DB, opts ...gen.DOOption) douyinEcpmConfig { - _douyinEcpmConfig := douyinEcpmConfig{} - - _douyinEcpmConfig.douyinEcpmConfigDo.UseDB(db, opts...) - _douyinEcpmConfig.douyinEcpmConfigDo.UseModel(&model.DouyinEcpmConfig{}) - - tableName := _douyinEcpmConfig.douyinEcpmConfigDo.TableName() - _douyinEcpmConfig.ALL = field.NewAsterisk(tableName) - _douyinEcpmConfig.ID = field.NewUint32(tableName, "id") - _douyinEcpmConfig.AppAccountID = field.NewUint32(tableName, "app_account_id") - _douyinEcpmConfig.EcpmValue = field.NewUint32(tableName, "ecpm_value") - _douyinEcpmConfig.EcpmView = field.NewUint32(tableName, "ecpm_view") - - _douyinEcpmConfig.fillFieldMap() - - return _douyinEcpmConfig -} - -type douyinEcpmConfig struct { - douyinEcpmConfigDo - - ALL field.Asterisk - ID field.Uint32 - AppAccountID field.Uint32 - EcpmValue field.Uint32 - EcpmView field.Uint32 - - fieldMap map[string]field.Expr -} - -func (d douyinEcpmConfig) Table(newTableName string) *douyinEcpmConfig { - d.douyinEcpmConfigDo.UseTable(newTableName) - return d.updateTableName(newTableName) -} - -func (d douyinEcpmConfig) As(alias string) *douyinEcpmConfig { - d.douyinEcpmConfigDo.DO = *(d.douyinEcpmConfigDo.As(alias).(*gen.DO)) - return d.updateTableName(alias) -} - -func (d *douyinEcpmConfig) updateTableName(table string) *douyinEcpmConfig { - d.ALL = field.NewAsterisk(table) - d.ID = field.NewUint32(table, "id") - d.AppAccountID = field.NewUint32(table, "app_account_id") - d.EcpmValue = field.NewUint32(table, "ecpm_value") - d.EcpmView = field.NewUint32(table, "ecpm_view") - - d.fillFieldMap() - - return d -} - -func (d *douyinEcpmConfig) GetFieldByName(fieldName string) (field.OrderExpr, bool) { - _f, ok := d.fieldMap[fieldName] - if !ok || _f == nil { - return nil, false - } - _oe, ok := _f.(field.OrderExpr) - return _oe, ok -} - -func (d *douyinEcpmConfig) fillFieldMap() { - d.fieldMap = make(map[string]field.Expr, 4) - d.fieldMap["id"] = d.ID - d.fieldMap["app_account_id"] = d.AppAccountID - d.fieldMap["ecpm_value"] = d.EcpmValue - d.fieldMap["ecpm_view"] = d.EcpmView -} - -func (d douyinEcpmConfig) clone(db *gorm.DB) douyinEcpmConfig { - d.douyinEcpmConfigDo.ReplaceConnPool(db.Statement.ConnPool) - return d -} - -func (d douyinEcpmConfig) replaceDB(db *gorm.DB) douyinEcpmConfig { - d.douyinEcpmConfigDo.ReplaceDB(db) - return d -} - -type douyinEcpmConfigDo struct{ gen.DO } - -type IDouyinEcpmConfigDo interface { - gen.SubQuery - Debug() IDouyinEcpmConfigDo - WithContext(ctx context.Context) IDouyinEcpmConfigDo - WithResult(fc func(tx gen.Dao)) gen.ResultInfo - ReplaceDB(db *gorm.DB) - ReadDB() IDouyinEcpmConfigDo - WriteDB() IDouyinEcpmConfigDo - As(alias string) gen.Dao - Session(config *gorm.Session) IDouyinEcpmConfigDo - Columns(cols ...field.Expr) gen.Columns - Clauses(conds ...clause.Expression) IDouyinEcpmConfigDo - Not(conds ...gen.Condition) IDouyinEcpmConfigDo - Or(conds ...gen.Condition) IDouyinEcpmConfigDo - Select(conds ...field.Expr) IDouyinEcpmConfigDo - Where(conds ...gen.Condition) IDouyinEcpmConfigDo - Order(conds ...field.Expr) IDouyinEcpmConfigDo - Distinct(cols ...field.Expr) IDouyinEcpmConfigDo - Omit(cols ...field.Expr) IDouyinEcpmConfigDo - Join(table schema.Tabler, on ...field.Expr) IDouyinEcpmConfigDo - LeftJoin(table schema.Tabler, on ...field.Expr) IDouyinEcpmConfigDo - RightJoin(table schema.Tabler, on ...field.Expr) IDouyinEcpmConfigDo - Group(cols ...field.Expr) IDouyinEcpmConfigDo - Having(conds ...gen.Condition) IDouyinEcpmConfigDo - Limit(limit int) IDouyinEcpmConfigDo - Offset(offset int) IDouyinEcpmConfigDo - Count() (count int64, err error) - Scopes(funcs ...func(gen.Dao) gen.Dao) IDouyinEcpmConfigDo - Unscoped() IDouyinEcpmConfigDo - Create(values ...*model.DouyinEcpmConfig) error - CreateInBatches(values []*model.DouyinEcpmConfig, batchSize int) error - Save(values ...*model.DouyinEcpmConfig) error - First() (*model.DouyinEcpmConfig, error) - Take() (*model.DouyinEcpmConfig, error) - Last() (*model.DouyinEcpmConfig, error) - Find() ([]*model.DouyinEcpmConfig, error) - FindInBatch(batchSize int, fc func(tx gen.Dao, batch int) error) (results []*model.DouyinEcpmConfig, err error) - FindInBatches(result *[]*model.DouyinEcpmConfig, batchSize int, fc func(tx gen.Dao, batch int) error) error - Pluck(column field.Expr, dest interface{}) error - Delete(...*model.DouyinEcpmConfig) (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) IDouyinEcpmConfigDo - Assign(attrs ...field.AssignExpr) IDouyinEcpmConfigDo - Joins(fields ...field.RelationField) IDouyinEcpmConfigDo - Preload(fields ...field.RelationField) IDouyinEcpmConfigDo - FirstOrInit() (*model.DouyinEcpmConfig, error) - FirstOrCreate() (*model.DouyinEcpmConfig, error) - FindByPage(offset int, limit int) (result []*model.DouyinEcpmConfig, 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) IDouyinEcpmConfigDo - UnderlyingDB() *gorm.DB - schema.Tabler -} - -func (d douyinEcpmConfigDo) Debug() IDouyinEcpmConfigDo { - return d.withDO(d.DO.Debug()) -} - -func (d douyinEcpmConfigDo) WithContext(ctx context.Context) IDouyinEcpmConfigDo { - return d.withDO(d.DO.WithContext(ctx)) -} - -func (d douyinEcpmConfigDo) ReadDB() IDouyinEcpmConfigDo { - return d.Clauses(dbresolver.Read) -} - -func (d douyinEcpmConfigDo) WriteDB() IDouyinEcpmConfigDo { - return d.Clauses(dbresolver.Write) -} - -func (d douyinEcpmConfigDo) Session(config *gorm.Session) IDouyinEcpmConfigDo { - return d.withDO(d.DO.Session(config)) -} - -func (d douyinEcpmConfigDo) Clauses(conds ...clause.Expression) IDouyinEcpmConfigDo { - return d.withDO(d.DO.Clauses(conds...)) -} - -func (d douyinEcpmConfigDo) Returning(value interface{}, columns ...string) IDouyinEcpmConfigDo { - return d.withDO(d.DO.Returning(value, columns...)) -} - -func (d douyinEcpmConfigDo) Not(conds ...gen.Condition) IDouyinEcpmConfigDo { - return d.withDO(d.DO.Not(conds...)) -} - -func (d douyinEcpmConfigDo) Or(conds ...gen.Condition) IDouyinEcpmConfigDo { - return d.withDO(d.DO.Or(conds...)) -} - -func (d douyinEcpmConfigDo) Select(conds ...field.Expr) IDouyinEcpmConfigDo { - return d.withDO(d.DO.Select(conds...)) -} - -func (d douyinEcpmConfigDo) Where(conds ...gen.Condition) IDouyinEcpmConfigDo { - return d.withDO(d.DO.Where(conds...)) -} - -func (d douyinEcpmConfigDo) Order(conds ...field.Expr) IDouyinEcpmConfigDo { - return d.withDO(d.DO.Order(conds...)) -} - -func (d douyinEcpmConfigDo) Distinct(cols ...field.Expr) IDouyinEcpmConfigDo { - return d.withDO(d.DO.Distinct(cols...)) -} - -func (d douyinEcpmConfigDo) Omit(cols ...field.Expr) IDouyinEcpmConfigDo { - return d.withDO(d.DO.Omit(cols...)) -} - -func (d douyinEcpmConfigDo) Join(table schema.Tabler, on ...field.Expr) IDouyinEcpmConfigDo { - return d.withDO(d.DO.Join(table, on...)) -} - -func (d douyinEcpmConfigDo) LeftJoin(table schema.Tabler, on ...field.Expr) IDouyinEcpmConfigDo { - return d.withDO(d.DO.LeftJoin(table, on...)) -} - -func (d douyinEcpmConfigDo) RightJoin(table schema.Tabler, on ...field.Expr) IDouyinEcpmConfigDo { - return d.withDO(d.DO.RightJoin(table, on...)) -} - -func (d douyinEcpmConfigDo) Group(cols ...field.Expr) IDouyinEcpmConfigDo { - return d.withDO(d.DO.Group(cols...)) -} - -func (d douyinEcpmConfigDo) Having(conds ...gen.Condition) IDouyinEcpmConfigDo { - return d.withDO(d.DO.Having(conds...)) -} - -func (d douyinEcpmConfigDo) Limit(limit int) IDouyinEcpmConfigDo { - return d.withDO(d.DO.Limit(limit)) -} - -func (d douyinEcpmConfigDo) Offset(offset int) IDouyinEcpmConfigDo { - return d.withDO(d.DO.Offset(offset)) -} - -func (d douyinEcpmConfigDo) Scopes(funcs ...func(gen.Dao) gen.Dao) IDouyinEcpmConfigDo { - return d.withDO(d.DO.Scopes(funcs...)) -} - -func (d douyinEcpmConfigDo) Unscoped() IDouyinEcpmConfigDo { - return d.withDO(d.DO.Unscoped()) -} - -func (d douyinEcpmConfigDo) Create(values ...*model.DouyinEcpmConfig) error { - if len(values) == 0 { - return nil - } - return d.DO.Create(values) -} - -func (d douyinEcpmConfigDo) CreateInBatches(values []*model.DouyinEcpmConfig, batchSize int) error { - return d.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 (d douyinEcpmConfigDo) Save(values ...*model.DouyinEcpmConfig) error { - if len(values) == 0 { - return nil - } - return d.DO.Save(values) -} - -func (d douyinEcpmConfigDo) First() (*model.DouyinEcpmConfig, error) { - if result, err := d.DO.First(); err != nil { - return nil, err - } else { - return result.(*model.DouyinEcpmConfig), nil - } -} - -func (d douyinEcpmConfigDo) Take() (*model.DouyinEcpmConfig, error) { - if result, err := d.DO.Take(); err != nil { - return nil, err - } else { - return result.(*model.DouyinEcpmConfig), nil - } -} - -func (d douyinEcpmConfigDo) Last() (*model.DouyinEcpmConfig, error) { - if result, err := d.DO.Last(); err != nil { - return nil, err - } else { - return result.(*model.DouyinEcpmConfig), nil - } -} - -func (d douyinEcpmConfigDo) Find() ([]*model.DouyinEcpmConfig, error) { - result, err := d.DO.Find() - return result.([]*model.DouyinEcpmConfig), err -} - -func (d douyinEcpmConfigDo) FindInBatch(batchSize int, fc func(tx gen.Dao, batch int) error) (results []*model.DouyinEcpmConfig, err error) { - buf := make([]*model.DouyinEcpmConfig, 0, batchSize) - err = d.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 (d douyinEcpmConfigDo) FindInBatches(result *[]*model.DouyinEcpmConfig, batchSize int, fc func(tx gen.Dao, batch int) error) error { - return d.DO.FindInBatches(result, batchSize, fc) -} - -func (d douyinEcpmConfigDo) Attrs(attrs ...field.AssignExpr) IDouyinEcpmConfigDo { - return d.withDO(d.DO.Attrs(attrs...)) -} - -func (d douyinEcpmConfigDo) Assign(attrs ...field.AssignExpr) IDouyinEcpmConfigDo { - return d.withDO(d.DO.Assign(attrs...)) -} - -func (d douyinEcpmConfigDo) Joins(fields ...field.RelationField) IDouyinEcpmConfigDo { - for _, _f := range fields { - d = *d.withDO(d.DO.Joins(_f)) - } - return &d -} - -func (d douyinEcpmConfigDo) Preload(fields ...field.RelationField) IDouyinEcpmConfigDo { - for _, _f := range fields { - d = *d.withDO(d.DO.Preload(_f)) - } - return &d -} - -func (d douyinEcpmConfigDo) FirstOrInit() (*model.DouyinEcpmConfig, error) { - if result, err := d.DO.FirstOrInit(); err != nil { - return nil, err - } else { - return result.(*model.DouyinEcpmConfig), nil - } -} - -func (d douyinEcpmConfigDo) FirstOrCreate() (*model.DouyinEcpmConfig, error) { - if result, err := d.DO.FirstOrCreate(); err != nil { - return nil, err - } else { - return result.(*model.DouyinEcpmConfig), nil - } -} - -func (d douyinEcpmConfigDo) FindByPage(offset int, limit int) (result []*model.DouyinEcpmConfig, count int64, err error) { - result, err = d.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 = d.Offset(-1).Limit(-1).Count() - return -} - -func (d douyinEcpmConfigDo) ScanByPage(result interface{}, offset int, limit int) (count int64, err error) { - count, err = d.Count() - if err != nil { - return - } - - err = d.Offset(offset).Limit(limit).Scan(result) - return -} - -func (d douyinEcpmConfigDo) Scan(result interface{}) (err error) { - return d.DO.Scan(result) -} - -func (d douyinEcpmConfigDo) Delete(models ...*model.DouyinEcpmConfig) (result gen.ResultInfo, err error) { - return d.DO.Delete(models) -} - -func (d *douyinEcpmConfigDo) withDO(do gen.Dao) *douyinEcpmConfigDo { - d.DO = *do.(*gen.DO) - return d -} diff --git a/gorm-gen/query/game_score.gen.go b/gorm-gen/query/game_score.gen.go deleted file mode 100644 index 5a2af5c..0000000 --- a/gorm-gen/query/game_score.gen.go +++ /dev/null @@ -1,448 +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 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 -} diff --git a/gorm-gen/query/gen.go b/gorm-gen/query/gen.go deleted file mode 100644 index 975700f..0000000 --- a/gorm-gen/query/gen.go +++ /dev/null @@ -1,127 +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 query - -import ( - "context" - "database/sql" - - "gorm.io/gorm" - - "gorm.io/gen" - - "gorm.io/plugin/dbresolver" -) - -var ( - Q = new(Query) - AppAccount *appAccount - AppUser *appUser - DouyinEcpmConfig *douyinEcpmConfig - GameScore *gameScore -) - -func SetDefault(db *gorm.DB, opts ...gen.DOOption) { - *Q = *Use(db, opts...) - AppAccount = &Q.AppAccount - AppUser = &Q.AppUser - DouyinEcpmConfig = &Q.DouyinEcpmConfig - GameScore = &Q.GameScore -} - -func Use(db *gorm.DB, opts ...gen.DOOption) *Query { - return &Query{ - db: db, - AppAccount: newAppAccount(db, opts...), - AppUser: newAppUser(db, opts...), - DouyinEcpmConfig: newDouyinEcpmConfig(db, opts...), - GameScore: newGameScore(db, opts...), - } -} - -type Query struct { - db *gorm.DB - - AppAccount appAccount - AppUser appUser - DouyinEcpmConfig douyinEcpmConfig - GameScore gameScore -} - -func (q *Query) Available() bool { return q.db != nil } - -func (q *Query) clone(db *gorm.DB) *Query { - return &Query{ - db: db, - AppAccount: q.AppAccount.clone(db), - AppUser: q.AppUser.clone(db), - DouyinEcpmConfig: q.DouyinEcpmConfig.clone(db), - GameScore: q.GameScore.clone(db), - } -} - -func (q *Query) ReadDB() *Query { - return q.ReplaceDB(q.db.Clauses(dbresolver.Read)) -} - -func (q *Query) WriteDB() *Query { - return q.ReplaceDB(q.db.Clauses(dbresolver.Write)) -} - -func (q *Query) ReplaceDB(db *gorm.DB) *Query { - return &Query{ - db: db, - AppAccount: q.AppAccount.replaceDB(db), - AppUser: q.AppUser.replaceDB(db), - DouyinEcpmConfig: q.DouyinEcpmConfig.replaceDB(db), - GameScore: q.GameScore.replaceDB(db), - } -} - -type queryCtx struct { - AppAccount IAppAccountDo - AppUser IAppUserDo - DouyinEcpmConfig IDouyinEcpmConfigDo - GameScore IGameScoreDo -} - -func (q *Query) WithContext(ctx context.Context) *queryCtx { - return &queryCtx{ - AppAccount: q.AppAccount.WithContext(ctx), - AppUser: q.AppUser.WithContext(ctx), - DouyinEcpmConfig: q.DouyinEcpmConfig.WithContext(ctx), - GameScore: q.GameScore.WithContext(ctx), - } -} - -func (q *Query) Transaction(fc func(tx *Query) error, opts ...*sql.TxOptions) error { - return q.db.Transaction(func(tx *gorm.DB) error { return fc(q.clone(tx)) }, opts...) -} - -func (q *Query) Begin(opts ...*sql.TxOptions) *QueryTx { - tx := q.db.Begin(opts...) - return &QueryTx{Query: q.clone(tx), Error: tx.Error} -} - -type QueryTx struct { - *Query - Error error -} - -func (q *QueryTx) Commit() error { - return q.db.Commit().Error -} - -func (q *QueryTx) Rollback() error { - return q.db.Rollback().Error -} - -func (q *QueryTx) SavePoint(name string) error { - return q.db.SavePoint(name).Error -} - -func (q *QueryTx) RollbackTo(name string) error { - return q.db.RollbackTo(name).Error -}