Files
go_process_manager/internal/app/repository/query/gen.go
2025-08-29 16:25:43 +08:00

168 lines
3.7 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 query
import (
"context"
"database/sql"
"gorm.io/gorm"
"gorm.io/gen"
"gorm.io/plugin/dbresolver"
)
var (
Q = new(Query)
Config *config
Event *event
Permission *permission
Process *process
ProcessLog *processLog
Push *push
Task *task
User *user
WsShare *wsShare
)
func SetDefault(db *gorm.DB, opts ...gen.DOOption) {
*Q = *Use(db, opts...)
Config = &Q.Config
Event = &Q.Event
Permission = &Q.Permission
Process = &Q.Process
ProcessLog = &Q.ProcessLog
Push = &Q.Push
Task = &Q.Task
User = &Q.User
WsShare = &Q.WsShare
}
func Use(db *gorm.DB, opts ...gen.DOOption) *Query {
return &Query{
db: db,
Config: newConfig(db, opts...),
Event: newEvent(db, opts...),
Permission: newPermission(db, opts...),
Process: newProcess(db, opts...),
ProcessLog: newProcessLog(db, opts...),
Push: newPush(db, opts...),
Task: newTask(db, opts...),
User: newUser(db, opts...),
WsShare: newWsShare(db, opts...),
}
}
type Query struct {
db *gorm.DB
Config config
Event event
Permission permission
Process process
ProcessLog processLog
Push push
Task task
User user
WsShare wsShare
}
func (q *Query) Available() bool { return q.db != nil }
func (q *Query) clone(db *gorm.DB) *Query {
return &Query{
db: db,
Config: q.Config.clone(db),
Event: q.Event.clone(db),
Permission: q.Permission.clone(db),
Process: q.Process.clone(db),
ProcessLog: q.ProcessLog.clone(db),
Push: q.Push.clone(db),
Task: q.Task.clone(db),
User: q.User.clone(db),
WsShare: q.WsShare.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,
Config: q.Config.replaceDB(db),
Event: q.Event.replaceDB(db),
Permission: q.Permission.replaceDB(db),
Process: q.Process.replaceDB(db),
ProcessLog: q.ProcessLog.replaceDB(db),
Push: q.Push.replaceDB(db),
Task: q.Task.replaceDB(db),
User: q.User.replaceDB(db),
WsShare: q.WsShare.replaceDB(db),
}
}
type queryCtx struct {
Config IConfigDo
Event IEventDo
Permission IPermissionDo
Process IProcessDo
ProcessLog IProcessLogDo
Push IPushDo
Task ITaskDo
User IUserDo
WsShare IWsShareDo
}
func (q *Query) WithContext(ctx context.Context) *queryCtx {
return &queryCtx{
Config: q.Config.WithContext(ctx),
Event: q.Event.WithContext(ctx),
Permission: q.Permission.WithContext(ctx),
Process: q.Process.WithContext(ctx),
ProcessLog: q.ProcessLog.WithContext(ctx),
Push: q.Push.WithContext(ctx),
Task: q.Task.WithContext(ctx),
User: q.User.WithContext(ctx),
WsShare: q.WsShare.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
}