2023-07-14 10:16:58 +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 dbquery
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"database/sql"
|
|
|
|
|
|
|
|
"gorm.io/gorm"
|
|
|
|
|
|
|
|
"gorm.io/gen"
|
|
|
|
|
|
|
|
"gorm.io/plugin/dbresolver"
|
|
|
|
)
|
|
|
|
|
|
|
|
var (
|
2023-11-22 17:05:38 +08:00
|
|
|
Q = new(Query)
|
|
|
|
AuthAPIPath *authAPIPath
|
|
|
|
AuthRole *authRole
|
|
|
|
AuthRoleAPIPath *authRoleAPIPath
|
|
|
|
AuthRoleUser *authRoleUser
|
|
|
|
Category *category
|
|
|
|
Drafting *drafting
|
|
|
|
Project *project
|
|
|
|
ProjectPublishLink *projectPublishLink
|
|
|
|
ProjectRunConfig *projectRunConfig
|
|
|
|
Published *published
|
|
|
|
PublishedVersion *publishedVersion
|
|
|
|
TrainInfo *trainInfo
|
|
|
|
User *user
|
2023-07-14 10:16:58 +08:00
|
|
|
)
|
|
|
|
|
|
|
|
func SetDefault(db *gorm.DB, opts ...gen.DOOption) {
|
|
|
|
*Q = *Use(db, opts...)
|
2023-08-30 09:28:21 +08:00
|
|
|
AuthAPIPath = &Q.AuthAPIPath
|
|
|
|
AuthRole = &Q.AuthRole
|
|
|
|
AuthRoleAPIPath = &Q.AuthRoleAPIPath
|
|
|
|
AuthRoleUser = &Q.AuthRoleUser
|
2023-08-03 17:01:28 +08:00
|
|
|
Category = &Q.Category
|
2023-07-14 10:16:58 +08:00
|
|
|
Drafting = &Q.Drafting
|
2023-08-25 10:41:13 +08:00
|
|
|
Project = &Q.Project
|
|
|
|
ProjectPublishLink = &Q.ProjectPublishLink
|
2023-10-24 16:37:27 +08:00
|
|
|
ProjectRunConfig = &Q.ProjectRunConfig
|
2023-11-17 16:22:22 +08:00
|
|
|
Published = &Q.Published
|
|
|
|
PublishedVersion = &Q.PublishedVersion
|
|
|
|
TrainInfo = &Q.TrainInfo
|
2023-07-14 10:16:58 +08:00
|
|
|
User = &Q.User
|
|
|
|
}
|
|
|
|
|
|
|
|
func Use(db *gorm.DB, opts ...gen.DOOption) *Query {
|
|
|
|
return &Query{
|
2023-11-22 17:05:38 +08:00
|
|
|
db: db,
|
|
|
|
AuthAPIPath: newAuthAPIPath(db, opts...),
|
|
|
|
AuthRole: newAuthRole(db, opts...),
|
|
|
|
AuthRoleAPIPath: newAuthRoleAPIPath(db, opts...),
|
|
|
|
AuthRoleUser: newAuthRoleUser(db, opts...),
|
|
|
|
Category: newCategory(db, opts...),
|
|
|
|
Drafting: newDrafting(db, opts...),
|
|
|
|
Project: newProject(db, opts...),
|
|
|
|
ProjectPublishLink: newProjectPublishLink(db, opts...),
|
|
|
|
ProjectRunConfig: newProjectRunConfig(db, opts...),
|
|
|
|
Published: newPublished(db, opts...),
|
|
|
|
PublishedVersion: newPublishedVersion(db, opts...),
|
|
|
|
TrainInfo: newTrainInfo(db, opts...),
|
|
|
|
User: newUser(db, opts...),
|
2023-07-14 10:16:58 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
type Query struct {
|
|
|
|
db *gorm.DB
|
|
|
|
|
2023-11-22 17:05:38 +08:00
|
|
|
AuthAPIPath authAPIPath
|
|
|
|
AuthRole authRole
|
|
|
|
AuthRoleAPIPath authRoleAPIPath
|
|
|
|
AuthRoleUser authRoleUser
|
|
|
|
Category category
|
|
|
|
Drafting drafting
|
|
|
|
Project project
|
|
|
|
ProjectPublishLink projectPublishLink
|
|
|
|
ProjectRunConfig projectRunConfig
|
|
|
|
Published published
|
|
|
|
PublishedVersion publishedVersion
|
|
|
|
TrainInfo trainInfo
|
|
|
|
User user
|
2023-07-14 10:16:58 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
func (q *Query) Available() bool { return q.db != nil }
|
|
|
|
|
|
|
|
func (q *Query) clone(db *gorm.DB) *Query {
|
|
|
|
return &Query{
|
2023-11-22 17:05:38 +08:00
|
|
|
db: db,
|
|
|
|
AuthAPIPath: q.AuthAPIPath.clone(db),
|
|
|
|
AuthRole: q.AuthRole.clone(db),
|
|
|
|
AuthRoleAPIPath: q.AuthRoleAPIPath.clone(db),
|
|
|
|
AuthRoleUser: q.AuthRoleUser.clone(db),
|
|
|
|
Category: q.Category.clone(db),
|
|
|
|
Drafting: q.Drafting.clone(db),
|
|
|
|
Project: q.Project.clone(db),
|
|
|
|
ProjectPublishLink: q.ProjectPublishLink.clone(db),
|
|
|
|
ProjectRunConfig: q.ProjectRunConfig.clone(db),
|
|
|
|
Published: q.Published.clone(db),
|
|
|
|
PublishedVersion: q.PublishedVersion.clone(db),
|
|
|
|
TrainInfo: q.TrainInfo.clone(db),
|
|
|
|
User: q.User.clone(db),
|
2023-07-14 10:16:58 +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{
|
2023-11-22 17:05:38 +08:00
|
|
|
db: db,
|
|
|
|
AuthAPIPath: q.AuthAPIPath.replaceDB(db),
|
|
|
|
AuthRole: q.AuthRole.replaceDB(db),
|
|
|
|
AuthRoleAPIPath: q.AuthRoleAPIPath.replaceDB(db),
|
|
|
|
AuthRoleUser: q.AuthRoleUser.replaceDB(db),
|
|
|
|
Category: q.Category.replaceDB(db),
|
|
|
|
Drafting: q.Drafting.replaceDB(db),
|
|
|
|
Project: q.Project.replaceDB(db),
|
|
|
|
ProjectPublishLink: q.ProjectPublishLink.replaceDB(db),
|
|
|
|
ProjectRunConfig: q.ProjectRunConfig.replaceDB(db),
|
|
|
|
Published: q.Published.replaceDB(db),
|
|
|
|
PublishedVersion: q.PublishedVersion.replaceDB(db),
|
|
|
|
TrainInfo: q.TrainInfo.replaceDB(db),
|
|
|
|
User: q.User.replaceDB(db),
|
2023-07-14 10:16:58 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
type queryCtx struct {
|
2023-11-22 17:05:38 +08:00
|
|
|
AuthAPIPath IAuthAPIPathDo
|
|
|
|
AuthRole IAuthRoleDo
|
|
|
|
AuthRoleAPIPath IAuthRoleAPIPathDo
|
|
|
|
AuthRoleUser IAuthRoleUserDo
|
|
|
|
Category ICategoryDo
|
|
|
|
Drafting IDraftingDo
|
|
|
|
Project IProjectDo
|
|
|
|
ProjectPublishLink IProjectPublishLinkDo
|
|
|
|
ProjectRunConfig IProjectRunConfigDo
|
|
|
|
Published IPublishedDo
|
|
|
|
PublishedVersion IPublishedVersionDo
|
|
|
|
TrainInfo ITrainInfoDo
|
|
|
|
User IUserDo
|
2023-07-14 10:16:58 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
func (q *Query) WithContext(ctx context.Context) *queryCtx {
|
|
|
|
return &queryCtx{
|
2023-11-22 17:05:38 +08:00
|
|
|
AuthAPIPath: q.AuthAPIPath.WithContext(ctx),
|
|
|
|
AuthRole: q.AuthRole.WithContext(ctx),
|
|
|
|
AuthRoleAPIPath: q.AuthRoleAPIPath.WithContext(ctx),
|
|
|
|
AuthRoleUser: q.AuthRoleUser.WithContext(ctx),
|
|
|
|
Category: q.Category.WithContext(ctx),
|
|
|
|
Drafting: q.Drafting.WithContext(ctx),
|
|
|
|
Project: q.Project.WithContext(ctx),
|
|
|
|
ProjectPublishLink: q.ProjectPublishLink.WithContext(ctx),
|
|
|
|
ProjectRunConfig: q.ProjectRunConfig.WithContext(ctx),
|
|
|
|
Published: q.Published.WithContext(ctx),
|
|
|
|
PublishedVersion: q.PublishedVersion.WithContext(ctx),
|
|
|
|
TrainInfo: q.TrainInfo.WithContext(ctx),
|
|
|
|
User: q.User.WithContext(ctx),
|
2023-07-14 10:16:58 +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
|
|
|
|
}
|