1
0
mirror of https://github.com/astaxie/beego.git synced 2024-11-22 07:10:55 +00:00

rename modelRegister to modelCacheHandler

This commit is contained in:
Anker Jam 2020-09-02 00:33:46 +08:00
parent 7574b91760
commit 7a53baaf9b
4 changed files with 22 additions and 15 deletions

View File

@ -32,7 +32,7 @@ var _ TxOrmer = new(filterOrmDecorator)
type filterOrmDecorator struct {
ormer
modelRegister
modelCacheHandler
TxBeginner
TxCommitter
@ -44,15 +44,15 @@ type filterOrmDecorator struct {
}
func (f *filterOrmDecorator) RegisterModels(models ...interface{}) (err error) {
return f.modelRegister.RegisterModels(models...)
return f.modelCacheHandler.RegisterModels(models...)
}
func (f *filterOrmDecorator) RegisterModelsWithPrefix(prefix string, models ...interface{}) (err error) {
return f.modelRegister.RegisterModelsWithPrefix(prefix, models...)
return f.modelCacheHandler.RegisterModelsWithPrefix(prefix, models...)
}
func (f *filterOrmDecorator) RegisterModelsWithSuffix(suffix string, models ...interface{}) (err error) {
return f.modelRegister.RegisterModelsWithSuffix(suffix, models...)
return f.modelCacheHandler.RegisterModelsWithSuffix(suffix, models...)
}
func NewFilterOrmDecorator(delegate Ormer, filterChains ...FilterChain) Ormer {

View File

@ -33,13 +33,10 @@ const (
)
var (
modelCache = &_modelCache{
cache: make(map[string]*modelInfo),
cacheByFullName: make(map[string]*modelInfo),
}
modelCache = NewModelCacheHandler()
)
type modelRegister interface {
type modelCacheHandler interface {
//RegisterModels register models without prefix or suffix
RegisterModels(models ...interface{}) (err error)
//RegisterModelsWithPrefix register models with prefix
@ -57,7 +54,15 @@ type _modelCache struct {
done bool
}
var _ modelRegister = new(_modelCache)
//NewModelCacheHandler generator of _modelCache
func NewModelCacheHandler() *_modelCache {
return &_modelCache{
cache: make(map[string]*modelInfo),
cacheByFullName: make(map[string]*modelInfo),
}
}
var _ modelCacheHandler = new(_modelCache)
func (mc *_modelCache) RegisterModels(models ...interface{}) (err error) {
return mc.register(``, true, models...)

View File

@ -498,21 +498,21 @@ func (o *ormBase) DBStats() *sql.DBStats {
type orm struct {
ormBase
modelRegister
modelCacheHandler
}
var _ Ormer = new(orm)
func (o *orm) RegisterModels(models ...interface{}) (err error) {
return o.modelRegister.RegisterModels(models)
return o.modelCacheHandler.RegisterModels(models)
}
func (o *orm) RegisterModelsWithPrefix(prefix string, models ...interface{}) (err error) {
return o.modelRegister.RegisterModelsWithPrefix(prefix, models...)
return o.modelCacheHandler.RegisterModelsWithPrefix(prefix, models...)
}
func (o *orm) RegisterModelsWithSuffix(suffix string, models ...interface{}) (err error) {
return o.modelRegister.RegisterModelsWithSuffix(suffix, models...)
return o.modelCacheHandler.RegisterModelsWithSuffix(suffix, models...)
}
func (o *orm) Begin() (TxOrmer, error) {
@ -635,6 +635,8 @@ func newDBWithAlias(al *alias) Ormer {
o.db = al.DB
}
o.modelCacheHandler = NewModelCacheHandler()
if len(globalFilterChains) > 0 {
return NewFilterOrmDecorator(o, globalFilterChains...)
}

View File

@ -214,7 +214,7 @@ type ormer interface {
type Ormer interface {
ormer
modelRegister
modelCacheHandler
TxBeginner
}