Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
二次元的罪恶王冠
beego
提交
7574b917
B
beego
项目概览
二次元的罪恶王冠
/
beego
与 Fork 源项目一致
从无法访问的项目Fork
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
B
beego
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
7574b917
编写于
9月 02, 2020
作者:
A
Anker Jam
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
add type modelRegister interface into Ormer
上级
e54dbabf
变更
6
隐藏空白更改
内联
并排
Showing
6 changed file
with
62 addition
and
7 deletion
+62
-7
pkg/client/orm/do_nothing_orm.go
pkg/client/orm/do_nothing_orm.go
+12
-0
pkg/client/orm/filter_orm_decorator.go
pkg/client/orm/filter_orm_decorator.go
+13
-0
pkg/client/orm/models.go
pkg/client/orm/models.go
+23
-0
pkg/client/orm/models_boot.go
pkg/client/orm/models_boot.go
+0
-7
pkg/client/orm/orm.go
pkg/client/orm/orm.go
+13
-0
pkg/client/orm/types.go
pkg/client/orm/types.go
+1
-0
未找到文件。
pkg/client/orm/do_nothing_orm.go
浏览文件 @
7574b917
...
...
@@ -30,6 +30,18 @@ var _ Ormer = new(DoNothingOrm)
type
DoNothingOrm
struct
{
}
func
(
d
*
DoNothingOrm
)
RegisterModels
(
models
...
interface
{})
(
err
error
)
{
return
nil
}
func
(
d
*
DoNothingOrm
)
RegisterModelsWithPrefix
(
prefix
string
,
models
...
interface
{})
(
err
error
)
{
return
nil
}
func
(
d
*
DoNothingOrm
)
RegisterModelsWithSuffix
(
suffix
string
,
models
...
interface
{})
(
err
error
)
{
return
nil
}
func
(
d
*
DoNothingOrm
)
Read
(
md
interface
{},
cols
...
string
)
error
{
return
nil
}
...
...
pkg/client/orm/filter_orm_decorator.go
浏览文件 @
7574b917
...
...
@@ -32,6 +32,7 @@ var _ TxOrmer = new(filterOrmDecorator)
type
filterOrmDecorator
struct
{
ormer
modelRegister
TxBeginner
TxCommitter
...
...
@@ -42,6 +43,18 @@ type filterOrmDecorator struct {
txName
string
}
func
(
f
*
filterOrmDecorator
)
RegisterModels
(
models
...
interface
{})
(
err
error
)
{
return
f
.
modelRegister
.
RegisterModels
(
models
...
)
}
func
(
f
*
filterOrmDecorator
)
RegisterModelsWithPrefix
(
prefix
string
,
models
...
interface
{})
(
err
error
)
{
return
f
.
modelRegister
.
RegisterModelsWithPrefix
(
prefix
,
models
...
)
}
func
(
f
*
filterOrmDecorator
)
RegisterModelsWithSuffix
(
suffix
string
,
models
...
interface
{})
(
err
error
)
{
return
f
.
modelRegister
.
RegisterModelsWithSuffix
(
suffix
,
models
...
)
}
func
NewFilterOrmDecorator
(
delegate
Ormer
,
filterChains
...
FilterChain
)
Ormer
{
res
:=
&
filterOrmDecorator
{
ormer
:
delegate
,
...
...
pkg/client/orm/models.go
浏览文件 @
7574b917
...
...
@@ -39,6 +39,15 @@ var (
}
)
type
modelRegister
interface
{
//RegisterModels register models without prefix or suffix
RegisterModels
(
models
...
interface
{})
(
err
error
)
//RegisterModelsWithPrefix register models with prefix
RegisterModelsWithPrefix
(
prefix
string
,
models
...
interface
{})
(
err
error
)
//RegisterModelsWithSuffix register models with suffix
RegisterModelsWithSuffix
(
suffix
string
,
models
...
interface
{})
(
err
error
)
}
// model info collection
type
_modelCache
struct
{
sync
.
RWMutex
// only used outsite for bootStrap
...
...
@@ -48,6 +57,20 @@ type _modelCache struct {
done
bool
}
var
_
modelRegister
=
new
(
_modelCache
)
func
(
mc
*
_modelCache
)
RegisterModels
(
models
...
interface
{})
(
err
error
)
{
return
mc
.
register
(
``
,
true
,
models
...
)
}
func
(
mc
*
_modelCache
)
RegisterModelsWithPrefix
(
prefix
string
,
models
...
interface
{})
(
err
error
)
{
return
mc
.
register
(
prefix
,
true
,
models
...
)
}
func
(
mc
*
_modelCache
)
RegisterModelsWithSuffix
(
suffix
string
,
models
...
interface
{})
(
err
error
)
{
return
mc
.
register
(
suffix
,
false
,
models
...
)
}
// get all model info
func
(
mc
*
_modelCache
)
all
()
map
[
string
]
*
modelInfo
{
m
:=
make
(
map
[
string
]
*
modelInfo
,
len
(
mc
.
cache
))
...
...
pkg/client/orm/models_boot.go
浏览文件 @
7574b917
...
...
@@ -14,15 +14,8 @@
package
orm
import
(
"fmt"
)
// RegisterModel register models
func
RegisterModel
(
models
...
interface
{})
{
if
modelCache
.
done
{
panic
(
fmt
.
Errorf
(
"RegisterModel must be run before BootStrap"
))
}
RegisterModelWithPrefix
(
""
,
models
...
)
}
...
...
pkg/client/orm/orm.go
浏览文件 @
7574b917
...
...
@@ -498,10 +498,23 @@ func (o *ormBase) DBStats() *sql.DBStats {
type
orm
struct
{
ormBase
modelRegister
}
var
_
Ormer
=
new
(
orm
)
func
(
o
*
orm
)
RegisterModels
(
models
...
interface
{})
(
err
error
)
{
return
o
.
modelRegister
.
RegisterModels
(
models
)
}
func
(
o
*
orm
)
RegisterModelsWithPrefix
(
prefix
string
,
models
...
interface
{})
(
err
error
)
{
return
o
.
modelRegister
.
RegisterModelsWithPrefix
(
prefix
,
models
...
)
}
func
(
o
*
orm
)
RegisterModelsWithSuffix
(
suffix
string
,
models
...
interface
{})
(
err
error
)
{
return
o
.
modelRegister
.
RegisterModelsWithSuffix
(
suffix
,
models
...
)
}
func
(
o
*
orm
)
Begin
()
(
TxOrmer
,
error
)
{
return
o
.
BeginWithCtx
(
context
.
Background
())
}
...
...
pkg/client/orm/types.go
浏览文件 @
7574b917
...
...
@@ -214,6 +214,7 @@ type ormer interface {
type
Ormer
interface
{
ormer
modelRegister
TxBeginner
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录