Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
X
xpkg
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
屠思豪
xpkg
Commits
ff4eee31
提交
ff4eee31
authored
12月 11, 2025
作者:
mooncake
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
update
上级
0963312f
隐藏空白字符变更
内嵌
并排
正在显示
1 个修改的文件
包含
13 行增加
和
14 行删除
+13
-14
gormutils.go
xutils/gormutils/gormutils.go
+13
-14
没有找到文件。
xutils/gormutils/gormutils.go
浏览文件 @
ff4eee31
...
...
@@ -22,7 +22,7 @@ func MakeScopes(where, resultType any) func(db *gorm.DB) *gorm.DB {
func
makeScopes
(
db
*
gorm
.
DB
,
where
,
resultType
any
)
*
gorm
.
DB
{
condition
:=
&
gormCondition
{}
resolveSearchQuery
(
where
,
condition
,
resultType
)
makeConditions
(
where
,
condition
,
resultType
)
for
k
,
v
:=
range
condition
.
Where
{
db
=
db
.
Where
(
k
,
v
...
)
...
...
@@ -81,7 +81,7 @@ type joinCondition struct {
gormCondition
}
//
resolveSearchQuery
解析
//
makeConditions
解析
/**
* eq 等于(默认不填都可以)
* like 包含
...
...
@@ -93,13 +93,13 @@ type joinCondition struct {
* isnull
* order 排序 e.g. order[key]=desc order[key]=asc
*/
func
resolveSearchQuery
(
q
any
,
condition
Condition
,
resultType
any
)
{
func
makeConditions
(
q
any
,
condition
Condition
,
resultType
any
)
{
qType
:=
reflect
.
TypeOf
(
q
)
qValue
:=
reflect
.
ValueOf
(
q
)
var
tag
string
var
ok
bool
var
t
*
resolveSearchTag
var
t
*
Tagger
var
tname
string
if
qType
.
Kind
()
==
reflect
.
Ptr
{
...
...
@@ -121,7 +121,7 @@ func resolveSearchQuery(q any, condition Condition, resultType any) {
if
!
ok
{
tag
,
ok
=
field
.
Tag
.
Lookup
(
Tag2
)
if
!
ok
{
resolveSearchQuery
(
fieldValue
.
Interface
(),
condition
,
resultType
)
makeConditions
(
fieldValue
.
Interface
(),
condition
,
resultType
)
continue
}
}
...
...
@@ -151,12 +151,12 @@ func resolveSearchQuery(q any, condition Condition, resultType any) {
if
t
.
Column
==
""
{
if
kind
==
reflect
.
Array
||
kind
==
reflect
.
Slice
{
if
strings
.
HasSuffix
(
fieldName
,
"s"
)
{
t
.
Column
=
snakeCas
e
(
strings
.
TrimSuffix
(
fieldName
,
"s"
),
false
)
t
.
Column
=
CamelToSnak
e
(
strings
.
TrimSuffix
(
fieldName
,
"s"
),
false
)
}
else
{
t
.
Column
=
snakeCas
e
(
fieldName
,
false
)
t
.
Column
=
CamelToSnak
e
(
fieldName
,
false
)
}
}
else
{
t
.
Column
=
snakeCas
e
(
fieldName
,
false
)
t
.
Column
=
CamelToSnak
e
(
fieldName
,
false
)
}
}
...
...
@@ -168,7 +168,7 @@ func resolveSearchQuery(q any, condition Condition, resultType any) {
}
}
func
mysql
(
t
*
resolveSearchTag
,
condition
Condition
,
qValue
reflect
.
Value
,
i
int
,
resultType
any
)
{
func
mysql
(
t
*
Tagger
,
condition
Condition
,
qValue
reflect
.
Value
,
i
int
,
resultType
any
)
{
if
t
.
Type
==
""
{
condition
.
SetWhere
(
fmt
.
Sprintf
(
"`%s`.`%s` = ?"
,
t
.
Table
,
t
.
Column
),
[]
any
{
qValue
.
Field
(
i
)
.
Interface
()})
return
...
...
@@ -222,7 +222,7 @@ func mysql(t *resolveSearchTag, condition Condition, qValue reflect.Value, i int
}
}
type
resolveSearchTag
struct
{
type
Tagger
struct
{
Type
string
Column
string
Table
string
...
...
@@ -230,9 +230,8 @@ type resolveSearchTag struct {
Join
string
}
// parseTag 解析search的tag标签
func
parseTag
(
tag
string
)
*
resolveSearchTag
{
r
:=
&
resolveSearchTag
{}
func
parseTag
(
tag
string
)
*
Tagger
{
r
:=
&
Tagger
{}
tags
:=
strings
.
Split
(
tag
,
";"
)
var
ts
[]
string
for
_
,
t
:=
range
tags
{
...
...
@@ -289,7 +288,7 @@ const (
/**
* 驼峰转蛇形 snake string
**/
func
snakeCas
e
(
s
string
,
allMode
bool
)
string
{
func
CamelToSnak
e
(
s
string
,
allMode
bool
)
string
{
num
:=
len
(
s
)
data
:=
make
([]
byte
,
0
,
num
*
2
)
for
i
:=
0
;
i
<
num
;
i
++
{
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论