Documentation
¶
Index ¶
- Constants
- func BuildJsonContainsClause(driver, column string, value interface{}) (string, []interface{})
- func BuildJsonContainsOrNullClause(driver, column string, value interface{}) (string, []interface{})
- func ResolveSearchQuery(driver string, q interface{}, condition Condition)
- type Condition
- type GormCondition
- type GormJoin
- type GormPublic
Constants ¶
View Source
const ( // FromQueryTag tag标记 FromQueryTag = "search" // Mysql 数据库标识 Mysql = "mysql" // Postgres 数据库标识 Postgres = "postgres" )
Variables ¶
This section is empty.
Functions ¶
func BuildJsonContainsClause ¶ added in v1.7.0
BuildJsonContainsClause 构造"JSON 数组精确包含值"的 WHERE 子句和参数。 用于 Service 层函数式调用(非 DTO + search tag 路径)需要单 Service 手写白名单时复用。
driver: "mysql" / "postgres" / 其他(默认走 MySQL 语法) column: 完整列引用,如 "agent_codes" 或 "t.agent_codes" value: JSON 数组中要查找的标量值(通常是 string)
返回 (sqlClause, args) 可直接传 *gorm.DB.Where(sqlClause, args...)。
func BuildJsonContainsOrNullClause ¶ added in v1.7.0
func BuildJsonContainsOrNullClause(driver, column string, value interface{}) (string, []interface{})
BuildJsonContainsOrNullClause 构造"JSON 数组三态白名单语义"的 WHERE 子句和参数:
- 列为 NULL → 全部命中(视为不限制)
- 列为空数组 → 全部命中
- 列为非空数组 → 仅匹配值才命中
适合"白名单字段:未配置 = 全部允许;配置后 = 仅指定项允许"的最小权限模型。
driver: "mysql" / "postgres" / 其他(默认走 MySQL 语法) column: 完整列引用,如 "agent_codes" 或 "t.agent_codes" value: JSON 数组中要查找的标量值(通常是 string)
func ResolveSearchQuery ¶
ResolveSearchQuery 解析 *
- exact / iexact 等于
- contains / icontains 包含
- gt / gte 大于 / 大于等于
- lt / lte 小于 / 小于等于
- startswith / istartswith 以…起始
- endswith / iendswith 以…结束
- in
- isnull
- json_contains JSON 数组精确包含值(MySQL JSON_CONTAINS / Postgres @>)
- json_contains_or_null JSON 数组三态语义:NULL / 空数组 → 全部命中;非空 → 按值匹配(白名单语义)
- order 排序 e.g. order[key]=desc order[key]=asc
Types ¶
type GormCondition ¶
type GormCondition struct {
GormPublic
Join []*GormJoin
}
func (*GormCondition) SetJoinOn ¶
func (e *GormCondition) SetJoinOn(t, on string) Condition
type GormJoin ¶
type GormJoin struct {
Type string
JoinOn string
GormPublic
}
type GormPublic ¶
type GormPublic struct {
Where map[string][]interface{}
Order []string
Or map[string][]interface{}
}
func (*GormPublic) SetOr ¶
func (e *GormPublic) SetOr(k string, v []interface{})
func (*GormPublic) SetOrder ¶
func (e *GormPublic) SetOrder(k string)
func (*GormPublic) SetWhere ¶
func (e *GormPublic) SetWhere(k string, v []interface{})
Click to show internal directories.
Click to hide internal directories.