排行榜部分功能完善

This commit is contained in:
xiabin 2025-02-07 17:01:48 +08:00
parent 31fa8fe1a8
commit b0f83e5356
32 changed files with 3209 additions and 163 deletions

View File

@ -1,6 +1,9 @@
Name: rankingmanagement.rpc
Name: ranking_management.rpc
ListenOn: 0.0.0.0:8080
Etcd:
Hosts:
- 127.0.0.1:2379
Key: rankingmanagement.rpc
Key: ranking_management.rpc
RedisHost: 127.0.0.1:6379
Mysql:
Dsn: root:youtu!0113@tcp(localhost:3306)/ecpm?charset=utf8mb4&parseTime=True&loc=Local

View File

@ -4,4 +4,8 @@ import "github.com/zeromicro/go-zero/zrpc"
type Config struct {
zrpc.RpcServerConf
RedisHost string
Mysql struct {
Dsn string
}
}

View File

@ -2,8 +2,12 @@ package logic
import (
"context"
"errors"
"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"
ranking_management2 "gitea.youtukeji.com.cn/xiabin/youtu_grpc/app/ranking_management/ranking_management"
"gorm.io/gorm"
"strconv"
"github.com/zeromicro/go-zero/core/logx"
)
@ -22,8 +26,57 @@ func NewGetRankingListLogic(ctx context.Context, svcCtx *svc.ServiceContext) *Ge
}
}
func (l *GetRankingListLogic) GetRankingList(in *ranking_management2.PageRequest, stream ranking_management2.RankingManagement_GetRankingListServer) error {
// todo: add your logic here and delete this line
return nil
func (l *GetRankingListLogic) GetRankingList(in *ranking_management2.GetRankingListRequest) (resp *ranking_management2.GetRankingListResponse, err error) {
cacheData, err := l.svcCtx.RedisRanking.GetList(l.ctx, rankings.GetRankingsCacheKey(in.AppId, in.Type), 0, 99)
if err != nil {
return nil, err
}
var flag bool
resp.RankingData = make([]*ranking_management2.RankingList, 0, len(cacheData))
var userRank *ranking_management2.RankingList
for i, datum := range cacheData {
userId, err := strconv.Atoi(datum.Member.(string))
if err != nil {
continue
}
//查询用户数据FindOne带缓存
user, err := l.svcCtx.Query.AppUser.Where(l.svcCtx.Query.AppUser.ID.Eq(uint64(userId))).Take()
if err != nil {
return nil, err
}
data := &ranking_management2.RankingList{
Nickname: user.Nickname,
Avatar: user.Avatar,
Score: uint32(uint64(datum.Score) >> 32),
Rank: uint32(i) + 1,
Self: user.ID == in.UserId,
}
if user.ID == in.UserId {
flag = true
userRank = data
}
resp.RankingData = append(resp.RankingData, data)
}
if !flag {
tmp, err := l.svcCtx.Query.GameScore.GetUserRank(in.AppId, in.UserId, in.Type)
if err != nil && !errors.Is(err, gorm.ErrRecordNotFound) {
return nil, err
}
userRank = &ranking_management2.RankingList{
Nickname: tmp.Nickname,
Avatar: tmp.Avatar,
Score: tmp.Score,
Rank: tmp.Rank,
Self: tmp.Self,
UserId: tmp.UserId,
}
userRank.Self = true
}
resp.RankingData = append(resp.RankingData, userRank)
return
}

View File

@ -23,7 +23,5 @@ func NewPingLogic(ctx context.Context, svcCtx *svc.ServiceContext) *PingLogic {
}
func (l *PingLogic) Ping(in *ranking_management.Request) (*ranking_management.Response, error) {
// todo: add your logic here and delete this line
return &ranking_management.Response{}, nil
return &ranking_management.Response{Pong: in.Ping}, nil
}

View File

@ -0,0 +1,45 @@
package rankings
import (
"context"
"fmt"
"github.com/redis/go-redis/v9"
)
// Ranking 排行榜结构体
type Ranking struct {
c *redis.Client
}
const EcpmRankingsListPrefix = "ecpm:rankings:"
// NewRanking 创建一个新的排行榜实例
func NewRanking(c *redis.Client) *Ranking {
return &Ranking{
c: c,
}
}
func GetRankingsCacheKey(appId uint32, t uint32) string {
return fmt.Sprintf("%sappId:%d:type:%d", EcpmRankingsListPrefix, appId, t)
}
// SetList 向排行榜中添加成员及其分数
func (r *Ranking) SetList(ctx context.Context, key string, data ...redis.Z) {
r.c.ZAdd(ctx, key, data...)
}
// GetList 获取排行榜,按照分数从高到低排序
func (r *Ranking) GetList(ctx context.Context, key string, start, stop int64) (data []redis.Z, err error) {
return r.c.ZRevRangeWithScores(ctx, key, start, stop).Result()
}
// GetRank 获取指定成员在排行榜中的排名(排名从 0 开始,分数越高排名越靠前)
func (r *Ranking) GetRank(ctx context.Context, key, member string) (rank int64, err error) {
return r.c.ZRevRank(ctx, key, member).Result()
}
// GetScore 获取指定成员在排行榜中的分数
func (r *Ranking) GetScore(ctx context.Context, key, member string) (score float64, err error) {
return r.c.ZScore(ctx, key, member).Result()
}

View File

@ -2,8 +2,14 @@ package logic
import (
"context"
"errors"
"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"
"github.com/zeromicro/go-zero/core/logx"
)
@ -23,7 +29,46 @@ func NewSetUserGameScoreLogic(ctx context.Context, svcCtx *svc.ServiceContext) *
}
func (l *SetUserGameScoreLogic) SetUserGameScore(in *ranking_management.SetUserGameScoreRequest) (*ranking_management.BaseResult, error) {
// todo: add your logic here and delete this line
gs := l.svcCtx.Query.GameScore
// 查询旧分数
oldScore, err := gs.
WithContext(l.ctx).
Where(
gs.AppUserID.Eq(in.UserId),
gs.AppAccount.Eq(in.AppId),
gs.T.Eq(in.Type),
).
Take()
if err != nil && !errors.Is(err, gorm.ErrRecordNotFound) {
return nil, err
}
if oldScore == nil {
oldScore = new(model.GameScore)
}
// 判断是否需要更新(只保留最高分)
if in.Score <= oldScore.Score {
return &ranking_management.BaseResult{}, nil
}
oldScore.Score = in.Score
oldScore.T = in.Type
oldScore.AppUserID = in.UserId
oldScore.AppAccount = in.AppId
// 更新数据库
err = gs.WithContext(l.ctx).Where(gs.ID.Eq(oldScore.ID)).Save(oldScore)
if err != nil {
return nil, err
}
// 更新排行榜
l.svcCtx.RedisRanking.SetList(l.ctx, rankings.GetRankingsCacheKey(in.AppId, in.Type), redis.Z{
Member: in.UserId,
Score: float64(uint64(in.Score)<<32 + uint64(time.Now().Unix())),
})
return &ranking_management.BaseResult{}, nil
}

View File

@ -6,14 +6,15 @@ package server
import (
"context"
logic2 "gitea.youtukeji.com.cn/xiabin/youtu_grpc/app/ranking_management/internal/logic"
"gitea.youtukeji.com.cn/xiabin/youtu_grpc/app/ranking_management/internal/logic"
"gitea.youtukeji.com.cn/xiabin/youtu_grpc/app/ranking_management/internal/svc"
ranking_management2 "gitea.youtukeji.com.cn/xiabin/youtu_grpc/app/ranking_management/ranking_management"
"gitea.youtukeji.com.cn/xiabin/youtu_grpc/app/ranking_management/ranking_management"
)
type RankingManagementServer struct {
svcCtx *svc.ServiceContext
ranking_management2.UnimplementedRankingManagementServer
ranking_management.UnimplementedRankingManagementServer
}
func NewRankingManagementServer(svcCtx *svc.ServiceContext) *RankingManagementServer {
@ -22,17 +23,17 @@ func NewRankingManagementServer(svcCtx *svc.ServiceContext) *RankingManagementSe
}
}
func (s *RankingManagementServer) Ping(ctx context.Context, in *ranking_management2.Request) (*ranking_management2.Response, error) {
l := logic2.NewPingLogic(ctx, s.svcCtx)
func (s *RankingManagementServer) Ping(ctx context.Context, in *ranking_management.Request) (*ranking_management.Response, error) {
l := logic.NewPingLogic(ctx, s.svcCtx)
return l.Ping(in)
}
func (s *RankingManagementServer) SetUserGameScore(ctx context.Context, in *ranking_management2.SetUserGameScoreRequest) (*ranking_management2.BaseResult, error) {
l := logic2.NewSetUserGameScoreLogic(ctx, s.svcCtx)
func (s *RankingManagementServer) SetUserGameScore(ctx context.Context, in *ranking_management.SetUserGameScoreRequest) (*ranking_management.BaseResult, error) {
l := logic.NewSetUserGameScoreLogic(ctx, s.svcCtx)
return l.SetUserGameScore(in)
}
func (s *RankingManagementServer) GetRankingList(in *ranking_management2.PageRequest, stream ranking_management2.RankingManagement_GetRankingListServer) error {
l := logic2.NewGetRankingListLogic(stream.Context(), s.svcCtx)
return l.GetRankingList(in, stream)
func (s *RankingManagementServer) GetRankingList(ctx context.Context, in *ranking_management.GetRankingListRequest) (*ranking_management.GetRankingListResponse, error) {
l := logic.NewGetRankingListLogic(ctx, s.svcCtx)
return l.GetRankingList(in)
}

View File

@ -1,15 +1,70 @@
package svc
import (
"context"
"gitea.youtukeji.com.cn/xiabin/youtu_grpc/app/ranking_management/internal/config"
"gitea.youtukeji.com.cn/xiabin/youtu_grpc/app/ranking_management/internal/logic/rankings"
"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"
)
type ServiceContext struct {
Config config.Config
Query *query.Query
RedisRanking *rankings.Ranking
}
func NewServiceContext(c config.Config) *ServiceContext {
return &ServiceContext{
svc := &ServiceContext{
Config: c,
}
//初始化redis client
redisClient := redis.NewClient(&redis.Options{
Addr: c.RedisHost,
})
//初始化数据库
//todo
db, err := my_gorm.NewDBWithCache(mysql.Open(c.Mysql.Dsn), &gorm.Config{}, redisClient)
if err != nil {
panic(err)
}
svc.Query = query.Use(db)
//初始化排行榜对象
svc.InitRankings(redisClient)
return svc
}
func (svc *ServiceContext) InitRankings(redisClient *redis.Client) {
//初始化排行榜对象
svc.RedisRanking = rankings.NewRanking(redisClient)
//获取所有不同的排行榜
gs := svc.Query.GameScore
r, err := gs.FindDistinctRanking()
if err != nil {
panic(err)
}
//获取所有排行榜
for _, ranking := range r {
scores, err := gs.Where(gs.AppAccount.Eq(ranking.AppAccount), gs.T.Eq(ranking.T)).Find()
if err != nil {
panic(err)
}
data := make([]redis.Z, 0, len(scores))
for _, score := range scores {
data = append(data, redis.Z{
Score: float64(uint64(score.Score)<<32 + uint64(score.UpdatedAt.Unix())),
Member: score.AppUserID,
})
}
svc.RedisRanking.SetList(context.Background(), rankings.GetRankingsCacheKey(ranking.AppAccount, ranking.T), data...)
}
}

View File

@ -15,11 +15,12 @@ message Response {
message SetUserGameScoreRequest {
uint32 score = 1; // json的"score"
uint32 type = 2; // json的"type", 0
uint32 userId = 3;
uint64 userId = 3; // id
uint32 appId = 4; // id
}
// RankingData消息类型
message RankingData {
message RankingList {
string nickname = 1; // db:"nickname"
string avatar = 2; // db:"avatar"
uint32 score = 3; // db:"score"
@ -28,10 +29,14 @@ message RankingData {
bool self = 6; //
}
//
message PageRequest {
int32 page = 1;
int32 limit = 2;
message GetRankingListResponse {
repeated RankingList rankingData = 1;
}
message GetRankingListRequest {
uint32 appId = 1;
uint32 type = 2;
uint64 userId = 3;
}
// Base响应结构
@ -45,5 +50,5 @@ service Ranking_management {
rpc SetUserGameScore (SetUserGameScoreRequest) returns (BaseResult);
rpc GetRankingList (PageRequest) returns (stream RankingData);
rpc GetRankingList (GetRankingListRequest) returns (GetRankingListResponse);
}

View File

@ -114,7 +114,8 @@ type SetUserGameScoreRequest struct {
state protoimpl.MessageState `protogen:"open.v1"`
Score uint32 `protobuf:"varint,1,opt,name=score,proto3" json:"score,omitempty"` // 对应json的"score"
Type uint32 `protobuf:"varint,2,opt,name=type,proto3" json:"type,omitempty"` // 对应json的"type", 带默认值0
UserId uint32 `protobuf:"varint,3,opt,name=userId,proto3" json:"userId,omitempty"`
UserId uint64 `protobuf:"varint,3,opt,name=userId,proto3" json:"userId,omitempty"` // 用户id
AppId uint32 `protobuf:"varint,4,opt,name=appId,proto3" json:"appId,omitempty"` // 小程序id
unknownFields protoimpl.UnknownFields
sizeCache protoimpl.SizeCache
}
@ -163,15 +164,22 @@ func (x *SetUserGameScoreRequest) GetType() uint32 {
return 0
}
func (x *SetUserGameScoreRequest) GetUserId() uint32 {
func (x *SetUserGameScoreRequest) GetUserId() uint64 {
if x != nil {
return x.UserId
}
return 0
}
func (x *SetUserGameScoreRequest) GetAppId() uint32 {
if x != nil {
return x.AppId
}
return 0
}
// 定义RankingData消息类型
type RankingData struct {
type RankingList struct {
state protoimpl.MessageState `protogen:"open.v1"`
Nickname string `protobuf:"bytes,1,opt,name=nickname,proto3" json:"nickname,omitempty"` // 昵称对应db:"nickname"
Avatar string `protobuf:"bytes,2,opt,name=avatar,proto3" json:"avatar,omitempty"` // 头像对应db:"avatar"
@ -183,20 +191,20 @@ type RankingData struct {
sizeCache protoimpl.SizeCache
}
func (x *RankingData) Reset() {
*x = RankingData{}
func (x *RankingList) Reset() {
*x = RankingList{}
mi := &file_ranking_management_proto_msgTypes[3]
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
ms.StoreMessageInfo(mi)
}
func (x *RankingData) String() string {
func (x *RankingList) String() string {
return protoimpl.X.MessageStringOf(x)
}
func (*RankingData) ProtoMessage() {}
func (*RankingList) ProtoMessage() {}
func (x *RankingData) ProtoReflect() protoreflect.Message {
func (x *RankingList) ProtoReflect() protoreflect.Message {
mi := &file_ranking_management_proto_msgTypes[3]
if x != nil {
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
@ -208,76 +216,74 @@ func (x *RankingData) ProtoReflect() protoreflect.Message {
return mi.MessageOf(x)
}
// Deprecated: Use RankingData.ProtoReflect.Descriptor instead.
func (*RankingData) Descriptor() ([]byte, []int) {
// Deprecated: Use RankingList.ProtoReflect.Descriptor instead.
func (*RankingList) Descriptor() ([]byte, []int) {
return file_ranking_management_proto_rawDescGZIP(), []int{3}
}
func (x *RankingData) GetNickname() string {
func (x *RankingList) GetNickname() string {
if x != nil {
return x.Nickname
}
return ""
}
func (x *RankingData) GetAvatar() string {
func (x *RankingList) GetAvatar() string {
if x != nil {
return x.Avatar
}
return ""
}
func (x *RankingData) GetScore() uint32 {
func (x *RankingList) GetScore() uint32 {
if x != nil {
return x.Score
}
return 0
}
func (x *RankingData) GetUserId() uint64 {
func (x *RankingList) GetUserId() uint64 {
if x != nil {
return x.UserId
}
return 0
}
func (x *RankingData) GetRank() uint32 {
func (x *RankingList) GetRank() uint32 {
if x != nil {
return x.Rank
}
return 0
}
func (x *RankingData) GetSelf() bool {
func (x *RankingList) GetSelf() bool {
if x != nil {
return x.Self
}
return false
}
// 定义分页请求参数(如果有的话)
type PageRequest struct {
type GetRankingListResponse struct {
state protoimpl.MessageState `protogen:"open.v1"`
Page int32 `protobuf:"varint,1,opt,name=page,proto3" json:"page,omitempty"`
Limit int32 `protobuf:"varint,2,opt,name=limit,proto3" json:"limit,omitempty"`
RankingData []*RankingList `protobuf:"bytes,1,rep,name=rankingData,proto3" json:"rankingData,omitempty"`
unknownFields protoimpl.UnknownFields
sizeCache protoimpl.SizeCache
}
func (x *PageRequest) Reset() {
*x = PageRequest{}
func (x *GetRankingListResponse) Reset() {
*x = GetRankingListResponse{}
mi := &file_ranking_management_proto_msgTypes[4]
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
ms.StoreMessageInfo(mi)
}
func (x *PageRequest) String() string {
func (x *GetRankingListResponse) String() string {
return protoimpl.X.MessageStringOf(x)
}
func (*PageRequest) ProtoMessage() {}
func (*GetRankingListResponse) ProtoMessage() {}
func (x *PageRequest) ProtoReflect() protoreflect.Message {
func (x *GetRankingListResponse) ProtoReflect() protoreflect.Message {
mi := &file_ranking_management_proto_msgTypes[4]
if x != nil {
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
@ -289,21 +295,74 @@ func (x *PageRequest) ProtoReflect() protoreflect.Message {
return mi.MessageOf(x)
}
// Deprecated: Use PageRequest.ProtoReflect.Descriptor instead.
func (*PageRequest) Descriptor() ([]byte, []int) {
// Deprecated: Use GetRankingListResponse.ProtoReflect.Descriptor instead.
func (*GetRankingListResponse) Descriptor() ([]byte, []int) {
return file_ranking_management_proto_rawDescGZIP(), []int{4}
}
func (x *PageRequest) GetPage() int32 {
func (x *GetRankingListResponse) GetRankingData() []*RankingList {
if x != nil {
return x.Page
return x.RankingData
}
return nil
}
type GetRankingListRequest struct {
state protoimpl.MessageState `protogen:"open.v1"`
AppId uint32 `protobuf:"varint,1,opt,name=appId,proto3" json:"appId,omitempty"`
Type uint32 `protobuf:"varint,2,opt,name=type,proto3" json:"type,omitempty"`
UserId uint64 `protobuf:"varint,3,opt,name=userId,proto3" json:"userId,omitempty"`
unknownFields protoimpl.UnknownFields
sizeCache protoimpl.SizeCache
}
func (x *GetRankingListRequest) Reset() {
*x = GetRankingListRequest{}
mi := &file_ranking_management_proto_msgTypes[5]
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
ms.StoreMessageInfo(mi)
}
func (x *GetRankingListRequest) String() string {
return protoimpl.X.MessageStringOf(x)
}
func (*GetRankingListRequest) ProtoMessage() {}
func (x *GetRankingListRequest) ProtoReflect() protoreflect.Message {
mi := &file_ranking_management_proto_msgTypes[5]
if x != nil {
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
if ms.LoadMessageInfo() == nil {
ms.StoreMessageInfo(mi)
}
return ms
}
return mi.MessageOf(x)
}
// Deprecated: Use GetRankingListRequest.ProtoReflect.Descriptor instead.
func (*GetRankingListRequest) Descriptor() ([]byte, []int) {
return file_ranking_management_proto_rawDescGZIP(), []int{5}
}
func (x *GetRankingListRequest) GetAppId() uint32 {
if x != nil {
return x.AppId
}
return 0
}
func (x *PageRequest) GetLimit() int32 {
func (x *GetRankingListRequest) GetType() uint32 {
if x != nil {
return x.Limit
return x.Type
}
return 0
}
func (x *GetRankingListRequest) GetUserId() uint64 {
if x != nil {
return x.UserId
}
return 0
}
@ -319,7 +378,7 @@ type BaseResult struct {
func (x *BaseResult) Reset() {
*x = BaseResult{}
mi := &file_ranking_management_proto_msgTypes[5]
mi := &file_ranking_management_proto_msgTypes[6]
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
ms.StoreMessageInfo(mi)
}
@ -331,7 +390,7 @@ func (x *BaseResult) String() string {
func (*BaseResult) ProtoMessage() {}
func (x *BaseResult) ProtoReflect() protoreflect.Message {
mi := &file_ranking_management_proto_msgTypes[5]
mi := &file_ranking_management_proto_msgTypes[6]
if x != nil {
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
if ms.LoadMessageInfo() == nil {
@ -344,7 +403,7 @@ func (x *BaseResult) ProtoReflect() protoreflect.Message {
// Deprecated: Use BaseResult.ProtoReflect.Descriptor instead.
func (*BaseResult) Descriptor() ([]byte, []int) {
return file_ranking_management_proto_rawDescGZIP(), []int{5}
return file_ranking_management_proto_rawDescGZIP(), []int{6}
}
func (x *BaseResult) GetErrorCode() int32 {
@ -370,50 +429,61 @@ var file_ranking_management_proto_rawDesc = string([]byte{
0x0a, 0x07, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x12, 0x0a, 0x04, 0x70, 0x69, 0x6e,
0x67, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x04, 0x70, 0x69, 0x6e, 0x67, 0x22, 0x1e, 0x0a,
0x08, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x12, 0x0a, 0x04, 0x70, 0x6f, 0x6e,
0x67, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x04, 0x70, 0x6f, 0x6e, 0x67, 0x22, 0x5b, 0x0a,
0x67, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x04, 0x70, 0x6f, 0x6e, 0x67, 0x22, 0x71, 0x0a,
0x17, 0x53, 0x65, 0x74, 0x55, 0x73, 0x65, 0x72, 0x47, 0x61, 0x6d, 0x65, 0x53, 0x63, 0x6f, 0x72,
0x65, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x14, 0x0a, 0x05, 0x73, 0x63, 0x6f, 0x72,
0x65, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0d, 0x52, 0x05, 0x73, 0x63, 0x6f, 0x72, 0x65, 0x12, 0x12,
0x0a, 0x04, 0x74, 0x79, 0x70, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x0d, 0x52, 0x04, 0x74, 0x79,
0x70, 0x65, 0x12, 0x16, 0x0a, 0x06, 0x75, 0x73, 0x65, 0x72, 0x49, 0x64, 0x18, 0x03, 0x20, 0x01,
0x28, 0x0d, 0x52, 0x06, 0x75, 0x73, 0x65, 0x72, 0x49, 0x64, 0x22, 0x98, 0x01, 0x0a, 0x0b, 0x52,
0x61, 0x6e, 0x6b, 0x69, 0x6e, 0x67, 0x44, 0x61, 0x74, 0x61, 0x12, 0x1a, 0x0a, 0x08, 0x6e, 0x69,
0x63, 0x6b, 0x6e, 0x61, 0x6d, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x08, 0x6e, 0x69,
0x63, 0x6b, 0x6e, 0x61, 0x6d, 0x65, 0x12, 0x16, 0x0a, 0x06, 0x61, 0x76, 0x61, 0x74, 0x61, 0x72,
0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x06, 0x61, 0x76, 0x61, 0x74, 0x61, 0x72, 0x12, 0x14,
0x0a, 0x05, 0x73, 0x63, 0x6f, 0x72, 0x65, 0x18, 0x03, 0x20, 0x01, 0x28, 0x0d, 0x52, 0x05, 0x73,
0x63, 0x6f, 0x72, 0x65, 0x12, 0x17, 0x0a, 0x07, 0x75, 0x73, 0x65, 0x72, 0x5f, 0x69, 0x64, 0x18,
0x04, 0x20, 0x01, 0x28, 0x04, 0x52, 0x06, 0x75, 0x73, 0x65, 0x72, 0x49, 0x64, 0x12, 0x12, 0x0a,
0x04, 0x72, 0x61, 0x6e, 0x6b, 0x18, 0x05, 0x20, 0x01, 0x28, 0x0d, 0x52, 0x04, 0x72, 0x61, 0x6e,
0x6b, 0x12, 0x12, 0x0a, 0x04, 0x73, 0x65, 0x6c, 0x66, 0x18, 0x06, 0x20, 0x01, 0x28, 0x08, 0x52,
0x04, 0x73, 0x65, 0x6c, 0x66, 0x22, 0x37, 0x0a, 0x0b, 0x50, 0x61, 0x67, 0x65, 0x52, 0x65, 0x71,
0x75, 0x65, 0x73, 0x74, 0x12, 0x12, 0x0a, 0x04, 0x70, 0x61, 0x67, 0x65, 0x18, 0x01, 0x20, 0x01,
0x28, 0x05, 0x52, 0x04, 0x70, 0x61, 0x67, 0x65, 0x12, 0x14, 0x0a, 0x05, 0x6c, 0x69, 0x6d, 0x69,
0x74, 0x18, 0x02, 0x20, 0x01, 0x28, 0x05, 0x52, 0x05, 0x6c, 0x69, 0x6d, 0x69, 0x74, 0x22, 0x48,
0x0a, 0x0a, 0x42, 0x61, 0x73, 0x65, 0x52, 0x65, 0x73, 0x75, 0x6c, 0x74, 0x12, 0x1d, 0x0a, 0x0a,
0x65, 0x72, 0x72, 0x6f, 0x72, 0x5f, 0x63, 0x6f, 0x64, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, 0x05,
0x52, 0x09, 0x65, 0x72, 0x72, 0x6f, 0x72, 0x43, 0x6f, 0x64, 0x65, 0x12, 0x1b, 0x0a, 0x09, 0x65,
0x72, 0x72, 0x6f, 0x72, 0x5f, 0x6d, 0x73, 0x67, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x08,
0x65, 0x72, 0x72, 0x6f, 0x72, 0x4d, 0x73, 0x67, 0x32, 0x8e, 0x02, 0x0a, 0x12, 0x52, 0x61, 0x6e,
0x6b, 0x69, 0x6e, 0x67, 0x5f, 0x6d, 0x61, 0x6e, 0x61, 0x67, 0x65, 0x6d, 0x65, 0x6e, 0x74, 0x12,
0x41, 0x0a, 0x04, 0x50, 0x69, 0x6e, 0x67, 0x12, 0x1b, 0x2e, 0x72, 0x61, 0x6e, 0x6b, 0x69, 0x6e,
0x67, 0x5f, 0x6d, 0x61, 0x6e, 0x61, 0x67, 0x65, 0x6d, 0x65, 0x6e, 0x74, 0x2e, 0x52, 0x65, 0x71,
0x75, 0x65, 0x73, 0x74, 0x1a, 0x1c, 0x2e, 0x72, 0x61, 0x6e, 0x6b, 0x69, 0x6e, 0x67, 0x5f, 0x6d,
0x61, 0x6e, 0x61, 0x67, 0x65, 0x6d, 0x65, 0x6e, 0x74, 0x2e, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e,
0x73, 0x65, 0x12, 0x5f, 0x0a, 0x10, 0x53, 0x65, 0x74, 0x55, 0x73, 0x65, 0x72, 0x47, 0x61, 0x6d,
0x65, 0x53, 0x63, 0x6f, 0x72, 0x65, 0x12, 0x2b, 0x2e, 0x72, 0x61, 0x6e, 0x6b, 0x69, 0x6e, 0x67,
0x5f, 0x6d, 0x61, 0x6e, 0x61, 0x67, 0x65, 0x6d, 0x65, 0x6e, 0x74, 0x2e, 0x53, 0x65, 0x74, 0x55,
0x73, 0x65, 0x72, 0x47, 0x61, 0x6d, 0x65, 0x53, 0x63, 0x6f, 0x72, 0x65, 0x52, 0x65, 0x71, 0x75,
0x65, 0x73, 0x74, 0x1a, 0x1e, 0x2e, 0x72, 0x61, 0x6e, 0x6b, 0x69, 0x6e, 0x67, 0x5f, 0x6d, 0x61,
0x6e, 0x61, 0x67, 0x65, 0x6d, 0x65, 0x6e, 0x74, 0x2e, 0x42, 0x61, 0x73, 0x65, 0x52, 0x65, 0x73,
0x75, 0x6c, 0x74, 0x12, 0x54, 0x0a, 0x0e, 0x47, 0x65, 0x74, 0x52, 0x61, 0x6e, 0x6b, 0x69, 0x6e,
0x67, 0x4c, 0x69, 0x73, 0x74, 0x12, 0x1f, 0x2e, 0x72, 0x61, 0x6e, 0x6b, 0x69, 0x6e, 0x67, 0x5f,
0x6d, 0x61, 0x6e, 0x61, 0x67, 0x65, 0x6d, 0x65, 0x6e, 0x74, 0x2e, 0x50, 0x61, 0x67, 0x65, 0x52,
0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x1f, 0x2e, 0x72, 0x61, 0x6e, 0x6b, 0x69, 0x6e, 0x67,
0x5f, 0x6d, 0x61, 0x6e, 0x61, 0x67, 0x65, 0x6d, 0x65, 0x6e, 0x74, 0x2e, 0x52, 0x61, 0x6e, 0x6b,
0x69, 0x6e, 0x67, 0x44, 0x61, 0x74, 0x61, 0x30, 0x01, 0x42, 0x16, 0x5a, 0x14, 0x2e, 0x2f, 0x72,
0x28, 0x04, 0x52, 0x06, 0x75, 0x73, 0x65, 0x72, 0x49, 0x64, 0x12, 0x14, 0x0a, 0x05, 0x61, 0x70,
0x70, 0x49, 0x64, 0x18, 0x04, 0x20, 0x01, 0x28, 0x0d, 0x52, 0x05, 0x61, 0x70, 0x70, 0x49, 0x64,
0x22, 0x98, 0x01, 0x0a, 0x0b, 0x52, 0x61, 0x6e, 0x6b, 0x69, 0x6e, 0x67, 0x4c, 0x69, 0x73, 0x74,
0x12, 0x1a, 0x0a, 0x08, 0x6e, 0x69, 0x63, 0x6b, 0x6e, 0x61, 0x6d, 0x65, 0x18, 0x01, 0x20, 0x01,
0x28, 0x09, 0x52, 0x08, 0x6e, 0x69, 0x63, 0x6b, 0x6e, 0x61, 0x6d, 0x65, 0x12, 0x16, 0x0a, 0x06,
0x61, 0x76, 0x61, 0x74, 0x61, 0x72, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x06, 0x61, 0x76,
0x61, 0x74, 0x61, 0x72, 0x12, 0x14, 0x0a, 0x05, 0x73, 0x63, 0x6f, 0x72, 0x65, 0x18, 0x03, 0x20,
0x01, 0x28, 0x0d, 0x52, 0x05, 0x73, 0x63, 0x6f, 0x72, 0x65, 0x12, 0x17, 0x0a, 0x07, 0x75, 0x73,
0x65, 0x72, 0x5f, 0x69, 0x64, 0x18, 0x04, 0x20, 0x01, 0x28, 0x04, 0x52, 0x06, 0x75, 0x73, 0x65,
0x72, 0x49, 0x64, 0x12, 0x12, 0x0a, 0x04, 0x72, 0x61, 0x6e, 0x6b, 0x18, 0x05, 0x20, 0x01, 0x28,
0x0d, 0x52, 0x04, 0x72, 0x61, 0x6e, 0x6b, 0x12, 0x12, 0x0a, 0x04, 0x73, 0x65, 0x6c, 0x66, 0x18,
0x06, 0x20, 0x01, 0x28, 0x08, 0x52, 0x04, 0x73, 0x65, 0x6c, 0x66, 0x22, 0x5b, 0x0a, 0x16, 0x47,
0x65, 0x74, 0x52, 0x61, 0x6e, 0x6b, 0x69, 0x6e, 0x67, 0x4c, 0x69, 0x73, 0x74, 0x52, 0x65, 0x73,
0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x41, 0x0a, 0x0b, 0x72, 0x61, 0x6e, 0x6b, 0x69, 0x6e, 0x67,
0x44, 0x61, 0x74, 0x61, 0x18, 0x01, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x1f, 0x2e, 0x72, 0x61, 0x6e,
0x6b, 0x69, 0x6e, 0x67, 0x5f, 0x6d, 0x61, 0x6e, 0x61, 0x67, 0x65, 0x6d, 0x65, 0x6e, 0x74, 0x2e,
0x52, 0x61, 0x6e, 0x6b, 0x69, 0x6e, 0x67, 0x4c, 0x69, 0x73, 0x74, 0x52, 0x0b, 0x72, 0x61, 0x6e,
0x6b, 0x69, 0x6e, 0x67, 0x44, 0x61, 0x74, 0x61, 0x22, 0x59, 0x0a, 0x15, 0x47, 0x65, 0x74, 0x52,
0x61, 0x6e, 0x6b, 0x69, 0x6e, 0x67, 0x4c, 0x69, 0x73, 0x74, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73,
0x74, 0x12, 0x14, 0x0a, 0x05, 0x61, 0x70, 0x70, 0x49, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0d,
0x52, 0x05, 0x61, 0x70, 0x70, 0x49, 0x64, 0x12, 0x12, 0x0a, 0x04, 0x74, 0x79, 0x70, 0x65, 0x18,
0x02, 0x20, 0x01, 0x28, 0x0d, 0x52, 0x04, 0x74, 0x79, 0x70, 0x65, 0x12, 0x16, 0x0a, 0x06, 0x75,
0x73, 0x65, 0x72, 0x49, 0x64, 0x18, 0x03, 0x20, 0x01, 0x28, 0x04, 0x52, 0x06, 0x75, 0x73, 0x65,
0x72, 0x49, 0x64, 0x22, 0x48, 0x0a, 0x0a, 0x42, 0x61, 0x73, 0x65, 0x52, 0x65, 0x73, 0x75, 0x6c,
0x74, 0x12, 0x1d, 0x0a, 0x0a, 0x65, 0x72, 0x72, 0x6f, 0x72, 0x5f, 0x63, 0x6f, 0x64, 0x65, 0x18,
0x01, 0x20, 0x01, 0x28, 0x05, 0x52, 0x09, 0x65, 0x72, 0x72, 0x6f, 0x72, 0x43, 0x6f, 0x64, 0x65,
0x12, 0x1b, 0x0a, 0x09, 0x65, 0x72, 0x72, 0x6f, 0x72, 0x5f, 0x6d, 0x73, 0x67, 0x18, 0x02, 0x20,
0x01, 0x28, 0x09, 0x52, 0x08, 0x65, 0x72, 0x72, 0x6f, 0x72, 0x4d, 0x73, 0x67, 0x32, 0xa1, 0x02,
0x0a, 0x12, 0x52, 0x61, 0x6e, 0x6b, 0x69, 0x6e, 0x67, 0x5f, 0x6d, 0x61, 0x6e, 0x61, 0x67, 0x65,
0x6d, 0x65, 0x6e, 0x74, 0x12, 0x41, 0x0a, 0x04, 0x50, 0x69, 0x6e, 0x67, 0x12, 0x1b, 0x2e, 0x72,
0x61, 0x6e, 0x6b, 0x69, 0x6e, 0x67, 0x5f, 0x6d, 0x61, 0x6e, 0x61, 0x67, 0x65, 0x6d, 0x65, 0x6e,
0x74, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33,
0x74, 0x2e, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x1c, 0x2e, 0x72, 0x61, 0x6e, 0x6b,
0x69, 0x6e, 0x67, 0x5f, 0x6d, 0x61, 0x6e, 0x61, 0x67, 0x65, 0x6d, 0x65, 0x6e, 0x74, 0x2e, 0x52,
0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x5f, 0x0a, 0x10, 0x53, 0x65, 0x74, 0x55, 0x73,
0x65, 0x72, 0x47, 0x61, 0x6d, 0x65, 0x53, 0x63, 0x6f, 0x72, 0x65, 0x12, 0x2b, 0x2e, 0x72, 0x61,
0x6e, 0x6b, 0x69, 0x6e, 0x67, 0x5f, 0x6d, 0x61, 0x6e, 0x61, 0x67, 0x65, 0x6d, 0x65, 0x6e, 0x74,
0x2e, 0x53, 0x65, 0x74, 0x55, 0x73, 0x65, 0x72, 0x47, 0x61, 0x6d, 0x65, 0x53, 0x63, 0x6f, 0x72,
0x65, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x1e, 0x2e, 0x72, 0x61, 0x6e, 0x6b, 0x69,
0x6e, 0x67, 0x5f, 0x6d, 0x61, 0x6e, 0x61, 0x67, 0x65, 0x6d, 0x65, 0x6e, 0x74, 0x2e, 0x42, 0x61,
0x73, 0x65, 0x52, 0x65, 0x73, 0x75, 0x6c, 0x74, 0x12, 0x67, 0x0a, 0x0e, 0x47, 0x65, 0x74, 0x52,
0x61, 0x6e, 0x6b, 0x69, 0x6e, 0x67, 0x4c, 0x69, 0x73, 0x74, 0x12, 0x29, 0x2e, 0x72, 0x61, 0x6e,
0x6b, 0x69, 0x6e, 0x67, 0x5f, 0x6d, 0x61, 0x6e, 0x61, 0x67, 0x65, 0x6d, 0x65, 0x6e, 0x74, 0x2e,
0x47, 0x65, 0x74, 0x52, 0x61, 0x6e, 0x6b, 0x69, 0x6e, 0x67, 0x4c, 0x69, 0x73, 0x74, 0x52, 0x65,
0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x2a, 0x2e, 0x72, 0x61, 0x6e, 0x6b, 0x69, 0x6e, 0x67, 0x5f,
0x6d, 0x61, 0x6e, 0x61, 0x67, 0x65, 0x6d, 0x65, 0x6e, 0x74, 0x2e, 0x47, 0x65, 0x74, 0x52, 0x61,
0x6e, 0x6b, 0x69, 0x6e, 0x67, 0x4c, 0x69, 0x73, 0x74, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73,
0x65, 0x42, 0x16, 0x5a, 0x14, 0x2e, 0x2f, 0x72, 0x61, 0x6e, 0x6b, 0x69, 0x6e, 0x67, 0x5f, 0x6d,
0x61, 0x6e, 0x61, 0x67, 0x65, 0x6d, 0x65, 0x6e, 0x74, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f,
0x33,
})
var (
@ -428,27 +498,29 @@ func file_ranking_management_proto_rawDescGZIP() []byte {
return file_ranking_management_proto_rawDescData
}
var file_ranking_management_proto_msgTypes = make([]protoimpl.MessageInfo, 6)
var file_ranking_management_proto_msgTypes = make([]protoimpl.MessageInfo, 7)
var file_ranking_management_proto_goTypes = []any{
(*Request)(nil), // 0: ranking_management.Request
(*Response)(nil), // 1: ranking_management.Response
(*SetUserGameScoreRequest)(nil), // 2: ranking_management.SetUserGameScoreRequest
(*RankingData)(nil), // 3: ranking_management.RankingData
(*PageRequest)(nil), // 4: ranking_management.PageRequest
(*BaseResult)(nil), // 5: ranking_management.BaseResult
(*RankingList)(nil), // 3: ranking_management.RankingList
(*GetRankingListResponse)(nil), // 4: ranking_management.GetRankingListResponse
(*GetRankingListRequest)(nil), // 5: ranking_management.GetRankingListRequest
(*BaseResult)(nil), // 6: ranking_management.BaseResult
}
var file_ranking_management_proto_depIdxs = []int32{
0, // 0: ranking_management.Ranking_management.Ping:input_type -> ranking_management.Request
2, // 1: ranking_management.Ranking_management.SetUserGameScore:input_type -> ranking_management.SetUserGameScoreRequest
4, // 2: ranking_management.Ranking_management.GetRankingList:input_type -> ranking_management.PageRequest
1, // 3: ranking_management.Ranking_management.Ping:output_type -> ranking_management.Response
5, // 4: ranking_management.Ranking_management.SetUserGameScore:output_type -> ranking_management.BaseResult
3, // 5: ranking_management.Ranking_management.GetRankingList:output_type -> ranking_management.RankingData
3, // [3:6] is the sub-list for method output_type
0, // [0:3] is the sub-list for method input_type
0, // [0:0] is the sub-list for extension type_name
0, // [0:0] is the sub-list for extension extendee
0, // [0:0] is the sub-list for field type_name
3, // 0: ranking_management.GetRankingListResponse.rankingData:type_name -> ranking_management.RankingList
0, // 1: ranking_management.Ranking_management.Ping:input_type -> ranking_management.Request
2, // 2: ranking_management.Ranking_management.SetUserGameScore:input_type -> ranking_management.SetUserGameScoreRequest
5, // 3: ranking_management.Ranking_management.GetRankingList:input_type -> ranking_management.GetRankingListRequest
1, // 4: ranking_management.Ranking_management.Ping:output_type -> ranking_management.Response
6, // 5: ranking_management.Ranking_management.SetUserGameScore:output_type -> ranking_management.BaseResult
4, // 6: ranking_management.Ranking_management.GetRankingList:output_type -> ranking_management.GetRankingListResponse
4, // [4:7] is the sub-list for method output_type
1, // [1:4] is the sub-list for method input_type
1, // [1:1] is the sub-list for extension type_name
1, // [1:1] is the sub-list for extension extendee
0, // [0:1] is the sub-list for field type_name
}
func init() { file_ranking_management_proto_init() }
@ -462,7 +534,7 @@ func file_ranking_management_proto_init() {
GoPackagePath: reflect.TypeOf(x{}).PkgPath(),
RawDescriptor: unsafe.Slice(unsafe.StringData(file_ranking_management_proto_rawDesc), len(file_ranking_management_proto_rawDesc)),
NumEnums: 0,
NumMessages: 6,
NumMessages: 7,
NumExtensions: 0,
NumServices: 1,
},

View File

@ -30,7 +30,7 @@ const (
type RankingManagementClient interface {
Ping(ctx context.Context, in *Request, opts ...grpc.CallOption) (*Response, error)
SetUserGameScore(ctx context.Context, in *SetUserGameScoreRequest, opts ...grpc.CallOption) (*BaseResult, error)
GetRankingList(ctx context.Context, in *PageRequest, opts ...grpc.CallOption) (grpc.ServerStreamingClient[RankingData], error)
GetRankingList(ctx context.Context, in *GetRankingListRequest, opts ...grpc.CallOption) (*GetRankingListResponse, error)
}
type rankingManagementClient struct {
@ -61,24 +61,15 @@ func (c *rankingManagementClient) SetUserGameScore(ctx context.Context, in *SetU
return out, nil
}
func (c *rankingManagementClient) GetRankingList(ctx context.Context, in *PageRequest, opts ...grpc.CallOption) (grpc.ServerStreamingClient[RankingData], error) {
func (c *rankingManagementClient) GetRankingList(ctx context.Context, in *GetRankingListRequest, opts ...grpc.CallOption) (*GetRankingListResponse, error) {
cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...)
stream, err := c.cc.NewStream(ctx, &RankingManagement_ServiceDesc.Streams[0], RankingManagement_GetRankingList_FullMethodName, cOpts...)
out := new(GetRankingListResponse)
err := c.cc.Invoke(ctx, RankingManagement_GetRankingList_FullMethodName, in, out, cOpts...)
if err != nil {
return nil, err
}
x := &grpc.GenericClientStream[PageRequest, RankingData]{ClientStream: stream}
if err := x.ClientStream.SendMsg(in); err != nil {
return nil, err
return out, nil
}
if err := x.ClientStream.CloseSend(); err != nil {
return nil, err
}
return x, nil
}
// This type alias is provided for backwards compatibility with existing code that references the prior non-generic stream type by name.
type RankingManagement_GetRankingListClient = grpc.ServerStreamingClient[RankingData]
// RankingManagementServer is the server API for RankingManagement service.
// All implementations must embed UnimplementedRankingManagementServer
@ -86,7 +77,7 @@ type RankingManagement_GetRankingListClient = grpc.ServerStreamingClient[Ranking
type RankingManagementServer interface {
Ping(context.Context, *Request) (*Response, error)
SetUserGameScore(context.Context, *SetUserGameScoreRequest) (*BaseResult, error)
GetRankingList(*PageRequest, grpc.ServerStreamingServer[RankingData]) error
GetRankingList(context.Context, *GetRankingListRequest) (*GetRankingListResponse, error)
mustEmbedUnimplementedRankingManagementServer()
}
@ -103,8 +94,8 @@ func (UnimplementedRankingManagementServer) Ping(context.Context, *Request) (*Re
func (UnimplementedRankingManagementServer) SetUserGameScore(context.Context, *SetUserGameScoreRequest) (*BaseResult, error) {
return nil, status.Errorf(codes.Unimplemented, "method SetUserGameScore not implemented")
}
func (UnimplementedRankingManagementServer) GetRankingList(*PageRequest, grpc.ServerStreamingServer[RankingData]) error {
return status.Errorf(codes.Unimplemented, "method GetRankingList not implemented")
func (UnimplementedRankingManagementServer) GetRankingList(context.Context, *GetRankingListRequest) (*GetRankingListResponse, error) {
return nil, status.Errorf(codes.Unimplemented, "method GetRankingList not implemented")
}
func (UnimplementedRankingManagementServer) mustEmbedUnimplementedRankingManagementServer() {}
func (UnimplementedRankingManagementServer) testEmbeddedByValue() {}
@ -163,16 +154,23 @@ func _RankingManagement_SetUserGameScore_Handler(srv interface{}, ctx context.Co
return interceptor(ctx, in, info, handler)
}
func _RankingManagement_GetRankingList_Handler(srv interface{}, stream grpc.ServerStream) error {
m := new(PageRequest)
if err := stream.RecvMsg(m); err != nil {
return err
func _RankingManagement_GetRankingList_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
in := new(GetRankingListRequest)
if err := dec(in); err != nil {
return nil, err
}
return srv.(RankingManagementServer).GetRankingList(m, &grpc.GenericServerStream[PageRequest, RankingData]{ServerStream: stream})
if interceptor == nil {
return srv.(RankingManagementServer).GetRankingList(ctx, in)
}
info := &grpc.UnaryServerInfo{
Server: srv,
FullMethod: RankingManagement_GetRankingList_FullMethodName,
}
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
return srv.(RankingManagementServer).GetRankingList(ctx, req.(*GetRankingListRequest))
}
return interceptor(ctx, in, info, handler)
}
// This type alias is provided for backwards compatibility with existing code that references the prior non-generic stream type by name.
type RankingManagement_GetRankingListServer = grpc.ServerStreamingServer[RankingData]
// RankingManagement_ServiceDesc is the grpc.ServiceDesc for RankingManagement service.
// It's only intended for direct use with grpc.RegisterService,
@ -189,13 +187,11 @@ var RankingManagement_ServiceDesc = grpc.ServiceDesc{
MethodName: "SetUserGameScore",
Handler: _RankingManagement_SetUserGameScore_Handler,
},
},
Streams: []grpc.StreamDesc{
{
StreamName: "GetRankingList",
MethodName: "GetRankingList",
Handler: _RankingManagement_GetRankingList_Handler,
ServerStreams: true,
},
},
Streams: []grpc.StreamDesc{},
Metadata: "ranking_management.proto",
}

View File

@ -6,24 +6,26 @@ package ranking_management_client
import (
"context"
ranking_management2 "gitea.youtukeji.com.cn/xiabin/youtu_grpc/app/ranking_management/ranking_management"
"gitea.youtukeji.com.cn/xiabin/youtu_grpc/app/ranking_management/ranking_management"
"github.com/zeromicro/go-zero/zrpc"
"google.golang.org/grpc"
)
type (
BaseResult = ranking_management2.BaseResult
PageRequest = ranking_management2.PageRequest
RankingData = ranking_management2.RankingData
Request = ranking_management2.Request
Response = ranking_management2.Response
SetUserGameScoreRequest = ranking_management2.SetUserGameScoreRequest
BaseResult = ranking_management.BaseResult
GetRankingListRequest = ranking_management.GetRankingListRequest
GetRankingListResponse = ranking_management.GetRankingListResponse
RankingList = ranking_management.RankingList
Request = ranking_management.Request
Response = ranking_management.Response
SetUserGameScoreRequest = ranking_management.SetUserGameScoreRequest
RankingManagement interface {
Ping(ctx context.Context, in *Request, opts ...grpc.CallOption) (*Response, error)
SetUserGameScore(ctx context.Context, in *SetUserGameScoreRequest, opts ...grpc.CallOption) (*BaseResult, error)
GetRankingList(ctx context.Context, in *PageRequest, opts ...grpc.CallOption) (ranking_management2.RankingManagement_GetRankingListClient, error)
GetRankingList(ctx context.Context, in *GetRankingListRequest, opts ...grpc.CallOption) (*GetRankingListResponse, error)
}
defaultRankingManagement struct {
@ -38,16 +40,16 @@ func NewRankingManagement(cli zrpc.Client) RankingManagement {
}
func (m *defaultRankingManagement) Ping(ctx context.Context, in *Request, opts ...grpc.CallOption) (*Response, error) {
client := ranking_management2.NewRankingManagementClient(m.cli.Conn())
client := ranking_management.NewRankingManagementClient(m.cli.Conn())
return client.Ping(ctx, in, opts...)
}
func (m *defaultRankingManagement) SetUserGameScore(ctx context.Context, in *SetUserGameScoreRequest, opts ...grpc.CallOption) (*BaseResult, error) {
client := ranking_management2.NewRankingManagementClient(m.cli.Conn())
client := ranking_management.NewRankingManagementClient(m.cli.Conn())
return client.SetUserGameScore(ctx, in, opts...)
}
func (m *defaultRankingManagement) GetRankingList(ctx context.Context, in *PageRequest, opts ...grpc.CallOption) (ranking_management2.RankingManagement_GetRankingListClient, error) {
client := ranking_management2.NewRankingManagementClient(m.cli.Conn())
func (m *defaultRankingManagement) GetRankingList(ctx context.Context, in *GetRankingListRequest, opts ...grpc.CallOption) (*GetRankingListResponse, error) {
client := ranking_management.NewRankingManagementClient(m.cli.Conn())
return client.GetRankingList(ctx, in, opts...)
}

12
go.mod
View File

@ -13,10 +13,14 @@ require (
go.etcd.io/etcd/client/v3 v3.5.18
google.golang.org/grpc v1.70.0
google.golang.org/protobuf v1.36.5
gorm.io/driver/sqlite v1.4.3
gorm.io/gen v0.3.26
gorm.io/gorm v1.25.12
gorm.io/plugin/dbresolver v1.5.3
)
require (
filippo.io/edwards25519 v1.1.0 // indirect
github.com/beorn7/perks v1.0.1 // indirect
github.com/bradfitz/gomemcache v0.0.0-20230905024940-24af94b03874 // indirect
github.com/cenkalti/backoff/v4 v4.3.0 // indirect
@ -34,6 +38,7 @@ require (
github.com/go-openapi/jsonreference v0.21.0 // indirect
github.com/go-openapi/swag v0.23.0 // indirect
github.com/go-redis/redis/v8 v8.11.5 // indirect
github.com/go-sql-driver/mysql v1.8.1 // indirect
github.com/gogo/protobuf v1.3.2 // indirect
github.com/golang/mock v1.6.0 // indirect
github.com/golang/protobuf v1.5.4 // indirect
@ -50,6 +55,7 @@ require (
github.com/mailru/easyjson v0.9.0 // indirect
github.com/mattn/go-colorable v0.1.14 // indirect
github.com/mattn/go-isatty v0.0.20 // indirect
github.com/mattn/go-sqlite3 v1.14.15 // indirect
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
github.com/modern-go/reflect2 v1.0.2 // indirect
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 // indirect
@ -80,18 +86,24 @@ require (
go.uber.org/multierr v1.11.0 // indirect
go.uber.org/zap v1.27.0 // indirect
golang.org/x/crypto v0.32.0 // indirect
golang.org/x/mod v0.21.0 // indirect
golang.org/x/net v0.34.0 // indirect
golang.org/x/oauth2 v0.26.0 // indirect
golang.org/x/sync v0.11.0 // indirect
golang.org/x/sys v0.30.0 // indirect
golang.org/x/term v0.29.0 // indirect
golang.org/x/text v0.22.0 // indirect
golang.org/x/time v0.10.0 // indirect
golang.org/x/tools v0.26.0 // indirect
google.golang.org/genproto/googleapis/api v0.0.0-20250204164813-702378808489 // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20250204164813-702378808489 // indirect
gopkg.in/evanphx/json-patch.v4 v4.12.0 // indirect
gopkg.in/inf.v0 v0.9.1 // indirect
gopkg.in/yaml.v2 v2.4.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
gorm.io/datatypes v1.1.1-0.20230130040222-c43177d3cf8c // indirect
gorm.io/driver/mysql v1.5.7 // indirect
gorm.io/hints v1.1.0 // indirect
k8s.io/api v0.32.1 // indirect
k8s.io/apimachinery v0.32.1 // indirect
k8s.io/client-go v0.32.1 // indirect

76
go.sum
View File

@ -1,3 +1,5 @@
filippo.io/edwards25519 v1.1.0 h1:FNf4tywRC1HmFuKW5xopWpigGjJKiJSV0Cqo0cJWDaA=
filippo.io/edwards25519 v1.1.0/go.mod h1:BxyFTGdWcka3PhytdK4V28tE5sGfRvvvRV7EaN4VDT4=
gitea.youtukeji.com.cn/youtu/openapi-helper v0.0.0-20250123094517-b5871b3f4784 h1:Ey/s51gRB3rpN/TCXY1rAqZulktSlkdXrxyfBtnEtAc=
gitea.youtukeji.com.cn/youtu/openapi-helper v0.0.0-20250123094517-b5871b3f4784/go.mod h1:o3XiYjUmxptrwcYPbTwNc2SQSOeOj7qbQPdNNVU0H5w=
github.com/alicebob/gopher-json v0.0.0-20200520072559-a9ecdc9d1d3a/go.mod h1:SGnFV6hVsYE877CKEZ6tDNTjaSXYUk6QqoIK6PrAtcc=
@ -58,6 +60,9 @@ github.com/go-openapi/swag v0.23.0 h1:vsEVJDUo2hPJ2tu0/Xc+4noaxyEffXNIs3cOULZ+Gr
github.com/go-openapi/swag v0.23.0/go.mod h1:esZ8ITTYEsH1V2trKHjAN8Ai7xHb8RV+YSZ577vPjgQ=
github.com/go-redis/redis/v8 v8.11.5 h1:AcZZR7igkdvfVmQTPnu9WE37LRrO/YrBH5zWyjDC0oI=
github.com/go-redis/redis/v8 v8.11.5/go.mod h1:gREzHqY1hg6oD9ngVRbLStwAWKhA0FEgq8Jd4h5lpwo=
github.com/go-sql-driver/mysql v1.7.0/go.mod h1:OXbVy3sEdcQ2Doequ6Z5BW6fXNQTmx+9S1MCJN5yJMI=
github.com/go-sql-driver/mysql v1.8.1 h1:LedoTUt/eveggdHS9qUFC1EFSa8bU2+1pZjSRpvNJ1Y=
github.com/go-sql-driver/mysql v1.8.1/go.mod h1:wEBSXgmK//2ZFJyE+qWnIsVGmvmEKlqwuVSjsCm7DZg=
github.com/go-task/slim-sprig v0.0.0-20210107165309-348f09dbbbc0/go.mod h1:fyg7847qk6SyHyPtNmDHnmrv/HOrqktSC+C9fM+CJOE=
github.com/go-task/slim-sprig v0.0.0-20230315185526-52ccab3ef572 h1:tfuBGBXKqDEevZMzYi5KSi8KkcZtzBcTgAUUtapy0OI=
github.com/go-task/slim-sprig/v3 v3.0.0 h1:sUs3vkvUymDpBKi3qH1YSqBQk9+9D/8M2mN1vB6EwHI=
@ -65,6 +70,10 @@ github.com/go-task/slim-sprig/v3 v3.0.0/go.mod h1:W848ghGpv3Qj3dhTPRyJypKRiqCdHZ
github.com/godbus/dbus/v5 v5.0.4/go.mod h1:xhWf0FNVPg57R7Z0UbKHbJfkEywrmjJnf7w5xrFpKfA=
github.com/gogo/protobuf v1.3.2 h1:Ov1cvc58UF3b5XjBnZv7+opcTcQFZebYjWzi34vdm4Q=
github.com/gogo/protobuf v1.3.2/go.mod h1:P1XiOD3dCwIKUDQYPy72D8LYyHL2YPYrpS2s69NZV8Q=
github.com/golang-sql/civil v0.0.0-20220223132316-b832511892a9 h1:au07oEsX2xN0ktxqI+Sida1w446QrXBRJ0nee3SNZlA=
github.com/golang-sql/civil v0.0.0-20220223132316-b832511892a9/go.mod h1:8vg3r2VgvsThLBIFL93Qb5yWzgyZWhEmBwUJWevAkK0=
github.com/golang-sql/sqlexp v0.1.0 h1:ZCD6MBpcuOVfGVqsEmY5/4FtYiKz6tSyUv9LPEDei6A=
github.com/golang-sql/sqlexp v0.1.0/go.mod h1:J4ad9Vo8ZCWQ2GMrC4UCQy1JpCbwU9m3EOqtpKwwwHI=
github.com/golang/mock v1.6.0 h1:ErTB+efbowRARo13NNdxyJji2egdxLGQhRaY+DUumQc=
github.com/golang/mock v1.6.0/go.mod h1:p6yTPP+5HYm5mzsMV8JkE6ZKdX+/wYM6Hr+LicevLPs=
github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
@ -101,8 +110,26 @@ github.com/h2non/parth v0.0.0-20190131123155-b4df798d6542 h1:2VTzZjLZBgl62/EtslC
github.com/h2non/parth v0.0.0-20190131123155-b4df798d6542/go.mod h1:Ow0tF8D4Kplbc8s8sSb3V2oUCygFHVp8gC3Dn6U4MNI=
github.com/hpcloud/tail v1.0.0/go.mod h1:ab1qPbhIpdTxEkNHXyeSf5vhxWSCs/tWer42PpOxQnU=
github.com/ianlancetaylor/demangle v0.0.0-20200824232613-28f6c0f3b639/go.mod h1:aSSvb/t6k1mPoxDqO4vJh6VOCGPwU4O0C2/Eqndh1Sc=
github.com/jackc/chunkreader/v2 v2.0.1 h1:i+RDz65UE+mmpjTfyz0MoVTnzeYxroil2G82ki7MGG8=
github.com/jackc/chunkreader/v2 v2.0.1/go.mod h1:odVSm741yZoC3dpHEUXIqA9tQRhFrgOHwnPIn9lDKlk=
github.com/jackc/pgconn v1.13.0 h1:3L1XMNV2Zvca/8BYhzcRFS70Lr0WlDg16Di6SFGAbys=
github.com/jackc/pgconn v1.13.0/go.mod h1:AnowpAqO4CMIIJNZl2VJp+KrkAZciAkhEl0W0JIobpI=
github.com/jackc/pgio v1.0.0 h1:g12B9UwVnzGhueNavwioyEEpAmqMe1E/BN9ES+8ovkE=
github.com/jackc/pgio v1.0.0/go.mod h1:oP+2QK2wFfUWgr+gxjoBH9KGBb31Eio69xUb0w5bYf8=
github.com/jackc/pgpassfile v1.0.0 h1:/6Hmqy13Ss2zCq62VdNG8tM1wchn8zjSGOBJ6icpsIM=
github.com/jackc/pgpassfile v1.0.0/go.mod h1:CEx0iS5ambNFdcRtxPj5JhEz+xB6uRky5eyVu/W2HEg=
github.com/jackc/pgproto3/v2 v2.3.1 h1:nwj7qwf0S+Q7ISFfBndqeLwSwxs+4DPsbRFjECT1Y4Y=
github.com/jackc/pgproto3/v2 v2.3.1/go.mod h1:WfJCnwN3HIg9Ish/j3sgWXnAfK8A9Y0bwXYU5xKaEdA=
github.com/jackc/pgservicefile v0.0.0-20240606120523-5a60cdf6a761 h1:iCEnooe7UlwOQYpKFhBabPMi4aNAfoODPEFNiAnClxo=
github.com/jackc/pgservicefile v0.0.0-20240606120523-5a60cdf6a761/go.mod h1:5TJZWKEWniPve33vlWYSoGYefn3gLQRzjfDlhSJ9ZKM=
github.com/jackc/pgtype v1.12.0 h1:Dlq8Qvcch7kiehm8wPGIW0W3KsCCHJnRacKW0UM8n5w=
github.com/jackc/pgtype v1.12.0/go.mod h1:LUMuVrfsFfdKGLw+AFFVv6KtHOFMwRgDDzBt76IqCA4=
github.com/jackc/pgx/v4 v4.17.2 h1:0Ut0rpeKwvIVbMQ1KbMBU4h6wxehBI535LK6Flheh8E=
github.com/jackc/pgx/v4 v4.17.2/go.mod h1:lcxIZN44yMIrWI78a5CpucdD14hX0SBDbNRvjDBItsw=
github.com/jinzhu/inflection v1.0.0 h1:K317FqzuhWc8YvSVlFMCCUb36O/S9MCKRDI7QkRKD/E=
github.com/jinzhu/inflection v1.0.0/go.mod h1:h+uFLlag+Qp1Va5pdKtLDYj+kHp5pxUVkryuEj+Srlc=
github.com/jinzhu/now v1.1.2/go.mod h1:d3SSVoowX0Lcu0IBviAWJpolVfI5UJVZZ7cO71lE/z8=
github.com/jinzhu/now v1.1.4/go.mod h1:d3SSVoowX0Lcu0IBviAWJpolVfI5UJVZZ7cO71lE/z8=
github.com/jinzhu/now v1.1.5 h1:/o9tlHleP7gOFmsnYNz3RGnqzefHA47wQpKrrdTIwXQ=
github.com/jinzhu/now v1.1.5/go.mod h1:d3SSVoowX0Lcu0IBviAWJpolVfI5UJVZZ7cO71lE/z8=
github.com/josharian/intern v1.0.0 h1:vlS4z54oSdjm0bgjRigI+G1HpF+tI+9rE5LLzOg8HmY=
@ -125,6 +152,11 @@ github.com/mattn/go-colorable v0.1.14 h1:9A9LHSqF/7dyVVX6g0U9cwm9pG3kP9gSzcuIPHP
github.com/mattn/go-colorable v0.1.14/go.mod h1:6LmQG8QLFO4G5z1gPvYEzlUgJ2wF+stgPZH1UqBm1s8=
github.com/mattn/go-isatty v0.0.20 h1:xfD0iDuEKnDkl03q4limB+vH+GxLEtL/jb4xVJSWWEY=
github.com/mattn/go-isatty v0.0.20/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y=
github.com/mattn/go-sqlite3 v1.14.8/go.mod h1:NyWgC/yNuGj7Q9rpYnZvas74GogHl5/Z4A/KQRfk6bU=
github.com/mattn/go-sqlite3 v1.14.15 h1:vfoHhTN1af61xCRSWzFIWzx2YskyMTwHLrExkBOjvxI=
github.com/mattn/go-sqlite3 v1.14.15/go.mod h1:2eHXhiwb8IkHr+BDWZGa96P6+rkvnG63S2DGjv9HUNg=
github.com/microsoft/go-mssqldb v0.17.0 h1:Fto83dMZPnYv1Zwx5vHHxpNraeEaUlQ/hhHLgZiaenE=
github.com/microsoft/go-mssqldb v0.17.0/go.mod h1:OkoNGhGEs8EZqchVTtochlXruEhEOaO4S0d2sB5aeGQ=
github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q=
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd h1:TRLaZ9cD/w8PVh93nsPXa1VrQ6jlwL5oN8l14QlcNfg=
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q=
@ -199,6 +231,7 @@ github.com/x448/float16 v0.8.4/go.mod h1:14CWIYCyZA/cWjXOioeEpHeN/83MdbZDRQHoFcY
github.com/yuin/goldmark v1.1.27/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
github.com/yuin/goldmark v1.2.1/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
github.com/yuin/goldmark v1.3.5/go.mod h1:mwnBkeHKe2W/ZEtQ+71ViKU8L12m81fl3OWwC1Zlc8k=
github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY=
github.com/yuin/gopher-lua v0.0.0-20220504180219-658193537a64/go.mod h1:GBR0iDaNXjAgGg9zfCvksxSRnQx76gclCIb7kdAd1Pw=
github.com/yuin/gopher-lua v1.1.1 h1:kYKnWBjvbNP4XLT3+bPEwAXJx262OhaHDWDVOPjL46M=
github.com/yuin/gopher-lua v1.1.1/go.mod h1:GBR0iDaNXjAgGg9zfCvksxSRnQx76gclCIb7kdAd1Pw=
@ -247,21 +280,29 @@ go.uber.org/zap v1.27.0/go.mod h1:GB2qFLM7cTU87MWRP2mPIjqfIDnGu+VIO4V/SdhGo2E=
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc=
golang.org/x/crypto v0.0.0-20220622213112-05595931fe9d/go.mod h1:IxCIyHEi3zRg3s0A5j5BB6A9Jmi73HwBIUl50j+osU4=
golang.org/x/crypto v0.32.0 h1:euUpcYgM8WcP71gNpTqQCn6rC2t6ULUPiOzfWaXVVfc=
golang.org/x/crypto v0.32.0/go.mod h1:ZnnJkOaASj8g0AjIduWNlq2NRxL0PlBrbKVyZ6V/Ugc=
golang.org/x/mod v0.2.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
golang.org/x/mod v0.3.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
golang.org/x/mod v0.4.2/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4/go.mod h1:jJ57K6gSWd91VN4djpZkiMVwK6gcyfeH4XE8wZrZaV4=
golang.org/x/mod v0.8.0/go.mod h1:iBbtSCu2XBx23ZKBPSOrRkjjQPZFPuis4dIYUhu/chs=
golang.org/x/mod v0.21.0 h1:vvrHzRwRfVKSiLrG+d4FMl/Qi4ukBCE6kZlTUkDYRT0=
golang.org/x/mod v0.21.0/go.mod h1:6SkKJ3Xj0I0BrPOZoBy3bdMptDDU9oJrpohJ3eWZ1fY=
golang.org/x/net v0.0.0-20180906233101-161cd47e91fd/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
golang.org/x/net v0.0.0-20200226121028-0de0cce0169b/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
golang.org/x/net v0.0.0-20200520004742-59133d7f0dd7/go.mod h1:qpuaurCH72eLCgpAm/N6yyVIVM9cpaDIP3A8BGJEC5A=
golang.org/x/net v0.0.0-20201021035429-f5854403a974/go.mod h1:sp8m0HH+o8qH0wwXwYZr8TS3Oi6o0r6Gce1SSxlDquU=
golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg=
golang.org/x/net v0.0.0-20210405180319-a5a99cb37ef4/go.mod h1:p54w0d4576C0XHj96bSt6lcn1PtDYWL6XObtHCRCNQM=
golang.org/x/net v0.0.0-20210428140749-89ef3d95e781/go.mod h1:OJAsFXCWl8Ukc7SiCT/9KSuxbyM7479/AVlXFRxuMCk=
golang.org/x/net v0.0.0-20211112202133-69e39bad7dc2/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y=
golang.org/x/net v0.0.0-20220722155237-a158d28d115b/go.mod h1:XRhObCWvk6IyKnWLug+ECip1KBveYUHfp+8e9klMJ9c=
golang.org/x/net v0.6.0/go.mod h1:2Tu9+aMcznHK/AK1HMvgo6xiTLG5rD5rZLDS+rp2Bjs=
golang.org/x/net v0.34.0 h1:Mb7Mrk043xzHgnRM88suvJFwzVrRfHEHJEl5/71CKw0=
golang.org/x/net v0.34.0/go.mod h1:di0qlW3YNM5oh6GqDGQr92MyTozJPmybPK4Ev/Gm31k=
golang.org/x/oauth2 v0.26.0 h1:afQXWNNaeC4nvZ0Ed9XvCCzXM6UHJG7iCg0W4fPqSBE=
@ -271,6 +312,10 @@ golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJ
golang.org/x/sync v0.0.0-20190911185100-cd5d95a43a6e/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.0.0-20201020160332-67f06af15bc9/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.0.0-20210220032951-036812b2e83c/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.0.0-20220722155255-886fb9371eb4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.1.0/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.11.0 h1:GGz8+XQP4FvTTrjZPzNKTMFtSXH80RAzG+5ghFPgK9w=
golang.org/x/sync v0.11.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk=
golang.org/x/sys v0.0.0-20180909124046-d0be0721c37e/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20190204203706-41f3e6584952/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
@ -288,16 +333,24 @@ golang.org/x/sys v0.0.0-20210423082822-04245dca01da/go.mod h1:h1NjWce9XRLGQEsW7w
golang.org/x/sys v0.0.0-20210510120138-977fb7262007/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20211216021012-1d35b9e2eb4e/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.5.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.30.0 h1:QjkSwP/36a20jFYWkSue1YwXzLmsV5Gfq7Eiy72C1uc=
golang.org/x/sys v0.30.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8=
golang.org/x/term v0.5.0/go.mod h1:jMB1sMXY+tzblOD4FWmEbocvup2/aLOaQEp7JmGp78k=
golang.org/x/term v0.29.0 h1:L6pJp37ocefwRRtYPKSWOWzOtWSxVajvz2ldH/xi3iU=
golang.org/x/term v0.29.0/go.mod h1:6bl4lRlvVuDgSf3179VpIxBF0o10JUpXWOnI7nErv7s=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ=
golang.org/x/text v0.7.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8=
golang.org/x/text v0.14.0/go.mod h1:18ZOQIKpY8NJVqYksKHtTdi31H5itFRjB5/qKTNYzSU=
golang.org/x/text v0.22.0 h1:bofq7m3/HAFvbF51jz3Q9wLg3jkvSPuiZu/pD1XwgtM=
golang.org/x/text v0.22.0/go.mod h1:YRoo4H8PVmsu+E3Ou7cqLVH8oXWIHVoX0jqUWALQhfY=
golang.org/x/time v0.10.0 h1:3usCWA8tQn0L8+hFJQNgzpWbd89begxN66o1Ojdn5L4=
@ -308,6 +361,8 @@ golang.org/x/tools v0.0.0-20200619180055-7c47624df98f/go.mod h1:EkVYQZoAsY45+roY
golang.org/x/tools v0.0.0-20201224043029-2b0845dc783e/go.mod h1:emZCQorbCU4vsT4fOWvOPXz4eW1wZW4PmDk9uLelYpA=
golang.org/x/tools v0.0.0-20210106214847-113979e3529a/go.mod h1:emZCQorbCU4vsT4fOWvOPXz4eW1wZW4PmDk9uLelYpA=
golang.org/x/tools v0.1.1/go.mod h1:o0xws9oXOQQZyjljx8fwUC0k7L1pTE6eaCbjGeHmOkk=
golang.org/x/tools v0.1.12/go.mod h1:hNGJHUnrk76NpqgfD5Aqm5Crs+Hm0VOH/i9J2+nxYbc=
golang.org/x/tools v0.6.0/go.mod h1:Xwgl3UAJ/d3gWutnCtw505GrjyAbvKui8lOU390QaIU=
golang.org/x/tools v0.26.0 h1:v/60pFQmzmT9ExmjDv2gGIfi3OqfKoEP6I5+umXlbnQ=
golang.org/x/tools v0.26.0/go.mod h1:TPVVj70c7JJ3WCazhD8OdXcZg/og+b9+tH/KxylGwH0=
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
@ -350,8 +405,29 @@ gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ=
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
gorm.io/datatypes v1.1.1-0.20230130040222-c43177d3cf8c h1:jWdr7cHgl8c/ua5vYbR2WhSp+NQmzhsj0xoY3foTzW8=
gorm.io/datatypes v1.1.1-0.20230130040222-c43177d3cf8c/go.mod h1:SH2K9R+2RMjuX1CkCONrPwoe9JzVv2hkQvEu4bXGojE=
gorm.io/driver/mysql v1.5.7 h1:MndhOPYOfEp2rHKgkZIhJ16eVUIRf2HmzgoPmh7FCWo=
gorm.io/driver/mysql v1.5.7/go.mod h1:sEtPWMiqiN1N1cMXoXmBbd8C6/l+TESwriotuRRpkDM=
gorm.io/driver/postgres v1.4.5 h1:mTeXTTtHAgnS9PgmhN2YeUbazYpLhUI1doLnw42XUZc=
gorm.io/driver/postgres v1.4.5/go.mod h1:GKNQYSJ14qvWkvPwXljMGehpKrhlDNsqYRr5HnYGncg=
gorm.io/driver/sqlite v1.1.6/go.mod h1:W8LmC/6UvVbHKah0+QOC7Ja66EaZXHwUTjgXY8YNWX8=
gorm.io/driver/sqlite v1.4.3 h1:HBBcZSDnWi5BW3B3rwvVTc510KGkBkexlOg0QrmLUuU=
gorm.io/driver/sqlite v1.4.3/go.mod h1:0Aq3iPO+v9ZKbcdiz8gLWRw5VOPcBOPUQJFLq5e2ecI=
gorm.io/driver/sqlserver v1.4.1 h1:t4r4r6Jam5E6ejqP7N82qAJIJAht27EGT41HyPfXRw0=
gorm.io/driver/sqlserver v1.4.1/go.mod h1:DJ4P+MeZbc5rvY58PnmN1Lnyvb5gw5NPzGshHDnJLig=
gorm.io/gen v0.3.26 h1:sFf1j7vNStimPRRAtH4zz5NiHM+1dr6eA9aaRdplyhY=
gorm.io/gen v0.3.26/go.mod h1:a5lq5y3w4g5LMxBcw0wnO6tYUCdNutWODq5LrIt75LE=
gorm.io/gorm v1.21.15/go.mod h1:F+OptMscr0P2F2qU97WT1WimdH9GaQPoDW7AYd5i2Y0=
gorm.io/gorm v1.22.2/go.mod h1:F+OptMscr0P2F2qU97WT1WimdH9GaQPoDW7AYd5i2Y0=
gorm.io/gorm v1.24.0/go.mod h1:DVrVomtaYTbqs7gB/x2uVvqnXzv0nqjB396B8cG4dBA=
gorm.io/gorm v1.25.7/go.mod h1:hbnx/Oo0ChWMn1BIhpy1oYozzpM15i4YPuHDmfYtwg8=
gorm.io/gorm v1.25.12 h1:I0u8i2hWQItBq1WfE0o2+WuL9+8L21K9e2HHSTE/0f8=
gorm.io/gorm v1.25.12/go.mod h1:xh7N7RHfYlNc5EmcI/El95gXusucDrQnHXe0+CgWcLQ=
gorm.io/hints v1.1.0 h1:Lp4z3rxREufSdxn4qmkK3TLDltrM10FLTHiuqwDPvXw=
gorm.io/hints v1.1.0/go.mod h1:lKQ0JjySsPBj3uslFzY3JhYDtqEwzm+G1hv8rWujB6Y=
gorm.io/plugin/dbresolver v1.5.3 h1:wFwINGZZmttuu9h7XpvbDHd8Lf9bb8GNzp/NpAMV2wU=
gorm.io/plugin/dbresolver v1.5.3/go.mod h1:TSrVhaUg2DZAWP3PrHlDlITEJmNOkL0tFTjvTEsQ4XE=
k8s.io/api v0.32.1 h1:f562zw9cy+GvXzXf0CKlVQ7yHJVYzLfL6JAS4kOAaOc=
k8s.io/api v0.32.1/go.mod h1:/Yi/BqkuueW1BgpoePYBRdDYfjPF5sgTr5+YqDZra5k=
k8s.io/apimachinery v0.32.1 h1:683ENpaCBjma4CYqsmZyhEzrGz6cjn1MY/X2jB2hkZs=

View File

@ -0,0 +1,26 @@
// 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

@ -0,0 +1,30 @@
// 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

@ -0,0 +1,20 @@
// 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

@ -0,0 +1,26 @@
// 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 TableNameGameScore = "game_score"
// GameScore mapped from table <game_score>
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"` // 得分类型(区分相同小游戏中的不同模式得分)
UpdatedAt time.Time `gorm:"column:updated_at;type:timestamp;not null;default:CURRENT_TIMESTAMP;comment:更新时间" json:"updated_at"` // 更新时间
}
// TableName GameScore's table name
func (*GameScore) TableName() string {
return TableNameGameScore
}

View File

@ -0,0 +1,417 @@
// 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

@ -0,0 +1,145 @@
// 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

@ -0,0 +1,412 @@
// 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

@ -0,0 +1,145 @@
// 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

@ -0,0 +1,392 @@
// 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

@ -0,0 +1,145 @@
// 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)
}
}

View File

@ -0,0 +1,457 @@
// 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"
"gitea.youtukeji.com.cn/xiabin/youtu_grpc/pkg/my_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.UpdatedAt = field.NewTime(tableName, "updated_at")
_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
UpdatedAt field.Time
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.UpdatedAt = field.NewTime(table, "updated_at")
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, 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 {
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 = @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;
func (g gameScoreDo) GetUserRank(appId uint32, userId uint64, t uint32) (result querier.RankingData, err error) {
var params []interface{}
var generateSQL strings.Builder
params = append(params, t)
params = append(params, appId)
params = append(params, userId)
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(), params...).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
}

View File

@ -0,0 +1,145 @@
// 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.GameScore{})
if err != nil {
fmt.Printf("Error: AutoMigrate(&model.GameScore{}) fail: %s", err)
}
}
func Test_gameScoreQuery(t *testing.T) {
gameScore := newGameScore(_gen_test_db)
gameScore = *gameScore.As(gameScore.TableName())
_do := gameScore.WithContext(context.Background()).Debug()
primaryKey := field.NewString(gameScore.TableName(), clause.PrimaryKey)
_, err := _do.Unscoped().Where(primaryKey.IsNotNull()).Delete()
if err != nil {
t.Error("clean table <game_score> fail:", err)
return
}
_, ok := gameScore.GetFieldByName("")
if ok {
t.Error("GetFieldByName(\"\") from gameScore success")
}
err = _do.Create(&model.GameScore{})
if err != nil {
t.Error("create item in table <game_score> fail:", err)
}
err = _do.Save(&model.GameScore{})
if err != nil {
t.Error("create item in table <game_score> fail:", err)
}
err = _do.CreateInBatches([]*model.GameScore{{}, {}}, 10)
if err != nil {
t.Error("create item in table <game_score> fail:", err)
}
_, err = _do.Select(gameScore.ALL).Take()
if err != nil {
t.Error("Take() on table <game_score> fail:", err)
}
_, err = _do.First()
if err != nil {
t.Error("First() on table <game_score> fail:", err)
}
_, err = _do.Last()
if err != nil {
t.Error("First() on table <game_score> 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 <game_score> fail:", err)
}
err = _do.Where(primaryKey.IsNotNull()).FindInBatches(&[]*model.GameScore{}, 10, func(tx gen.Dao, batch int) error { return nil })
if err != nil {
t.Error("FindInBatches() on table <game_score> fail:", err)
}
_, err = _do.Select(gameScore.ALL).Where(primaryKey.IsNotNull()).Order(primaryKey.Desc()).Find()
if err != nil {
t.Error("Find() on table <game_score> fail:", err)
}
_, err = _do.Distinct(primaryKey).Take()
if err != nil {
t.Error("select Distinct() on table <game_score> fail:", err)
}
_, err = _do.Select(gameScore.ALL).Omit(primaryKey).Take()
if err != nil {
t.Error("Omit() on table <game_score> fail:", err)
}
_, err = _do.Group(primaryKey).Find()
if err != nil {
t.Error("Group() on table <game_score> 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 <game_score> fail:", err)
}
_, _, err = _do.FindByPage(0, 1)
if err != nil {
t.Error("FindByPage() on table <game_score> fail:", err)
}
_, err = _do.ScanByPage(&model.GameScore{}, 0, 1)
if err != nil {
t.Error("ScanByPage() on table <game_score> fail:", err)
}
_, err = _do.Attrs(primaryKey).Assign(primaryKey).FirstOrInit()
if err != nil {
t.Error("FirstOrInit() on table <game_score> fail:", err)
}
_, err = _do.Attrs(primaryKey).Assign(primaryKey).FirstOrCreate()
if err != nil {
t.Error("FirstOrCreate() on table <game_score> 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 <game_score> fail:", err)
}
err = _do.LeftJoin(&_a, primaryKey.EqCol(_aPK)).Scan(map[string]interface{}{})
if err != nil {
t.Error("LeftJoin() on table <game_score> fail:", err)
}
_, err = _do.Not().Or().Clauses().Take()
if err != nil {
t.Error("Not/Or/Clauses on table <game_score> fail:", err)
}
}

View File

@ -0,0 +1,127 @@
// 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
}

View File

@ -0,0 +1,121 @@
// 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"
"reflect"
"sync"
"testing"
"gorm.io/driver/sqlite"
"gorm.io/gorm"
)
type Input struct {
Args []interface{}
}
type Expectation struct {
Ret []interface{}
}
type TestCase struct {
Input
Expectation
}
const _gen_test_db_name = "gen_test.db"
var _gen_test_db *gorm.DB
var _gen_test_once sync.Once
func init() {
InitializeDB()
_gen_test_db.AutoMigrate(&_another{})
}
func InitializeDB() {
_gen_test_once.Do(func() {
var err error
_gen_test_db, err = gorm.Open(sqlite.Open(_gen_test_db_name), &gorm.Config{})
if err != nil {
panic(fmt.Errorf("open sqlite %q fail: %w", _gen_test_db_name, err))
}
})
}
func assert(t *testing.T, methodName string, res, exp interface{}) {
if !reflect.DeepEqual(res, exp) {
t.Errorf("%v() gotResult = %v, want %v", methodName, res, exp)
}
}
type _another struct {
ID uint64 `gorm:"primaryKey"`
}
func (*_another) TableName() string { return "another_for_unit_test" }
func Test_Available(t *testing.T) {
if !Use(_gen_test_db).Available() {
t.Errorf("query.Available() == false")
}
}
func Test_WithContext(t *testing.T) {
query := Use(_gen_test_db)
if !query.Available() {
t.Errorf("query Use(_gen_test_db) fail: query.Available() == false")
}
type Content string
var key, value Content = "gen_tag", "unit_test"
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 {
t.Errorf("get value from context fail, expect %q, got %q", value, v)
}
}
}
func Test_Transaction(t *testing.T) {
query := Use(_gen_test_db)
if !query.Available() {
t.Errorf("query Use(_gen_test_db) fail: query.Available() == false")
}
err := query.Transaction(func(tx *Query) error { return nil })
if err != nil {
t.Errorf("query.Transaction execute fail: %s", err)
}
tx := query.Begin()
err = tx.SavePoint("point")
if err != nil {
t.Errorf("query tx SavePoint fail: %s", err)
}
err = tx.RollbackTo("point")
if err != nil {
t.Errorf("query tx RollbackTo fail: %s", err)
}
err = tx.Commit()
if err != nil {
t.Errorf("query tx Commit fail: %s", err)
}
err = query.Begin().Rollback()
if err != nil {
t.Errorf("query tx Rollback fail: %s", err)
}
}

17
pkg/my_gorm/gen/gen.yaml Normal file
View File

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

View File

@ -0,0 +1,54 @@
package querier
import (
"gorm.io/gen"
)
type AppAccountQuerier interface {
//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
GetAppConfig() ([]*gen.T, error)
}
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

@ -1,7 +1,7 @@
package gorm
package my_gorm
import (
redisCacher "gitea.youtukeji.com.cn/xiabin/youtu_grpc/pkg/gorm/redis"
redisCacher "gitea.youtukeji.com.cn/xiabin/youtu_grpc/pkg/my_gorm/redis"
"github.com/go-gorm/caches/v4"
"github.com/redis/go-redis/v9"
"gorm.io/gorm"