feat: 支持JSONB字段查询
All checks were successful
ci/woodpecker/push/my-first-workflow Pipeline was successful
All checks were successful
ci/woodpecker/push/my-first-workflow Pipeline was successful
This commit is contained in:
@@ -38,6 +38,7 @@ type Service struct {
|
||||
// List/Add接口条件配置
|
||||
type QueryOp struct {
|
||||
FieldEQ []string // 字段等于 多个字段选择以及高级搜索都是这个
|
||||
DataFieldEQ []string // 新增:JSONB data->>'xxx' 字段 = ? 多个字段选择以及高级搜索都是这个
|
||||
KeyWordField []string // 模糊搜索匹配的数据库字段,对应普通搜索
|
||||
AddOrderby g.MapStrStr // 添加排序
|
||||
Where func(ctx context.Context) []g.Array // 自定义条件
|
||||
@@ -233,6 +234,16 @@ func (s *Service) ServiceList(ctx context.Context, req *ListReq) (data interface
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 2. JSONB data->>'xxx' 字段查询(你要的 data 类查找)
|
||||
if len(s.ListQueryOp.DataFieldEQ) > 0 {
|
||||
for _, field := range s.ListQueryOp.DataFieldEQ {
|
||||
if val := r.Get(field); val.String() != "" {
|
||||
// 关键:拼接 data->>'字段名' = ?
|
||||
m.Where("data->>? = ?", field, val)
|
||||
}
|
||||
}
|
||||
}
|
||||
// 如果KeyWordField不为空 则添加查询条件
|
||||
if !r.Get("keyWord").IsEmpty() {
|
||||
if len(s.ListQueryOp.KeyWordField) > 0 {
|
||||
@@ -339,6 +350,16 @@ func (s *Service) ServicePage(ctx context.Context, req *PageReq) (data interface
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 2. JSONB data->>'xxx' 字段查询(你要的 data 类查找)
|
||||
if len(s.ListQueryOp.DataFieldEQ) > 0 {
|
||||
for _, field := range s.ListQueryOp.DataFieldEQ {
|
||||
if val := r.Get(field); val.String() != "" {
|
||||
// 关键:拼接 data->>'字段名' = ?
|
||||
m.Where("data->>? = ?", field, val)
|
||||
}
|
||||
}
|
||||
}
|
||||
// 如果KeyWordField不为空 则添加查询条件
|
||||
if !r.Get("keyWord").IsEmpty() {
|
||||
if len(s.PageQueryOp.KeyWordField) > 0 {
|
||||
|
||||
Reference in New Issue
Block a user