Documentation ¶
Index ¶
- Constants
- Variables
- type Any
- type Condition
- type Expression
- type F
- type FieldNode
- type FieldType
- type GetTableName
- type Group
- type Groups
- type Having
- type Join
- type M
- type Order
- type Orders
- type Query
- func (gou *Query) Build()
- func (gou *Query) Clone() *Query
- func (gou Query) First(data maps.Map) share.Record
- func (gou Query) Get(data maps.Map) []share.Record
- func (gou Query) GetBindings() []interface{}
- func (gou Query) GetPage(data maps.Map) int
- func (gou Query) GetPageSize(data maps.Map) int
- func (gou *Query) ID(exp Expression) string
- func (gou *Query) Load(data interface{}) (share.DSL, error)
- func (gou *Query) NameOf(exp Expression) string
- func (gou Query) Paginate(data maps.Map) share.Paginate
- func (gou Query) Run(data maps.Map) interface{}
- func (gou *Query) SetAESKey(key string) *Query
- func (gou Query) SetLimit(qb query.Query, data maps.Map)
- func (gou Query) SetOffset(qb query.Query, data maps.Map)
- func (gou *Query) TableName(getTableName GetTableName) *Query
- func (gou Query) ToSQL() string
- func (gou *Query) With(qb query.Query, getTableName ...GetTableName) *Query
- func (gou *Query) WrapNameOf(exp Expression) string
- type QueryDSL
- func (gou QueryDSL) MarshalJSON() ([]byte, error)
- func (gou QueryDSL) ToMap() map[string]interface{}
- func (gou QueryDSL) Validate() []error
- func (gou QueryDSL) ValidateFrom() []error
- func (gou QueryDSL) ValidateGroups() []error
- func (gou QueryDSL) ValidateHavings() []error
- func (gou QueryDSL) ValidateJoins() []error
- func (gou QueryDSL) ValidateOrders() []error
- func (gou QueryDSL) ValidateQuery() []error
- func (gou QueryDSL) ValidateSQL() []error
- func (gou QueryDSL) ValidateSelect() []error
- func (gou QueryDSL) ValidateUnions() []error
- func (gou QueryDSL) ValidateWheres() []error
- type SQL
- type Table
- type Where
Constants ¶
const Star = -1
Star 数组索引 *
Variables ¶
var OPs = map[string]func(cond Condition) error{
"=": condShouldHaveValue,
">": condShouldHaveValue,
">=": condShouldHaveValue,
"<": condShouldHaveValue,
"<=": condShouldHaveValue,
"<>": condShouldHaveValue,
"like": condShouldHaveValue,
"match": condShouldHaveValue,
"in": condShouldHaveValue,
"is": condShouldHaveNull,
}
OPs 可用的操作符
var RegAlias = regexp.MustCompile("[ ]+[Aa][Ss][ ]+")
RegAlias 别名正则表达式
var RegArrayIndex = regexp.MustCompile("\\[([0-9\\*]+)\\]")
RegArrayIndex 字段表达式数组下标
var RegCommaSpaces = regexp.MustCompile("[ ]*,[ ]*")
RegCommaSpaces 连续空格 + 逗号+连续空格 " , " | "," | ", " | " ,"
var RegField = regexp.MustCompile("^[A-Za-z0-9_\u4e00-\u9fa5]+$")
RegField 字段表达式字段为数据表字段
var RegFieldFun = regexp.MustCompile("^\\:([A-Za-z0-9_]+)\\((.*)\\)$")
RegFieldFun 字段表达式为函数
var RegFieldIsArray = regexp.MustCompile("^([A-Za-z0-9_\u4e00-\u9fa5]+)([@\\[]{1})")
RegFieldIsArray 字段表达式字段是否为数组
var RegFieldIsArrayObject = regexp.MustCompile("\\.[A-Za-z0-9_\u4e00-\u9fa5]+")
RegFieldIsArrayObject 字段表达式字段是否为数组
var RegFieldTable = regexp.MustCompile("^[$]*([A-Za-z0-9_\u4e00-\u9fa5]+)\\.")
RegFieldTable 字段表达式字段中的指定的数据表
var RegFieldType = regexp.MustCompile("\\([ ]*([a-zA-Z0-9, ]+)[ ]*\\)[ ]*$")
RegFieldType 字段表达式的类型声明
var RegIsNumber = regexp.MustCompile("^[0-9]{1}[\\.]*[0-9]*$")
RegIsNumber 字段表达式字段是否为数字
var RegSelectSTMT = regexp.MustCompile("^select(.+)from")
RegSelectSTMT SQL语句中的 Select 语句
var RegSpaces = regexp.MustCompile("[ ]+")
RegSpaces 连续空格
var RegTable = regexp.MustCompile("^[A-Za-z0-9_\u4e00-\u9fa5]+$")
RegTable Table 正则表达式
Functions ¶
This section is empty.
Types ¶
type Condition ¶
type Condition struct { Field *Expression `json:"field"` // 查询字段 Value interface{} `json:"value,omitempty"` // 匹配数值 ValueExpression *Expression `json:"-"` // 数值表达式 OP string `json:"op"` // 匹配关系运算符 OR bool `json:"or,omitempty"` // true 查询条件逻辑关系为 or, 默认为 false 查询条件逻辑关系为 and Query *QueryDSL `json:"query,omitempty"` // 子查询, 如设定 query 则忽略 value 数值。 Comment string `json:"comment,omitempty"` // 查询条件注释 }
Condition 查询条件
func ConditionOf ¶
ConditionOf 从 map[string]interface{}
func (Condition) MarshalJSON ¶
MarshalJSON for json marshalJSON
func (*Condition) UnmarshalJSON ¶
UnmarshalJSON for json marshalJSON
type Expression ¶
type Expression struct { Origin string // 原始数据 Table string // 数据表名称 Field string // 字段名称 Value interface{} // 常量数值 FunName string // 函数名称 FunArgs []Expression // 函数参数表 Alias string // 字段别名 Type *FieldType // 字段类型(用于自动转换和JSON Table) Index int // 数组字段索引 const Star -1 全部, 0 ~ n 数组 Key string // 对象字段键名 IsModel bool // 数据表是否为模型 $model.name IsFun bool // 是否为函数 :max(name) IsConst bool // 是否为常量 1,0.618, 'foo' IsNumber bool // 是否为数字常量 IsString bool // 是否为字符串常量 IsArray bool // 是否为数组 array@, array[0], array[*] IsObject bool // 是否为对象 object$.foo IsAES bool // 是否为加密字段 name* IsArrayObject bool // 是否为对象数组 array@.foo.bar IsBinding bool // 是否为绑定参数 ?:name }
Expression 字段表达式
func (*Expression) MarshalJSON ¶
func (exp *Expression) MarshalJSON() ([]byte, error)
MarshalJSON for json marshalJSON
func (*Expression) UnmarshalJSON ¶
func (exp *Expression) UnmarshalJSON(data []byte) error
UnmarshalJSON for json marshalJSON
type FieldType ¶
type FieldType struct { Name string `json:"name,omitempty"` // JSON数组字段类型(用于生成 JSON Table) Length int `json:"length,omitempty"` // 字段长度,对 string 等类型字段有效 Precision int `json:"precision,omitempty"` // 字段位数(含小数位),对 float、decimal 等类型字段有效 Scale int `json:"scale,omitempty"` // 字段小数位位数,对 float、decimal 等类型字段有效 }
FieldType 字段类型(用于自动转换和JSON Table)
type Group ¶
type Group struct { Field *Expression `json:"field"` // 排序字段 Rollup string `json:"rollup,omitempty"` // 同时返回多层级统计结果,对应聚合字段数值的名称。 Comment string `json:"comment,omitempty"` // 查询条件注释 }
Group 聚合条件
func (Group) MarshalJSON ¶
MarshalJSON for json marshalJSON
type Groups ¶
type Groups []Group
Groups 聚合条件集合
func (*Groups) PushString ¶
PushString 添加一个排序条件 string
func (*Groups) UnmarshalJSON ¶
UnmarshalJSON for json marshalJSON
type Having ¶
type Having struct { Condition Havings []Having `json:"havings,omitempty"` // 分组查询。用于 condition 1 and ( condition 2 OR condition 3) 的场景 }
Having 聚合结果筛选条件
func (Having) MarshalJSON ¶
MarshalJSON for json marshalJSON
func (*Having) UnmarshalJSON ¶
UnmarshalJSON for json marshalJSON
type Join ¶
type Join struct { From *Table `json:"from"` // 查询数据表名称或数据模型 Key *Expression `json:"key"` // 关联连接表字段名称 Foreign *Expression `json:"foreign"` // 关联目标表字段名称(需指定表名或别名) Left bool `json:"left,omitempty"` // true 连接方式为 LEFT JOIN, 默认为 false 连接方式为 JOIN Right bool `json:"right,omitempty"` // true 连接方式为 RIGHT JOIN, 默认为 false 连接方式为 JOIN Comment string `json:"comment,omitempty"` // 关联条件注释 }
Join 数据表连接
type Order ¶
type Order struct { Field *Expression `json:"field"` // 排序字段 Sort string `json:"sort,omitempty"` // 排序方式 Comment string `json:"comment,omitempty"` // 查询条件注释 }
Order 排序条件
func (Order) MarshalJSON ¶
MarshalJSON for json marshalJSON
type Orders ¶
type Orders []Order
Orders 排序条件集合
func (*Orders) PushString ¶
PushString 添加一个排序条件 string
func (*Orders) UnmarshalJSON ¶
UnmarshalJSON for json marshalJSON
type Query ¶
type Query struct { QueryDSL Query query.Query GetTableName GetTableName Bindings []interface{} Selects map[string]FieldNode AESKey string STMT string }
Query Query share.DSL
func (Query) GetPageSize ¶
GetPageSize get Page Size
func (*Query) TableName ¶
func (gou *Query) TableName(getTableName GetTableName) *Query
TableName 绑定数据模型数据表读取方式
type QueryDSL ¶
type QueryDSL struct { Select []Expression `json:"select"` // 查询字段列表 From *Table `json:"from,omitempty"` // 查询数据表名称或数据模型 Wheres []Where `json:"wheres,omitempty"` // 数据查询条件 Orders Orders `json:"orders,omitempty"` // 排序条件 Groups *Groups `json:"groups,omitempty"` // 聚合条件 Havings []Having `json:"havings,omitempty"` // 聚合查询结果筛选条件 First interface{} `json:"first,omitempty"` // 限定读取单条数据 Limit interface{} `json:"limit,omitempty"` // 限定读取记录的数量 Offset interface{} `json:"offset,omitempty"` // 记录开始位置 Page interface{} `json:"page,omitempty"` // 分页查询当前页面页码 PageSize interface{} `json:"pagesize,omitempty"` // 每页读取记录的数量 DataOnly interface{} `json:"data-only,omitempty"` // 设定为 true, 查询结果为 []Record; 设定为 false, 查询结果为 Paginate Unions []QueryDSL `json:"unions,omitempty"` // 联合查询 SubQuery *QueryDSL `json:"query,omitempty"` // 子查询 Alias string `json:"name,omitempty"` // 子查询别名 Joins []Join `json:"joins,omitempty"` // 表连接 SQL *SQL `json:"sql,omitempty"` // SQL语句 Comment string `json:"comment,omitempty"` // 查询条件注释 Debug bool `json:"debug,omitempty"` // 是否开启调试(开启后计入查询日志) }
QueryDSL Gou Query Domain Specific Language
func (QueryDSL) MarshalJSON ¶
MarshalJSON for json marshalJSON
func (QueryDSL) ValidateGroups ¶
ValidateGroups 校验 groups
func (QueryDSL) ValidateHavings ¶
ValidateHavings 校验 havings
func (QueryDSL) ValidateOrders ¶
ValidateOrders 校验 orders
func (QueryDSL) ValidateSelect ¶
ValidateSelect 校验 select
func (QueryDSL) ValidateUnions ¶
ValidateUnions 校验 unions
func (QueryDSL) ValidateWheres ¶
ValidateWheres 校验 wheres
type SQL ¶
type SQL struct { STMT string `json:"stmt,omitempty"` // SQL 语句 Args []interface{} `json:"args,omitempty"` // 绑定参数表 Comment string `json:"comment,omitempty"` // SQL语句注释 }
SQL 语句
type Table ¶
Table 数据表名称或数据模型
func (Table) MarshalJSON ¶
MarshalJSON for json marshalJSON
func (*Table) UnmarshalJSON ¶
UnmarshalJSON for json marshalJSON
type Where ¶
type Where struct { Condition Wheres []Where `json:"wheres,omitempty"` // 分组查询。用于 condition 1 and ( condition 2 OR condition 3) 的场景 }
Where 查询条件
func (Where) MarshalJSON ¶
MarshalJSON for json marshalJSON
func (*Where) UnmarshalJSON ¶
UnmarshalJSON for json marshalJSON