Documentation ¶
Index ¶
- Constants
- Variables
- func AnalyzeTPLFromCache(template SQLTemplate, tpl string, input map[string]interface{}, ph Placeholder) (sql string, values []any, err error)
- func DefaultGetPropName(fullKey string) (fullField, propName, oper string)
- func GetPatternRegexp(pattern string) *regexp.Regexp
- func IsNil(input interface{}) bool
- func Register(tpl SQLTemplate)
- func RegisterOperator(dbProto string, oper Operator) error
- func RegisterSymbol(dbProto string, symbol Symbol) error
- func TransArgs(args []sql.NamedArg) []interface{}
- type DBParam
- type FixedContext
- func (ctx *FixedContext) AnalyzeTPL(tpl string, input map[string]interface{}, ph Placeholder) (sql string, item *ReplaceItem, err error)
- func (ctx *FixedContext) GetSQLContext(tpl string, input map[string]interface{}) (query string, args []any, err error)
- func (ctx FixedContext) Name() string
- func (ctx *FixedContext) Placeholder() Placeholder
- func (ctx *FixedContext) RegisterOperator(oper Operator) error
- func (ctx *FixedContext) RegisterSymbol(symbol Symbol) error
- type Operator
- type OperatorCallback
- type OperatorMap
- type Placeholder
- type ReplaceItem
- type SQLTemplate
- type SeqContext
- func (ctx *SeqContext) AnalyzeTPL(tpl string, input map[string]interface{}, ph Placeholder) (sql string, item *ReplaceItem, err error)
- func (ctx *SeqContext) GetSQLContext(tpl string, input map[string]interface{}) (sql string, args []any, err error)
- func (ctx SeqContext) Name() string
- func (ctx *SeqContext) Placeholder() Placeholder
- func (ctx *SeqContext) RegisterOperator(oper Operator) error
- func (ctx *SeqContext) RegisterSymbol(symbol Symbol) error
- type Symbol
- type SymbolCallback
- type SymbolMap
Constants ¶
View Source
const ( TotalPattern = `` /* 160-byte string literal not displayed */ // ParamPattern = `[@]\{\w*[\.]?\w+\}` // AndPattern = `[&]\{\w*[\.]?\w+\}` // OrPattern = `[\|]\{\w*[\.]?\w+\}` ReplacePattern = `\$\{\w*[\.]?\w+\}` SymbolAt = "@" SymbolAnd = "&" SymbolOr = "|" )
Variables ¶
View Source
var GetPropName func(fullKey string) (field, propName, oper string)
根据表达式获取
Functions ¶
func AnalyzeTPLFromCache ¶
func AnalyzeTPLFromCache(template SQLTemplate, tpl string, input map[string]interface{}, ph Placeholder) (sql string, values []any, err error)
AnalyzeTPLFromCache 从缓存中获取已解析的SQL语句 @表达式,替换为参数化字符如: :1,:2,:3 $表达式,检查值,值为空时返加"",否则直接替换字符 &条件表达式,检查值,值为空时返加"",否则返回: and name=value |条件表达式,检查值,值为空时返回"", 否则返回: or name=value
func DefaultGetPropName ¶ added in v0.5.1
field, tbl.field , tbl.field like , tbl.field >=
func GetPatternRegexp ¶ added in v0.5.0
获取模式匹配的正则表达式
func Register ¶
func Register(tpl SQLTemplate)
func RegisterOperator ¶ added in v0.5.1
RegisterSymbol 给数据库注册语法解析
func RegisterSymbol ¶ added in v0.5.0
RegisterSymbol 给数据库注册语法解析
Types ¶
type DBParam ¶ added in v0.1.30
type DBParam map[string]interface{}
type FixedContext ¶
type FixedContext struct {
// contains filtered or unexported fields
}
FixedContext 模板
func (*FixedContext) AnalyzeTPL ¶
func (ctx *FixedContext) AnalyzeTPL(tpl string, input map[string]interface{}, ph Placeholder) (sql string, item *ReplaceItem, err error)
func (*FixedContext) GetSQLContext ¶
func (ctx *FixedContext) GetSQLContext(tpl string, input map[string]interface{}) (query string, args []any, err error)
GetSQLContext 获取查询串
func (FixedContext) Name ¶
func (ctx FixedContext) Name() string
func (*FixedContext) Placeholder ¶
func (ctx *FixedContext) Placeholder() Placeholder
func (*FixedContext) RegisterOperator ¶ added in v0.5.1
func (ctx *FixedContext) RegisterOperator(oper Operator) error
func (*FixedContext) RegisterSymbol ¶ added in v0.5.0
func (ctx *FixedContext) RegisterSymbol(symbol Symbol) error
type OperatorMap ¶ added in v0.5.1
type OperatorMap interface { LoadOrStore(name string, callback OperatorCallback) (loaded bool) Load(name string) (OperatorCallback, bool) Clone() OperatorMap }
var DefaultOperator OperatorMap
func NewOperatorMap ¶ added in v0.5.1
func NewOperatorMap() OperatorMap
type Placeholder ¶
type ReplaceItem ¶
type ReplaceItem struct { Names []string Values []interface{} NameCache map[string]string Placeholder Placeholder HasAndOper bool HasOrOper bool }
func DefaultAnalyze ¶
func DefaultAnalyze(symbols SymbolMap, tpl string, input map[string]interface{}, placeholder Placeholder) (string, *ReplaceItem, error)
func (*ReplaceItem) CanCache ¶ added in v0.1.41
func (p *ReplaceItem) CanCache() bool
func (*ReplaceItem) Clone ¶ added in v0.1.41
func (p *ReplaceItem) Clone() *ReplaceItem
type SQLTemplate ¶
type SQLTemplate interface { Name() string Placeholder() Placeholder GetSQLContext(tpl string, input map[string]interface{}) (query string, args []any, err error) AnalyzeTPL(tpl string, input map[string]interface{}, ph Placeholder) (sql string, item *ReplaceItem, err error) RegisterSymbol(symbol Symbol) error RegisterOperator(Operator) error }
Template 模板上下文
func NewFixed ¶
func NewFixed(name, prefix string) SQLTemplate
func NewSeq ¶
func NewSeq(name, prefix string) SQLTemplate
type SeqContext ¶
type SeqContext struct {
// contains filtered or unexported fields
}
SeqContext 参数化时使用@+参数名作为占位符的SQL数据库如:oracle,sql server
func (*SeqContext) AnalyzeTPL ¶
func (ctx *SeqContext) AnalyzeTPL(tpl string, input map[string]interface{}, ph Placeholder) (sql string, item *ReplaceItem, err error)
func (*SeqContext) GetSQLContext ¶
func (ctx *SeqContext) GetSQLContext(tpl string, input map[string]interface{}) (sql string, args []any, err error)
GetSQLContext 获取查询串
func (SeqContext) Name ¶
func (ctx SeqContext) Name() string
func (*SeqContext) Placeholder ¶
func (ctx *SeqContext) Placeholder() Placeholder
func (*SeqContext) RegisterOperator ¶ added in v0.5.1
func (ctx *SeqContext) RegisterOperator(oper Operator) error
func (*SeqContext) RegisterSymbol ¶ added in v0.5.0
func (ctx *SeqContext) RegisterSymbol(symbol Symbol) error
type SymbolCallback ¶
符号回调函数
type SymbolMap ¶ added in v0.5.0
type SymbolMap interface { GetPattern() string //Store(name string, callback SymbolCallback) Register(Symbol) error Operator(Operator) error LoadOperator(oper string) (OperatorCallback, bool) LoadOrStore(name string, callback SymbolCallback) (loaded bool) Delete(name string) Load(name string) (SymbolCallback, bool) Clone() SymbolMap }
func NewSymbolMap ¶ added in v0.5.0
func NewSymbolMap(operMap OperatorMap) SymbolMap
Click to show internal directories.
Click to hide internal directories.