// 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)
	CasbinRule                 *casbinRule
	ExaAttachmentCategory      *exaAttachmentCategory
	ExaCustomer                *exaCustomer
	ExaFile                    *exaFile
	ExaFileChunk               *exaFileChunk
	ExaFileUploadAndDownload   *exaFileUploadAndDownload
	GvaAnnouncementsInfo       *gvaAnnouncementsInfo
	JwtBlacklist               *jwtBlacklist
	SysAPI                     *sysAPI
	SysAuthority               *sysAuthority
	SysAuthorityBtn            *sysAuthorityBtn
	SysAuthorityMenu           *sysAuthorityMenu
	SysAutoCodeHistory         *sysAutoCodeHistory
	SysAutoCodePackage         *sysAutoCodePackage
	SysBaseMenu                *sysBaseMenu
	SysBaseMenuBtn             *sysBaseMenuBtn
	SysBaseMenuParameter       *sysBaseMenuParameter
	SysDataAuthorityID         *sysDataAuthorityID
	SysDictionary              *sysDictionary
	SysDictionaryDetail        *sysDictionaryDetail
	SysError                   *sysError
	SysExportTemplate          *sysExportTemplate
	SysExportTemplateCondition *sysExportTemplateCondition
	SysExportTemplateJoin      *sysExportTemplateJoin
	SysIgnoreAPI               *sysIgnoreAPI
	SysOperationRecord         *sysOperationRecord
	SysParam                   *sysParam
	SysUser                    *sysUser
	SysUserAuthority           *sysUserAuthority
	SysVersion                 *sysVersion
)

func SetDefault(db *gorm.DB, opts ...gen.DOOption) {
	*Q = *Use(db, opts...)
	CasbinRule = &Q.CasbinRule
	ExaAttachmentCategory = &Q.ExaAttachmentCategory
	ExaCustomer = &Q.ExaCustomer
	ExaFile = &Q.ExaFile
	ExaFileChunk = &Q.ExaFileChunk
	ExaFileUploadAndDownload = &Q.ExaFileUploadAndDownload
	GvaAnnouncementsInfo = &Q.GvaAnnouncementsInfo
	JwtBlacklist = &Q.JwtBlacklist
	SysAPI = &Q.SysAPI
	SysAuthority = &Q.SysAuthority
	SysAuthorityBtn = &Q.SysAuthorityBtn
	SysAuthorityMenu = &Q.SysAuthorityMenu
	SysAutoCodeHistory = &Q.SysAutoCodeHistory
	SysAutoCodePackage = &Q.SysAutoCodePackage
	SysBaseMenu = &Q.SysBaseMenu
	SysBaseMenuBtn = &Q.SysBaseMenuBtn
	SysBaseMenuParameter = &Q.SysBaseMenuParameter
	SysDataAuthorityID = &Q.SysDataAuthorityID
	SysDictionary = &Q.SysDictionary
	SysDictionaryDetail = &Q.SysDictionaryDetail
	SysError = &Q.SysError
	SysExportTemplate = &Q.SysExportTemplate
	SysExportTemplateCondition = &Q.SysExportTemplateCondition
	SysExportTemplateJoin = &Q.SysExportTemplateJoin
	SysIgnoreAPI = &Q.SysIgnoreAPI
	SysOperationRecord = &Q.SysOperationRecord
	SysParam = &Q.SysParam
	SysUser = &Q.SysUser
	SysUserAuthority = &Q.SysUserAuthority
	SysVersion = &Q.SysVersion
}

func Use(db *gorm.DB, opts ...gen.DOOption) *Query {
	return &Query{
		db:                         db,
		CasbinRule:                 newCasbinRule(db, opts...),
		ExaAttachmentCategory:      newExaAttachmentCategory(db, opts...),
		ExaCustomer:                newExaCustomer(db, opts...),
		ExaFile:                    newExaFile(db, opts...),
		ExaFileChunk:               newExaFileChunk(db, opts...),
		ExaFileUploadAndDownload:   newExaFileUploadAndDownload(db, opts...),
		GvaAnnouncementsInfo:       newGvaAnnouncementsInfo(db, opts...),
		JwtBlacklist:               newJwtBlacklist(db, opts...),
		SysAPI:                     newSysAPI(db, opts...),
		SysAuthority:               newSysAuthority(db, opts...),
		SysAuthorityBtn:            newSysAuthorityBtn(db, opts...),
		SysAuthorityMenu:           newSysAuthorityMenu(db, opts...),
		SysAutoCodeHistory:         newSysAutoCodeHistory(db, opts...),
		SysAutoCodePackage:         newSysAutoCodePackage(db, opts...),
		SysBaseMenu:                newSysBaseMenu(db, opts...),
		SysBaseMenuBtn:             newSysBaseMenuBtn(db, opts...),
		SysBaseMenuParameter:       newSysBaseMenuParameter(db, opts...),
		SysDataAuthorityID:         newSysDataAuthorityID(db, opts...),
		SysDictionary:              newSysDictionary(db, opts...),
		SysDictionaryDetail:        newSysDictionaryDetail(db, opts...),
		SysError:                   newSysError(db, opts...),
		SysExportTemplate:          newSysExportTemplate(db, opts...),
		SysExportTemplateCondition: newSysExportTemplateCondition(db, opts...),
		SysExportTemplateJoin:      newSysExportTemplateJoin(db, opts...),
		SysIgnoreAPI:               newSysIgnoreAPI(db, opts...),
		SysOperationRecord:         newSysOperationRecord(db, opts...),
		SysParam:                   newSysParam(db, opts...),
		SysUser:                    newSysUser(db, opts...),
		SysUserAuthority:           newSysUserAuthority(db, opts...),
		SysVersion:                 newSysVersion(db, opts...),
	}
}

type Query struct {
	db *gorm.DB

	CasbinRule                 casbinRule
	ExaAttachmentCategory      exaAttachmentCategory
	ExaCustomer                exaCustomer
	ExaFile                    exaFile
	ExaFileChunk               exaFileChunk
	ExaFileUploadAndDownload   exaFileUploadAndDownload
	GvaAnnouncementsInfo       gvaAnnouncementsInfo
	JwtBlacklist               jwtBlacklist
	SysAPI                     sysAPI
	SysAuthority               sysAuthority
	SysAuthorityBtn            sysAuthorityBtn
	SysAuthorityMenu           sysAuthorityMenu
	SysAutoCodeHistory         sysAutoCodeHistory
	SysAutoCodePackage         sysAutoCodePackage
	SysBaseMenu                sysBaseMenu
	SysBaseMenuBtn             sysBaseMenuBtn
	SysBaseMenuParameter       sysBaseMenuParameter
	SysDataAuthorityID         sysDataAuthorityID
	SysDictionary              sysDictionary
	SysDictionaryDetail        sysDictionaryDetail
	SysError                   sysError
	SysExportTemplate          sysExportTemplate
	SysExportTemplateCondition sysExportTemplateCondition
	SysExportTemplateJoin      sysExportTemplateJoin
	SysIgnoreAPI               sysIgnoreAPI
	SysOperationRecord         sysOperationRecord
	SysParam                   sysParam
	SysUser                    sysUser
	SysUserAuthority           sysUserAuthority
	SysVersion                 sysVersion
}

func (q *Query) Available() bool { return q.db != nil }

func (q *Query) clone(db *gorm.DB) *Query {
	return &Query{
		db:                         db,
		CasbinRule:                 q.CasbinRule.clone(db),
		ExaAttachmentCategory:      q.ExaAttachmentCategory.clone(db),
		ExaCustomer:                q.ExaCustomer.clone(db),
		ExaFile:                    q.ExaFile.clone(db),
		ExaFileChunk:               q.ExaFileChunk.clone(db),
		ExaFileUploadAndDownload:   q.ExaFileUploadAndDownload.clone(db),
		GvaAnnouncementsInfo:       q.GvaAnnouncementsInfo.clone(db),
		JwtBlacklist:               q.JwtBlacklist.clone(db),
		SysAPI:                     q.SysAPI.clone(db),
		SysAuthority:               q.SysAuthority.clone(db),
		SysAuthorityBtn:            q.SysAuthorityBtn.clone(db),
		SysAuthorityMenu:           q.SysAuthorityMenu.clone(db),
		SysAutoCodeHistory:         q.SysAutoCodeHistory.clone(db),
		SysAutoCodePackage:         q.SysAutoCodePackage.clone(db),
		SysBaseMenu:                q.SysBaseMenu.clone(db),
		SysBaseMenuBtn:             q.SysBaseMenuBtn.clone(db),
		SysBaseMenuParameter:       q.SysBaseMenuParameter.clone(db),
		SysDataAuthorityID:         q.SysDataAuthorityID.clone(db),
		SysDictionary:              q.SysDictionary.clone(db),
		SysDictionaryDetail:        q.SysDictionaryDetail.clone(db),
		SysError:                   q.SysError.clone(db),
		SysExportTemplate:          q.SysExportTemplate.clone(db),
		SysExportTemplateCondition: q.SysExportTemplateCondition.clone(db),
		SysExportTemplateJoin:      q.SysExportTemplateJoin.clone(db),
		SysIgnoreAPI:               q.SysIgnoreAPI.clone(db),
		SysOperationRecord:         q.SysOperationRecord.clone(db),
		SysParam:                   q.SysParam.clone(db),
		SysUser:                    q.SysUser.clone(db),
		SysUserAuthority:           q.SysUserAuthority.clone(db),
		SysVersion:                 q.SysVersion.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,
		CasbinRule:                 q.CasbinRule.replaceDB(db),
		ExaAttachmentCategory:      q.ExaAttachmentCategory.replaceDB(db),
		ExaCustomer:                q.ExaCustomer.replaceDB(db),
		ExaFile:                    q.ExaFile.replaceDB(db),
		ExaFileChunk:               q.ExaFileChunk.replaceDB(db),
		ExaFileUploadAndDownload:   q.ExaFileUploadAndDownload.replaceDB(db),
		GvaAnnouncementsInfo:       q.GvaAnnouncementsInfo.replaceDB(db),
		JwtBlacklist:               q.JwtBlacklist.replaceDB(db),
		SysAPI:                     q.SysAPI.replaceDB(db),
		SysAuthority:               q.SysAuthority.replaceDB(db),
		SysAuthorityBtn:            q.SysAuthorityBtn.replaceDB(db),
		SysAuthorityMenu:           q.SysAuthorityMenu.replaceDB(db),
		SysAutoCodeHistory:         q.SysAutoCodeHistory.replaceDB(db),
		SysAutoCodePackage:         q.SysAutoCodePackage.replaceDB(db),
		SysBaseMenu:                q.SysBaseMenu.replaceDB(db),
		SysBaseMenuBtn:             q.SysBaseMenuBtn.replaceDB(db),
		SysBaseMenuParameter:       q.SysBaseMenuParameter.replaceDB(db),
		SysDataAuthorityID:         q.SysDataAuthorityID.replaceDB(db),
		SysDictionary:              q.SysDictionary.replaceDB(db),
		SysDictionaryDetail:        q.SysDictionaryDetail.replaceDB(db),
		SysError:                   q.SysError.replaceDB(db),
		SysExportTemplate:          q.SysExportTemplate.replaceDB(db),
		SysExportTemplateCondition: q.SysExportTemplateCondition.replaceDB(db),
		SysExportTemplateJoin:      q.SysExportTemplateJoin.replaceDB(db),
		SysIgnoreAPI:               q.SysIgnoreAPI.replaceDB(db),
		SysOperationRecord:         q.SysOperationRecord.replaceDB(db),
		SysParam:                   q.SysParam.replaceDB(db),
		SysUser:                    q.SysUser.replaceDB(db),
		SysUserAuthority:           q.SysUserAuthority.replaceDB(db),
		SysVersion:                 q.SysVersion.replaceDB(db),
	}
}

type queryCtx struct {
	CasbinRule                 ICasbinRuleDo
	ExaAttachmentCategory      IExaAttachmentCategoryDo
	ExaCustomer                IExaCustomerDo
	ExaFile                    IExaFileDo
	ExaFileChunk               IExaFileChunkDo
	ExaFileUploadAndDownload   IExaFileUploadAndDownloadDo
	GvaAnnouncementsInfo       IGvaAnnouncementsInfoDo
	JwtBlacklist               IJwtBlacklistDo
	SysAPI                     ISysAPIDo
	SysAuthority               ISysAuthorityDo
	SysAuthorityBtn            ISysAuthorityBtnDo
	SysAuthorityMenu           ISysAuthorityMenuDo
	SysAutoCodeHistory         ISysAutoCodeHistoryDo
	SysAutoCodePackage         ISysAutoCodePackageDo
	SysBaseMenu                ISysBaseMenuDo
	SysBaseMenuBtn             ISysBaseMenuBtnDo
	SysBaseMenuParameter       ISysBaseMenuParameterDo
	SysDataAuthorityID         ISysDataAuthorityIDDo
	SysDictionary              ISysDictionaryDo
	SysDictionaryDetail        ISysDictionaryDetailDo
	SysError                   ISysErrorDo
	SysExportTemplate          ISysExportTemplateDo
	SysExportTemplateCondition ISysExportTemplateConditionDo
	SysExportTemplateJoin      ISysExportTemplateJoinDo
	SysIgnoreAPI               ISysIgnoreAPIDo
	SysOperationRecord         ISysOperationRecordDo
	SysParam                   ISysParamDo
	SysUser                    ISysUserDo
	SysUserAuthority           ISysUserAuthorityDo
	SysVersion                 ISysVersionDo
}

func (q *Query) WithContext(ctx context.Context) *queryCtx {
	return &queryCtx{
		CasbinRule:                 q.CasbinRule.WithContext(ctx),
		ExaAttachmentCategory:      q.ExaAttachmentCategory.WithContext(ctx),
		ExaCustomer:                q.ExaCustomer.WithContext(ctx),
		ExaFile:                    q.ExaFile.WithContext(ctx),
		ExaFileChunk:               q.ExaFileChunk.WithContext(ctx),
		ExaFileUploadAndDownload:   q.ExaFileUploadAndDownload.WithContext(ctx),
		GvaAnnouncementsInfo:       q.GvaAnnouncementsInfo.WithContext(ctx),
		JwtBlacklist:               q.JwtBlacklist.WithContext(ctx),
		SysAPI:                     q.SysAPI.WithContext(ctx),
		SysAuthority:               q.SysAuthority.WithContext(ctx),
		SysAuthorityBtn:            q.SysAuthorityBtn.WithContext(ctx),
		SysAuthorityMenu:           q.SysAuthorityMenu.WithContext(ctx),
		SysAutoCodeHistory:         q.SysAutoCodeHistory.WithContext(ctx),
		SysAutoCodePackage:         q.SysAutoCodePackage.WithContext(ctx),
		SysBaseMenu:                q.SysBaseMenu.WithContext(ctx),
		SysBaseMenuBtn:             q.SysBaseMenuBtn.WithContext(ctx),
		SysBaseMenuParameter:       q.SysBaseMenuParameter.WithContext(ctx),
		SysDataAuthorityID:         q.SysDataAuthorityID.WithContext(ctx),
		SysDictionary:              q.SysDictionary.WithContext(ctx),
		SysDictionaryDetail:        q.SysDictionaryDetail.WithContext(ctx),
		SysError:                   q.SysError.WithContext(ctx),
		SysExportTemplate:          q.SysExportTemplate.WithContext(ctx),
		SysExportTemplateCondition: q.SysExportTemplateCondition.WithContext(ctx),
		SysExportTemplateJoin:      q.SysExportTemplateJoin.WithContext(ctx),
		SysIgnoreAPI:               q.SysIgnoreAPI.WithContext(ctx),
		SysOperationRecord:         q.SysOperationRecord.WithContext(ctx),
		SysParam:                   q.SysParam.WithContext(ctx),
		SysUser:                    q.SysUser.WithContext(ctx),
		SysUserAuthority:           q.SysUserAuthority.WithContext(ctx),
		SysVersion:                 q.SysVersion.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
}
