112 lines
2.6 KiB
Go
Raw Permalink Normal View History

2025-01-14 13:09:25 +08:00
// 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{
2025-01-18 17:56:36 +08:00
db: db,
AppAccount: newAppAccount(db, opts...),
AppUserInfo: newAppUserInfo(db, opts...),
DouyinEcpmConfig: newDouyinEcpmConfig(db, opts...),
GameScore: newGameScore(db, opts...),
2025-01-14 13:09:25 +08:00
}
}
type Query struct {
db *gorm.DB
2025-01-18 17:56:36 +08:00
AppAccount appAccount
AppUserInfo appUserInfo
DouyinEcpmConfig douyinEcpmConfig
GameScore gameScore
2025-01-14 13:09:25 +08:00
}
func (q *Query) Available() bool { return q.db != nil }
func (q *Query) clone(db *gorm.DB) *Query {
return &Query{
2025-01-18 17:56:36 +08:00
db: db,
AppAccount: q.AppAccount.clone(db),
AppUserInfo: q.AppUserInfo.clone(db),
DouyinEcpmConfig: q.DouyinEcpmConfig.clone(db),
GameScore: q.GameScore.clone(db),
2025-01-14 13:09:25 +08:00
}
}
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{
2025-01-18 17:56:36 +08:00
db: db,
AppAccount: q.AppAccount.replaceDB(db),
AppUserInfo: q.AppUserInfo.replaceDB(db),
DouyinEcpmConfig: q.DouyinEcpmConfig.replaceDB(db),
GameScore: q.GameScore.replaceDB(db),
2025-01-14 13:09:25 +08:00
}
}
type queryCtx struct {
2025-01-18 17:56:36 +08:00
AppAccount *appAccountDo
AppUserInfo *appUserInfoDo
DouyinEcpmConfig *douyinEcpmConfigDo
GameScore *gameScoreDo
2025-01-14 13:09:25 +08:00
}
func (q *Query) WithContext(ctx context.Context) *queryCtx {
return &queryCtx{
2025-01-18 17:56:36 +08:00
AppAccount: q.AppAccount.WithContext(ctx),
AppUserInfo: q.AppUserInfo.WithContext(ctx),
DouyinEcpmConfig: q.DouyinEcpmConfig.WithContext(ctx),
GameScore: q.GameScore.WithContext(ctx),
2025-01-14 13:09:25 +08:00
}
}
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
}