query

package module
v0.0.0-...-97e1fcd Latest Latest
Warning

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

Go to latest
Published: Mar 17, 2023 License: GPL-2.0 Imports: 13 Imported by: 0

Documentation

Overview

* @Author: Wangjun * @Date: 2021-06-08 11:35:05 * @LastEditTime: 2022-10-28 14:52:56 * @LastEditors: Wangjun * @Description:查询schema * @FilePath: \xrengined:\go\src\gitee.com\haodreams\query\schema.go * hnxr

* @Author: Wangjun * @Date: 2021-05-27 14:34:55 * @LastEditTime: 2022-09-14 18:37:48 * @LastEditors: Wangjun * @Description: * @FilePath: \xrengined:\go\src\gitee.com\haodreams\query\table.go * hnxr

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func FieldByIndex

func FieldByIndex(v reflect.Value, index []int) (rv reflect.Value, err error)

*

  • @description: 查找给定值的值
  • @param {reflect.Value} v
  • @param {[]int} index
  • @return {*}

func GetSchema

func GetSchema(name ...string) string

获取指定的schema

func GetTableNames

func GetTableNames() []string

GetTableNames 获取表名列表

func RegisterTable

func RegisterTable(tableName string, table *Table) (err error)

*

  • @description:
  • @param {string} tableName
  • @param {*Query} table
  • @return {*}

Types

type Func

type Func struct {
	Name   string   `parser:"'.' @Ident"`
	Params []*Param `parser:"'(' ( @@ ( ',' @@ )* )? ')'"`
	// contains filtered or unexported fields
}

FORM("es").LT("Genpower.Value",0).GT("Genpower.Value",-5000).Sum("Genpower.Value")

func (*Func) Key

func (m *Func) Key() string

func (*Func) String

func (m *Func) String() string

type Param

type Param struct {
	Number *float64 `parser:"@('-'?(Float|Int))"`
	String *string  `parser:"| @String"`
}

func (*Param) Float64

func (m *Param) Float64() float64

func (*Param) GetValue

func (m *Param) GetValue() interface{}

func (*Param) Key

func (m *Param) Key() string

type QueryFunc

type QueryFunc func(*Table, []*Param) (*Table, error)

最后一个缺省是and运算

type Schema

type Schema struct {
	Table string  `parser:"'FROM' '(' @String ')'"`
	Funcs []*Func `parser:"@@+"`
	Err   string  //错误消息

	Result      string //暂存数据的地方
	Desc        string //存放描述的地方
	Query       string
	SourceQuery string //优化后的查询
	LastRunTime int64  //最后一次运行时间
	UsedTime    string //耗时
	Value       string //运行结果
	OK          bool
	// contains filtered or unexported fields
}

func NewFastSchema

func NewFastSchema(s string) (schema *Schema, err error)

*

  • @description: 开启优化查询,后面需要手动调用 Parser
  • @param {string} s
  • @return {*}

func NewSchema

func NewSchema(s string) (se *Schema, err error)

*

  • @description: 不开启优化
  • @param {string} s
  • @return {*}

func (*Schema) Eval

func (m *Schema) Eval() (value interface{}, err error)

Eval 执行计算

func (*Schema) FastTable

func (m *Schema) FastTable() (table *Table, err error)

*

  • @description:获取快速表
  • @param {*}
  • @return {*}

func (*Schema) GetColumns

func (m *Schema) GetColumns() []string

GetColumns 获取列名

func (*Schema) Parser

func (m *Schema) Parser(s string) (err error)

初始化数据

type Table

type Table struct {
	// contains filtered or unexported fields
}

func Add

func Add(q *Table, params []*Param) (*Table, error)

加法

func Avg

func Avg(q *Table, params []*Param) (*Table, error)

func ColAdd

func ColAdd(q *Table, params []*Param) (*Table, error)

ColAdd 列加法

func ColAvg

func ColAvg(q *Table, params []*Param) (*Table, error)

ColSum 列求平均

func ColEqCount

func ColEqCount(q *Table, params []*Param) (*Table, error)

ColEqCount 等于判断

func ColGtCount

func ColGtCount(q *Table, params []*Param) (*Table, error)

ColGtCount 统计列符合条件的个数

func ColLtCount

func ColLtCount(q *Table, params []*Param) (*Table, error)

ColLtCount 小于判断

func ColMult

func ColMult(q *Table, params []*Param) (*Table, error)

ColAdd 列乘法

func ColSub

func ColSub(q *Table, params []*Param) (*Table, error)

ColAdd 列减法

func ColSum

func ColSum(q *Table, params []*Param) (*Table, error)

ColSum 变量相加

func Count

func Count(q *Table, params []*Param) (*Table, error)

func Divi

func Divi(q *Table, params []*Param) (*Table, error)

除法

func EQ

func EQ(q *Table, params []*Param) (*Table, error)

func GE

func GE(q *Table, params []*Param) (*Table, error)

func GT

func GT(q *Table, params []*Param) (*Table, error)

===================过滤函数===================

func GetTable

func GetTable(tableName string) *Table

*

  • @description:
  • @param {string} tableName
  • @return {*}

func IN

func IN(q *Table, params []*Param) (*Table, error)

func IfEQ

func IfEQ(q *Table, params []*Param) (*Table, error)

IfGT if 等于判断 this>x?a:b

func IfGT

func IfGT(q *Table, params []*Param) (*Table, error)

IfGT if 大于判断 this>x?a:b

func IfLT

func IfLT(q *Table, params []*Param) (*Table, error)

IfGT if 小于判断 this>x?a:b

func LE

func LE(q *Table, params []*Param) (*Table, error)

func LT

func LT(q *Table, params []*Param) (*Table, error)

func Like

func Like(q *Table, params []*Param) (*Table, error)

func Match

func Match(q *Table, params []*Param) (*Table, error)

func Max

func Max(q *Table, params []*Param) (*Table, error)

===================统计函数=================== 最大值

func Min

func Min(q *Table, params []*Param) (*Table, error)

func Mult

func Mult(q *Table, params []*Param) (*Table, error)

乘法

func NE

func NE(q *Table, params []*Param) (*Table, error)

func NewFastTable

func NewFastTable(s string) (table *Table, err error)

*

  • @description: 获取快速表(大表转小标)
  • @param {string} s
  • @return {*}

func NewTable

func NewTable(objects interface{}) (q *Table, err error)

新建一个查询

func OrEQ

func OrEQ(q *Table, params []*Param) (*Table, error)

func OrGE

func OrGE(q *Table, params []*Param) (*Table, error)

func OrGT

func OrGT(q *Table, params []*Param) (*Table, error)

func OrIN

func OrIN(q *Table, params []*Param) (*Table, error)

func OrLE

func OrLE(q *Table, params []*Param) (*Table, error)

func OrLT

func OrLT(q *Table, params []*Param) (*Table, error)

func OrLike

func OrLike(q *Table, params []*Param) (*Table, error)

func OrMatch

func OrMatch(q *Table, params []*Param) (*Table, error)

func OrNE

func OrNE(q *Table, params []*Param) (*Table, error)

func Sub

func Sub(q *Table, params []*Param) (*Table, error)

减法

func Sum

func Sum(q *Table, params []*Param) (*Table, error)

func (*Table) Avg

func (m *Table) Avg(key string) (val interface{}, err error)

*

  • @description: 平均值
  • @param {string} key
  • @return {*}

func (*Table) Column

func (m *Table) Column(key string) (val float64, err error)

*

  • @description:获取某列的值
  • @param {string} key
  • @return {*}

func (*Table) Count

func (m *Table) Count(key string) (val int, err error)

*

  • @description: 统计数量
  • @param {string} key
  • @return {*}

func (*Table) EQ

func (m *Table) EQ(key string, value interface{}, isAnd bool) (*Table, error)

*

  • @description: ?=value
  • @param {string} key
  • @param {interface{}} value [string,int64,float64]
  • @return {*}

func (*Table) GE

func (m *Table) GE(key string, value interface{}, isAnd bool) (*Table, error)

*

  • @description: ?>=value
  • @param {string} key
  • @param {float64} value
  • @return {*}

func (*Table) GT

func (m *Table) GT(key string, value interface{}, isAnd bool) (*Table, error)

*

  • @description: ?>value
  • @param {string} key
  • @param {float64} value
  • @return {*}

func (*Table) IN

func (m *Table) IN(key string, value interface{}, isAnd bool) (*Table, error)

*

  • @description: ?=value
  • @param {string} key
  • @param {interface{}} value [string,int64,float64]
  • @return {*}

func (*Table) In

func (m *Table) In(
	isAnd bool,
	key string,
	value interface{},
	intFunc func(a int64, b []float64) bool,
	floatFunc func(a float64, b []float64) bool,
	stringFunc func(a string, b []string) bool,
) (arr *Table, err error)

*

  • @description: 过虑满足条件的数据
  • @param {*Query} m
  • @return {*}

func (*Table) Keys

func (m *Table) Keys() (keys []string)

*

  • @description: 获取字段名
  • @param {*}
  • @return {*}

func (*Table) LE

func (m *Table) LE(key string, value interface{}, isAnd bool) (*Table, error)

*

  • @description: ?<=value
  • @param {string} key
  • @param {float64} value
  • @return {*}

func (*Table) LT

func (m *Table) LT(key string, value interface{}, isAnd bool) (*Table, error)

*

  • @description: ?<value
  • @param {string} key
  • @param {float64} value
  • @return {*}

func (*Table) Like

func (m *Table) Like(key string, value interface{}, isAnd bool) (*Table, error)

func (*Table) Match

func (m *Table) Match(key string, value interface{}, isAnd bool) (*Table, error)

正则匹配

func (*Table) Max

func (m *Table) Max(key string) (val interface{}, err error)

*

  • @description: 最大值
  • @param {string} key
  • @return {*}

func (*Table) Min

func (m *Table) Min(key string) (val interface{}, err error)

*

  • @description: 最小值
  • @param {string} key
  • @return {*}

func (*Table) NE

func (m *Table) NE(key string, value interface{}, isAnd bool) (*Table, error)

*

  • @description: ? !=value
  • @param {string} key
  • @param {float64} value
  • @return {*}

func (*Table) ParentRows

func (m *Table) ParentRows() interface{}

*

  • @description: 获取父记录集
  • @param {*}
  • @return {*}

func (*Table) Result

func (m *Table) Result() interface{}

Result 计算的结果

func (*Table) Rows

func (m *Table) Rows() interface{}

*

  • @description: 获取记录集
  • @param {*}
  • @return {*}

func (*Table) Sum

func (m *Table) Sum(key string) (val interface{}, err error)

*

  • @description: 求和
  • @param {string} key
  • @return {*}

Jump to

Keyboard shortcuts

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