rts-sim-testing-service/db/dbquery/gen.go
2023-08-22 16:44:34 +08:00

136 lines
2.9 KiB
Go

// 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 dbquery
import (
"context"
"database/sql"
"gorm.io/gorm"
"gorm.io/gen"
"gorm.io/plugin/dbresolver"
)
var (
Q = new(Query)
Category *category
Drafting *drafting
PublishedGi *publishedGi
TrainModel *trainModel
User *user
)
func SetDefault(db *gorm.DB, opts ...gen.DOOption) {
*Q = *Use(db, opts...)
Category = &Q.Category
Drafting = &Q.Drafting
PublishedGi = &Q.PublishedGi
TrainModel = &Q.TrainModel
User = &Q.User
}
func Use(db *gorm.DB, opts ...gen.DOOption) *Query {
return &Query{
db: db,
Category: newCategory(db, opts...),
Drafting: newDrafting(db, opts...),
PublishedGi: newPublishedGi(db, opts...),
TrainModel: newTrainModel(db, opts...),
User: newUser(db, opts...),
}
}
type Query struct {
db *gorm.DB
Category category
Drafting drafting
PublishedGi publishedGi
TrainModel trainModel
User user
}
func (q *Query) Available() bool { return q.db != nil }
func (q *Query) clone(db *gorm.DB) *Query {
return &Query{
db: db,
Category: q.Category.clone(db),
Drafting: q.Drafting.clone(db),
PublishedGi: q.PublishedGi.clone(db),
TrainModel: q.TrainModel.clone(db),
User: q.User.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,
Category: q.Category.replaceDB(db),
Drafting: q.Drafting.replaceDB(db),
PublishedGi: q.PublishedGi.replaceDB(db),
TrainModel: q.TrainModel.replaceDB(db),
User: q.User.replaceDB(db),
}
}
type queryCtx struct {
Category ICategoryDo
Drafting IDraftingDo
PublishedGi IPublishedGiDo
TrainModel ITrainModelDo
User IUserDo
}
func (q *Query) WithContext(ctx context.Context) *queryCtx {
return &queryCtx{
Category: q.Category.WithContext(ctx),
Drafting: q.Drafting.WithContext(ctx),
PublishedGi: q.PublishedGi.WithContext(ctx),
TrainModel: q.TrainModel.WithContext(ctx),
User: q.User.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
}