1
Some checks failed
Auth & User Management Service CI / build-services (app/auth_service/Dockerfile, auth_service, auth_service) (push) Successful in 37s
Auth & User Management Service CI / build-services (app/douyin_ecpm_calculation_service/Dockerfile, douyin_ecpm_calculation_service, douyin_ecpm_calculation_service) (push) Successful in 37s
Auth & User Management Service CI / build-services (app/ranking_management/Dockerfile, ranking_management, ranking_management) (push) Failing after 28s
Auth & User Management Service CI / build-services (app/user_management/Dockerfile, user_manager, user_management) (push) Successful in 40s
Auth & User Management Service CI / start-services (push) Has been skipped

This commit is contained in:
xiabin 2025-02-11 17:14:53 +08:00
parent c7f5f9828a
commit d952782011
18 changed files with 136 additions and 1774 deletions

View File

@ -17,7 +17,7 @@ import (
"gorm.io/plugin/dbresolver"
"gitea.youtukeji.com.cn/xiabin/youtu_grpc/pkg/my_gorm/gen/dao/model"
"gitea.youtukeji.com.cn/xiabin/youtu_grpc/app/ranking_management/internal/gen/dao/model"
"gitea.youtukeji.com.cn/xiabin/youtu_grpc/pkg/my_gorm/gen/querier"
)

View File

@ -7,9 +7,10 @@ package query
import (
"context"
"fmt"
"strconv"
"testing"
"gitea.youtukeji.com.cn/xiabin/youtu_grpc/pkg/my_gorm/gen/dao/model"
"gitea.youtukeji.com.cn/xiabin/youtu_grpc/app/ranking_management/internal/gen/dao/model"
"gorm.io/gen"
"gorm.io/gen/field"
"gorm.io/gorm/clause"
@ -143,3 +144,33 @@ func Test_gameScoreQuery(t *testing.T) {
t.Error("Not/Or/Clauses on table <game_score> fail:", err)
}
}
var GameScoreGetUserRankTestCase = []TestCase{}
func Test_gameScore_GetUserRank(t *testing.T) {
gameScore := newGameScore(_gen_test_db)
do := gameScore.WithContext(context.Background()).Debug()
for i, tt := range GameScoreGetUserRankTestCase {
t.Run("GetUserRank_"+strconv.Itoa(i), func(t *testing.T) {
res1, res2 := do.GetUserRank(tt.Input.Args[0].(uint32), tt.Input.Args[1].(uint64), tt.Input.Args[2].(uint32))
assert(t, "GetUserRank", res1, tt.Expectation.Ret[0])
assert(t, "GetUserRank", res2, tt.Expectation.Ret[1])
})
}
}
var GameScoreFindDistinctRankingTestCase = []TestCase{}
func Test_gameScore_FindDistinctRanking(t *testing.T) {
gameScore := newGameScore(_gen_test_db)
do := gameScore.WithContext(context.Background()).Debug()
for i, tt := range GameScoreFindDistinctRankingTestCase {
t.Run("FindDistinctRanking_"+strconv.Itoa(i), func(t *testing.T) {
res1, res2 := do.FindDistinctRanking()
assert(t, "FindDistinctRanking", res1, tt.Expectation.Ret[0])
assert(t, "FindDistinctRanking", res2, tt.Expectation.Ret[1])
})
}
}

View File

@ -17,26 +17,17 @@ import (
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...),
}
}
@ -44,9 +35,6 @@ func Use(db *gorm.DB, opts ...gen.DOOption) *Query {
type Query struct {
db *gorm.DB
AppAccount appAccount
AppUser appUser
DouyinEcpmConfig douyinEcpmConfig
GameScore gameScore
}
@ -55,9 +43,6 @@ 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),
}
}
@ -73,25 +58,16 @@ func (q *Query) WriteDB() *Query {
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),
}
}

View File

@ -77,9 +77,6 @@ func Test_WithContext(t *testing.T) {
qCtx := query.WithContext(context.WithValue(context.Background(), key, value))
for _, ctx := range []context.Context{
qCtx.AppAccount.UnderlyingDB().Statement.Context,
qCtx.AppUser.UnderlyingDB().Statement.Context,
qCtx.DouyinEcpmConfig.UnderlyingDB().Statement.Context,
qCtx.GameScore.UnderlyingDB().Statement.Context,
} {
if v := ctx.Value(key); v != value {

View File

@ -0,0 +1,14 @@
version: "0.1"
database:
dsn : "root:youtu!0113@tcp(192.168.0.47:3306)/ecpm?charset=utf8mb4&parseTime=True&loc=Local"
db : "mysql"
tables :
- "game_score"
outPath : "./dao/query"
outFile : ""
withUnitTest : true
modelPkgName : "model"
fieldNullable : true
fieldWithIndexTag : true
fieldWithTypeTag : true
fieldSignable : true

View File

@ -0,0 +1,76 @@
package main
import (
"gitea.youtukeji.com.cn/xiabin/youtu_grpc/app/ranking_management/internal/gen/dao/model"
"gitea.youtukeji.com.cn/xiabin/youtu_grpc/pkg/my_gorm/gen/querier"
"gorm.io/driver/mysql"
"gorm.io/gen"
"gorm.io/gorm"
)
func main() {
g := gen.NewGenerator(gen.Config{
OutPath: "./app/ranking_management/internal/gen/dao/query",
Mode: gen.WithoutContext | gen.WithDefaultQuery | gen.WithQueryInterface, // generate mode
WithUnitTest: true,
})
dsn := "root:youtu!0113@tcp(192.168.0.47:3306)/ecpm?charset=utf8&parseTime=True&loc=Local"
db, err := gorm.Open(mysql.Open(dsn), &gorm.Config{})
if err != nil {
panic(err)
}
// gormdb, _ := gorm.Open(mysql.Open("root:@(127.0.0.1:3306)/demo?charset=utf8mb4&parseTime=True&loc=Local"))
g.UseDB(db) // reuse your gorm db
//g.ApplyBasic(model.AppAccount{}, model.AppUser{}, model.DouyinEcpmConfig{}, model.GameScore{})
// Generate Type Safe API with Dynamic SQL defined on Querier interface for `model.User` and `model.Company`
g.ApplyInterface(func(querier.GameScoreQuerier) {}, model.GameScore{})
g.ApplyBasic(model.GameScore{})
// Generate the code
g.Execute()
}
type GameScoreQuerier interface {
/*
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 = @t
AND game_score.app_account = @appId
) AS gs
LEFT JOIN app_user ON app_user.id = gs.app_user_id
WHERE
gs.app_user_id = @userId
LIMIT 1;
*/
GetUserRank(appId uint32, userId uint64, t uint32) (resp RankingData, err error)
//select DISTINCT app_account,t from game_score
FindDistinctRanking() (resp []*gen.T, err error)
}
type RankingData struct {
Nickname string `json:"nickname" db:"nickname"` // 昵称
Avatar string `json:"avatar" db:"avatar"` // 头像
Score uint32 `json:"score" db:"score"` // 得分
UserId uint64 `json:"userId" db:"app_user_id"` // 用户 ID
Rank uint32 `json:"rank" db:"t_rank"` // 排名
Self bool `json:"self" db:"-"` // 是否是自己
}

View File

@ -3,10 +3,10 @@ package logic
import (
"context"
"errors"
"gitea.youtukeji.com.cn/xiabin/youtu_grpc/app/ranking_management/internal/gen/dao/model"
"gitea.youtukeji.com.cn/xiabin/youtu_grpc/app/ranking_management/internal/logic/rankings"
"gitea.youtukeji.com.cn/xiabin/youtu_grpc/app/ranking_management/internal/svc"
"gitea.youtukeji.com.cn/xiabin/youtu_grpc/app/ranking_management/ranking_management"
"gitea.youtukeji.com.cn/xiabin/youtu_grpc/pkg/my_gorm/gen/dao/model"
"github.com/redis/go-redis/v9"
"gorm.io/gorm"
"time"

View File

@ -2,10 +2,10 @@ package svc
import (
"context"
"gitea.youtukeji.com.cn/xiabin/youtu_grpc/app/ranking_management/internal/gen/dao/query"
"gitea.youtukeji.com.cn/xiabin/youtu_grpc/app/ranking_management/internal/logic/rankings"
"gitea.youtukeji.com.cn/xiabin/youtu_grpc/pkg/config"
"gitea.youtukeji.com.cn/xiabin/youtu_grpc/pkg/my_gorm"
"gitea.youtukeji.com.cn/xiabin/youtu_grpc/pkg/my_gorm/gen/dao/query"
"github.com/redis/go-redis/v9"
"gorm.io/driver/mysql"
"gorm.io/gorm"

View File

@ -1,26 +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 model
import (
"gorm.io/gorm"
)
const TableNameAppAccount = "app_account"
// AppAccount mapped from table <app_account>
type AppAccount struct {
ID uint32 `gorm:"column:id;type:int unsigned;primaryKey;autoIncrement:true" json:"id"`
Type uint32 `gorm:"column:type;type:tinyint unsigned;not null;comment:类型(0:抖音,1:微信)" json:"type"` // 类型(0:抖音,1:微信)
AppID string `gorm:"column:app_id;type:char(20);not null;uniqueIndex:app_id,priority:1" json:"app_id"`
Secret string `gorm:"column:secret;type:char(40);not null" json:"secret"`
Remark *string `gorm:"column:remark;type:varchar(255);comment:备注" json:"remark"` // 备注
DeletedAt gorm.DeletedAt `gorm:"column:deleted_at;type:time" json:"deleted_at"`
}
// TableName AppAccount's table name
func (*AppAccount) TableName() string {
return TableNameAppAccount
}

View File

@ -1,30 +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 model
import (
"time"
)
const TableNameAppUser = "app_user"
// AppUser mapped from table <app_user>
type AppUser struct {
ID uint64 `gorm:"column:id;type:bigint unsigned;primaryKey;autoIncrement:true;index:idx_app_user_id,priority:1" json:"id"`
AppAccountID uint32 `gorm:"column:app_account_id;type:int unsigned;not null;uniqueIndex:app_account_id_open_id,priority:1;comment:app_account表外键" json:"app_account_id"` // app_account表外键
Openid string `gorm:"column:openid;type:varchar(255);not null;uniqueIndex:app_account_id_open_id,priority:2" json:"openid"`
Unionid string `gorm:"column:unionid;type:varchar(255);not null" json:"unionid"`
Nickname string `gorm:"column:nickname;type:varchar(255);not null;comment:昵称" json:"nickname"` // 昵称
Avatar string `gorm:"column:avatar;type:varchar(255);not null;comment:头像" json:"avatar"` // 头像
AnonymousOpenid string `gorm:"column:anonymous_openid;type:varchar(255);not null;comment:匿名openid" json:"anonymous_openid"` // 匿名openid
IsGetNicknameAndAvatar bool `gorm:"column:is_get_nickname_and_avatar;type:tinyint(1);not null;default:0;comment:是否获取到昵称和头像(初始化)" json:"is_get_nickname_and_avatar"`
CreatedAt time.Time `gorm:"column:created_at;type:datetime;not null;default:CURRENT_TIMESTAMP;comment:创建时间" json:"created_at"` // 创建时间
UpdatedAt time.Time `gorm:"column:updated_at;type:datetime;not null;default:CURRENT_TIMESTAMP;comment:更新时间" json:"updated_at"` // 更新时间
}
// TableName AppUser's table name
func (*AppUser) TableName() string {
return TableNameAppUser
}

View File

@ -1,20 +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 model
const TableNameDouyinEcpmConfig = "douyin_ecpm_config"
// DouyinEcpmConfig mapped from table <douyin_ecpm_config>
type DouyinEcpmConfig struct {
ID uint32 `gorm:"column:id;type:int unsigned;primaryKey;autoIncrement:true" json:"id"`
AppAccountID uint32 `gorm:"column:app_account_id;type:int unsigned;not null;index:app_account_id,priority:1" json:"app_account_id"`
EcpmValue uint32 `gorm:"column:ecpm_value;type:int unsigned;not null;comment:值" json:"ecpm_value"` // 值
EcpmView uint32 `gorm:"column:ecpm_view;type:int unsigned;not null;comment:浏览次数" json:"ecpm_view"` // 浏览次数
}
// TableName DouyinEcpmConfig's table name
func (*DouyinEcpmConfig) TableName() string {
return TableNameDouyinEcpmConfig
}

View File

@ -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_grpc/pkg/my_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
}

View File

@ -1,145 +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"
"fmt"
"testing"
"gitea.youtukeji.com.cn/xiabin/youtu_grpc/pkg/my_gorm/gen/dao/model"
"gorm.io/gen"
"gorm.io/gen/field"
"gorm.io/gorm/clause"
)
func init() {
InitializeDB()
err := _gen_test_db.AutoMigrate(&model.AppAccount{})
if err != nil {
fmt.Printf("Error: AutoMigrate(&model.AppAccount{}) fail: %s", err)
}
}
func Test_appAccountQuery(t *testing.T) {
appAccount := newAppAccount(_gen_test_db)
appAccount = *appAccount.As(appAccount.TableName())
_do := appAccount.WithContext(context.Background()).Debug()
primaryKey := field.NewString(appAccount.TableName(), clause.PrimaryKey)
_, err := _do.Unscoped().Where(primaryKey.IsNotNull()).Delete()
if err != nil {
t.Error("clean table <app_account> fail:", err)
return
}
_, ok := appAccount.GetFieldByName("")
if ok {
t.Error("GetFieldByName(\"\") from appAccount success")
}
err = _do.Create(&model.AppAccount{})
if err != nil {
t.Error("create item in table <app_account> fail:", err)
}
err = _do.Save(&model.AppAccount{})
if err != nil {
t.Error("create item in table <app_account> fail:", err)
}
err = _do.CreateInBatches([]*model.AppAccount{{}, {}}, 10)
if err != nil {
t.Error("create item in table <app_account> fail:", err)
}
_, err = _do.Select(appAccount.ALL).Take()
if err != nil {
t.Error("Take() on table <app_account> fail:", err)
}
_, err = _do.First()
if err != nil {
t.Error("First() on table <app_account> fail:", err)
}
_, err = _do.Last()
if err != nil {
t.Error("First() on table <app_account> fail:", err)
}
_, err = _do.Where(primaryKey.IsNotNull()).FindInBatch(10, func(tx gen.Dao, batch int) error { return nil })
if err != nil {
t.Error("FindInBatch() on table <app_account> fail:", err)
}
err = _do.Where(primaryKey.IsNotNull()).FindInBatches(&[]*model.AppAccount{}, 10, func(tx gen.Dao, batch int) error { return nil })
if err != nil {
t.Error("FindInBatches() on table <app_account> fail:", err)
}
_, err = _do.Select(appAccount.ALL).Where(primaryKey.IsNotNull()).Order(primaryKey.Desc()).Find()
if err != nil {
t.Error("Find() on table <app_account> fail:", err)
}
_, err = _do.Distinct(primaryKey).Take()
if err != nil {
t.Error("select Distinct() on table <app_account> fail:", err)
}
_, err = _do.Select(appAccount.ALL).Omit(primaryKey).Take()
if err != nil {
t.Error("Omit() on table <app_account> fail:", err)
}
_, err = _do.Group(primaryKey).Find()
if err != nil {
t.Error("Group() on table <app_account> fail:", err)
}
_, err = _do.Scopes(func(dao gen.Dao) gen.Dao { return dao.Where(primaryKey.IsNotNull()) }).Find()
if err != nil {
t.Error("Scopes() on table <app_account> fail:", err)
}
_, _, err = _do.FindByPage(0, 1)
if err != nil {
t.Error("FindByPage() on table <app_account> fail:", err)
}
_, err = _do.ScanByPage(&model.AppAccount{}, 0, 1)
if err != nil {
t.Error("ScanByPage() on table <app_account> fail:", err)
}
_, err = _do.Attrs(primaryKey).Assign(primaryKey).FirstOrInit()
if err != nil {
t.Error("FirstOrInit() on table <app_account> fail:", err)
}
_, err = _do.Attrs(primaryKey).Assign(primaryKey).FirstOrCreate()
if err != nil {
t.Error("FirstOrCreate() on table <app_account> fail:", err)
}
var _a _another
var _aPK = field.NewString(_a.TableName(), "id")
err = _do.Join(&_a, primaryKey.EqCol(_aPK)).Scan(map[string]interface{}{})
if err != nil {
t.Error("Join() on table <app_account> fail:", err)
}
err = _do.LeftJoin(&_a, primaryKey.EqCol(_aPK)).Scan(map[string]interface{}{})
if err != nil {
t.Error("LeftJoin() on table <app_account> fail:", err)
}
_, err = _do.Not().Or().Clauses().Take()
if err != nil {
t.Error("Not/Or/Clauses on table <app_account> fail:", err)
}
}

View File

@ -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_grpc/pkg/my_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
}

View File

@ -1,145 +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"
"fmt"
"testing"
"gitea.youtukeji.com.cn/xiabin/youtu_grpc/pkg/my_gorm/gen/dao/model"
"gorm.io/gen"
"gorm.io/gen/field"
"gorm.io/gorm/clause"
)
func init() {
InitializeDB()
err := _gen_test_db.AutoMigrate(&model.AppUser{})
if err != nil {
fmt.Printf("Error: AutoMigrate(&model.AppUser{}) fail: %s", err)
}
}
func Test_appUserQuery(t *testing.T) {
appUser := newAppUser(_gen_test_db)
appUser = *appUser.As(appUser.TableName())
_do := appUser.WithContext(context.Background()).Debug()
primaryKey := field.NewString(appUser.TableName(), clause.PrimaryKey)
_, err := _do.Unscoped().Where(primaryKey.IsNotNull()).Delete()
if err != nil {
t.Error("clean table <app_user> fail:", err)
return
}
_, ok := appUser.GetFieldByName("")
if ok {
t.Error("GetFieldByName(\"\") from appUser success")
}
err = _do.Create(&model.AppUser{})
if err != nil {
t.Error("create item in table <app_user> fail:", err)
}
err = _do.Save(&model.AppUser{})
if err != nil {
t.Error("create item in table <app_user> fail:", err)
}
err = _do.CreateInBatches([]*model.AppUser{{}, {}}, 10)
if err != nil {
t.Error("create item in table <app_user> fail:", err)
}
_, err = _do.Select(appUser.ALL).Take()
if err != nil {
t.Error("Take() on table <app_user> fail:", err)
}
_, err = _do.First()
if err != nil {
t.Error("First() on table <app_user> fail:", err)
}
_, err = _do.Last()
if err != nil {
t.Error("First() on table <app_user> fail:", err)
}
_, err = _do.Where(primaryKey.IsNotNull()).FindInBatch(10, func(tx gen.Dao, batch int) error { return nil })
if err != nil {
t.Error("FindInBatch() on table <app_user> fail:", err)
}
err = _do.Where(primaryKey.IsNotNull()).FindInBatches(&[]*model.AppUser{}, 10, func(tx gen.Dao, batch int) error { return nil })
if err != nil {
t.Error("FindInBatches() on table <app_user> fail:", err)
}
_, err = _do.Select(appUser.ALL).Where(primaryKey.IsNotNull()).Order(primaryKey.Desc()).Find()
if err != nil {
t.Error("Find() on table <app_user> fail:", err)
}
_, err = _do.Distinct(primaryKey).Take()
if err != nil {
t.Error("select Distinct() on table <app_user> fail:", err)
}
_, err = _do.Select(appUser.ALL).Omit(primaryKey).Take()
if err != nil {
t.Error("Omit() on table <app_user> fail:", err)
}
_, err = _do.Group(primaryKey).Find()
if err != nil {
t.Error("Group() on table <app_user> fail:", err)
}
_, err = _do.Scopes(func(dao gen.Dao) gen.Dao { return dao.Where(primaryKey.IsNotNull()) }).Find()
if err != nil {
t.Error("Scopes() on table <app_user> fail:", err)
}
_, _, err = _do.FindByPage(0, 1)
if err != nil {
t.Error("FindByPage() on table <app_user> fail:", err)
}
_, err = _do.ScanByPage(&model.AppUser{}, 0, 1)
if err != nil {
t.Error("ScanByPage() on table <app_user> fail:", err)
}
_, err = _do.Attrs(primaryKey).Assign(primaryKey).FirstOrInit()
if err != nil {
t.Error("FirstOrInit() on table <app_user> fail:", err)
}
_, err = _do.Attrs(primaryKey).Assign(primaryKey).FirstOrCreate()
if err != nil {
t.Error("FirstOrCreate() on table <app_user> fail:", err)
}
var _a _another
var _aPK = field.NewString(_a.TableName(), "id")
err = _do.Join(&_a, primaryKey.EqCol(_aPK)).Scan(map[string]interface{}{})
if err != nil {
t.Error("Join() on table <app_user> fail:", err)
}
err = _do.LeftJoin(&_a, primaryKey.EqCol(_aPK)).Scan(map[string]interface{}{})
if err != nil {
t.Error("LeftJoin() on table <app_user> fail:", err)
}
_, err = _do.Not().Or().Clauses().Take()
if err != nil {
t.Error("Not/Or/Clauses on table <app_user> fail:", err)
}
}

View File

@ -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_grpc/pkg/my_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
}

View File

@ -1,145 +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"
"fmt"
"testing"
"gitea.youtukeji.com.cn/xiabin/youtu_grpc/pkg/my_gorm/gen/dao/model"
"gorm.io/gen"
"gorm.io/gen/field"
"gorm.io/gorm/clause"
)
func init() {
InitializeDB()
err := _gen_test_db.AutoMigrate(&model.DouyinEcpmConfig{})
if err != nil {
fmt.Printf("Error: AutoMigrate(&model.DouyinEcpmConfig{}) fail: %s", err)
}
}
func Test_douyinEcpmConfigQuery(t *testing.T) {
douyinEcpmConfig := newDouyinEcpmConfig(_gen_test_db)
douyinEcpmConfig = *douyinEcpmConfig.As(douyinEcpmConfig.TableName())
_do := douyinEcpmConfig.WithContext(context.Background()).Debug()
primaryKey := field.NewString(douyinEcpmConfig.TableName(), clause.PrimaryKey)
_, err := _do.Unscoped().Where(primaryKey.IsNotNull()).Delete()
if err != nil {
t.Error("clean table <douyin_ecpm_config> fail:", err)
return
}
_, ok := douyinEcpmConfig.GetFieldByName("")
if ok {
t.Error("GetFieldByName(\"\") from douyinEcpmConfig success")
}
err = _do.Create(&model.DouyinEcpmConfig{})
if err != nil {
t.Error("create item in table <douyin_ecpm_config> fail:", err)
}
err = _do.Save(&model.DouyinEcpmConfig{})
if err != nil {
t.Error("create item in table <douyin_ecpm_config> fail:", err)
}
err = _do.CreateInBatches([]*model.DouyinEcpmConfig{{}, {}}, 10)
if err != nil {
t.Error("create item in table <douyin_ecpm_config> fail:", err)
}
_, err = _do.Select(douyinEcpmConfig.ALL).Take()
if err != nil {
t.Error("Take() on table <douyin_ecpm_config> fail:", err)
}
_, err = _do.First()
if err != nil {
t.Error("First() on table <douyin_ecpm_config> fail:", err)
}
_, err = _do.Last()
if err != nil {
t.Error("First() on table <douyin_ecpm_config> fail:", err)
}
_, err = _do.Where(primaryKey.IsNotNull()).FindInBatch(10, func(tx gen.Dao, batch int) error { return nil })
if err != nil {
t.Error("FindInBatch() on table <douyin_ecpm_config> fail:", err)
}
err = _do.Where(primaryKey.IsNotNull()).FindInBatches(&[]*model.DouyinEcpmConfig{}, 10, func(tx gen.Dao, batch int) error { return nil })
if err != nil {
t.Error("FindInBatches() on table <douyin_ecpm_config> fail:", err)
}
_, err = _do.Select(douyinEcpmConfig.ALL).Where(primaryKey.IsNotNull()).Order(primaryKey.Desc()).Find()
if err != nil {
t.Error("Find() on table <douyin_ecpm_config> fail:", err)
}
_, err = _do.Distinct(primaryKey).Take()
if err != nil {
t.Error("select Distinct() on table <douyin_ecpm_config> fail:", err)
}
_, err = _do.Select(douyinEcpmConfig.ALL).Omit(primaryKey).Take()
if err != nil {
t.Error("Omit() on table <douyin_ecpm_config> fail:", err)
}
_, err = _do.Group(primaryKey).Find()
if err != nil {
t.Error("Group() on table <douyin_ecpm_config> fail:", err)
}
_, err = _do.Scopes(func(dao gen.Dao) gen.Dao { return dao.Where(primaryKey.IsNotNull()) }).Find()
if err != nil {
t.Error("Scopes() on table <douyin_ecpm_config> fail:", err)
}
_, _, err = _do.FindByPage(0, 1)
if err != nil {
t.Error("FindByPage() on table <douyin_ecpm_config> fail:", err)
}
_, err = _do.ScanByPage(&model.DouyinEcpmConfig{}, 0, 1)
if err != nil {
t.Error("ScanByPage() on table <douyin_ecpm_config> fail:", err)
}
_, err = _do.Attrs(primaryKey).Assign(primaryKey).FirstOrInit()
if err != nil {
t.Error("FirstOrInit() on table <douyin_ecpm_config> fail:", err)
}
_, err = _do.Attrs(primaryKey).Assign(primaryKey).FirstOrCreate()
if err != nil {
t.Error("FirstOrCreate() on table <douyin_ecpm_config> fail:", err)
}
var _a _another
var _aPK = field.NewString(_a.TableName(), "id")
err = _do.Join(&_a, primaryKey.EqCol(_aPK)).Scan(map[string]interface{}{})
if err != nil {
t.Error("Join() on table <douyin_ecpm_config> fail:", err)
}
err = _do.LeftJoin(&_a, primaryKey.EqCol(_aPK)).Scan(map[string]interface{}{})
if err != nil {
t.Error("LeftJoin() on table <douyin_ecpm_config> fail:", err)
}
_, err = _do.Not().Or().Clauses().Take()
if err != nil {
t.Error("Not/Or/Clauses on table <douyin_ecpm_config> fail:", err)
}
}