156 lines
4.3 KiB
Go
156 lines
4.3 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)
|
|
Migration *migration
|
|
SysAPI *sysAPI
|
|
SysDictionary *sysDictionary
|
|
SysDictionaryDetail *sysDictionaryDetail
|
|
SysOperationRecord *sysOperationRecord
|
|
SysRole *sysRole
|
|
User *user
|
|
UserRole *userRole
|
|
)
|
|
|
|
func SetDefault(db *gorm.DB, opts ...gen.DOOption) {
|
|
*Q = *Use(db, opts...)
|
|
Migration = &Q.Migration
|
|
SysAPI = &Q.SysAPI
|
|
SysDictionary = &Q.SysDictionary
|
|
SysDictionaryDetail = &Q.SysDictionaryDetail
|
|
SysOperationRecord = &Q.SysOperationRecord
|
|
SysRole = &Q.SysRole
|
|
User = &Q.User
|
|
UserRole = &Q.UserRole
|
|
}
|
|
|
|
func Use(db *gorm.DB, opts ...gen.DOOption) *Query {
|
|
return &Query{
|
|
db: db,
|
|
Migration: newMigration(db, opts...),
|
|
SysAPI: newSysAPI(db, opts...),
|
|
SysDictionary: newSysDictionary(db, opts...),
|
|
SysDictionaryDetail: newSysDictionaryDetail(db, opts...),
|
|
SysOperationRecord: newSysOperationRecord(db, opts...),
|
|
SysRole: newSysRole(db, opts...),
|
|
User: newUser(db, opts...),
|
|
UserRole: newUserRole(db, opts...),
|
|
}
|
|
}
|
|
|
|
type Query struct {
|
|
db *gorm.DB
|
|
|
|
Migration migration
|
|
SysAPI sysAPI
|
|
SysDictionary sysDictionary
|
|
SysDictionaryDetail sysDictionaryDetail
|
|
SysOperationRecord sysOperationRecord
|
|
SysRole sysRole
|
|
User user
|
|
UserRole userRole
|
|
}
|
|
|
|
func (q *Query) Available() bool { return q.db != nil }
|
|
|
|
func (q *Query) clone(db *gorm.DB) *Query {
|
|
return &Query{
|
|
db: db,
|
|
Migration: q.Migration.clone(db),
|
|
SysAPI: q.SysAPI.clone(db),
|
|
SysDictionary: q.SysDictionary.clone(db),
|
|
SysDictionaryDetail: q.SysDictionaryDetail.clone(db),
|
|
SysOperationRecord: q.SysOperationRecord.clone(db),
|
|
SysRole: q.SysRole.clone(db),
|
|
User: q.User.clone(db),
|
|
UserRole: q.UserRole.clone(db),
|
|
}
|
|
}
|
|
|
|
func (q *Query) ReadDB() *Query {
|
|
return q.clone(q.db.Clauses(dbresolver.Read))
|
|
}
|
|
|
|
func (q *Query) WriteDB() *Query {
|
|
return q.clone(q.db.Clauses(dbresolver.Write))
|
|
}
|
|
|
|
func (q *Query) ReplaceDB(db *gorm.DB) *Query {
|
|
return &Query{
|
|
db: db,
|
|
Migration: q.Migration.replaceDB(db),
|
|
SysAPI: q.SysAPI.replaceDB(db),
|
|
SysDictionary: q.SysDictionary.replaceDB(db),
|
|
SysDictionaryDetail: q.SysDictionaryDetail.replaceDB(db),
|
|
SysOperationRecord: q.SysOperationRecord.replaceDB(db),
|
|
SysRole: q.SysRole.replaceDB(db),
|
|
User: q.User.replaceDB(db),
|
|
UserRole: q.UserRole.replaceDB(db),
|
|
}
|
|
}
|
|
|
|
type queryCtx struct {
|
|
Migration IMigrationDo
|
|
SysAPI ISysAPIDo
|
|
SysDictionary ISysDictionaryDo
|
|
SysDictionaryDetail ISysDictionaryDetailDo
|
|
SysOperationRecord ISysOperationRecordDo
|
|
SysRole ISysRoleDo
|
|
User IUserDo
|
|
UserRole IUserRoleDo
|
|
}
|
|
|
|
func (q *Query) WithContext(ctx context.Context) *queryCtx {
|
|
return &queryCtx{
|
|
Migration: q.Migration.WithContext(ctx),
|
|
SysAPI: q.SysAPI.WithContext(ctx),
|
|
SysDictionary: q.SysDictionary.WithContext(ctx),
|
|
SysDictionaryDetail: q.SysDictionaryDetail.WithContext(ctx),
|
|
SysOperationRecord: q.SysOperationRecord.WithContext(ctx),
|
|
SysRole: q.SysRole.WithContext(ctx),
|
|
User: q.User.WithContext(ctx),
|
|
UserRole: q.UserRole.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 {
|
|
return &QueryTx{q.clone(q.db.Begin(opts...))}
|
|
}
|
|
|
|
type QueryTx struct{ *Query }
|
|
|
|
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
|
|
}
|