From f638652270912c5e67546727cfd78a59c18e5ba0 Mon Sep 17 00:00:00 2001 From: xiabin Date: Sat, 25 Jan 2025 18:05:02 +0800 Subject: [PATCH] =?UTF-8?q?fix=E8=8E=B7=E5=8F=96=E6=8E=92=E8=A1=8C?= =?UTF-8?q?=E6=A6=9C=E5=88=9D=E5=A7=8B=E5=8C=96=E6=95=B0=E6=8D=AE=E9=97=AE?= =?UTF-8?q?=E9=A2=98=EF=BC=8Csql=E6=89=A7=E8=A1=8C=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- gorm-gen/dao/model/app_account.gen.go | 26 + gorm-gen/dao/model/app_user.gen.go | 29 ++ gorm-gen/dao/model/douyin_ecpm_config.gen.go | 20 + gorm-gen/dao/model/game_score.gen.go | 21 + gorm-gen/dao/query/app_account.gen.go | 349 ++++++++++++++ gorm-gen/dao/query/app_account.gen_test.go | 145 ++++++ gorm-gen/dao/query/app_user.gen.go | 359 ++++++++++++++ gorm-gen/dao/query/app_user.gen_test.go | 145 ++++++ gorm-gen/dao/query/douyin_ecpm_config.gen.go | 343 ++++++++++++++ .../dao/query/douyin_ecpm_config.gen_test.go | 145 ++++++ gorm-gen/dao/query/game_score.gen.go | 345 ++++++++++++++ gorm-gen/dao/query/game_score.gen_test.go | 145 ++++++ gorm-gen/dao/query/gen.go | 111 +++++ gorm-gen/dao/query/gen_test.go | 121 +++++ gorm-gen/query/app_account.gen.go | 417 ++++++++++++++++ gorm-gen/query/app_user.gen.go | 412 ++++++++++++++++ gorm-gen/query/douyin_ecpm_config.gen.go | 392 +++++++++++++++ gorm-gen/query/game_score.gen.go | 448 ++++++++++++++++++ gorm-gen/query/gen.go | 127 +++++ 19 files changed, 4100 insertions(+) create mode 100644 gorm-gen/dao/model/app_account.gen.go create mode 100644 gorm-gen/dao/model/app_user.gen.go create mode 100644 gorm-gen/dao/model/douyin_ecpm_config.gen.go create mode 100644 gorm-gen/dao/model/game_score.gen.go create mode 100644 gorm-gen/dao/query/app_account.gen.go create mode 100644 gorm-gen/dao/query/app_account.gen_test.go create mode 100644 gorm-gen/dao/query/app_user.gen.go create mode 100644 gorm-gen/dao/query/app_user.gen_test.go create mode 100644 gorm-gen/dao/query/douyin_ecpm_config.gen.go create mode 100644 gorm-gen/dao/query/douyin_ecpm_config.gen_test.go create mode 100644 gorm-gen/dao/query/game_score.gen.go create mode 100644 gorm-gen/dao/query/game_score.gen_test.go create mode 100644 gorm-gen/dao/query/gen.go create mode 100644 gorm-gen/dao/query/gen_test.go create mode 100644 gorm-gen/query/app_account.gen.go create mode 100644 gorm-gen/query/app_user.gen.go create mode 100644 gorm-gen/query/douyin_ecpm_config.gen.go create mode 100644 gorm-gen/query/game_score.gen.go create mode 100644 gorm-gen/query/gen.go diff --git a/gorm-gen/dao/model/app_account.gen.go b/gorm-gen/dao/model/app_account.gen.go new file mode 100644 index 0000000..72e01ba --- /dev/null +++ b/gorm-gen/dao/model/app_account.gen.go @@ -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 +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 +} diff --git a/gorm-gen/dao/model/app_user.gen.go b/gorm-gen/dao/model/app_user.gen.go new file mode 100644 index 0000000..2b47a00 --- /dev/null +++ b/gorm-gen/dao/model/app_user.gen.go @@ -0,0 +1,29 @@ +// 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 +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 + 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 +} diff --git a/gorm-gen/dao/model/douyin_ecpm_config.gen.go b/gorm-gen/dao/model/douyin_ecpm_config.gen.go new file mode 100644 index 0000000..c4a2248 --- /dev/null +++ b/gorm-gen/dao/model/douyin_ecpm_config.gen.go @@ -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 +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 +} diff --git a/gorm-gen/dao/model/game_score.gen.go b/gorm-gen/dao/model/game_score.gen.go new file mode 100644 index 0000000..efa5626 --- /dev/null +++ b/gorm-gen/dao/model/game_score.gen.go @@ -0,0 +1,21 @@ +// 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 TableNameGameScore = "game_score" + +// GameScore mapped from table +type GameScore struct { + ID uint64 `gorm:"column:id;type:bigint unsigned;primaryKey;autoIncrement:true" json:"id"` + AppAccount uint32 `gorm:"column:app_account;type:int unsigned;not null;uniqueIndex:rank_list,priority:1;comment:小游戏id" json:"app_account"` // 小游戏id + AppUserID uint64 `gorm:"column:app_user_id;type:bigint unsigned;not null;uniqueIndex:rank_list,priority:3;index:user_id,priority:1;comment:用户id" json:"app_user_id"` // 用户id + Score uint32 `gorm:"column:score;type:int unsigned;not null;comment:得分" json:"score"` // 得分 + T uint32 `gorm:"column:t;type:tinyint unsigned;not null;uniqueIndex:rank_list,priority:2;comment:得分类型(区分相同小游戏中的不同模式得分)" json:"t"` // 得分类型(区分相同小游戏中的不同模式得分) +} + +// TableName GameScore's table name +func (*GameScore) TableName() string { + return TableNameGameScore +} diff --git a/gorm-gen/dao/query/app_account.gen.go b/gorm-gen/dao/query/app_account.gen.go new file mode 100644 index 0000000..87841f5 --- /dev/null +++ b/gorm-gen/dao/query/app_account.gen.go @@ -0,0 +1,349 @@ +// Code generated by gorm.io/gen. DO NOT EDIT. +// Code generated by gorm.io/gen. DO NOT EDIT. +// Code generated by gorm.io/gen. DO NOT EDIT. + +package query + +import ( + "context" + + "gorm.io/gorm" + "gorm.io/gorm/clause" + "gorm.io/gorm/schema" + + "gorm.io/gen" + "gorm.io/gen/field" + + "gorm.io/plugin/dbresolver" + + "gitea.youtukeji.com.cn/xiabin/youtu_server/gorm-gen/dao/model" +) + +func 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 appAccountDo + + ALL field.Asterisk + ID field.Uint32 + Type field.Uint32 // 类型(0:抖音,1:微信) + 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) WithContext(ctx context.Context) *appAccountDo { + return a.appAccountDo.WithContext(ctx) +} + +func (a appAccount) TableName() string { return a.appAccountDo.TableName() } + +func (a appAccount) Alias() string { return a.appAccountDo.Alias() } + +func (a appAccount) Columns(cols ...field.Expr) gen.Columns { return a.appAccountDo.Columns(cols...) } + +func (a *appAccount) GetFieldByName(fieldName string) (field.OrderExpr, bool) { + _f, ok := a.fieldMap[fieldName] + if !ok || _f == nil { + 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 } + +func (a appAccountDo) Debug() *appAccountDo { + return a.withDO(a.DO.Debug()) +} + +func (a appAccountDo) WithContext(ctx context.Context) *appAccountDo { + return a.withDO(a.DO.WithContext(ctx)) +} + +func (a appAccountDo) ReadDB() *appAccountDo { + return a.Clauses(dbresolver.Read) +} + +func (a appAccountDo) WriteDB() *appAccountDo { + return a.Clauses(dbresolver.Write) +} + +func (a appAccountDo) Session(config *gorm.Session) *appAccountDo { + return a.withDO(a.DO.Session(config)) +} + +func (a appAccountDo) Clauses(conds ...clause.Expression) *appAccountDo { + return a.withDO(a.DO.Clauses(conds...)) +} + +func (a appAccountDo) Returning(value interface{}, columns ...string) *appAccountDo { + return a.withDO(a.DO.Returning(value, columns...)) +} + +func (a appAccountDo) Not(conds ...gen.Condition) *appAccountDo { + return a.withDO(a.DO.Not(conds...)) +} + +func (a appAccountDo) Or(conds ...gen.Condition) *appAccountDo { + return a.withDO(a.DO.Or(conds...)) +} + +func (a appAccountDo) Select(conds ...field.Expr) *appAccountDo { + return a.withDO(a.DO.Select(conds...)) +} + +func (a appAccountDo) Where(conds ...gen.Condition) *appAccountDo { + return a.withDO(a.DO.Where(conds...)) +} + +func (a appAccountDo) Order(conds ...field.Expr) *appAccountDo { + return a.withDO(a.DO.Order(conds...)) +} + +func (a appAccountDo) Distinct(cols ...field.Expr) *appAccountDo { + return a.withDO(a.DO.Distinct(cols...)) +} + +func (a appAccountDo) Omit(cols ...field.Expr) *appAccountDo { + return a.withDO(a.DO.Omit(cols...)) +} + +func (a appAccountDo) Join(table schema.Tabler, on ...field.Expr) *appAccountDo { + return a.withDO(a.DO.Join(table, on...)) +} + +func (a appAccountDo) LeftJoin(table schema.Tabler, on ...field.Expr) *appAccountDo { + return a.withDO(a.DO.LeftJoin(table, on...)) +} + +func (a appAccountDo) RightJoin(table schema.Tabler, on ...field.Expr) *appAccountDo { + return a.withDO(a.DO.RightJoin(table, on...)) +} + +func (a appAccountDo) Group(cols ...field.Expr) *appAccountDo { + return a.withDO(a.DO.Group(cols...)) +} + +func (a appAccountDo) Having(conds ...gen.Condition) *appAccountDo { + return a.withDO(a.DO.Having(conds...)) +} + +func (a appAccountDo) Limit(limit int) *appAccountDo { + return a.withDO(a.DO.Limit(limit)) +} + +func (a appAccountDo) Offset(offset int) *appAccountDo { + return a.withDO(a.DO.Offset(offset)) +} + +func (a appAccountDo) Scopes(funcs ...func(gen.Dao) gen.Dao) *appAccountDo { + return a.withDO(a.DO.Scopes(funcs...)) +} + +func (a appAccountDo) Unscoped() *appAccountDo { + 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) *appAccountDo { + return a.withDO(a.DO.Attrs(attrs...)) +} + +func (a appAccountDo) Assign(attrs ...field.AssignExpr) *appAccountDo { + return a.withDO(a.DO.Assign(attrs...)) +} + +func (a appAccountDo) Joins(fields ...field.RelationField) *appAccountDo { + for _, _f := range fields { + a = *a.withDO(a.DO.Joins(_f)) + } + return &a +} + +func (a appAccountDo) Preload(fields ...field.RelationField) *appAccountDo { + for _, _f := range fields { + a = *a.withDO(a.DO.Preload(_f)) + } + return &a +} + +func (a appAccountDo) FirstOrInit() (*model.AppAccount, error) { + if result, err := a.DO.FirstOrInit(); err != nil { + return nil, err + } else { + return result.(*model.AppAccount), nil + } +} + +func (a appAccountDo) FirstOrCreate() (*model.AppAccount, error) { + if result, err := a.DO.FirstOrCreate(); err != nil { + return nil, err + } else { + return result.(*model.AppAccount), nil + } +} + +func (a appAccountDo) FindByPage(offset int, limit int) (result []*model.AppAccount, count int64, err error) { + result, err = a.Offset(offset).Limit(limit).Find() + if err != nil { + return + } + + if size := len(result); 0 < limit && 0 < size && size < limit { + count = int64(size + offset) + return + } + + count, err = a.Offset(-1).Limit(-1).Count() + return +} + +func (a appAccountDo) ScanByPage(result interface{}, offset int, limit int) (count int64, err error) { + count, err = a.Count() + if err != nil { + return + } + + err = a.Offset(offset).Limit(limit).Scan(result) + return +} + +func (a appAccountDo) Scan(result interface{}) (err error) { + return a.DO.Scan(result) +} + +func (a appAccountDo) Delete(models ...*model.AppAccount) (result gen.ResultInfo, err error) { + return a.DO.Delete(models) +} + +func (a *appAccountDo) withDO(do gen.Dao) *appAccountDo { + a.DO = *do.(*gen.DO) + return a +} diff --git a/gorm-gen/dao/query/app_account.gen_test.go b/gorm-gen/dao/query/app_account.gen_test.go new file mode 100644 index 0000000..9e32386 --- /dev/null +++ b/gorm-gen/dao/query/app_account.gen_test.go @@ -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_server/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 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 fail:", err) + } + + err = _do.Save(&model.AppAccount{}) + if err != nil { + t.Error("create item in table fail:", err) + } + + err = _do.CreateInBatches([]*model.AppAccount{{}, {}}, 10) + if err != nil { + t.Error("create item in table fail:", err) + } + + _, err = _do.Select(appAccount.ALL).Take() + if err != nil { + t.Error("Take() on table fail:", err) + } + + _, err = _do.First() + if err != nil { + t.Error("First() on table fail:", err) + } + + _, err = _do.Last() + if err != nil { + t.Error("First() on table 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 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 fail:", err) + } + + _, err = _do.Select(appAccount.ALL).Where(primaryKey.IsNotNull()).Order(primaryKey.Desc()).Find() + if err != nil { + t.Error("Find() on table fail:", err) + } + + _, err = _do.Distinct(primaryKey).Take() + if err != nil { + t.Error("select Distinct() on table fail:", err) + } + + _, err = _do.Select(appAccount.ALL).Omit(primaryKey).Take() + if err != nil { + t.Error("Omit() on table fail:", err) + } + + _, err = _do.Group(primaryKey).Find() + if err != nil { + t.Error("Group() on table 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 fail:", err) + } + + _, _, err = _do.FindByPage(0, 1) + if err != nil { + t.Error("FindByPage() on table fail:", err) + } + + _, err = _do.ScanByPage(&model.AppAccount{}, 0, 1) + if err != nil { + t.Error("ScanByPage() on table fail:", err) + } + + _, err = _do.Attrs(primaryKey).Assign(primaryKey).FirstOrInit() + if err != nil { + t.Error("FirstOrInit() on table fail:", err) + } + + _, err = _do.Attrs(primaryKey).Assign(primaryKey).FirstOrCreate() + if err != nil { + t.Error("FirstOrCreate() on table 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 fail:", err) + } + + err = _do.LeftJoin(&_a, primaryKey.EqCol(_aPK)).Scan(map[string]interface{}{}) + if err != nil { + t.Error("LeftJoin() on table fail:", err) + } + + _, err = _do.Not().Or().Clauses().Take() + if err != nil { + t.Error("Not/Or/Clauses on table fail:", err) + } +} diff --git a/gorm-gen/dao/query/app_user.gen.go b/gorm-gen/dao/query/app_user.gen.go new file mode 100644 index 0000000..477a314 --- /dev/null +++ b/gorm-gen/dao/query/app_user.gen.go @@ -0,0 +1,359 @@ +// Code generated by gorm.io/gen. DO NOT EDIT. +// Code generated by gorm.io/gen. DO NOT EDIT. +// Code generated by gorm.io/gen. DO NOT EDIT. + +package query + +import ( + "context" + + "gorm.io/gorm" + "gorm.io/gorm/clause" + "gorm.io/gorm/schema" + + "gorm.io/gen" + "gorm.io/gen/field" + + "gorm.io/plugin/dbresolver" + + "gitea.youtukeji.com.cn/xiabin/youtu_server/gorm-gen/dao/model" +) + +func newAppUser(db *gorm.DB, opts ...gen.DOOption) appUser { + _appUser := appUser{} + + _appUser.appUserDo.UseDB(db, opts...) + _appUser.appUserDo.UseModel(&model.AppUser{}) + + tableName := _appUser.appUserDo.TableName() + _appUser.ALL = field.NewAsterisk(tableName) + _appUser.ID = field.NewUint64(tableName, "id") + _appUser.AppAccountID = field.NewUint32(tableName, "app_account_id") + _appUser.Openid = field.NewString(tableName, "openid") + _appUser.Unionid = field.NewString(tableName, "unionid") + _appUser.Nickname = field.NewString(tableName, "nickname") + _appUser.Avatar = field.NewString(tableName, "avatar") + _appUser.AnonymousOpenid = field.NewString(tableName, "anonymous_openid") + _appUser.CreatedAt = field.NewTime(tableName, "created_at") + _appUser.UpdatedAt = field.NewTime(tableName, "updated_at") + + _appUser.fillFieldMap() + + return _appUser +} + +type appUser struct { + appUserDo appUserDo + + ALL field.Asterisk + ID field.Uint64 + AppAccountID field.Uint32 // app_account表外键 + Openid field.String + Unionid field.String + Nickname field.String // 昵称 + Avatar field.String // 头像 + AnonymousOpenid field.String // 匿名openid + 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) WithContext(ctx context.Context) *appUserDo { return a.appUserDo.WithContext(ctx) } + +func (a appUser) TableName() string { return a.appUserDo.TableName() } + +func (a appUser) Alias() string { return a.appUserDo.Alias() } + +func (a appUser) Columns(cols ...field.Expr) gen.Columns { return a.appUserDo.Columns(cols...) } + +func (a *appUser) GetFieldByName(fieldName string) (field.OrderExpr, bool) { + _f, ok := a.fieldMap[fieldName] + if !ok || _f == nil { + 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 } + +func (a appUserDo) Debug() *appUserDo { + return a.withDO(a.DO.Debug()) +} + +func (a appUserDo) WithContext(ctx context.Context) *appUserDo { + return a.withDO(a.DO.WithContext(ctx)) +} + +func (a appUserDo) ReadDB() *appUserDo { + return a.Clauses(dbresolver.Read) +} + +func (a appUserDo) WriteDB() *appUserDo { + return a.Clauses(dbresolver.Write) +} + +func (a appUserDo) Session(config *gorm.Session) *appUserDo { + return a.withDO(a.DO.Session(config)) +} + +func (a appUserDo) Clauses(conds ...clause.Expression) *appUserDo { + return a.withDO(a.DO.Clauses(conds...)) +} + +func (a appUserDo) Returning(value interface{}, columns ...string) *appUserDo { + return a.withDO(a.DO.Returning(value, columns...)) +} + +func (a appUserDo) Not(conds ...gen.Condition) *appUserDo { + return a.withDO(a.DO.Not(conds...)) +} + +func (a appUserDo) Or(conds ...gen.Condition) *appUserDo { + return a.withDO(a.DO.Or(conds...)) +} + +func (a appUserDo) Select(conds ...field.Expr) *appUserDo { + return a.withDO(a.DO.Select(conds...)) +} + +func (a appUserDo) Where(conds ...gen.Condition) *appUserDo { + return a.withDO(a.DO.Where(conds...)) +} + +func (a appUserDo) Order(conds ...field.Expr) *appUserDo { + return a.withDO(a.DO.Order(conds...)) +} + +func (a appUserDo) Distinct(cols ...field.Expr) *appUserDo { + return a.withDO(a.DO.Distinct(cols...)) +} + +func (a appUserDo) Omit(cols ...field.Expr) *appUserDo { + return a.withDO(a.DO.Omit(cols...)) +} + +func (a appUserDo) Join(table schema.Tabler, on ...field.Expr) *appUserDo { + return a.withDO(a.DO.Join(table, on...)) +} + +func (a appUserDo) LeftJoin(table schema.Tabler, on ...field.Expr) *appUserDo { + return a.withDO(a.DO.LeftJoin(table, on...)) +} + +func (a appUserDo) RightJoin(table schema.Tabler, on ...field.Expr) *appUserDo { + return a.withDO(a.DO.RightJoin(table, on...)) +} + +func (a appUserDo) Group(cols ...field.Expr) *appUserDo { + return a.withDO(a.DO.Group(cols...)) +} + +func (a appUserDo) Having(conds ...gen.Condition) *appUserDo { + return a.withDO(a.DO.Having(conds...)) +} + +func (a appUserDo) Limit(limit int) *appUserDo { + return a.withDO(a.DO.Limit(limit)) +} + +func (a appUserDo) Offset(offset int) *appUserDo { + return a.withDO(a.DO.Offset(offset)) +} + +func (a appUserDo) Scopes(funcs ...func(gen.Dao) gen.Dao) *appUserDo { + return a.withDO(a.DO.Scopes(funcs...)) +} + +func (a appUserDo) Unscoped() *appUserDo { + 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) *appUserDo { + return a.withDO(a.DO.Attrs(attrs...)) +} + +func (a appUserDo) Assign(attrs ...field.AssignExpr) *appUserDo { + return a.withDO(a.DO.Assign(attrs...)) +} + +func (a appUserDo) Joins(fields ...field.RelationField) *appUserDo { + for _, _f := range fields { + a = *a.withDO(a.DO.Joins(_f)) + } + return &a +} + +func (a appUserDo) Preload(fields ...field.RelationField) *appUserDo { + for _, _f := range fields { + a = *a.withDO(a.DO.Preload(_f)) + } + return &a +} + +func (a appUserDo) FirstOrInit() (*model.AppUser, error) { + if result, err := a.DO.FirstOrInit(); err != nil { + return nil, err + } else { + return result.(*model.AppUser), nil + } +} + +func (a appUserDo) FirstOrCreate() (*model.AppUser, error) { + if result, err := a.DO.FirstOrCreate(); err != nil { + return nil, err + } else { + return result.(*model.AppUser), nil + } +} + +func (a appUserDo) FindByPage(offset int, limit int) (result []*model.AppUser, count int64, err error) { + result, err = a.Offset(offset).Limit(limit).Find() + if err != nil { + return + } + + if size := len(result); 0 < limit && 0 < size && size < limit { + count = int64(size + offset) + return + } + + count, err = a.Offset(-1).Limit(-1).Count() + return +} + +func (a appUserDo) ScanByPage(result interface{}, offset int, limit int) (count int64, err error) { + count, err = a.Count() + if err != nil { + return + } + + err = a.Offset(offset).Limit(limit).Scan(result) + return +} + +func (a appUserDo) Scan(result interface{}) (err error) { + return a.DO.Scan(result) +} + +func (a appUserDo) Delete(models ...*model.AppUser) (result gen.ResultInfo, err error) { + return a.DO.Delete(models) +} + +func (a *appUserDo) withDO(do gen.Dao) *appUserDo { + a.DO = *do.(*gen.DO) + return a +} diff --git a/gorm-gen/dao/query/app_user.gen_test.go b/gorm-gen/dao/query/app_user.gen_test.go new file mode 100644 index 0000000..507055c --- /dev/null +++ b/gorm-gen/dao/query/app_user.gen_test.go @@ -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_server/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 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 fail:", err) + } + + err = _do.Save(&model.AppUser{}) + if err != nil { + t.Error("create item in table fail:", err) + } + + err = _do.CreateInBatches([]*model.AppUser{{}, {}}, 10) + if err != nil { + t.Error("create item in table fail:", err) + } + + _, err = _do.Select(appUser.ALL).Take() + if err != nil { + t.Error("Take() on table fail:", err) + } + + _, err = _do.First() + if err != nil { + t.Error("First() on table fail:", err) + } + + _, err = _do.Last() + if err != nil { + t.Error("First() on table 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 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 fail:", err) + } + + _, err = _do.Select(appUser.ALL).Where(primaryKey.IsNotNull()).Order(primaryKey.Desc()).Find() + if err != nil { + t.Error("Find() on table fail:", err) + } + + _, err = _do.Distinct(primaryKey).Take() + if err != nil { + t.Error("select Distinct() on table fail:", err) + } + + _, err = _do.Select(appUser.ALL).Omit(primaryKey).Take() + if err != nil { + t.Error("Omit() on table fail:", err) + } + + _, err = _do.Group(primaryKey).Find() + if err != nil { + t.Error("Group() on table 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 fail:", err) + } + + _, _, err = _do.FindByPage(0, 1) + if err != nil { + t.Error("FindByPage() on table fail:", err) + } + + _, err = _do.ScanByPage(&model.AppUser{}, 0, 1) + if err != nil { + t.Error("ScanByPage() on table fail:", err) + } + + _, err = _do.Attrs(primaryKey).Assign(primaryKey).FirstOrInit() + if err != nil { + t.Error("FirstOrInit() on table fail:", err) + } + + _, err = _do.Attrs(primaryKey).Assign(primaryKey).FirstOrCreate() + if err != nil { + t.Error("FirstOrCreate() on table 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 fail:", err) + } + + err = _do.LeftJoin(&_a, primaryKey.EqCol(_aPK)).Scan(map[string]interface{}{}) + if err != nil { + t.Error("LeftJoin() on table fail:", err) + } + + _, err = _do.Not().Or().Clauses().Take() + if err != nil { + t.Error("Not/Or/Clauses on table fail:", err) + } +} diff --git a/gorm-gen/dao/query/douyin_ecpm_config.gen.go b/gorm-gen/dao/query/douyin_ecpm_config.gen.go new file mode 100644 index 0000000..b23e00e --- /dev/null +++ b/gorm-gen/dao/query/douyin_ecpm_config.gen.go @@ -0,0 +1,343 @@ +// Code generated by gorm.io/gen. DO NOT EDIT. +// Code generated by gorm.io/gen. DO NOT EDIT. +// Code generated by gorm.io/gen. DO NOT EDIT. + +package query + +import ( + "context" + + "gorm.io/gorm" + "gorm.io/gorm/clause" + "gorm.io/gorm/schema" + + "gorm.io/gen" + "gorm.io/gen/field" + + "gorm.io/plugin/dbresolver" + + "gitea.youtukeji.com.cn/xiabin/youtu_server/gorm-gen/dao/model" +) + +func newDouyinEcpmConfig(db *gorm.DB, opts ...gen.DOOption) douyinEcpmConfig { + _douyinEcpmConfig := douyinEcpmConfig{} + + _douyinEcpmConfig.douyinEcpmConfigDo.UseDB(db, opts...) + _douyinEcpmConfig.douyinEcpmConfigDo.UseModel(&model.DouyinEcpmConfig{}) + + tableName := _douyinEcpmConfig.douyinEcpmConfigDo.TableName() + _douyinEcpmConfig.ALL = field.NewAsterisk(tableName) + _douyinEcpmConfig.ID = field.NewUint32(tableName, "id") + _douyinEcpmConfig.AppAccountID = field.NewUint32(tableName, "app_account_id") + _douyinEcpmConfig.EcpmValue = field.NewUint32(tableName, "ecpm_value") + _douyinEcpmConfig.EcpmView = field.NewUint32(tableName, "ecpm_view") + + _douyinEcpmConfig.fillFieldMap() + + return _douyinEcpmConfig +} + +type douyinEcpmConfig struct { + douyinEcpmConfigDo 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) WithContext(ctx context.Context) *douyinEcpmConfigDo { + return d.douyinEcpmConfigDo.WithContext(ctx) +} + +func (d douyinEcpmConfig) TableName() string { return d.douyinEcpmConfigDo.TableName() } + +func (d douyinEcpmConfig) Alias() string { return d.douyinEcpmConfigDo.Alias() } + +func (d douyinEcpmConfig) Columns(cols ...field.Expr) gen.Columns { + return d.douyinEcpmConfigDo.Columns(cols...) +} + +func (d *douyinEcpmConfig) GetFieldByName(fieldName string) (field.OrderExpr, bool) { + _f, ok := d.fieldMap[fieldName] + if !ok || _f == nil { + 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 } + +func (d douyinEcpmConfigDo) Debug() *douyinEcpmConfigDo { + return d.withDO(d.DO.Debug()) +} + +func (d douyinEcpmConfigDo) WithContext(ctx context.Context) *douyinEcpmConfigDo { + return d.withDO(d.DO.WithContext(ctx)) +} + +func (d douyinEcpmConfigDo) ReadDB() *douyinEcpmConfigDo { + return d.Clauses(dbresolver.Read) +} + +func (d douyinEcpmConfigDo) WriteDB() *douyinEcpmConfigDo { + return d.Clauses(dbresolver.Write) +} + +func (d douyinEcpmConfigDo) Session(config *gorm.Session) *douyinEcpmConfigDo { + return d.withDO(d.DO.Session(config)) +} + +func (d douyinEcpmConfigDo) Clauses(conds ...clause.Expression) *douyinEcpmConfigDo { + return d.withDO(d.DO.Clauses(conds...)) +} + +func (d douyinEcpmConfigDo) Returning(value interface{}, columns ...string) *douyinEcpmConfigDo { + return d.withDO(d.DO.Returning(value, columns...)) +} + +func (d douyinEcpmConfigDo) Not(conds ...gen.Condition) *douyinEcpmConfigDo { + return d.withDO(d.DO.Not(conds...)) +} + +func (d douyinEcpmConfigDo) Or(conds ...gen.Condition) *douyinEcpmConfigDo { + return d.withDO(d.DO.Or(conds...)) +} + +func (d douyinEcpmConfigDo) Select(conds ...field.Expr) *douyinEcpmConfigDo { + return d.withDO(d.DO.Select(conds...)) +} + +func (d douyinEcpmConfigDo) Where(conds ...gen.Condition) *douyinEcpmConfigDo { + return d.withDO(d.DO.Where(conds...)) +} + +func (d douyinEcpmConfigDo) Order(conds ...field.Expr) *douyinEcpmConfigDo { + return d.withDO(d.DO.Order(conds...)) +} + +func (d douyinEcpmConfigDo) Distinct(cols ...field.Expr) *douyinEcpmConfigDo { + return d.withDO(d.DO.Distinct(cols...)) +} + +func (d douyinEcpmConfigDo) Omit(cols ...field.Expr) *douyinEcpmConfigDo { + return d.withDO(d.DO.Omit(cols...)) +} + +func (d douyinEcpmConfigDo) Join(table schema.Tabler, on ...field.Expr) *douyinEcpmConfigDo { + return d.withDO(d.DO.Join(table, on...)) +} + +func (d douyinEcpmConfigDo) LeftJoin(table schema.Tabler, on ...field.Expr) *douyinEcpmConfigDo { + return d.withDO(d.DO.LeftJoin(table, on...)) +} + +func (d douyinEcpmConfigDo) RightJoin(table schema.Tabler, on ...field.Expr) *douyinEcpmConfigDo { + return d.withDO(d.DO.RightJoin(table, on...)) +} + +func (d douyinEcpmConfigDo) Group(cols ...field.Expr) *douyinEcpmConfigDo { + return d.withDO(d.DO.Group(cols...)) +} + +func (d douyinEcpmConfigDo) Having(conds ...gen.Condition) *douyinEcpmConfigDo { + return d.withDO(d.DO.Having(conds...)) +} + +func (d douyinEcpmConfigDo) Limit(limit int) *douyinEcpmConfigDo { + return d.withDO(d.DO.Limit(limit)) +} + +func (d douyinEcpmConfigDo) Offset(offset int) *douyinEcpmConfigDo { + return d.withDO(d.DO.Offset(offset)) +} + +func (d douyinEcpmConfigDo) Scopes(funcs ...func(gen.Dao) gen.Dao) *douyinEcpmConfigDo { + return d.withDO(d.DO.Scopes(funcs...)) +} + +func (d douyinEcpmConfigDo) Unscoped() *douyinEcpmConfigDo { + 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) *douyinEcpmConfigDo { + return d.withDO(d.DO.Attrs(attrs...)) +} + +func (d douyinEcpmConfigDo) Assign(attrs ...field.AssignExpr) *douyinEcpmConfigDo { + return d.withDO(d.DO.Assign(attrs...)) +} + +func (d douyinEcpmConfigDo) Joins(fields ...field.RelationField) *douyinEcpmConfigDo { + for _, _f := range fields { + d = *d.withDO(d.DO.Joins(_f)) + } + return &d +} + +func (d douyinEcpmConfigDo) Preload(fields ...field.RelationField) *douyinEcpmConfigDo { + for _, _f := range fields { + d = *d.withDO(d.DO.Preload(_f)) + } + return &d +} + +func (d douyinEcpmConfigDo) FirstOrInit() (*model.DouyinEcpmConfig, error) { + if result, err := d.DO.FirstOrInit(); err != nil { + return nil, err + } else { + return result.(*model.DouyinEcpmConfig), nil + } +} + +func (d douyinEcpmConfigDo) FirstOrCreate() (*model.DouyinEcpmConfig, error) { + if result, err := d.DO.FirstOrCreate(); err != nil { + return nil, err + } else { + return result.(*model.DouyinEcpmConfig), nil + } +} + +func (d douyinEcpmConfigDo) FindByPage(offset int, limit int) (result []*model.DouyinEcpmConfig, count int64, err error) { + result, err = d.Offset(offset).Limit(limit).Find() + if err != nil { + return + } + + if size := len(result); 0 < limit && 0 < size && size < limit { + count = int64(size + offset) + return + } + + count, err = d.Offset(-1).Limit(-1).Count() + return +} + +func (d douyinEcpmConfigDo) ScanByPage(result interface{}, offset int, limit int) (count int64, err error) { + count, err = d.Count() + if err != nil { + return + } + + err = d.Offset(offset).Limit(limit).Scan(result) + return +} + +func (d douyinEcpmConfigDo) Scan(result interface{}) (err error) { + return d.DO.Scan(result) +} + +func (d douyinEcpmConfigDo) Delete(models ...*model.DouyinEcpmConfig) (result gen.ResultInfo, err error) { + return d.DO.Delete(models) +} + +func (d *douyinEcpmConfigDo) withDO(do gen.Dao) *douyinEcpmConfigDo { + d.DO = *do.(*gen.DO) + return d +} diff --git a/gorm-gen/dao/query/douyin_ecpm_config.gen_test.go b/gorm-gen/dao/query/douyin_ecpm_config.gen_test.go new file mode 100644 index 0000000..e924fa1 --- /dev/null +++ b/gorm-gen/dao/query/douyin_ecpm_config.gen_test.go @@ -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_server/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 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 fail:", err) + } + + err = _do.Save(&model.DouyinEcpmConfig{}) + if err != nil { + t.Error("create item in table fail:", err) + } + + err = _do.CreateInBatches([]*model.DouyinEcpmConfig{{}, {}}, 10) + if err != nil { + t.Error("create item in table fail:", err) + } + + _, err = _do.Select(douyinEcpmConfig.ALL).Take() + if err != nil { + t.Error("Take() on table fail:", err) + } + + _, err = _do.First() + if err != nil { + t.Error("First() on table fail:", err) + } + + _, err = _do.Last() + if err != nil { + t.Error("First() on table 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 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 fail:", err) + } + + _, err = _do.Select(douyinEcpmConfig.ALL).Where(primaryKey.IsNotNull()).Order(primaryKey.Desc()).Find() + if err != nil { + t.Error("Find() on table fail:", err) + } + + _, err = _do.Distinct(primaryKey).Take() + if err != nil { + t.Error("select Distinct() on table fail:", err) + } + + _, err = _do.Select(douyinEcpmConfig.ALL).Omit(primaryKey).Take() + if err != nil { + t.Error("Omit() on table fail:", err) + } + + _, err = _do.Group(primaryKey).Find() + if err != nil { + t.Error("Group() on table 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 fail:", err) + } + + _, _, err = _do.FindByPage(0, 1) + if err != nil { + t.Error("FindByPage() on table fail:", err) + } + + _, err = _do.ScanByPage(&model.DouyinEcpmConfig{}, 0, 1) + if err != nil { + t.Error("ScanByPage() on table fail:", err) + } + + _, err = _do.Attrs(primaryKey).Assign(primaryKey).FirstOrInit() + if err != nil { + t.Error("FirstOrInit() on table fail:", err) + } + + _, err = _do.Attrs(primaryKey).Assign(primaryKey).FirstOrCreate() + if err != nil { + t.Error("FirstOrCreate() on table 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 fail:", err) + } + + err = _do.LeftJoin(&_a, primaryKey.EqCol(_aPK)).Scan(map[string]interface{}{}) + if err != nil { + t.Error("LeftJoin() on table fail:", err) + } + + _, err = _do.Not().Or().Clauses().Take() + if err != nil { + t.Error("Not/Or/Clauses on table fail:", err) + } +} diff --git a/gorm-gen/dao/query/game_score.gen.go b/gorm-gen/dao/query/game_score.gen.go new file mode 100644 index 0000000..9a2c7a5 --- /dev/null +++ b/gorm-gen/dao/query/game_score.gen.go @@ -0,0 +1,345 @@ +// Code generated by gorm.io/gen. DO NOT EDIT. +// Code generated by gorm.io/gen. DO NOT EDIT. +// Code generated by gorm.io/gen. DO NOT EDIT. + +package query + +import ( + "context" + + "gorm.io/gorm" + "gorm.io/gorm/clause" + "gorm.io/gorm/schema" + + "gorm.io/gen" + "gorm.io/gen/field" + + "gorm.io/plugin/dbresolver" + + "gitea.youtukeji.com.cn/xiabin/youtu_server/gorm-gen/dao/model" +) + +func newGameScore(db *gorm.DB, opts ...gen.DOOption) gameScore { + _gameScore := gameScore{} + + _gameScore.gameScoreDo.UseDB(db, opts...) + _gameScore.gameScoreDo.UseModel(&model.GameScore{}) + + tableName := _gameScore.gameScoreDo.TableName() + _gameScore.ALL = field.NewAsterisk(tableName) + _gameScore.ID = field.NewUint64(tableName, "id") + _gameScore.AppAccount = field.NewUint32(tableName, "app_account") + _gameScore.AppUserID = field.NewUint64(tableName, "app_user_id") + _gameScore.Score = field.NewUint32(tableName, "score") + _gameScore.T = field.NewUint32(tableName, "t") + + _gameScore.fillFieldMap() + + return _gameScore +} + +type gameScore struct { + gameScoreDo gameScoreDo + + ALL field.Asterisk + ID field.Uint64 + AppAccount field.Uint32 // 小游戏id + AppUserID field.Uint64 // 用户id + Score field.Uint32 // 得分 + T field.Uint32 // 得分类型(区分相同小游戏中的不同模式得分) + + fieldMap map[string]field.Expr +} + +func (g gameScore) Table(newTableName string) *gameScore { + g.gameScoreDo.UseTable(newTableName) + return g.updateTableName(newTableName) +} + +func (g gameScore) As(alias string) *gameScore { + g.gameScoreDo.DO = *(g.gameScoreDo.As(alias).(*gen.DO)) + return g.updateTableName(alias) +} + +func (g *gameScore) updateTableName(table string) *gameScore { + g.ALL = field.NewAsterisk(table) + g.ID = field.NewUint64(table, "id") + g.AppAccount = field.NewUint32(table, "app_account") + g.AppUserID = field.NewUint64(table, "app_user_id") + g.Score = field.NewUint32(table, "score") + g.T = field.NewUint32(table, "t") + + g.fillFieldMap() + + return g +} + +func (g *gameScore) WithContext(ctx context.Context) *gameScoreDo { + return g.gameScoreDo.WithContext(ctx) +} + +func (g gameScore) TableName() string { return g.gameScoreDo.TableName() } + +func (g gameScore) Alias() string { return g.gameScoreDo.Alias() } + +func (g gameScore) Columns(cols ...field.Expr) gen.Columns { return g.gameScoreDo.Columns(cols...) } + +func (g *gameScore) GetFieldByName(fieldName string) (field.OrderExpr, bool) { + _f, ok := g.fieldMap[fieldName] + if !ok || _f == nil { + return nil, false + } + _oe, ok := _f.(field.OrderExpr) + return _oe, ok +} + +func (g *gameScore) fillFieldMap() { + g.fieldMap = make(map[string]field.Expr, 5) + g.fieldMap["id"] = g.ID + g.fieldMap["app_account"] = g.AppAccount + g.fieldMap["app_user_id"] = g.AppUserID + g.fieldMap["score"] = g.Score + g.fieldMap["t"] = g.T +} + +func (g gameScore) clone(db *gorm.DB) gameScore { + g.gameScoreDo.ReplaceConnPool(db.Statement.ConnPool) + return g +} + +func (g gameScore) replaceDB(db *gorm.DB) gameScore { + g.gameScoreDo.ReplaceDB(db) + return g +} + +type gameScoreDo struct{ gen.DO } + +func (g gameScoreDo) Debug() *gameScoreDo { + return g.withDO(g.DO.Debug()) +} + +func (g gameScoreDo) WithContext(ctx context.Context) *gameScoreDo { + return g.withDO(g.DO.WithContext(ctx)) +} + +func (g gameScoreDo) ReadDB() *gameScoreDo { + return g.Clauses(dbresolver.Read) +} + +func (g gameScoreDo) WriteDB() *gameScoreDo { + return g.Clauses(dbresolver.Write) +} + +func (g gameScoreDo) Session(config *gorm.Session) *gameScoreDo { + return g.withDO(g.DO.Session(config)) +} + +func (g gameScoreDo) Clauses(conds ...clause.Expression) *gameScoreDo { + return g.withDO(g.DO.Clauses(conds...)) +} + +func (g gameScoreDo) Returning(value interface{}, columns ...string) *gameScoreDo { + return g.withDO(g.DO.Returning(value, columns...)) +} + +func (g gameScoreDo) Not(conds ...gen.Condition) *gameScoreDo { + return g.withDO(g.DO.Not(conds...)) +} + +func (g gameScoreDo) Or(conds ...gen.Condition) *gameScoreDo { + return g.withDO(g.DO.Or(conds...)) +} + +func (g gameScoreDo) Select(conds ...field.Expr) *gameScoreDo { + return g.withDO(g.DO.Select(conds...)) +} + +func (g gameScoreDo) Where(conds ...gen.Condition) *gameScoreDo { + return g.withDO(g.DO.Where(conds...)) +} + +func (g gameScoreDo) Order(conds ...field.Expr) *gameScoreDo { + return g.withDO(g.DO.Order(conds...)) +} + +func (g gameScoreDo) Distinct(cols ...field.Expr) *gameScoreDo { + return g.withDO(g.DO.Distinct(cols...)) +} + +func (g gameScoreDo) Omit(cols ...field.Expr) *gameScoreDo { + return g.withDO(g.DO.Omit(cols...)) +} + +func (g gameScoreDo) Join(table schema.Tabler, on ...field.Expr) *gameScoreDo { + return g.withDO(g.DO.Join(table, on...)) +} + +func (g gameScoreDo) LeftJoin(table schema.Tabler, on ...field.Expr) *gameScoreDo { + return g.withDO(g.DO.LeftJoin(table, on...)) +} + +func (g gameScoreDo) RightJoin(table schema.Tabler, on ...field.Expr) *gameScoreDo { + return g.withDO(g.DO.RightJoin(table, on...)) +} + +func (g gameScoreDo) Group(cols ...field.Expr) *gameScoreDo { + return g.withDO(g.DO.Group(cols...)) +} + +func (g gameScoreDo) Having(conds ...gen.Condition) *gameScoreDo { + return g.withDO(g.DO.Having(conds...)) +} + +func (g gameScoreDo) Limit(limit int) *gameScoreDo { + return g.withDO(g.DO.Limit(limit)) +} + +func (g gameScoreDo) Offset(offset int) *gameScoreDo { + return g.withDO(g.DO.Offset(offset)) +} + +func (g gameScoreDo) Scopes(funcs ...func(gen.Dao) gen.Dao) *gameScoreDo { + return g.withDO(g.DO.Scopes(funcs...)) +} + +func (g gameScoreDo) Unscoped() *gameScoreDo { + 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) *gameScoreDo { + return g.withDO(g.DO.Attrs(attrs...)) +} + +func (g gameScoreDo) Assign(attrs ...field.AssignExpr) *gameScoreDo { + return g.withDO(g.DO.Assign(attrs...)) +} + +func (g gameScoreDo) Joins(fields ...field.RelationField) *gameScoreDo { + for _, _f := range fields { + g = *g.withDO(g.DO.Joins(_f)) + } + return &g +} + +func (g gameScoreDo) Preload(fields ...field.RelationField) *gameScoreDo { + for _, _f := range fields { + g = *g.withDO(g.DO.Preload(_f)) + } + return &g +} + +func (g gameScoreDo) FirstOrInit() (*model.GameScore, error) { + if result, err := g.DO.FirstOrInit(); err != nil { + return nil, err + } else { + return result.(*model.GameScore), nil + } +} + +func (g gameScoreDo) FirstOrCreate() (*model.GameScore, error) { + if result, err := g.DO.FirstOrCreate(); err != nil { + return nil, err + } else { + return result.(*model.GameScore), nil + } +} + +func (g gameScoreDo) FindByPage(offset int, limit int) (result []*model.GameScore, count int64, err error) { + result, err = g.Offset(offset).Limit(limit).Find() + if err != nil { + return + } + + if size := len(result); 0 < limit && 0 < size && size < limit { + count = int64(size + offset) + return + } + + count, err = g.Offset(-1).Limit(-1).Count() + return +} + +func (g gameScoreDo) ScanByPage(result interface{}, offset int, limit int) (count int64, err error) { + count, err = g.Count() + if err != nil { + return + } + + err = g.Offset(offset).Limit(limit).Scan(result) + return +} + +func (g gameScoreDo) Scan(result interface{}) (err error) { + return g.DO.Scan(result) +} + +func (g gameScoreDo) Delete(models ...*model.GameScore) (result gen.ResultInfo, err error) { + return g.DO.Delete(models) +} + +func (g *gameScoreDo) withDO(do gen.Dao) *gameScoreDo { + g.DO = *do.(*gen.DO) + return g +} diff --git a/gorm-gen/dao/query/game_score.gen_test.go b/gorm-gen/dao/query/game_score.gen_test.go new file mode 100644 index 0000000..468e6a1 --- /dev/null +++ b/gorm-gen/dao/query/game_score.gen_test.go @@ -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_server/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 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 fail:", err) + } + + err = _do.Save(&model.GameScore{}) + if err != nil { + t.Error("create item in table fail:", err) + } + + err = _do.CreateInBatches([]*model.GameScore{{}, {}}, 10) + if err != nil { + t.Error("create item in table fail:", err) + } + + _, err = _do.Select(gameScore.ALL).Take() + if err != nil { + t.Error("Take() on table fail:", err) + } + + _, err = _do.First() + if err != nil { + t.Error("First() on table fail:", err) + } + + _, err = _do.Last() + if err != nil { + t.Error("First() on table 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 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 fail:", err) + } + + _, err = _do.Select(gameScore.ALL).Where(primaryKey.IsNotNull()).Order(primaryKey.Desc()).Find() + if err != nil { + t.Error("Find() on table fail:", err) + } + + _, err = _do.Distinct(primaryKey).Take() + if err != nil { + t.Error("select Distinct() on table fail:", err) + } + + _, err = _do.Select(gameScore.ALL).Omit(primaryKey).Take() + if err != nil { + t.Error("Omit() on table fail:", err) + } + + _, err = _do.Group(primaryKey).Find() + if err != nil { + t.Error("Group() on table 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 fail:", err) + } + + _, _, err = _do.FindByPage(0, 1) + if err != nil { + t.Error("FindByPage() on table fail:", err) + } + + _, err = _do.ScanByPage(&model.GameScore{}, 0, 1) + if err != nil { + t.Error("ScanByPage() on table fail:", err) + } + + _, err = _do.Attrs(primaryKey).Assign(primaryKey).FirstOrInit() + if err != nil { + t.Error("FirstOrInit() on table fail:", err) + } + + _, err = _do.Attrs(primaryKey).Assign(primaryKey).FirstOrCreate() + if err != nil { + t.Error("FirstOrCreate() on table 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 fail:", err) + } + + err = _do.LeftJoin(&_a, primaryKey.EqCol(_aPK)).Scan(map[string]interface{}{}) + if err != nil { + t.Error("LeftJoin() on table fail:", err) + } + + _, err = _do.Not().Or().Clauses().Take() + if err != nil { + t.Error("Not/Or/Clauses on table fail:", err) + } +} diff --git a/gorm-gen/dao/query/gen.go b/gorm-gen/dao/query/gen.go new file mode 100644 index 0000000..92c75c7 --- /dev/null +++ b/gorm-gen/dao/query/gen.go @@ -0,0 +1,111 @@ +// 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" +) + +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 *appAccountDo + AppUser *appUserDo + DouyinEcpmConfig *douyinEcpmConfigDo + GameScore *gameScoreDo +} + +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 +} diff --git a/gorm-gen/dao/query/gen_test.go b/gorm-gen/dao/query/gen_test.go new file mode 100644 index 0000000..418a6f4 --- /dev/null +++ b/gorm-gen/dao/query/gen_test.go @@ -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) + } +} diff --git a/gorm-gen/query/app_account.gen.go b/gorm-gen/query/app_account.gen.go new file mode 100644 index 0000000..c523ce3 --- /dev/null +++ b/gorm-gen/query/app_account.gen.go @@ -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_server/gorm-gen/dao/model" +) + +func newAppAccount(db *gorm.DB, opts ...gen.DOOption) appAccount { + _appAccount := appAccount{} + + _appAccount.appAccountDo.UseDB(db, opts...) + _appAccount.appAccountDo.UseModel(&model.AppAccount{}) + + tableName := _appAccount.appAccountDo.TableName() + _appAccount.ALL = field.NewAsterisk(tableName) + _appAccount.ID = field.NewUint32(tableName, "id") + _appAccount.Type = field.NewUint32(tableName, "type") + _appAccount.AppID = field.NewString(tableName, "app_id") + _appAccount.Secret = field.NewString(tableName, "secret") + _appAccount.Remark = field.NewString(tableName, "remark") + _appAccount.DeletedAt = field.NewField(tableName, "deleted_at") + + _appAccount.fillFieldMap() + + return _appAccount +} + +type appAccount struct { + appAccountDo + + ALL field.Asterisk + ID field.Uint32 + Type field.Uint32 + AppID field.String + Secret field.String + Remark field.String + DeletedAt field.Field + + fieldMap map[string]field.Expr +} + +func (a appAccount) Table(newTableName string) *appAccount { + a.appAccountDo.UseTable(newTableName) + return a.updateTableName(newTableName) +} + +func (a appAccount) As(alias string) *appAccount { + a.appAccountDo.DO = *(a.appAccountDo.As(alias).(*gen.DO)) + return a.updateTableName(alias) +} + +func (a *appAccount) updateTableName(table string) *appAccount { + a.ALL = field.NewAsterisk(table) + a.ID = field.NewUint32(table, "id") + a.Type = field.NewUint32(table, "type") + a.AppID = field.NewString(table, "app_id") + a.Secret = field.NewString(table, "secret") + a.Remark = field.NewString(table, "remark") + a.DeletedAt = field.NewField(table, "deleted_at") + + a.fillFieldMap() + + return a +} + +func (a *appAccount) GetFieldByName(fieldName string) (field.OrderExpr, bool) { + _f, ok := a.fieldMap[fieldName] + if !ok || _f == nil { + return nil, false + } + _oe, ok := _f.(field.OrderExpr) + return _oe, ok +} + +func (a *appAccount) fillFieldMap() { + a.fieldMap = make(map[string]field.Expr, 6) + a.fieldMap["id"] = a.ID + a.fieldMap["type"] = a.Type + a.fieldMap["app_id"] = a.AppID + a.fieldMap["secret"] = a.Secret + a.fieldMap["remark"] = a.Remark + a.fieldMap["deleted_at"] = a.DeletedAt +} + +func (a appAccount) clone(db *gorm.DB) appAccount { + a.appAccountDo.ReplaceConnPool(db.Statement.ConnPool) + return a +} + +func (a appAccount) replaceDB(db *gorm.DB) appAccount { + a.appAccountDo.ReplaceDB(db) + return a +} + +type appAccountDo struct{ gen.DO } + +type IAppAccountDo interface { + gen.SubQuery + Debug() IAppAccountDo + WithContext(ctx context.Context) IAppAccountDo + WithResult(fc func(tx gen.Dao)) gen.ResultInfo + ReplaceDB(db *gorm.DB) + ReadDB() IAppAccountDo + WriteDB() IAppAccountDo + As(alias string) gen.Dao + Session(config *gorm.Session) IAppAccountDo + Columns(cols ...field.Expr) gen.Columns + Clauses(conds ...clause.Expression) IAppAccountDo + Not(conds ...gen.Condition) IAppAccountDo + Or(conds ...gen.Condition) IAppAccountDo + Select(conds ...field.Expr) IAppAccountDo + Where(conds ...gen.Condition) IAppAccountDo + Order(conds ...field.Expr) IAppAccountDo + Distinct(cols ...field.Expr) IAppAccountDo + Omit(cols ...field.Expr) IAppAccountDo + Join(table schema.Tabler, on ...field.Expr) IAppAccountDo + LeftJoin(table schema.Tabler, on ...field.Expr) IAppAccountDo + RightJoin(table schema.Tabler, on ...field.Expr) IAppAccountDo + Group(cols ...field.Expr) IAppAccountDo + Having(conds ...gen.Condition) IAppAccountDo + Limit(limit int) IAppAccountDo + Offset(offset int) IAppAccountDo + Count() (count int64, err error) + Scopes(funcs ...func(gen.Dao) gen.Dao) IAppAccountDo + Unscoped() IAppAccountDo + Create(values ...*model.AppAccount) error + CreateInBatches(values []*model.AppAccount, batchSize int) error + Save(values ...*model.AppAccount) error + First() (*model.AppAccount, error) + Take() (*model.AppAccount, error) + Last() (*model.AppAccount, error) + Find() ([]*model.AppAccount, error) + FindInBatch(batchSize int, fc func(tx gen.Dao, batch int) error) (results []*model.AppAccount, err error) + FindInBatches(result *[]*model.AppAccount, batchSize int, fc func(tx gen.Dao, batch int) error) error + Pluck(column field.Expr, dest interface{}) error + Delete(...*model.AppAccount) (info gen.ResultInfo, err error) + Update(column field.Expr, value interface{}) (info gen.ResultInfo, err error) + UpdateSimple(columns ...field.AssignExpr) (info gen.ResultInfo, err error) + Updates(value interface{}) (info gen.ResultInfo, err error) + UpdateColumn(column field.Expr, value interface{}) (info gen.ResultInfo, err error) + UpdateColumnSimple(columns ...field.AssignExpr) (info gen.ResultInfo, err error) + UpdateColumns(value interface{}) (info gen.ResultInfo, err error) + UpdateFrom(q gen.SubQuery) gen.Dao + Attrs(attrs ...field.AssignExpr) IAppAccountDo + Assign(attrs ...field.AssignExpr) IAppAccountDo + Joins(fields ...field.RelationField) IAppAccountDo + Preload(fields ...field.RelationField) IAppAccountDo + FirstOrInit() (*model.AppAccount, error) + FirstOrCreate() (*model.AppAccount, error) + FindByPage(offset int, limit int) (result []*model.AppAccount, count int64, err error) + ScanByPage(result interface{}, offset int, limit int) (count int64, err error) + Scan(result interface{}) (err error) + Returning(value interface{}, columns ...string) IAppAccountDo + UnderlyingDB() *gorm.DB + schema.Tabler + + GetAppConfig() (result []*model.AppAccount, err error) +} + +// GetAppConfig 获取所有小游戏配置 +// +// select `app_id`,`secret`,`ecpm_value`,`ecpm_view`,`type` from `app_account` left join douyin_ecpm_config on app_account.id = douyin_ecpm_config.app_account_id +func (a appAccountDo) GetAppConfig() (result []*model.AppAccount, err error) { + var generateSQL strings.Builder + generateSQL.WriteString("select `app_id`,`secret`,`ecpm_value`,`ecpm_view`,`type` from `app_account` left join douyin_ecpm_config on app_account.id = douyin_ecpm_config.app_account_id ") + + var executeSQL *gorm.DB + executeSQL = a.UnderlyingDB().Raw(generateSQL.String()).Find(&result) // ignore_security_alert + err = executeSQL.Error + + return +} + +func (a appAccountDo) Debug() IAppAccountDo { + return a.withDO(a.DO.Debug()) +} + +func (a appAccountDo) WithContext(ctx context.Context) IAppAccountDo { + return a.withDO(a.DO.WithContext(ctx)) +} + +func (a appAccountDo) ReadDB() IAppAccountDo { + return a.Clauses(dbresolver.Read) +} + +func (a appAccountDo) WriteDB() IAppAccountDo { + return a.Clauses(dbresolver.Write) +} + +func (a appAccountDo) Session(config *gorm.Session) IAppAccountDo { + return a.withDO(a.DO.Session(config)) +} + +func (a appAccountDo) Clauses(conds ...clause.Expression) IAppAccountDo { + return a.withDO(a.DO.Clauses(conds...)) +} + +func (a appAccountDo) Returning(value interface{}, columns ...string) IAppAccountDo { + return a.withDO(a.DO.Returning(value, columns...)) +} + +func (a appAccountDo) Not(conds ...gen.Condition) IAppAccountDo { + return a.withDO(a.DO.Not(conds...)) +} + +func (a appAccountDo) Or(conds ...gen.Condition) IAppAccountDo { + return a.withDO(a.DO.Or(conds...)) +} + +func (a appAccountDo) Select(conds ...field.Expr) IAppAccountDo { + return a.withDO(a.DO.Select(conds...)) +} + +func (a appAccountDo) Where(conds ...gen.Condition) IAppAccountDo { + return a.withDO(a.DO.Where(conds...)) +} + +func (a appAccountDo) Order(conds ...field.Expr) IAppAccountDo { + return a.withDO(a.DO.Order(conds...)) +} + +func (a appAccountDo) Distinct(cols ...field.Expr) IAppAccountDo { + return a.withDO(a.DO.Distinct(cols...)) +} + +func (a appAccountDo) Omit(cols ...field.Expr) IAppAccountDo { + return a.withDO(a.DO.Omit(cols...)) +} + +func (a appAccountDo) Join(table schema.Tabler, on ...field.Expr) IAppAccountDo { + return a.withDO(a.DO.Join(table, on...)) +} + +func (a appAccountDo) LeftJoin(table schema.Tabler, on ...field.Expr) IAppAccountDo { + return a.withDO(a.DO.LeftJoin(table, on...)) +} + +func (a appAccountDo) RightJoin(table schema.Tabler, on ...field.Expr) IAppAccountDo { + return a.withDO(a.DO.RightJoin(table, on...)) +} + +func (a appAccountDo) Group(cols ...field.Expr) IAppAccountDo { + return a.withDO(a.DO.Group(cols...)) +} + +func (a appAccountDo) Having(conds ...gen.Condition) IAppAccountDo { + return a.withDO(a.DO.Having(conds...)) +} + +func (a appAccountDo) Limit(limit int) IAppAccountDo { + return a.withDO(a.DO.Limit(limit)) +} + +func (a appAccountDo) Offset(offset int) IAppAccountDo { + return a.withDO(a.DO.Offset(offset)) +} + +func (a appAccountDo) Scopes(funcs ...func(gen.Dao) gen.Dao) IAppAccountDo { + return a.withDO(a.DO.Scopes(funcs...)) +} + +func (a appAccountDo) Unscoped() IAppAccountDo { + return a.withDO(a.DO.Unscoped()) +} + +func (a appAccountDo) Create(values ...*model.AppAccount) error { + if len(values) == 0 { + return nil + } + return a.DO.Create(values) +} + +func (a appAccountDo) CreateInBatches(values []*model.AppAccount, batchSize int) error { + return a.DO.CreateInBatches(values, batchSize) +} + +// Save : !!! underlying implementation is different with GORM +// The method is equivalent to executing the statement: db.Clauses(clause.OnConflict{UpdateAll: true}).Create(values) +func (a appAccountDo) Save(values ...*model.AppAccount) error { + if len(values) == 0 { + return nil + } + return a.DO.Save(values) +} + +func (a appAccountDo) First() (*model.AppAccount, error) { + if result, err := a.DO.First(); err != nil { + return nil, err + } else { + return result.(*model.AppAccount), nil + } +} + +func (a appAccountDo) Take() (*model.AppAccount, error) { + if result, err := a.DO.Take(); err != nil { + return nil, err + } else { + return result.(*model.AppAccount), nil + } +} + +func (a appAccountDo) Last() (*model.AppAccount, error) { + if result, err := a.DO.Last(); err != nil { + return nil, err + } else { + return result.(*model.AppAccount), nil + } +} + +func (a appAccountDo) Find() ([]*model.AppAccount, error) { + result, err := a.DO.Find() + return result.([]*model.AppAccount), err +} + +func (a appAccountDo) FindInBatch(batchSize int, fc func(tx gen.Dao, batch int) error) (results []*model.AppAccount, err error) { + buf := make([]*model.AppAccount, 0, batchSize) + err = a.DO.FindInBatches(&buf, batchSize, func(tx gen.Dao, batch int) error { + defer func() { results = append(results, buf...) }() + return fc(tx, batch) + }) + return results, err +} + +func (a appAccountDo) FindInBatches(result *[]*model.AppAccount, batchSize int, fc func(tx gen.Dao, batch int) error) error { + return a.DO.FindInBatches(result, batchSize, fc) +} + +func (a appAccountDo) Attrs(attrs ...field.AssignExpr) IAppAccountDo { + return a.withDO(a.DO.Attrs(attrs...)) +} + +func (a appAccountDo) Assign(attrs ...field.AssignExpr) IAppAccountDo { + return a.withDO(a.DO.Assign(attrs...)) +} + +func (a appAccountDo) Joins(fields ...field.RelationField) IAppAccountDo { + for _, _f := range fields { + a = *a.withDO(a.DO.Joins(_f)) + } + return &a +} + +func (a appAccountDo) Preload(fields ...field.RelationField) IAppAccountDo { + for _, _f := range fields { + a = *a.withDO(a.DO.Preload(_f)) + } + return &a +} + +func (a appAccountDo) FirstOrInit() (*model.AppAccount, error) { + if result, err := a.DO.FirstOrInit(); err != nil { + return nil, err + } else { + return result.(*model.AppAccount), nil + } +} + +func (a appAccountDo) FirstOrCreate() (*model.AppAccount, error) { + if result, err := a.DO.FirstOrCreate(); err != nil { + return nil, err + } else { + return result.(*model.AppAccount), nil + } +} + +func (a appAccountDo) FindByPage(offset int, limit int) (result []*model.AppAccount, count int64, err error) { + result, err = a.Offset(offset).Limit(limit).Find() + if err != nil { + return + } + + if size := len(result); 0 < limit && 0 < size && size < limit { + count = int64(size + offset) + return + } + + count, err = a.Offset(-1).Limit(-1).Count() + return +} + +func (a appAccountDo) ScanByPage(result interface{}, offset int, limit int) (count int64, err error) { + count, err = a.Count() + if err != nil { + return + } + + err = a.Offset(offset).Limit(limit).Scan(result) + return +} + +func (a appAccountDo) Scan(result interface{}) (err error) { + return a.DO.Scan(result) +} + +func (a appAccountDo) Delete(models ...*model.AppAccount) (result gen.ResultInfo, err error) { + return a.DO.Delete(models) +} + +func (a *appAccountDo) withDO(do gen.Dao) *appAccountDo { + a.DO = *do.(*gen.DO) + return a +} diff --git a/gorm-gen/query/app_user.gen.go b/gorm-gen/query/app_user.gen.go new file mode 100644 index 0000000..a71caeb --- /dev/null +++ b/gorm-gen/query/app_user.gen.go @@ -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_server/gorm-gen/dao/model" +) + +func newAppUser(db *gorm.DB, opts ...gen.DOOption) appUser { + _appUser := appUser{} + + _appUser.appUserDo.UseDB(db, opts...) + _appUser.appUserDo.UseModel(&model.AppUser{}) + + tableName := _appUser.appUserDo.TableName() + _appUser.ALL = field.NewAsterisk(tableName) + _appUser.ID = field.NewUint64(tableName, "id") + _appUser.AppAccountID = field.NewUint32(tableName, "app_account_id") + _appUser.Openid = field.NewString(tableName, "openid") + _appUser.Unionid = field.NewString(tableName, "unionid") + _appUser.Nickname = field.NewString(tableName, "nickname") + _appUser.Avatar = field.NewString(tableName, "avatar") + _appUser.AnonymousOpenid = field.NewString(tableName, "anonymous_openid") + _appUser.CreatedAt = field.NewTime(tableName, "created_at") + _appUser.UpdatedAt = field.NewTime(tableName, "updated_at") + + _appUser.fillFieldMap() + + return _appUser +} + +type appUser struct { + appUserDo + + ALL field.Asterisk + ID field.Uint64 + AppAccountID field.Uint32 + Openid field.String + Unionid field.String + Nickname field.String + Avatar field.String + AnonymousOpenid field.String + CreatedAt field.Time + UpdatedAt field.Time + + fieldMap map[string]field.Expr +} + +func (a appUser) Table(newTableName string) *appUser { + a.appUserDo.UseTable(newTableName) + return a.updateTableName(newTableName) +} + +func (a appUser) As(alias string) *appUser { + a.appUserDo.DO = *(a.appUserDo.As(alias).(*gen.DO)) + return a.updateTableName(alias) +} + +func (a *appUser) updateTableName(table string) *appUser { + a.ALL = field.NewAsterisk(table) + a.ID = field.NewUint64(table, "id") + a.AppAccountID = field.NewUint32(table, "app_account_id") + a.Openid = field.NewString(table, "openid") + a.Unionid = field.NewString(table, "unionid") + a.Nickname = field.NewString(table, "nickname") + a.Avatar = field.NewString(table, "avatar") + a.AnonymousOpenid = field.NewString(table, "anonymous_openid") + a.CreatedAt = field.NewTime(table, "created_at") + a.UpdatedAt = field.NewTime(table, "updated_at") + + a.fillFieldMap() + + return a +} + +func (a *appUser) GetFieldByName(fieldName string) (field.OrderExpr, bool) { + _f, ok := a.fieldMap[fieldName] + if !ok || _f == nil { + return nil, false + } + _oe, ok := _f.(field.OrderExpr) + return _oe, ok +} + +func (a *appUser) fillFieldMap() { + a.fieldMap = make(map[string]field.Expr, 9) + a.fieldMap["id"] = a.ID + a.fieldMap["app_account_id"] = a.AppAccountID + a.fieldMap["openid"] = a.Openid + a.fieldMap["unionid"] = a.Unionid + a.fieldMap["nickname"] = a.Nickname + a.fieldMap["avatar"] = a.Avatar + a.fieldMap["anonymous_openid"] = a.AnonymousOpenid + a.fieldMap["created_at"] = a.CreatedAt + a.fieldMap["updated_at"] = a.UpdatedAt +} + +func (a appUser) clone(db *gorm.DB) appUser { + a.appUserDo.ReplaceConnPool(db.Statement.ConnPool) + return a +} + +func (a appUser) replaceDB(db *gorm.DB) appUser { + a.appUserDo.ReplaceDB(db) + return a +} + +type appUserDo struct{ gen.DO } + +type IAppUserDo interface { + gen.SubQuery + Debug() IAppUserDo + WithContext(ctx context.Context) IAppUserDo + WithResult(fc func(tx gen.Dao)) gen.ResultInfo + ReplaceDB(db *gorm.DB) + ReadDB() IAppUserDo + WriteDB() IAppUserDo + As(alias string) gen.Dao + Session(config *gorm.Session) IAppUserDo + Columns(cols ...field.Expr) gen.Columns + Clauses(conds ...clause.Expression) IAppUserDo + Not(conds ...gen.Condition) IAppUserDo + Or(conds ...gen.Condition) IAppUserDo + Select(conds ...field.Expr) IAppUserDo + Where(conds ...gen.Condition) IAppUserDo + Order(conds ...field.Expr) IAppUserDo + Distinct(cols ...field.Expr) IAppUserDo + Omit(cols ...field.Expr) IAppUserDo + Join(table schema.Tabler, on ...field.Expr) IAppUserDo + LeftJoin(table schema.Tabler, on ...field.Expr) IAppUserDo + RightJoin(table schema.Tabler, on ...field.Expr) IAppUserDo + Group(cols ...field.Expr) IAppUserDo + Having(conds ...gen.Condition) IAppUserDo + Limit(limit int) IAppUserDo + Offset(offset int) IAppUserDo + Count() (count int64, err error) + Scopes(funcs ...func(gen.Dao) gen.Dao) IAppUserDo + Unscoped() IAppUserDo + Create(values ...*model.AppUser) error + CreateInBatches(values []*model.AppUser, batchSize int) error + Save(values ...*model.AppUser) error + First() (*model.AppUser, error) + Take() (*model.AppUser, error) + Last() (*model.AppUser, error) + Find() ([]*model.AppUser, error) + FindInBatch(batchSize int, fc func(tx gen.Dao, batch int) error) (results []*model.AppUser, err error) + FindInBatches(result *[]*model.AppUser, batchSize int, fc func(tx gen.Dao, batch int) error) error + Pluck(column field.Expr, dest interface{}) error + Delete(...*model.AppUser) (info gen.ResultInfo, err error) + Update(column field.Expr, value interface{}) (info gen.ResultInfo, err error) + UpdateSimple(columns ...field.AssignExpr) (info gen.ResultInfo, err error) + Updates(value interface{}) (info gen.ResultInfo, err error) + UpdateColumn(column field.Expr, value interface{}) (info gen.ResultInfo, err error) + UpdateColumnSimple(columns ...field.AssignExpr) (info gen.ResultInfo, err error) + UpdateColumns(value interface{}) (info gen.ResultInfo, err error) + UpdateFrom(q gen.SubQuery) gen.Dao + Attrs(attrs ...field.AssignExpr) IAppUserDo + Assign(attrs ...field.AssignExpr) IAppUserDo + Joins(fields ...field.RelationField) IAppUserDo + Preload(fields ...field.RelationField) IAppUserDo + FirstOrInit() (*model.AppUser, error) + FirstOrCreate() (*model.AppUser, error) + FindByPage(offset int, limit int) (result []*model.AppUser, count int64, err error) + ScanByPage(result interface{}, offset int, limit int) (count int64, err error) + Scan(result interface{}) (err error) + Returning(value interface{}, columns ...string) IAppUserDo + UnderlyingDB() *gorm.DB + schema.Tabler +} + +func (a appUserDo) Debug() IAppUserDo { + return a.withDO(a.DO.Debug()) +} + +func (a appUserDo) WithContext(ctx context.Context) IAppUserDo { + return a.withDO(a.DO.WithContext(ctx)) +} + +func (a appUserDo) ReadDB() IAppUserDo { + return a.Clauses(dbresolver.Read) +} + +func (a appUserDo) WriteDB() IAppUserDo { + return a.Clauses(dbresolver.Write) +} + +func (a appUserDo) Session(config *gorm.Session) IAppUserDo { + return a.withDO(a.DO.Session(config)) +} + +func (a appUserDo) Clauses(conds ...clause.Expression) IAppUserDo { + return a.withDO(a.DO.Clauses(conds...)) +} + +func (a appUserDo) Returning(value interface{}, columns ...string) IAppUserDo { + return a.withDO(a.DO.Returning(value, columns...)) +} + +func (a appUserDo) Not(conds ...gen.Condition) IAppUserDo { + return a.withDO(a.DO.Not(conds...)) +} + +func (a appUserDo) Or(conds ...gen.Condition) IAppUserDo { + return a.withDO(a.DO.Or(conds...)) +} + +func (a appUserDo) Select(conds ...field.Expr) IAppUserDo { + return a.withDO(a.DO.Select(conds...)) +} + +func (a appUserDo) Where(conds ...gen.Condition) IAppUserDo { + return a.withDO(a.DO.Where(conds...)) +} + +func (a appUserDo) Order(conds ...field.Expr) IAppUserDo { + return a.withDO(a.DO.Order(conds...)) +} + +func (a appUserDo) Distinct(cols ...field.Expr) IAppUserDo { + return a.withDO(a.DO.Distinct(cols...)) +} + +func (a appUserDo) Omit(cols ...field.Expr) IAppUserDo { + return a.withDO(a.DO.Omit(cols...)) +} + +func (a appUserDo) Join(table schema.Tabler, on ...field.Expr) IAppUserDo { + return a.withDO(a.DO.Join(table, on...)) +} + +func (a appUserDo) LeftJoin(table schema.Tabler, on ...field.Expr) IAppUserDo { + return a.withDO(a.DO.LeftJoin(table, on...)) +} + +func (a appUserDo) RightJoin(table schema.Tabler, on ...field.Expr) IAppUserDo { + return a.withDO(a.DO.RightJoin(table, on...)) +} + +func (a appUserDo) Group(cols ...field.Expr) IAppUserDo { + return a.withDO(a.DO.Group(cols...)) +} + +func (a appUserDo) Having(conds ...gen.Condition) IAppUserDo { + return a.withDO(a.DO.Having(conds...)) +} + +func (a appUserDo) Limit(limit int) IAppUserDo { + return a.withDO(a.DO.Limit(limit)) +} + +func (a appUserDo) Offset(offset int) IAppUserDo { + return a.withDO(a.DO.Offset(offset)) +} + +func (a appUserDo) Scopes(funcs ...func(gen.Dao) gen.Dao) IAppUserDo { + return a.withDO(a.DO.Scopes(funcs...)) +} + +func (a appUserDo) Unscoped() IAppUserDo { + return a.withDO(a.DO.Unscoped()) +} + +func (a appUserDo) Create(values ...*model.AppUser) error { + if len(values) == 0 { + return nil + } + return a.DO.Create(values) +} + +func (a appUserDo) CreateInBatches(values []*model.AppUser, batchSize int) error { + return a.DO.CreateInBatches(values, batchSize) +} + +// Save : !!! underlying implementation is different with GORM +// The method is equivalent to executing the statement: db.Clauses(clause.OnConflict{UpdateAll: true}).Create(values) +func (a appUserDo) Save(values ...*model.AppUser) error { + if len(values) == 0 { + return nil + } + return a.DO.Save(values) +} + +func (a appUserDo) First() (*model.AppUser, error) { + if result, err := a.DO.First(); err != nil { + return nil, err + } else { + return result.(*model.AppUser), nil + } +} + +func (a appUserDo) Take() (*model.AppUser, error) { + if result, err := a.DO.Take(); err != nil { + return nil, err + } else { + return result.(*model.AppUser), nil + } +} + +func (a appUserDo) Last() (*model.AppUser, error) { + if result, err := a.DO.Last(); err != nil { + return nil, err + } else { + return result.(*model.AppUser), nil + } +} + +func (a appUserDo) Find() ([]*model.AppUser, error) { + result, err := a.DO.Find() + return result.([]*model.AppUser), err +} + +func (a appUserDo) FindInBatch(batchSize int, fc func(tx gen.Dao, batch int) error) (results []*model.AppUser, err error) { + buf := make([]*model.AppUser, 0, batchSize) + err = a.DO.FindInBatches(&buf, batchSize, func(tx gen.Dao, batch int) error { + defer func() { results = append(results, buf...) }() + return fc(tx, batch) + }) + return results, err +} + +func (a appUserDo) FindInBatches(result *[]*model.AppUser, batchSize int, fc func(tx gen.Dao, batch int) error) error { + return a.DO.FindInBatches(result, batchSize, fc) +} + +func (a appUserDo) Attrs(attrs ...field.AssignExpr) IAppUserDo { + return a.withDO(a.DO.Attrs(attrs...)) +} + +func (a appUserDo) Assign(attrs ...field.AssignExpr) IAppUserDo { + return a.withDO(a.DO.Assign(attrs...)) +} + +func (a appUserDo) Joins(fields ...field.RelationField) IAppUserDo { + for _, _f := range fields { + a = *a.withDO(a.DO.Joins(_f)) + } + return &a +} + +func (a appUserDo) Preload(fields ...field.RelationField) IAppUserDo { + for _, _f := range fields { + a = *a.withDO(a.DO.Preload(_f)) + } + return &a +} + +func (a appUserDo) FirstOrInit() (*model.AppUser, error) { + if result, err := a.DO.FirstOrInit(); err != nil { + return nil, err + } else { + return result.(*model.AppUser), nil + } +} + +func (a appUserDo) FirstOrCreate() (*model.AppUser, error) { + if result, err := a.DO.FirstOrCreate(); err != nil { + return nil, err + } else { + return result.(*model.AppUser), nil + } +} + +func (a appUserDo) FindByPage(offset int, limit int) (result []*model.AppUser, count int64, err error) { + result, err = a.Offset(offset).Limit(limit).Find() + if err != nil { + return + } + + if size := len(result); 0 < limit && 0 < size && size < limit { + count = int64(size + offset) + return + } + + count, err = a.Offset(-1).Limit(-1).Count() + return +} + +func (a appUserDo) ScanByPage(result interface{}, offset int, limit int) (count int64, err error) { + count, err = a.Count() + if err != nil { + return + } + + err = a.Offset(offset).Limit(limit).Scan(result) + return +} + +func (a appUserDo) Scan(result interface{}) (err error) { + return a.DO.Scan(result) +} + +func (a appUserDo) Delete(models ...*model.AppUser) (result gen.ResultInfo, err error) { + return a.DO.Delete(models) +} + +func (a *appUserDo) withDO(do gen.Dao) *appUserDo { + a.DO = *do.(*gen.DO) + return a +} diff --git a/gorm-gen/query/douyin_ecpm_config.gen.go b/gorm-gen/query/douyin_ecpm_config.gen.go new file mode 100644 index 0000000..c0e8af4 --- /dev/null +++ b/gorm-gen/query/douyin_ecpm_config.gen.go @@ -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_server/gorm-gen/dao/model" +) + +func newDouyinEcpmConfig(db *gorm.DB, opts ...gen.DOOption) douyinEcpmConfig { + _douyinEcpmConfig := douyinEcpmConfig{} + + _douyinEcpmConfig.douyinEcpmConfigDo.UseDB(db, opts...) + _douyinEcpmConfig.douyinEcpmConfigDo.UseModel(&model.DouyinEcpmConfig{}) + + tableName := _douyinEcpmConfig.douyinEcpmConfigDo.TableName() + _douyinEcpmConfig.ALL = field.NewAsterisk(tableName) + _douyinEcpmConfig.ID = field.NewUint32(tableName, "id") + _douyinEcpmConfig.AppAccountID = field.NewUint32(tableName, "app_account_id") + _douyinEcpmConfig.EcpmValue = field.NewUint32(tableName, "ecpm_value") + _douyinEcpmConfig.EcpmView = field.NewUint32(tableName, "ecpm_view") + + _douyinEcpmConfig.fillFieldMap() + + return _douyinEcpmConfig +} + +type douyinEcpmConfig struct { + douyinEcpmConfigDo + + ALL field.Asterisk + ID field.Uint32 + AppAccountID field.Uint32 + EcpmValue field.Uint32 + EcpmView field.Uint32 + + fieldMap map[string]field.Expr +} + +func (d douyinEcpmConfig) Table(newTableName string) *douyinEcpmConfig { + d.douyinEcpmConfigDo.UseTable(newTableName) + return d.updateTableName(newTableName) +} + +func (d douyinEcpmConfig) As(alias string) *douyinEcpmConfig { + d.douyinEcpmConfigDo.DO = *(d.douyinEcpmConfigDo.As(alias).(*gen.DO)) + return d.updateTableName(alias) +} + +func (d *douyinEcpmConfig) updateTableName(table string) *douyinEcpmConfig { + d.ALL = field.NewAsterisk(table) + d.ID = field.NewUint32(table, "id") + d.AppAccountID = field.NewUint32(table, "app_account_id") + d.EcpmValue = field.NewUint32(table, "ecpm_value") + d.EcpmView = field.NewUint32(table, "ecpm_view") + + d.fillFieldMap() + + return d +} + +func (d *douyinEcpmConfig) GetFieldByName(fieldName string) (field.OrderExpr, bool) { + _f, ok := d.fieldMap[fieldName] + if !ok || _f == nil { + return nil, false + } + _oe, ok := _f.(field.OrderExpr) + return _oe, ok +} + +func (d *douyinEcpmConfig) fillFieldMap() { + d.fieldMap = make(map[string]field.Expr, 4) + d.fieldMap["id"] = d.ID + d.fieldMap["app_account_id"] = d.AppAccountID + d.fieldMap["ecpm_value"] = d.EcpmValue + d.fieldMap["ecpm_view"] = d.EcpmView +} + +func (d douyinEcpmConfig) clone(db *gorm.DB) douyinEcpmConfig { + d.douyinEcpmConfigDo.ReplaceConnPool(db.Statement.ConnPool) + return d +} + +func (d douyinEcpmConfig) replaceDB(db *gorm.DB) douyinEcpmConfig { + d.douyinEcpmConfigDo.ReplaceDB(db) + return d +} + +type douyinEcpmConfigDo struct{ gen.DO } + +type IDouyinEcpmConfigDo interface { + gen.SubQuery + Debug() IDouyinEcpmConfigDo + WithContext(ctx context.Context) IDouyinEcpmConfigDo + WithResult(fc func(tx gen.Dao)) gen.ResultInfo + ReplaceDB(db *gorm.DB) + ReadDB() IDouyinEcpmConfigDo + WriteDB() IDouyinEcpmConfigDo + As(alias string) gen.Dao + Session(config *gorm.Session) IDouyinEcpmConfigDo + Columns(cols ...field.Expr) gen.Columns + Clauses(conds ...clause.Expression) IDouyinEcpmConfigDo + Not(conds ...gen.Condition) IDouyinEcpmConfigDo + Or(conds ...gen.Condition) IDouyinEcpmConfigDo + Select(conds ...field.Expr) IDouyinEcpmConfigDo + Where(conds ...gen.Condition) IDouyinEcpmConfigDo + Order(conds ...field.Expr) IDouyinEcpmConfigDo + Distinct(cols ...field.Expr) IDouyinEcpmConfigDo + Omit(cols ...field.Expr) IDouyinEcpmConfigDo + Join(table schema.Tabler, on ...field.Expr) IDouyinEcpmConfigDo + LeftJoin(table schema.Tabler, on ...field.Expr) IDouyinEcpmConfigDo + RightJoin(table schema.Tabler, on ...field.Expr) IDouyinEcpmConfigDo + Group(cols ...field.Expr) IDouyinEcpmConfigDo + Having(conds ...gen.Condition) IDouyinEcpmConfigDo + Limit(limit int) IDouyinEcpmConfigDo + Offset(offset int) IDouyinEcpmConfigDo + Count() (count int64, err error) + Scopes(funcs ...func(gen.Dao) gen.Dao) IDouyinEcpmConfigDo + Unscoped() IDouyinEcpmConfigDo + Create(values ...*model.DouyinEcpmConfig) error + CreateInBatches(values []*model.DouyinEcpmConfig, batchSize int) error + Save(values ...*model.DouyinEcpmConfig) error + First() (*model.DouyinEcpmConfig, error) + Take() (*model.DouyinEcpmConfig, error) + Last() (*model.DouyinEcpmConfig, error) + Find() ([]*model.DouyinEcpmConfig, error) + FindInBatch(batchSize int, fc func(tx gen.Dao, batch int) error) (results []*model.DouyinEcpmConfig, err error) + FindInBatches(result *[]*model.DouyinEcpmConfig, batchSize int, fc func(tx gen.Dao, batch int) error) error + Pluck(column field.Expr, dest interface{}) error + Delete(...*model.DouyinEcpmConfig) (info gen.ResultInfo, err error) + Update(column field.Expr, value interface{}) (info gen.ResultInfo, err error) + UpdateSimple(columns ...field.AssignExpr) (info gen.ResultInfo, err error) + Updates(value interface{}) (info gen.ResultInfo, err error) + UpdateColumn(column field.Expr, value interface{}) (info gen.ResultInfo, err error) + UpdateColumnSimple(columns ...field.AssignExpr) (info gen.ResultInfo, err error) + UpdateColumns(value interface{}) (info gen.ResultInfo, err error) + UpdateFrom(q gen.SubQuery) gen.Dao + Attrs(attrs ...field.AssignExpr) IDouyinEcpmConfigDo + Assign(attrs ...field.AssignExpr) IDouyinEcpmConfigDo + Joins(fields ...field.RelationField) IDouyinEcpmConfigDo + Preload(fields ...field.RelationField) IDouyinEcpmConfigDo + FirstOrInit() (*model.DouyinEcpmConfig, error) + FirstOrCreate() (*model.DouyinEcpmConfig, error) + FindByPage(offset int, limit int) (result []*model.DouyinEcpmConfig, count int64, err error) + ScanByPage(result interface{}, offset int, limit int) (count int64, err error) + Scan(result interface{}) (err error) + Returning(value interface{}, columns ...string) IDouyinEcpmConfigDo + UnderlyingDB() *gorm.DB + schema.Tabler +} + +func (d douyinEcpmConfigDo) Debug() IDouyinEcpmConfigDo { + return d.withDO(d.DO.Debug()) +} + +func (d douyinEcpmConfigDo) WithContext(ctx context.Context) IDouyinEcpmConfigDo { + return d.withDO(d.DO.WithContext(ctx)) +} + +func (d douyinEcpmConfigDo) ReadDB() IDouyinEcpmConfigDo { + return d.Clauses(dbresolver.Read) +} + +func (d douyinEcpmConfigDo) WriteDB() IDouyinEcpmConfigDo { + return d.Clauses(dbresolver.Write) +} + +func (d douyinEcpmConfigDo) Session(config *gorm.Session) IDouyinEcpmConfigDo { + return d.withDO(d.DO.Session(config)) +} + +func (d douyinEcpmConfigDo) Clauses(conds ...clause.Expression) IDouyinEcpmConfigDo { + return d.withDO(d.DO.Clauses(conds...)) +} + +func (d douyinEcpmConfigDo) Returning(value interface{}, columns ...string) IDouyinEcpmConfigDo { + return d.withDO(d.DO.Returning(value, columns...)) +} + +func (d douyinEcpmConfigDo) Not(conds ...gen.Condition) IDouyinEcpmConfigDo { + return d.withDO(d.DO.Not(conds...)) +} + +func (d douyinEcpmConfigDo) Or(conds ...gen.Condition) IDouyinEcpmConfigDo { + return d.withDO(d.DO.Or(conds...)) +} + +func (d douyinEcpmConfigDo) Select(conds ...field.Expr) IDouyinEcpmConfigDo { + return d.withDO(d.DO.Select(conds...)) +} + +func (d douyinEcpmConfigDo) Where(conds ...gen.Condition) IDouyinEcpmConfigDo { + return d.withDO(d.DO.Where(conds...)) +} + +func (d douyinEcpmConfigDo) Order(conds ...field.Expr) IDouyinEcpmConfigDo { + return d.withDO(d.DO.Order(conds...)) +} + +func (d douyinEcpmConfigDo) Distinct(cols ...field.Expr) IDouyinEcpmConfigDo { + return d.withDO(d.DO.Distinct(cols...)) +} + +func (d douyinEcpmConfigDo) Omit(cols ...field.Expr) IDouyinEcpmConfigDo { + return d.withDO(d.DO.Omit(cols...)) +} + +func (d douyinEcpmConfigDo) Join(table schema.Tabler, on ...field.Expr) IDouyinEcpmConfigDo { + return d.withDO(d.DO.Join(table, on...)) +} + +func (d douyinEcpmConfigDo) LeftJoin(table schema.Tabler, on ...field.Expr) IDouyinEcpmConfigDo { + return d.withDO(d.DO.LeftJoin(table, on...)) +} + +func (d douyinEcpmConfigDo) RightJoin(table schema.Tabler, on ...field.Expr) IDouyinEcpmConfigDo { + return d.withDO(d.DO.RightJoin(table, on...)) +} + +func (d douyinEcpmConfigDo) Group(cols ...field.Expr) IDouyinEcpmConfigDo { + return d.withDO(d.DO.Group(cols...)) +} + +func (d douyinEcpmConfigDo) Having(conds ...gen.Condition) IDouyinEcpmConfigDo { + return d.withDO(d.DO.Having(conds...)) +} + +func (d douyinEcpmConfigDo) Limit(limit int) IDouyinEcpmConfigDo { + return d.withDO(d.DO.Limit(limit)) +} + +func (d douyinEcpmConfigDo) Offset(offset int) IDouyinEcpmConfigDo { + return d.withDO(d.DO.Offset(offset)) +} + +func (d douyinEcpmConfigDo) Scopes(funcs ...func(gen.Dao) gen.Dao) IDouyinEcpmConfigDo { + return d.withDO(d.DO.Scopes(funcs...)) +} + +func (d douyinEcpmConfigDo) Unscoped() IDouyinEcpmConfigDo { + return d.withDO(d.DO.Unscoped()) +} + +func (d douyinEcpmConfigDo) Create(values ...*model.DouyinEcpmConfig) error { + if len(values) == 0 { + return nil + } + return d.DO.Create(values) +} + +func (d douyinEcpmConfigDo) CreateInBatches(values []*model.DouyinEcpmConfig, batchSize int) error { + return d.DO.CreateInBatches(values, batchSize) +} + +// Save : !!! underlying implementation is different with GORM +// The method is equivalent to executing the statement: db.Clauses(clause.OnConflict{UpdateAll: true}).Create(values) +func (d douyinEcpmConfigDo) Save(values ...*model.DouyinEcpmConfig) error { + if len(values) == 0 { + return nil + } + return d.DO.Save(values) +} + +func (d douyinEcpmConfigDo) First() (*model.DouyinEcpmConfig, error) { + if result, err := d.DO.First(); err != nil { + return nil, err + } else { + return result.(*model.DouyinEcpmConfig), nil + } +} + +func (d douyinEcpmConfigDo) Take() (*model.DouyinEcpmConfig, error) { + if result, err := d.DO.Take(); err != nil { + return nil, err + } else { + return result.(*model.DouyinEcpmConfig), nil + } +} + +func (d douyinEcpmConfigDo) Last() (*model.DouyinEcpmConfig, error) { + if result, err := d.DO.Last(); err != nil { + return nil, err + } else { + return result.(*model.DouyinEcpmConfig), nil + } +} + +func (d douyinEcpmConfigDo) Find() ([]*model.DouyinEcpmConfig, error) { + result, err := d.DO.Find() + return result.([]*model.DouyinEcpmConfig), err +} + +func (d douyinEcpmConfigDo) FindInBatch(batchSize int, fc func(tx gen.Dao, batch int) error) (results []*model.DouyinEcpmConfig, err error) { + buf := make([]*model.DouyinEcpmConfig, 0, batchSize) + err = d.DO.FindInBatches(&buf, batchSize, func(tx gen.Dao, batch int) error { + defer func() { results = append(results, buf...) }() + return fc(tx, batch) + }) + return results, err +} + +func (d douyinEcpmConfigDo) FindInBatches(result *[]*model.DouyinEcpmConfig, batchSize int, fc func(tx gen.Dao, batch int) error) error { + return d.DO.FindInBatches(result, batchSize, fc) +} + +func (d douyinEcpmConfigDo) Attrs(attrs ...field.AssignExpr) IDouyinEcpmConfigDo { + return d.withDO(d.DO.Attrs(attrs...)) +} + +func (d douyinEcpmConfigDo) Assign(attrs ...field.AssignExpr) IDouyinEcpmConfigDo { + return d.withDO(d.DO.Assign(attrs...)) +} + +func (d douyinEcpmConfigDo) Joins(fields ...field.RelationField) IDouyinEcpmConfigDo { + for _, _f := range fields { + d = *d.withDO(d.DO.Joins(_f)) + } + return &d +} + +func (d douyinEcpmConfigDo) Preload(fields ...field.RelationField) IDouyinEcpmConfigDo { + for _, _f := range fields { + d = *d.withDO(d.DO.Preload(_f)) + } + return &d +} + +func (d douyinEcpmConfigDo) FirstOrInit() (*model.DouyinEcpmConfig, error) { + if result, err := d.DO.FirstOrInit(); err != nil { + return nil, err + } else { + return result.(*model.DouyinEcpmConfig), nil + } +} + +func (d douyinEcpmConfigDo) FirstOrCreate() (*model.DouyinEcpmConfig, error) { + if result, err := d.DO.FirstOrCreate(); err != nil { + return nil, err + } else { + return result.(*model.DouyinEcpmConfig), nil + } +} + +func (d douyinEcpmConfigDo) FindByPage(offset int, limit int) (result []*model.DouyinEcpmConfig, count int64, err error) { + result, err = d.Offset(offset).Limit(limit).Find() + if err != nil { + return + } + + if size := len(result); 0 < limit && 0 < size && size < limit { + count = int64(size + offset) + return + } + + count, err = d.Offset(-1).Limit(-1).Count() + return +} + +func (d douyinEcpmConfigDo) ScanByPage(result interface{}, offset int, limit int) (count int64, err error) { + count, err = d.Count() + if err != nil { + return + } + + err = d.Offset(offset).Limit(limit).Scan(result) + return +} + +func (d douyinEcpmConfigDo) Scan(result interface{}) (err error) { + return d.DO.Scan(result) +} + +func (d douyinEcpmConfigDo) Delete(models ...*model.DouyinEcpmConfig) (result gen.ResultInfo, err error) { + return d.DO.Delete(models) +} + +func (d *douyinEcpmConfigDo) withDO(do gen.Dao) *douyinEcpmConfigDo { + d.DO = *do.(*gen.DO) + return d +} diff --git a/gorm-gen/query/game_score.gen.go b/gorm-gen/query/game_score.gen.go new file mode 100644 index 0000000..5a2af5c --- /dev/null +++ b/gorm-gen/query/game_score.gen.go @@ -0,0 +1,448 @@ +// Code generated by gorm.io/gen. DO NOT EDIT. +// Code generated by gorm.io/gen. DO NOT EDIT. +// Code generated by gorm.io/gen. DO NOT EDIT. + +package query + +import ( + "context" + "strings" + + "gorm.io/gorm" + "gorm.io/gorm/clause" + "gorm.io/gorm/schema" + + "gorm.io/gen" + "gorm.io/gen/field" + + "gorm.io/plugin/dbresolver" + + "gitea.youtukeji.com.cn/xiabin/youtu_server/gorm-gen/dao/model" + "gitea.youtukeji.com.cn/xiabin/youtu_server/gorm-gen/querier" +) + +func newGameScore(db *gorm.DB, opts ...gen.DOOption) gameScore { + _gameScore := gameScore{} + + _gameScore.gameScoreDo.UseDB(db, opts...) + _gameScore.gameScoreDo.UseModel(&model.GameScore{}) + + tableName := _gameScore.gameScoreDo.TableName() + _gameScore.ALL = field.NewAsterisk(tableName) + _gameScore.ID = field.NewUint64(tableName, "id") + _gameScore.AppAccount = field.NewUint32(tableName, "app_account") + _gameScore.AppUserID = field.NewUint64(tableName, "app_user_id") + _gameScore.Score = field.NewUint32(tableName, "score") + _gameScore.T = field.NewUint32(tableName, "t") + + _gameScore.fillFieldMap() + + return _gameScore +} + +type gameScore struct { + gameScoreDo + + ALL field.Asterisk + ID field.Uint64 + AppAccount field.Uint32 + AppUserID field.Uint64 + Score field.Uint32 + T field.Uint32 + + fieldMap map[string]field.Expr +} + +func (g gameScore) Table(newTableName string) *gameScore { + g.gameScoreDo.UseTable(newTableName) + return g.updateTableName(newTableName) +} + +func (g gameScore) As(alias string) *gameScore { + g.gameScoreDo.DO = *(g.gameScoreDo.As(alias).(*gen.DO)) + return g.updateTableName(alias) +} + +func (g *gameScore) updateTableName(table string) *gameScore { + g.ALL = field.NewAsterisk(table) + g.ID = field.NewUint64(table, "id") + g.AppAccount = field.NewUint32(table, "app_account") + g.AppUserID = field.NewUint64(table, "app_user_id") + g.Score = field.NewUint32(table, "score") + g.T = field.NewUint32(table, "t") + + g.fillFieldMap() + + return g +} + +func (g *gameScore) GetFieldByName(fieldName string) (field.OrderExpr, bool) { + _f, ok := g.fieldMap[fieldName] + if !ok || _f == nil { + return nil, false + } + _oe, ok := _f.(field.OrderExpr) + return _oe, ok +} + +func (g *gameScore) fillFieldMap() { + g.fieldMap = make(map[string]field.Expr, 5) + g.fieldMap["id"] = g.ID + g.fieldMap["app_account"] = g.AppAccount + g.fieldMap["app_user_id"] = g.AppUserID + g.fieldMap["score"] = g.Score + g.fieldMap["t"] = g.T +} + +func (g gameScore) clone(db *gorm.DB) gameScore { + g.gameScoreDo.ReplaceConnPool(db.Statement.ConnPool) + return g +} + +func (g gameScore) replaceDB(db *gorm.DB) gameScore { + g.gameScoreDo.ReplaceDB(db) + return g +} + +type gameScoreDo struct{ gen.DO } + +type IGameScoreDo interface { + gen.SubQuery + Debug() IGameScoreDo + WithContext(ctx context.Context) IGameScoreDo + WithResult(fc func(tx gen.Dao)) gen.ResultInfo + ReplaceDB(db *gorm.DB) + ReadDB() IGameScoreDo + WriteDB() IGameScoreDo + As(alias string) gen.Dao + Session(config *gorm.Session) IGameScoreDo + Columns(cols ...field.Expr) gen.Columns + Clauses(conds ...clause.Expression) IGameScoreDo + Not(conds ...gen.Condition) IGameScoreDo + Or(conds ...gen.Condition) IGameScoreDo + Select(conds ...field.Expr) IGameScoreDo + Where(conds ...gen.Condition) IGameScoreDo + Order(conds ...field.Expr) IGameScoreDo + Distinct(cols ...field.Expr) IGameScoreDo + Omit(cols ...field.Expr) IGameScoreDo + Join(table schema.Tabler, on ...field.Expr) IGameScoreDo + LeftJoin(table schema.Tabler, on ...field.Expr) IGameScoreDo + RightJoin(table schema.Tabler, on ...field.Expr) IGameScoreDo + Group(cols ...field.Expr) IGameScoreDo + Having(conds ...gen.Condition) IGameScoreDo + Limit(limit int) IGameScoreDo + Offset(offset int) IGameScoreDo + Count() (count int64, err error) + Scopes(funcs ...func(gen.Dao) gen.Dao) IGameScoreDo + Unscoped() IGameScoreDo + Create(values ...*model.GameScore) error + CreateInBatches(values []*model.GameScore, batchSize int) error + Save(values ...*model.GameScore) error + First() (*model.GameScore, error) + Take() (*model.GameScore, error) + Last() (*model.GameScore, error) + Find() ([]*model.GameScore, error) + FindInBatch(batchSize int, fc func(tx gen.Dao, batch int) error) (results []*model.GameScore, err error) + FindInBatches(result *[]*model.GameScore, batchSize int, fc func(tx gen.Dao, batch int) error) error + Pluck(column field.Expr, dest interface{}) error + Delete(...*model.GameScore) (info gen.ResultInfo, err error) + Update(column field.Expr, value interface{}) (info gen.ResultInfo, err error) + UpdateSimple(columns ...field.AssignExpr) (info gen.ResultInfo, err error) + Updates(value interface{}) (info gen.ResultInfo, err error) + UpdateColumn(column field.Expr, value interface{}) (info gen.ResultInfo, err error) + UpdateColumnSimple(columns ...field.AssignExpr) (info gen.ResultInfo, err error) + UpdateColumns(value interface{}) (info gen.ResultInfo, err error) + UpdateFrom(q gen.SubQuery) gen.Dao + Attrs(attrs ...field.AssignExpr) IGameScoreDo + Assign(attrs ...field.AssignExpr) IGameScoreDo + Joins(fields ...field.RelationField) IGameScoreDo + Preload(fields ...field.RelationField) IGameScoreDo + FirstOrInit() (*model.GameScore, error) + FirstOrCreate() (*model.GameScore, error) + FindByPage(offset int, limit int) (result []*model.GameScore, count int64, err error) + ScanByPage(result interface{}, offset int, limit int) (count int64, err error) + Scan(result interface{}) (err error) + Returning(value interface{}, columns ...string) IGameScoreDo + UnderlyingDB() *gorm.DB + schema.Tabler + + GetUserRank(appId uint32, userId uint64, t uint32) (result querier.RankingData, err error) + FindDistinctRanking() (result []*model.GameScore, err error) +} + +// SELECT +// +// app_user.nickname, +// app_user.avatar, +// gs.score, +// gs.app_user_id, +// gs.t_rank +// FROM +// ( +// SELECT +// game_score.score, +// game_score.app_user_id, +// game_score.app_account, +// rank() OVER (ORDER BY game_score.score DESC) t_rank +// FROM +// game_score +// WHERE +// game_score.t = ? +// AND game_score.app_account = ? +// ) AS gs +// LEFT JOIN app_user ON app_user.id = gs.app_user_id +// WHERE +// gs.app_user_id = ? +// LIMIT 1; +func (g gameScoreDo) GetUserRank(appId uint32, userId uint64, t uint32) (result querier.RankingData, err error) { + var generateSQL strings.Builder + generateSQL.WriteString("SELECT app_user.nickname, app_user.avatar, gs.score, gs.app_user_id, gs.t_rank FROM ( SELECT game_score.score, game_score.app_user_id, game_score.app_account, rank() OVER (ORDER BY game_score.score DESC) t_rank FROM game_score WHERE game_score.t = ? AND game_score.app_account = ? ) AS gs LEFT JOIN app_user ON app_user.id = gs.app_user_id WHERE gs.app_user_id = ? LIMIT 1; ") + + var executeSQL *gorm.DB + executeSQL = g.UnderlyingDB().Raw(generateSQL.String()).Take(&result) // ignore_security_alert + err = executeSQL.Error + + return +} + +// select DISTINCT app_account,t from game_score +func (g gameScoreDo) FindDistinctRanking() (result []*model.GameScore, err error) { + var generateSQL strings.Builder + generateSQL.WriteString("select DISTINCT app_account,t from game_score ") + + var executeSQL *gorm.DB + executeSQL = g.UnderlyingDB().Raw(generateSQL.String()).Find(&result) // ignore_security_alert + err = executeSQL.Error + + return +} + +func (g gameScoreDo) Debug() IGameScoreDo { + return g.withDO(g.DO.Debug()) +} + +func (g gameScoreDo) WithContext(ctx context.Context) IGameScoreDo { + return g.withDO(g.DO.WithContext(ctx)) +} + +func (g gameScoreDo) ReadDB() IGameScoreDo { + return g.Clauses(dbresolver.Read) +} + +func (g gameScoreDo) WriteDB() IGameScoreDo { + return g.Clauses(dbresolver.Write) +} + +func (g gameScoreDo) Session(config *gorm.Session) IGameScoreDo { + return g.withDO(g.DO.Session(config)) +} + +func (g gameScoreDo) Clauses(conds ...clause.Expression) IGameScoreDo { + return g.withDO(g.DO.Clauses(conds...)) +} + +func (g gameScoreDo) Returning(value interface{}, columns ...string) IGameScoreDo { + return g.withDO(g.DO.Returning(value, columns...)) +} + +func (g gameScoreDo) Not(conds ...gen.Condition) IGameScoreDo { + return g.withDO(g.DO.Not(conds...)) +} + +func (g gameScoreDo) Or(conds ...gen.Condition) IGameScoreDo { + return g.withDO(g.DO.Or(conds...)) +} + +func (g gameScoreDo) Select(conds ...field.Expr) IGameScoreDo { + return g.withDO(g.DO.Select(conds...)) +} + +func (g gameScoreDo) Where(conds ...gen.Condition) IGameScoreDo { + return g.withDO(g.DO.Where(conds...)) +} + +func (g gameScoreDo) Order(conds ...field.Expr) IGameScoreDo { + return g.withDO(g.DO.Order(conds...)) +} + +func (g gameScoreDo) Distinct(cols ...field.Expr) IGameScoreDo { + return g.withDO(g.DO.Distinct(cols...)) +} + +func (g gameScoreDo) Omit(cols ...field.Expr) IGameScoreDo { + return g.withDO(g.DO.Omit(cols...)) +} + +func (g gameScoreDo) Join(table schema.Tabler, on ...field.Expr) IGameScoreDo { + return g.withDO(g.DO.Join(table, on...)) +} + +func (g gameScoreDo) LeftJoin(table schema.Tabler, on ...field.Expr) IGameScoreDo { + return g.withDO(g.DO.LeftJoin(table, on...)) +} + +func (g gameScoreDo) RightJoin(table schema.Tabler, on ...field.Expr) IGameScoreDo { + return g.withDO(g.DO.RightJoin(table, on...)) +} + +func (g gameScoreDo) Group(cols ...field.Expr) IGameScoreDo { + return g.withDO(g.DO.Group(cols...)) +} + +func (g gameScoreDo) Having(conds ...gen.Condition) IGameScoreDo { + return g.withDO(g.DO.Having(conds...)) +} + +func (g gameScoreDo) Limit(limit int) IGameScoreDo { + return g.withDO(g.DO.Limit(limit)) +} + +func (g gameScoreDo) Offset(offset int) IGameScoreDo { + return g.withDO(g.DO.Offset(offset)) +} + +func (g gameScoreDo) Scopes(funcs ...func(gen.Dao) gen.Dao) IGameScoreDo { + return g.withDO(g.DO.Scopes(funcs...)) +} + +func (g gameScoreDo) Unscoped() IGameScoreDo { + return g.withDO(g.DO.Unscoped()) +} + +func (g gameScoreDo) Create(values ...*model.GameScore) error { + if len(values) == 0 { + return nil + } + return g.DO.Create(values) +} + +func (g gameScoreDo) CreateInBatches(values []*model.GameScore, batchSize int) error { + return g.DO.CreateInBatches(values, batchSize) +} + +// Save : !!! underlying implementation is different with GORM +// The method is equivalent to executing the statement: db.Clauses(clause.OnConflict{UpdateAll: true}).Create(values) +func (g gameScoreDo) Save(values ...*model.GameScore) error { + if len(values) == 0 { + return nil + } + return g.DO.Save(values) +} + +func (g gameScoreDo) First() (*model.GameScore, error) { + if result, err := g.DO.First(); err != nil { + return nil, err + } else { + return result.(*model.GameScore), nil + } +} + +func (g gameScoreDo) Take() (*model.GameScore, error) { + if result, err := g.DO.Take(); err != nil { + return nil, err + } else { + return result.(*model.GameScore), nil + } +} + +func (g gameScoreDo) Last() (*model.GameScore, error) { + if result, err := g.DO.Last(); err != nil { + return nil, err + } else { + return result.(*model.GameScore), nil + } +} + +func (g gameScoreDo) Find() ([]*model.GameScore, error) { + result, err := g.DO.Find() + return result.([]*model.GameScore), err +} + +func (g gameScoreDo) FindInBatch(batchSize int, fc func(tx gen.Dao, batch int) error) (results []*model.GameScore, err error) { + buf := make([]*model.GameScore, 0, batchSize) + err = g.DO.FindInBatches(&buf, batchSize, func(tx gen.Dao, batch int) error { + defer func() { results = append(results, buf...) }() + return fc(tx, batch) + }) + return results, err +} + +func (g gameScoreDo) FindInBatches(result *[]*model.GameScore, batchSize int, fc func(tx gen.Dao, batch int) error) error { + return g.DO.FindInBatches(result, batchSize, fc) +} + +func (g gameScoreDo) Attrs(attrs ...field.AssignExpr) IGameScoreDo { + return g.withDO(g.DO.Attrs(attrs...)) +} + +func (g gameScoreDo) Assign(attrs ...field.AssignExpr) IGameScoreDo { + return g.withDO(g.DO.Assign(attrs...)) +} + +func (g gameScoreDo) Joins(fields ...field.RelationField) IGameScoreDo { + for _, _f := range fields { + g = *g.withDO(g.DO.Joins(_f)) + } + return &g +} + +func (g gameScoreDo) Preload(fields ...field.RelationField) IGameScoreDo { + for _, _f := range fields { + g = *g.withDO(g.DO.Preload(_f)) + } + return &g +} + +func (g gameScoreDo) FirstOrInit() (*model.GameScore, error) { + if result, err := g.DO.FirstOrInit(); err != nil { + return nil, err + } else { + return result.(*model.GameScore), nil + } +} + +func (g gameScoreDo) FirstOrCreate() (*model.GameScore, error) { + if result, err := g.DO.FirstOrCreate(); err != nil { + return nil, err + } else { + return result.(*model.GameScore), nil + } +} + +func (g gameScoreDo) FindByPage(offset int, limit int) (result []*model.GameScore, count int64, err error) { + result, err = g.Offset(offset).Limit(limit).Find() + if err != nil { + return + } + + if size := len(result); 0 < limit && 0 < size && size < limit { + count = int64(size + offset) + return + } + + count, err = g.Offset(-1).Limit(-1).Count() + return +} + +func (g gameScoreDo) ScanByPage(result interface{}, offset int, limit int) (count int64, err error) { + count, err = g.Count() + if err != nil { + return + } + + err = g.Offset(offset).Limit(limit).Scan(result) + return +} + +func (g gameScoreDo) Scan(result interface{}) (err error) { + return g.DO.Scan(result) +} + +func (g gameScoreDo) Delete(models ...*model.GameScore) (result gen.ResultInfo, err error) { + return g.DO.Delete(models) +} + +func (g *gameScoreDo) withDO(do gen.Dao) *gameScoreDo { + g.DO = *do.(*gen.DO) + return g +} diff --git a/gorm-gen/query/gen.go b/gorm-gen/query/gen.go new file mode 100644 index 0000000..975700f --- /dev/null +++ b/gorm-gen/query/gen.go @@ -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 +}