query

package
v0.1.5 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 20, 2025 License: Apache-2.0 Imports: 5 Imported by: 0

Documentation

Index

Constants

View Source
const (
	QP_LT  = "lt"  // 小于
	QP_GT  = "gt"  // 大于
	QP_LTE = "lte" // 小于等于
	QP_GTE = "gte" // 大于等于
	QP_EQ  = "eq"  // 等于
	QP_NEQ = "neq" // 不等于
	QP_LK  = "lk"  // LIKE
)

比较操作符常量(兼容 go-core)

View Source
const (
	QP_PD = "pd" // 降序(descending)
	QP_PA = "pa" // 升序(ascending)
)

排序操作符常量(兼容 go-core)

View Source
const (
	QP_ORLK = "orlk" // OR LIKE
	QP_ORLT = "orlt" // OR LT
	QP_ORGT = "orgt" // OR GT
)

或条件操作符常量(兼容 go-core)

Variables

This section is empty.

Functions

This section is empty.

Types

type BaseInfoFilter

type BaseInfoFilter struct {
	DBField    string        // 数据库字段名
	Values     []interface{} // 过滤值列表
	ExactMatch bool          // 是否精确匹配(默认 false 表示 LIKE)
	AllRegex   bool          // 是否全部匹配正则(所有值都包含)
}

BaseInfoFilter 基础过滤信息 - 借鉴 go-core 设计

func NewBaseInfoFilter

func NewBaseInfoFilter(field string, values []interface{}) *BaseInfoFilter

NewBaseInfoFilter 创建基础过滤信息

type Filter

type Filter struct {
	Field    string      // 字段名
	Operator Operator    // 操作符
	Value    interface{} // 值(可能是单个值或数组)
	Logic    string      // AND / OR
}

Filter 单个过滤条件

func NewFilter

func NewFilter(field string, operator Operator, value interface{}) *Filter

NewFilter 创建过滤条件

type FilterGroup

type FilterGroup struct {
	Filters []*Filter
	Groups  []*FilterGroup
	Logic   string // AND / OR
}

FilterGroup 过滤组(支持嵌套)

type FindOption

type FindOption struct {
	BusinessId    string        // 业务 ID
	ShopId        string        // 店铺 ID
	TablePrefix   string        // 表名前缀
	ExcludeField  bool          // 是否排除字段
	ExcludeFields []string      // 排除字段列表
	IncludeFields []string      // 包含字段列表
	NoCache       bool          // 是否不使用缓存
	CacheTTL      time.Duration // 缓存过期时间
}

FindOption 查询选项 - 借鉴 go-core 设计

func NewFindOption

func NewFindOption() *FindOption

NewFindOption 创建查询选项

func (*FindOption) WithBusinessId

func (fo *FindOption) WithBusinessId(id string) *FindOption

WithBusinessId 设置业务 ID

func (*FindOption) WithCacheTTL

func (fo *FindOption) WithCacheTTL(ttl time.Duration) *FindOption

WithCacheTTL 设置缓存 TTL

func (*FindOption) WithExcludeFields

func (fo *FindOption) WithExcludeFields(fields ...string) *FindOption

WithExcludeFields 设置排除字段

func (*FindOption) WithIncludeFields

func (fo *FindOption) WithIncludeFields(fields ...string) *FindOption

WithIncludeFields 设置包含字段

func (*FindOption) WithNoCache

func (fo *FindOption) WithNoCache() *FindOption

WithNoCache 禁用缓存

func (*FindOption) WithShopId

func (fo *FindOption) WithShopId(id string) *FindOption

WithShopId 设置店铺 ID

func (*FindOption) WithTablePrefix

func (fo *FindOption) WithTablePrefix(prefix string) *FindOption

WithTablePrefix 设置表名前缀

type Operator

type Operator string

Operator 查询操作符

const (
	OP_EQ          Operator = "="           // 等于
	OP_NEQ         Operator = "!="          // 不等于
	OP_GT          Operator = ">"           // 大于
	OP_GTE         Operator = ">="          // 大于等于
	OP_LT          Operator = "<"           // 小于
	OP_LTE         Operator = "<="          // 小于等于
	OP_LIKE        Operator = "LIKE"        // 模糊匹配
	OP_IN          Operator = "IN"          // 包含
	OP_BETWEEN     Operator = "BETWEEN"     // 范围
	OP_IS_NULL     Operator = "IS NULL"     // 为空
	OP_FIND_IN_SET Operator = "FIND_IN_SET" // MySQL FIND_IN_SET
)

type OrderBy

type OrderBy struct {
	Field string // 字段名
	Order string // ASC / DESC
}

OrderBy 排序条件

func NewOrderBy

func NewOrderBy(field string, order string) *OrderBy

NewOrderBy 创建排序条件

type PageBean

type PageBean struct {
	Page     int         `json:"page"`      // 当前页码
	PageSize int         `json:"page_size"` // 每页数量
	Total    int64       `json:"total"`     // 总数
	Pages    int         `json:"pages"`     // 总页数
	Rows     interface{} `json:"rows"`      // 数据行
}

PageBean 分页响应 - 借鉴 go-core 设计

func NewPageBean

func NewPageBean(page int, pageSize int, total int64, rows interface{}) *PageBean

NewPageBean 创建分页响应

type Param

type Param struct {
	Filters       []*Filter                 // 过滤条件
	FilterGroups  []*FilterGroup            // 过滤组(支持 AND/OR 混合)
	TimeRanges    map[string][2]interface{} // 时间范围 field -> [startTime, endTime]
	FindInSets    map[string][]string       // FIND_IN_SET 条件
	Orders        []*OrderBy                // 排序条件
	Page          int                       // 页码(从 1 开始)
	PageSize      int                       // 每页数量
	Offset        int                       // 偏移量(与 Page 互斥)
	Limit         int                       // 限制数量
	Distinct      bool                      // 是否去重
	SelectFields  []string                  // 指定查询字段
	HavingClauses []string                  // HAVING 子句
}

Param 高级查询参数 - 支持复杂过滤、排序、分页

func NewParam

func NewParam() *Param

NewParam 创建高级查询参数

func (*Param) AddEQ

func (p *Param) AddEQ(field string, value interface{}) *Param

AddEQ 添加等于过滤

func (*Param) AddEndsWith

func (p *Param) AddEndsWith(field string, value string) *Param

AddEndsWith 添加后缀匹配 LIKE 过滤

func (*Param) AddFilter

func (p *Param) AddFilter(field string, operator Operator, value interface{}) *Param

AddFilter 添加单个过滤条件

func (*Param) AddFindInSet

func (p *Param) AddFindInSet(field string, values ...string) *Param

AddFindInSet 添加 FIND_IN_SET 过滤(MySQL 特定)

func (*Param) AddGT

func (p *Param) AddGT(field string, value interface{}) *Param

AddGT 添加大于过滤

func (*Param) AddGTE

func (p *Param) AddGTE(field string, value interface{}) *Param

AddGTE 添加大于等于过滤

func (*Param) AddHaving

func (p *Param) AddHaving(clause string) *Param

AddHaving 添加 HAVING 子句

func (*Param) AddIn

func (p *Param) AddIn(field string, values ...interface{}) *Param

AddIn 添加 IN 过滤

func (*Param) AddLT

func (p *Param) AddLT(field string, value interface{}) *Param

AddLT 添加小于过滤

func (*Param) AddLTE

func (p *Param) AddLTE(field string, value interface{}) *Param

AddLTE 添加小于等于过滤

func (*Param) AddLike

func (p *Param) AddLike(field string, value string) *Param

AddLike 添加全模糊 LIKE 过滤

func (*Param) AddNEQ

func (p *Param) AddNEQ(field string, value interface{}) *Param

AddNEQ 添加不等于过滤

func (*Param) AddOrEQ

func (p *Param) AddOrEQ(field string, value interface{}) *Param

AddOrEQ 添加 OR 等于过滤

func (*Param) AddOrFilter

func (p *Param) AddOrFilter(field string, operator Operator, value interface{}) *Param

AddOrFilter 添加 OR 过滤条件

func (*Param) AddOrGT

func (p *Param) AddOrGT(field string, value interface{}) *Param

AddOrGT 添加 OR 大于过滤

func (*Param) AddOrGTE

func (p *Param) AddOrGTE(field string, value interface{}) *Param

AddOrGTE 添加 OR 大于等于过滤

func (*Param) AddOrIn

func (p *Param) AddOrIn(field string, values ...interface{}) *Param

AddOrIn 添加 OR IN 过滤

func (*Param) AddOrLT

func (p *Param) AddOrLT(field string, value interface{}) *Param

AddOrLT 添加 OR 小于过滤

func (*Param) AddOrLTE

func (p *Param) AddOrLTE(field string, value interface{}) *Param

AddOrLTE 添加 OR 小于等于过滤

func (*Param) AddOrLike

func (p *Param) AddOrLike(field string, value string) *Param

AddOrLike 添加 OR 全模糊 LIKE 过滤

func (*Param) AddOrNEQ

func (p *Param) AddOrNEQ(field string, value interface{}) *Param

AddOrNEQ 添加 OR 不等于过滤

func (*Param) AddOrder

func (p *Param) AddOrder(field string, order string) *Param

AddOrder 添加排序

func (*Param) AddOrderAsc

func (p *Param) AddOrderAsc(field string) *Param

AddOrderAsc 添加升序排序

func (*Param) AddOrderDesc

func (p *Param) AddOrderDesc(field string) *Param

AddOrderDesc 添加降序排序

func (*Param) AddStartsWith

func (p *Param) AddStartsWith(field string, value string) *Param

AddStartsWith 添加前缀匹配 LIKE 过滤

func (*Param) AddTimeRange

func (p *Param) AddTimeRange(field string, startTime, endTime interface{}) *Param

AddTimeRange 添加时间范围过滤

func (*Param) BuildWhereClause

func (p *Param) BuildWhereClause() (string, []interface{})

BuildWhereClause 构建 WHERE 子句 - 返回 WHERE SQL 片段和参数

func (*Param) SetDistinct

func (p *Param) SetDistinct(distinct bool) *Param

SetDistinct 设置去重

func (*Param) SetPage

func (p *Param) SetPage(page int, pageSize int) *Param

SetPage 设置分页

func (*Param) SetSelectFields

func (p *Param) SetSelectFields(fields ...string) *Param

SetSelectFields 设置查询字段

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL